fixed empathie !!!
This commit is contained in:
parent
7239c95f02
commit
06c13a8747
2 changed files with 57 additions and 88 deletions
|
|
@ -336,8 +336,8 @@ logs...</pre
|
||||||
|
|
||||||
socket.on("room:update", (data) => {
|
socket.on("room:update", (data) => {
|
||||||
log("room:update", data);
|
log("room:update", data);
|
||||||
if (playersEl) {
|
// Always update local player color mapping and orientation even if the players list UI is not present
|
||||||
playersEl.innerHTML = "";
|
try {
|
||||||
(data.players || []).forEach((p) => {
|
(data.players || []).forEach((p) => {
|
||||||
try {
|
try {
|
||||||
playerColors[p.id] = p.color;
|
playerColors[p.id] = p.color;
|
||||||
|
|
@ -346,8 +346,21 @@ logs...</pre
|
||||||
if (p.id === myPlayerId) {
|
if (p.id === myPlayerId) {
|
||||||
myColor = p.color;
|
myColor = p.color;
|
||||||
if (myColorEl) myColorEl.textContent = myColor;
|
if (myColorEl) myColorEl.textContent = myColor;
|
||||||
|
// ensure board orientation follows the (possibly changed) player color
|
||||||
|
try {
|
||||||
|
if (boardEl) {
|
||||||
|
if (myColor === "black") boardEl.classList.add("flipped");
|
||||||
|
else boardEl.classList.remove("flipped");
|
||||||
|
}
|
||||||
|
} catch (_) {}
|
||||||
}
|
}
|
||||||
} catch (_) {}
|
} catch (_) {}
|
||||||
|
});
|
||||||
|
} catch (_) {}
|
||||||
|
|
||||||
|
if (playersEl) {
|
||||||
|
playersEl.innerHTML = "";
|
||||||
|
(data.players || []).forEach((p) => {
|
||||||
const li = document.createElement("li");
|
const li = document.createElement("li");
|
||||||
li.textContent =
|
li.textContent =
|
||||||
(p.color || "Joueur") +
|
(p.color || "Joueur") +
|
||||||
|
|
@ -606,6 +619,22 @@ logs...</pre
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (e) {}
|
} catch (e) {}
|
||||||
|
// If empathie was applied, explicitly request a room refresh as a reliable fallback
|
||||||
|
try {
|
||||||
|
if (effect.type === "empathie") {
|
||||||
|
log("recv empathie effect — requesting room refresh");
|
||||||
|
try {
|
||||||
|
socket.emit("room:refresh", { roomId }, (resp) => {
|
||||||
|
log("room:refresh ack", resp);
|
||||||
|
});
|
||||||
|
} catch (_) {
|
||||||
|
try {
|
||||||
|
// last-resort: ask server for update via general event
|
||||||
|
socket.emit("room:refresh", { roomId }, () => {});
|
||||||
|
} catch (_) {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (_) {}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.warn("card:effect:applied handler error", e);
|
console.warn("card:effect:applied handler error", e);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
112
server.js
112
server.js
|
|
@ -566,7 +566,7 @@ function buildDefaultDeck() {
|
||||||
// ['vacances','Choisie une pièce qui sort du plateau pendant deux tours. Ce après quoi elle tente de revenir: si la case est occupée, alors la pièce vacancière est capturée par la pièce occupant la case.'],
|
// ['vacances','Choisie une pièce qui sort du plateau pendant deux tours. Ce après quoi elle tente de revenir: si la case est occupée, alors la pièce vacancière est capturée par la pièce occupant la case.'],
|
||||||
|
|
||||||
// a reflechir
|
// a reflechir
|
||||||
["Empathie", "On retourne le plateau", "empathie"], // pendant X tours ?
|
["Empathie", "Change la couleur associée à chaque joueur.", "empathie"],
|
||||||
// ['effet domino', "La pièce désigner peut rejouer tant qu'elle capture"]
|
// ['effet domino', "La pièce désigner peut rejouer tant qu'elle capture"]
|
||||||
// ['reversi','Si deux pions encadrent parfaitement une pièce adverse, cette dernière change de camp'],
|
// ['reversi','Si deux pions encadrent parfaitement une pièce adverse, cette dernière change de camp'],
|
||||||
// ['plus on est de fous','Si le joueur possède deux fous dans la même diagonale, alors toutes les pièces adverses encadrées par ces deux fous sont capturés'],
|
// ['plus on est de fous','Si le joueur possède deux fous dans la même diagonale, alors toutes les pièces adverses encadrées par ces deux fous sont capturés'],
|
||||||
|
|
@ -3000,6 +3000,9 @@ io.on("connection", (socket) => {
|
||||||
effect,
|
effect,
|
||||||
});
|
});
|
||||||
} catch (_) {}
|
} catch (_) {}
|
||||||
|
try {
|
||||||
|
sendRoomUpdate(room);
|
||||||
|
} catch (_) {}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error("toucher effect error", e);
|
console.error("toucher effect error", e);
|
||||||
}
|
}
|
||||||
|
|
@ -3388,11 +3391,11 @@ io.on("connection", (socket) => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// empathie
|
// empathie: minimal handler — swap the color associated to each player and nothing else
|
||||||
else if (cardId === "empathie") {
|
else if (cardId === "empathie") {
|
||||||
try {
|
try {
|
||||||
const board = room.boardState;
|
const board = room.boardState;
|
||||||
if (!board || !Array.isArray(board.pieces)) {
|
if (!board) {
|
||||||
try {
|
try {
|
||||||
room.hands = room.hands || {};
|
room.hands = room.hands || {};
|
||||||
room.hands[senderId] = room.hands[senderId] || [];
|
room.hands[senderId] = room.hands[senderId] || [];
|
||||||
|
|
@ -3410,89 +3413,24 @@ io.on("connection", (socket) => {
|
||||||
} catch (e) {}
|
} catch (e) {}
|
||||||
return (
|
return (
|
||||||
cb &&
|
cb &&
|
||||||
cb({
|
cb({ error: "no board to apply empathie", message: "Aucun plateau disponible." })
|
||||||
error: "no board to flip",
|
|
||||||
message: "Aucun plateau à retourner.",
|
|
||||||
})
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
function squareToCoord(sq) {
|
|
||||||
if (!sq) return null;
|
// Swap only the players' color mapping (white <-> black). Do NOT move pieces or change board.turn.
|
||||||
const s = String(sq).trim().toLowerCase();
|
|
||||||
if (!/^[a-z][1-9][0-9]*$/.test(s)) return null;
|
|
||||||
const file = s.charCodeAt(0) - "a".charCodeAt(0);
|
|
||||||
const rank = parseInt(s.slice(1), 10) - 1;
|
|
||||||
return { x: file, y: rank };
|
|
||||||
}
|
|
||||||
function coordToSquare(x, y) {
|
|
||||||
if (x < 0 || y < 0 || !board.width || !board.height) return null;
|
|
||||||
if (x < 0 || y < 0 || x >= board.width || y >= board.height)
|
|
||||||
return null;
|
|
||||||
return String.fromCharCode("a".charCodeAt(0) + x) + (y + 1);
|
|
||||||
}
|
|
||||||
const w = board.width || 8;
|
|
||||||
const h = board.height || 8;
|
|
||||||
(board.pieces || []).forEach((p) => {
|
|
||||||
try {
|
|
||||||
const c = squareToCoord(p.square);
|
|
||||||
if (c) {
|
|
||||||
const nx = w - 1 - c.x;
|
|
||||||
const ny = h - 1 - c.y;
|
|
||||||
const ns = coordToSquare(nx, ny);
|
|
||||||
if (ns) p.square = ns;
|
|
||||||
}
|
|
||||||
p.color = p.color === "w" ? "b" : p.color === "b" ? "w" : p.color;
|
|
||||||
} catch (_) {}
|
|
||||||
});
|
|
||||||
try {
|
try {
|
||||||
room.activeCardEffects = room.activeCardEffects || [];
|
(room.players || []).forEach((pl) => {
|
||||||
room.activeCardEffects.forEach((e) => {
|
if (!pl || !pl.color) return;
|
||||||
if (!e) return;
|
if (pl.color === "white") pl.color = "black";
|
||||||
try {
|
else if (pl.color === "black") pl.color = "white";
|
||||||
if (e.pieceSquare) {
|
|
||||||
const c = squareToCoord(e.pieceSquare);
|
|
||||||
if (c) {
|
|
||||||
const nx = w - 1 - c.x;
|
|
||||||
const ny = h - 1 - c.y;
|
|
||||||
const ns = coordToSquare(nx, ny);
|
|
||||||
if (ns) e.pieceSquare = ns;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (e.square) {
|
|
||||||
const c2 = squareToCoord(e.square);
|
|
||||||
if (c2) {
|
|
||||||
const nx = w - 1 - c2.x;
|
|
||||||
const ny = h - 1 - c2.y;
|
|
||||||
const ns2 = coordToSquare(nx, ny);
|
|
||||||
if (ns2) e.square = ns2;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (Array.isArray(e.allowedSquares)) {
|
|
||||||
e.allowedSquares = e.allowedSquares.map((sq) => {
|
|
||||||
const cc = squareToCoord(sq);
|
|
||||||
if (!cc) return sq;
|
|
||||||
const nx = w - 1 - cc.x;
|
|
||||||
const ny = h - 1 - cc.y;
|
|
||||||
return coordToSquare(nx, ny) || sq;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
} catch (_) {}
|
|
||||||
});
|
});
|
||||||
} catch (_) {}
|
} catch (_) {}
|
||||||
(room.players || []).forEach((pl) => {
|
|
||||||
try {
|
// bump version so clients pick up the change
|
||||||
pl.color =
|
try {
|
||||||
pl.color === "white"
|
board.version = (board.version || 0) + 1;
|
||||||
? "black"
|
} catch (_) {}
|
||||||
: pl.color === "black"
|
|
||||||
? "white"
|
|
||||||
: pl.color;
|
|
||||||
} catch (_) {}
|
|
||||||
});
|
|
||||||
if (board.turn)
|
|
||||||
board.turn =
|
|
||||||
board.turn === "w" ? "b" : board.turn === "b" ? "w" : board.turn;
|
|
||||||
board.version = (board.version || 0) + 1;
|
|
||||||
const effect = {
|
const effect = {
|
||||||
id: played.id,
|
id: played.id,
|
||||||
type: "empathie",
|
type: "empathie",
|
||||||
|
|
@ -3503,16 +3441,18 @@ io.on("connection", (socket) => {
|
||||||
room.activeCardEffects.push(effect);
|
room.activeCardEffects.push(effect);
|
||||||
played.payload = Object.assign({}, payload, { applied: "empathie" });
|
played.payload = Object.assign({}, payload, { applied: "empathie" });
|
||||||
try {
|
try {
|
||||||
io.to(room.id).emit("card:effect:applied", {
|
io.to(room.id).emit("card:effect:applied", { roomId: room.id, effect });
|
||||||
roomId: room.id,
|
|
||||||
effect,
|
|
||||||
});
|
|
||||||
} catch (_) {}
|
} catch (_) {}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
recordPlayerDrewPrev(room, senderId);
|
recordPlayerDrewPrev(room, senderId);
|
||||||
} catch (_) {}
|
} catch (_) {}
|
||||||
|
|
||||||
|
try {
|
||||||
|
sendRoomUpdate(room);
|
||||||
|
} catch (_) {}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error("empathie / changement de camp error", e);
|
console.error("empathie minimal handler error", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue