Files
Dune/game/table-turn.ts
T
Quintine 28ba1618ba Implement Homeworld mechanics through Caladan reinforcement checkpoint
Connect typed Homeworld custody, transport, battle, income, revival and Caladan reinforcement flows with private multiplayer recovery and controls. Preserve the optimized test workflow and keep unfinished rules modes gated. Verified with 3682 offline tests, typecheck, lint, production build and 40 HTTP tests; existing saved games remain unchanged.
2026-09-10 08:12:26 +10:00

52 lines
1.7 KiB
TypeScript

import type { GameView } from './engine';
type TurnView = Pick<
GameView,
| 'status'
| 'active'
| 'players'
| 'decision'
| 'battle'
| 'response'
| 'truthtrance'
| 'phaseOpening'
| 'automaticContinuationPending'
> &
Partial<Pick<GameView, 'biddingEnd'>>;
/** The single current decision owner for the table banner and seat highlight.
* Shared response windows have no single acting seat. Only public view fields
* participate; this does not decide which gameplay actions are legal. */
export function tableActionOwner(g: TurnView): string | null {
if (
g.status !== 'playing' ||
g.automaticContinuationPending ||
g.truthtrance ||
g.phaseOpening ||
g.response
)
return null;
const seated = (id: string | null | undefined) =>
g.players.some((p) => p.id === id) ? id! : null;
if (g.decision) return seated(g.decision.player);
if (g.biddingEnd) {
const pending = g.biddingEnd.owners.filter(
(id) => !g.biddingEnd!.ready.includes(id),
);
return pending.length === 1 ? seated(pending[0]) : null;
}
const b = g.battle;
if (!b) return seated(g.active);
const combatants = [b.attacker, b.defender];
const sole = (ids: string[]) => (ids.length === 1 ? seated(ids[0]) : null);
if (b.preLeader && !b.preLeader.closed)
return sole(combatants.filter((id) => !b.preLeader!.ready.includes(id)));
if (b.preparation) return seated(b.preparation.owner);
if (!b.revealed) {
if (b.fullPlan && !b.submitted.includes(b.fullPlan.target))
return seated(b.fullPlan.target);
return sole(combatants.filter((id) => !b.submitted.includes(id)));
}
return sole(b.traitorVoters.filter((id) => !b.traitorSubmitted.includes(id)));
}