diff --git a/src/components/InitiativeTracker.tsx b/src/components/InitiativeTracker.tsx index 92b42b9..125e70a 100644 --- a/src/components/InitiativeTracker.tsx +++ b/src/components/InitiativeTracker.tsx @@ -157,10 +157,34 @@ export function InitiativeTracker() { ); }, []); + // ponytail: conditions written as "Name (N)" auto-expire: the number + // decrements each time that combatant's turn starts, and the condition + // drops at zero. Plain conditions run until toggled off manually. + function tickDurations(id: string) { + setCombatants((prev) => + prev.map((c) => { + if (c.id !== id) return c; + const next: string[] = []; + for (const cn of c.conditions) { + const m = cn.match(/^(.*?)\s*\((\d+)\)$/); + if (!m) { + next.push(cn); + continue; + } + const n = parseInt(m[2], 10); + if (n > 1) next.push(`${m[1]} (${n - 1})`); + // n === 1 → expired, dropped + } + return { ...c, conditions: next }; + }), + ); + } + const nextTurn = useCallback(() => { if (combatants.length === 0) return; if (!activeId) { setActiveId(combatants[0].id); + tickDurations(combatants[0].id); bus.emit(Events.LogEntry, { text: `⚔ Combat starts — ${combatants[0].name}`, tag: "#combat" }); return; } @@ -168,9 +192,11 @@ export function InitiativeTracker() { if (idx === combatants.length - 1) { setRound((r) => r + 1); setActiveId(combatants[0].id); + tickDurations(combatants[0].id); bus.emit(Events.LogEntry, { text: `⚔ Round ${round + 1} — ${combatants[0].name}'s turn`, tag: "#combat" }); } else { setActiveId(combatants[idx + 1].id); + tickDurations(combatants[idx + 1].id); bus.emit(Events.LogEntry, { text: `⚔ ${combatants[idx + 1].name}'s turn`, tag: "#combat" }); } setTimerLeft(TURN_SECONDS); // ponytail: reset the per-turn timer. @@ -513,7 +539,8 @@ export function InitiativeTracker() {