'use client'; import { FACTIONS } from '@/game/catalog'; import type { Action, GameView } from '@/game/engine'; import { Button } from '@/components/ui/button'; /** Lobby allocation uses public seat identities only. The engine owns the * randomized order and validates every pick again at commitment. */ export function FactionAllocation({ game, send, busy }: { game: GameView; send: (action: Action) => Promise; busy: boolean; }) { if (game.status !== 'lobby') return null; const draft = game.factionDraft; const isHost = game.host === game.me; const seatName = (id: string) => { const player = game.players.find((candidate) => candidate.id === id); return player ? `${player.name}${player.bot ? ' (AI)' : ''}` : 'Unknown player'; }; if (!draft) return

Choose factions

Players can choose their own factions. The host can also randomly deal factions or start a prediction-card draft.

{isHost && <>

Random dealing changes the current choices immediately. Draft choices replace the current factions only after everyone has picked. Either option clears human readiness.

{game.players.length < 2 &&

At least two faction seats are needed to allocate factions.

}
}
; const next = draft.order[draft.picks.length]; const picked = new Map(draft.picks.map((pick) => [pick.player, pick.faction])); const used = new Set(draft.picks.map((pick) => pick.faction)); const available = FACTIONS.filter((faction) => (faction.expansion === 'base' || game.expansions.includes(faction.expansion)) && !used.has(faction.id)); const isTurn = next?.player === game.me; return

Prediction-card faction draft

Highest prediction card chooses first. Existing factions remain in place until every seat has picked; other lobby changes wait for the draft to finish.

    {draft.order.map((entry) => { const choice = picked.get(entry.player); const faction = FACTIONS.find((item) => item.id === choice); return
  1. {seatName(entry.player)} ยท prediction {entry.card}: {faction ? faction.name : next?.player === entry.player ? 'choosing now' : 'waiting'}
  2. ; })}
{isTurn ? <>

Choose your faction

Choose one of the remaining factions. Each faction can be chosen only once.

{available.map((faction) => )}
: next &&

Waiting for {seatName(next.player)} to choose a faction{game.players.find((player) => player.id === next.player)?.bot ? '; the AI will choose automatically' : ''}.

} {isHost && }
; }