'use client'; import { controlsLeader } from '@/game/leader-control'; import { leaderStrengthLabel } from '@/game/cards'; import { battleCardLabel, isWeaponCard, isStoneBurner, isDefenseCard, VOICE_KINDS, } from '@/game/battle-cards'; import { useState } from 'react'; import { Button } from '@/components/ui/button'; import { Input } from '@/components/ui/input'; import type { Action, GameView } from '@/game/engine'; export function BattlePreparation({ game, send, busy, }: { game: GameView; send: (action: Action) => Promise; busy: boolean; }) { const b = game.battle!; const preparation = b.preparation!; const me = game.players.find((p) => p.id === game.me)!; const [kind, setKind] = useState('poison'); const [must, setMust] = useState(false); const [value, setValue] = useState(''); const act = (action: Action) => void send(action); const beneficiary = game.players.find( (p) => p.id === preparation.beneficiary, )!; if (preparation.owner !== game.me) return (

Waiting for {game.players.find((p) => p.id === preparation.owner)?.name} {preparation.kind === 'voice' ? ' to choose or decline the Voice.' : preparation.kind === 'prescience' ? ' to choose or decline prescience.' : ' to reveal the requested battle-plan element.'}

); if (preparation.kind === 'voice') return ( <>

The Voice

{beneficiary.id === me.id ? 'Command your opponent' : `Assist ${beneficiary.name}`}{' '} before Atreides chooses prescience and the combatants seal their plans.

); const prescienceTarget = beneficiary.id === b.attacker ? b.defender : b.attacker; const noFieldTarget = b.noFieldPlayers.includes(prescienceTarget); if (preparation.kind === 'prescience') return ( <>

Battle prescience

Choose one element of{' '} {beneficiary.id === me.id ? 'your' : `${beneficiary.name}’s`}{' '} opponent’s plan. Only that element becomes fixed.

{noFieldTarget && (

A No-Field battle keeps the number dialed hidden from Atreides. You can inspect the leader, weapon, or defense.

)} {[ 'leader', 'weapon', 'defense', ...(noFieldTarget ? [] : ['dial']), ].map((field) => ( ))} ); const field = b.prescience!.field; const stoneReason = field === 'weapon' && isStoneBurner(me.hand?.find((c) => c.id === value)) ? b.stoneBurnerContext?.blocked : null; const choices = field === 'leader' ? [ ...me.leaders .filter( (l) => !l.dead && controlsLeader(me, l) && (!l.usedAt || l.usedAt === b.territory), ) .map((l) => ({ id: l.id, name: `${l.name} · ${leaderStrengthLabel(l)}`, })), ...(me.hand?.filter((c) => c.kind === 'hero') ?? []), ] : (me.hand?.filter((c) => field === 'weapon' ? isWeaponCard(c) : isDefenseCard(c), ) ?? []); return ( <>

Reveal your {field}

{beneficiary.name} will see this element. You may still change the rest of your plan before sealing it.

{b.voice && (

Voice: {b.voice.must ? 'must play' : 'cannot play'}{' '} {battleCardLabel(b.voice.kind)}.

)} {stoneReason &&

{stoneReason}

} ); }