srthstr
This commit is contained in:
parent
13e9e1e0fb
commit
71dde41f79
@ -466,7 +466,17 @@ function registerArenaHandlers(io, socket) {
|
||||
const { matchId, slot } = data;
|
||||
if (!matchId || !slot) return;
|
||||
const nextSlot = slot === "player1" ? "player2" : "player1";
|
||||
|
||||
// An alle im Room senden (Normalfall)
|
||||
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}`);
|
||||
});
|
||||
|
||||
|
||||
@ -427,6 +427,8 @@
|
||||
if (!state) {
|
||||
slot.innerHTML = '<span class="hs-icon">🃏</span>';
|
||||
slot.classList.remove("hand-slot-ready");
|
||||
slot.draggable = false;
|
||||
delete slot.dataset.cardSlotId;
|
||||
return;
|
||||
}
|
||||
|
||||
@ -682,9 +684,12 @@
|
||||
/* ── Zug beenden: CD ticken + Karte ziehen + Server informieren ── */
|
||||
document.getElementById("end-turn-btn")?.addEventListener("click", () => {
|
||||
if (!isMyTurn) return;
|
||||
// Sofort Timer stoppen und Zug abgeben – nicht auf turn_change warten
|
||||
clearInterval(turnTimerInt);
|
||||
stopTurnTimer();
|
||||
tickHandCooldowns();
|
||||
drawNextCard();
|
||||
lastTurnChangeSlot = null; // Duplikat-Schutz zurücksetzen
|
||||
setTurnState(false);
|
||||
socket.emit("end_turn", { matchId, slot: mySlot });
|
||||
});
|
||||
@ -859,7 +864,12 @@
|
||||
});
|
||||
|
||||
/* ── Server: Zugwechsel ──────────────────────────────── */
|
||||
let lastTurnChangeSlot = null;
|
||||
socket.on("turn_change", (data) => {
|
||||
// Duplikat-Schutz: dasselbe Event doppelt ignorieren
|
||||
if (data.activeSlot === lastTurnChangeSlot) return;
|
||||
lastTurnChangeSlot = data.activeSlot;
|
||||
|
||||
const nowMyTurn = data.activeSlot === mySlot;
|
||||
console.log(
|
||||
"[1v1] turn_change:",
|
||||
@ -1304,14 +1314,16 @@
|
||||
if (!slot) return;
|
||||
const idx = Number(slot.dataset.slotIndex);
|
||||
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;
|
||||
|
||||
// Karte vom Hand-Slot entfernen
|
||||
handSlotState[draggedCardSlotId] = null;
|
||||
renderHandSlot(draggedCardSlotId);
|
||||
handSlotState[sourceId] = null;
|
||||
renderHandSlot(sourceId);
|
||||
|
||||
// Karte auf Board-Slot legen
|
||||
boardState[slot.id] = cardState.card;
|
||||
@ -1331,7 +1343,7 @@
|
||||
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