srthstr
This commit is contained in:
parent
13e9e1e0fb
commit
71dde41f79
@ -466,7 +466,17 @@ function registerArenaHandlers(io, socket) {
|
|||||||
const { matchId, slot } = data;
|
const { matchId, slot } = data;
|
||||||
if (!matchId || !slot) return;
|
if (!matchId || !slot) return;
|
||||||
const nextSlot = slot === "player1" ? "player2" : "player1";
|
const nextSlot = slot === "player1" ? "player2" : "player1";
|
||||||
|
|
||||||
|
// An alle im Room senden (Normalfall)
|
||||||
io.to("arena_" + matchId).emit("turn_change", { activeSlot: nextSlot });
|
io.to("arena_" + matchId).emit("turn_change", { activeSlot: nextSlot });
|
||||||
|
|
||||||
|
// Zusätzlich direkt an den Socket des nächsten Spielers senden –
|
||||||
|
// Fallback falls der Gegner den Room verlassen hat (z.B. nach Reconnect)
|
||||||
|
const room = io._arenaRooms?.get(matchId);
|
||||||
|
if (room?.sockets[nextSlot]) {
|
||||||
|
io.to(room.sockets[nextSlot]).emit("turn_change", { activeSlot: nextSlot });
|
||||||
|
}
|
||||||
|
|
||||||
console.log(`[1v1] Zug: ${slot} → ${nextSlot} | Match ${matchId}`);
|
console.log(`[1v1] Zug: ${slot} → ${nextSlot} | Match ${matchId}`);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -427,6 +427,8 @@
|
|||||||
if (!state) {
|
if (!state) {
|
||||||
slot.innerHTML = '<span class="hs-icon">🃏</span>';
|
slot.innerHTML = '<span class="hs-icon">🃏</span>';
|
||||||
slot.classList.remove("hand-slot-ready");
|
slot.classList.remove("hand-slot-ready");
|
||||||
|
slot.draggable = false;
|
||||||
|
delete slot.dataset.cardSlotId;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -682,9 +684,12 @@
|
|||||||
/* ── Zug beenden: CD ticken + Karte ziehen + Server informieren ── */
|
/* ── Zug beenden: CD ticken + Karte ziehen + Server informieren ── */
|
||||||
document.getElementById("end-turn-btn")?.addEventListener("click", () => {
|
document.getElementById("end-turn-btn")?.addEventListener("click", () => {
|
||||||
if (!isMyTurn) return;
|
if (!isMyTurn) return;
|
||||||
|
// Sofort Timer stoppen und Zug abgeben – nicht auf turn_change warten
|
||||||
clearInterval(turnTimerInt);
|
clearInterval(turnTimerInt);
|
||||||
|
stopTurnTimer();
|
||||||
tickHandCooldowns();
|
tickHandCooldowns();
|
||||||
drawNextCard();
|
drawNextCard();
|
||||||
|
lastTurnChangeSlot = null; // Duplikat-Schutz zurücksetzen
|
||||||
setTurnState(false);
|
setTurnState(false);
|
||||||
socket.emit("end_turn", { matchId, slot: mySlot });
|
socket.emit("end_turn", { matchId, slot: mySlot });
|
||||||
});
|
});
|
||||||
@ -859,7 +864,12 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
/* ── Server: Zugwechsel ──────────────────────────────── */
|
/* ── Server: Zugwechsel ──────────────────────────────── */
|
||||||
|
let lastTurnChangeSlot = null;
|
||||||
socket.on("turn_change", (data) => {
|
socket.on("turn_change", (data) => {
|
||||||
|
// Duplikat-Schutz: dasselbe Event doppelt ignorieren
|
||||||
|
if (data.activeSlot === lastTurnChangeSlot) return;
|
||||||
|
lastTurnChangeSlot = data.activeSlot;
|
||||||
|
|
||||||
const nowMyTurn = data.activeSlot === mySlot;
|
const nowMyTurn = data.activeSlot === mySlot;
|
||||||
console.log(
|
console.log(
|
||||||
"[1v1] turn_change:",
|
"[1v1] turn_change:",
|
||||||
@ -1304,14 +1314,16 @@
|
|||||||
if (!slot) return;
|
if (!slot) return;
|
||||||
const idx = Number(slot.dataset.slotIndex);
|
const idx = Number(slot.dataset.slotIndex);
|
||||||
if (!isMyZone(idx) || boardState[slot.id]) return;
|
if (!isMyZone(idx) || boardState[slot.id]) return;
|
||||||
if (!draggedCardSlotId) return;
|
// Fallback: manche Browser liefern draggedCardSlotId über dataTransfer
|
||||||
|
const sourceId = draggedCardSlotId || e.dataTransfer.getData("text/plain");
|
||||||
|
if (!sourceId) return;
|
||||||
|
|
||||||
const cardState = handSlotState[draggedCardSlotId];
|
const cardState = handSlotState[sourceId];
|
||||||
if (!cardState || cardState.currentCd > 0) return;
|
if (!cardState || cardState.currentCd > 0) return;
|
||||||
|
|
||||||
// Karte vom Hand-Slot entfernen
|
// Karte vom Hand-Slot entfernen
|
||||||
handSlotState[draggedCardSlotId] = null;
|
handSlotState[sourceId] = null;
|
||||||
renderHandSlot(draggedCardSlotId);
|
renderHandSlot(sourceId);
|
||||||
|
|
||||||
// Karte auf Board-Slot legen
|
// Karte auf Board-Slot legen
|
||||||
boardState[slot.id] = cardState.card;
|
boardState[slot.id] = cardState.card;
|
||||||
@ -1331,7 +1343,7 @@
|
|||||||
card: cardState.card,
|
card: cardState.card,
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log(`[1v1] Karte gespielt: ${cardState.card.name} → ${slot.id}`);
|
console.log(`[1v1] Karte gespielt: ${cardState.card.name} → ${slot.id} (aus ${sourceId})`);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user