carte cachotier
This commit is contained in:
parent
7b4aeffe68
commit
9c756cdfb3
1 changed files with 98 additions and 2 deletions
98
server.js
98
server.js
|
|
@ -653,10 +653,16 @@ function buildDefaultDeck() {
|
|||
"empathie"
|
||||
],
|
||||
|
||||
[
|
||||
"Cachotier",
|
||||
"La prochaine carte jouée ne sera pas révélée à l'adversaire.",
|
||||
"cachotier"
|
||||
],
|
||||
|
||||
// facile et intéresssant
|
||||
// ["intrication quantique","Deux pièces sont intriquées. Quand l'une bouge, l'autre bouge de la même manière."],
|
||||
// ['kurby','Choisis une pièce. À sa prochaine capture, récupère tous les mouvements de la pièce capturée.'],
|
||||
// ["cachotier", "La prochaine carte jouée ne sera pas révélée à l'adversaire."],
|
||||
|
||||
// ['défausse','Le joueur adverse défausse une carte de son choix'],
|
||||
// ['glue','Toutes les pièces autour de la pièce désignée ne peuvent pas bouger tant que cette dernière ne bouge pas'],
|
||||
// ['immunité à la capture','Désigne une pièce qui ne pourra pas être capturée au prochain tour'],
|
||||
|
|
@ -5076,6 +5082,37 @@ io.on("connection", (socket) => {
|
|||
console.error("rebondir effect error", e);
|
||||
}
|
||||
}
|
||||
|
||||
// cachotier
|
||||
else if (cardId === "cachotier") {
|
||||
try {
|
||||
room.activeCardEffects = room.activeCardEffects || [];
|
||||
const effect = {
|
||||
id: played.id,
|
||||
type: "cachotier",
|
||||
playerId: senderId,
|
||||
// This effect lasts until the player plays their next card
|
||||
usesRemaining: 1,
|
||||
ts: Date.now(),
|
||||
};
|
||||
room.activeCardEffects.push(effect);
|
||||
try {
|
||||
// Only notify the player who played the card, not the opponent
|
||||
const owner = (room.players || []).find((p) => p.id === senderId);
|
||||
if (owner && owner.socketId)
|
||||
io.to(owner.socketId).emit("card:effect:applied", {
|
||||
roomId: room.id,
|
||||
effect,
|
||||
});
|
||||
} catch (_) {}
|
||||
played.payload = Object.assign({}, payload, {
|
||||
applied: "cachotier",
|
||||
appliedToPlayer: senderId,
|
||||
});
|
||||
} catch (e) {
|
||||
console.error("cachotier effect error", e);
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
console.error("card:play effect error", e);
|
||||
}
|
||||
|
|
@ -5090,7 +5127,66 @@ io.on("connection", (socket) => {
|
|||
} catch (e) {
|
||||
console.error("mark card played error", e);
|
||||
}
|
||||
|
||||
// Check if cachotier effect is active for the player who played the card
|
||||
let cachotierActive = false;
|
||||
let cachotierEffect = null;
|
||||
try {
|
||||
const active = room.activeCardEffects || [];
|
||||
cachotierEffect = active.find(
|
||||
(e) => e && e.type === "cachotier" && e.playerId === senderId && e.usesRemaining > 0
|
||||
);
|
||||
// Only apply cachotier if this is NOT the cachotier card itself being played
|
||||
if (cachotierEffect && cardId !== "cachotier") {
|
||||
cachotierActive = true;
|
||||
// Consume the cachotier effect
|
||||
cachotierEffect.usesRemaining = 0;
|
||||
// Remove the effect from active effects
|
||||
room.activeCardEffects = active.filter((e) => e !== cachotierEffect);
|
||||
try {
|
||||
io.to(room.id).emit("card:effect:removed", {
|
||||
roomId: room.id,
|
||||
effectId: cachotierEffect.id,
|
||||
type: "cachotier",
|
||||
playerId: cachotierEffect.playerId,
|
||||
});
|
||||
} catch (_) {}
|
||||
}
|
||||
} catch (e) {
|
||||
console.error("cachotier check error", e);
|
||||
}
|
||||
|
||||
if (cachotierActive) {
|
||||
// Send hidden version to opponent, full version to the player who played
|
||||
try {
|
||||
const hiddenPlayed = {
|
||||
id: played.id,
|
||||
playerId: played.playerId,
|
||||
cardId: "hidden",
|
||||
payload: { hidden: true },
|
||||
ts: played.ts,
|
||||
card: { id: "hidden", title: "Carte cachée", description: "Cette carte a été jouée secrètement.", hidden: true },
|
||||
_cachotier: true,
|
||||
};
|
||||
// Send to each player individually
|
||||
(room.players || []).forEach((p) => {
|
||||
if (!p || !p.socketId) return;
|
||||
if (p.id === senderId) {
|
||||
// Owner sees the full card
|
||||
io.to(p.socketId).emit("card:played", played);
|
||||
} else {
|
||||
// Opponent sees hidden card
|
||||
io.to(p.socketId).emit("card:played", hiddenPlayed);
|
||||
}
|
||||
});
|
||||
} catch (e) {
|
||||
console.error("cachotier emit error", e);
|
||||
// Fallback to normal emit
|
||||
io.to(roomId).emit("card:played", played);
|
||||
}
|
||||
} else {
|
||||
io.to(roomId).emit("card:played", played);
|
||||
}
|
||||
try {
|
||||
const countsAsMove = cardId === "inversion";
|
||||
if (countsAsMove) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue