diff --git a/shared/turn.js b/shared/turn.js index eaafe7e..57c7835 100644 --- a/shared/turn.js +++ b/shared/turn.js @@ -52,9 +52,22 @@ const computeTurnOrderAfterRemoval = (encounter, removedId, updatedParticipants) const updates = { turnOrderIds: newIds }; if (encounter.currentTurnParticipantId === removedId) { const removedPos = currentIds.indexOf(removedId); - const candidates = [...currentIds.slice(removedPos + 1), ...currentIds.slice(0, removedPos)]; - const nextId = candidates.find(id => updatedParticipants.find(p => p.id === id && p.isActive)) ?? null; - updates.currentTurnParticipantId = nextId; + // first try next-active AFTER removed (same round, no wrap) + const after = currentIds.slice(removedPos + 1); + const nextSameRound = after.find(id => + updatedParticipants.find(p => p.id === id && p.isActive)); + if (nextSameRound) { + updates.currentTurnParticipantId = nextSameRound; + } else { + // wrap: no active after removed → advance to first active at top of + // order AND bump round. Without the bump, nextTurn sees current already + // at order[0] and replays the whole round (BUG-5). + const before = currentIds.slice(0, removedPos); + const nextId = before.find(id => + updatedParticipants.find(p => p.id === id && p.isActive)) ?? null; + updates.currentTurnParticipantId = nextId; + if (nextId) updates.round = (encounter.round || 1) + 1; + } } return updates; };