The independent Ecaz Treachery variant now supports Harass in either physical battle-card slot. A category-null Prescience answer keeps its identity private without erasing the selected card. Exact undialed normal/elite counters return before battle losses; opposing successful Traitors cancel withdrawal, ordinary leader deaths still resolve, and the card is discarded exactly once. Controls, all four AI profiles and saved continuation share the same physical quote. Existing Planetologist inspection and literal Truthtrance slot promises retain their meanings. Unique Basic/Advanced physical allocations are supported. Ambiguous allocations, co-present Ecaz allied armies on either side, Richese card-family configurations and other optional modules remain gated before sealing from public/own context. The pending Stone Burner timing question is not assumed answered. Reveal-before-explosion order and mandatory disposal on an own-Traitor win are explicit source-timing/specificity inferences, consistent with existing Planetologist precedence. Reinforcements and full variant/public mode acceptance remain unfinished. Independent rules/privacy/persistence review fixed asymmetric selector legality, misleading blocked-card guidance, invalid restored battle pairs, native-only inspection bypass and unsupported allied-army admission. Ixian fixtures preserve all seven physical cyborgs. The first broad run caught a semantic-status lint error in the blocked guidance; replacing the paragraph role with an output element fixed it. A subsequent broad run passed 4,775 of 4,776 tests and exposed an old UI assertion requiring category-null slots to be disabled. The updated regression verifies enabled category-null selectors exclude ordinary held cards, while exact leader/dial locks and submitted values remain bound; focused controls pass 14/14. No game source changed after the eight samples or browser replay. Types, lint, 4776 offline tests, build and 43 HTTP tests pass with unchanged source. Authenticated SQLite cases verify sealed private restoration and competing duplicate traitor actions with one physical resolution. Eight fixed genuine six-seat games finish: basic/Easy: 1803 actions, 0 Harass plans, 0 withdrawals, 48 periodic restores; basic/Medium: 225 actions, 0 Harass plans, 0 withdrawals, 6 periodic restores; basic/Hard: 2184 actions, 1 Harass plans, 1 withdrawals, 59 periodic restores; basic/Brutal: 2073 actions, 1 Harass plans, 1 withdrawals, 56 periodic restores; advanced/Easy: 2057 actions, 1 Harass plans, 1 withdrawals, 55 periodic restores; advanced/Medium: 532 actions, 0 Harass plans, 0 withdrawals, 14 periodic restores; advanced/Hard: 538 actions, 0 Harass plans, 0 withdrawals, 14 periodic restores; advanced/Brutal: 544 actions, 0 Harass plans, 0 withdrawals, 14 periodic restores. All 218 game-source files match their source-stable runs; exact card/traitor/force custody and periodic/terminal private views are checked. Browser controls verify the full card, category None, Defense-first legality, actual sealing/reveal, four returned forces, ordinary leader death, disposal and refresh. A separate final-source replay verifies the conserved browser fixture and opposing continuation, including Face Dancer replacement. This is bounded playability evidence, not full compliance or AI calibration. All 936 opening games and their original seat/recovery records remain unchanged (970 after checks); all 937 present immediately before checks are also preserved. Database integrity and foreign keys pass. The healthy server was reused after the power failure without restart, reset or recurring automation. Verified source tree: be193613c455c5b76b49800fe3a7400504ea879af34c59621ade3d44f0fe019d
313 lines
12 KiB
TypeScript
313 lines
12 KiB
TypeScript
'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, PlanField } from '@/game/engine';
|
||
import type { CommittedPlanElement } from '@/game/battle-inspections';
|
||
import {
|
||
battleCardSlotEligible,
|
||
fixedBattleInspectionMatches,
|
||
validBattleSlotPair,
|
||
type BattleCardSlot,
|
||
} from '@/game/battle-card-slots';
|
||
import { canUsePlanetologistBattleSpecial } from '@/game/leader-skill-combat';
|
||
|
||
/** Both selectors evaluate the complete physical pair, in either selection order. */
|
||
export function battlePlanCardOptions(game: GameView, slot: BattleCardSlot, leader: string, weapon: string, defense: string) {
|
||
const me = game.players.find(player => player.id === game.me)!;
|
||
const fixed = battlePlanCommitments(game)[slot];
|
||
return (me.hand ?? []).filter(card => {
|
||
const w = slot === 'weapon' ? card : me.hand?.find(c => c.id === weapon);
|
||
const d = slot === 'defense' ? card : me.hand?.find(c => c.id === defense);
|
||
const planetologistWeapon = canUsePlanetologistBattleSpecial({
|
||
assignments: game.leaderSkills?.assignments.filter(a => a.controller === game.me) ?? [],
|
||
selectedLeader: leader, card: w,
|
||
});
|
||
return card.id !== 'ecaz-reinforcements' &&
|
||
(card.id !== 'ecaz-harass-withdraw' || (!!game.battle?.harassWithdraw && !game.battle.harassWithdraw.blocked)) &&
|
||
battleCardSlotEligible(slot, card, { planetologistWeapon }) &&
|
||
(!fixed || fixedBattleInspectionMatches(slot, fixed.value, card.id, card)) &&
|
||
validBattleSlotPair(w, d, planetologistWeapon);
|
||
});
|
||
}
|
||
|
||
/** Read only the recipient's projected commitments, including an explicit null. */
|
||
export function battlePlanCommitments(game: GameView): Partial<Record<PlanField, CommittedPlanElement>> {
|
||
const battle = game.battle;
|
||
if (!battle) return {};
|
||
const commitments = battle.ownCommitments ?? (
|
||
battle.insight && battle.prescience && battle.prescience.player !== game.me &&
|
||
[battle.attacker, battle.defender].includes(game.me)
|
||
? [{ source: 'native' as const, beneficiary: battle.prescience.player, target: game.me,
|
||
field: battle.insight.field, value: battle.insight.value }]
|
||
: []
|
||
);
|
||
return Object.fromEntries(commitments.filter((item) => item.target === game.me).map((item) => [item.field, item]));
|
||
}
|
||
|
||
export function bindBattlePlanCommitments(game: GameView, plan: Action): Action {
|
||
if (plan.type !== 'battlePlan') return plan;
|
||
return { ...plan, ...Object.fromEntries(Object.values(battlePlanCommitments(game)).map((item) => [item.field,
|
||
item.field === 'weapon' || item.field === 'defense'
|
||
? battlePlanCardValue(game, item.field, typeof plan[item.field] === 'string' ? plan[item.field] as string : '') || null
|
||
: item.value])) };
|
||
}
|
||
|
||
/** An inspected absence of a category still permits a legal slot-only Special. */
|
||
export function battlePlanCardValue(game: GameView, slot: BattleCardSlot, selected: string): string {
|
||
const commitment = battlePlanCommitments(game)[slot];
|
||
if (!commitment) return selected;
|
||
if (commitment.value !== null) return String(commitment.value);
|
||
const card = game.players.find((player) => player.id === game.me)?.hand?.find((card) => card.id === selected);
|
||
return card && fixedBattleInspectionMatches(slot, null, card.id, card) ? card.id : '';
|
||
}
|
||
|
||
export function battlePreparationField(game: GameView): PlanField | null {
|
||
const battle = game.battle;
|
||
if (battle?.preparation?.kind === 'nexusPrescienceAnswer') {
|
||
const inspection = battle.nexusInspection;
|
||
return inspection?.stage === 'answer' && inspection.event === battle.event &&
|
||
inspection.target === battle.preparation.owner && inspection.owner === battle.preparation.beneficiary
|
||
? inspection.field : null;
|
||
}
|
||
return battle?.preparation?.kind === 'prescienceAnswer' ? battle.prescience?.field ?? null : null;
|
||
}
|
||
|
||
export function battleInspectionAnswerAction(game: GameView, value: string): Action | null {
|
||
const battle = game.battle;
|
||
const field = battlePreparationField(game);
|
||
if (game.status !== 'playing' || game.phase !== 6 || !battle || battle.revealed ||
|
||
battle.preparation?.owner !== game.me || !field) return null;
|
||
const answer = field === 'dial' ? Number(value) : value || null;
|
||
if (field === 'dial' && (value.trim() === '' || !Number.isFinite(answer) || Number(answer) < 0 || !Number.isSafeInteger(Number(answer) * 2))) return null;
|
||
return battle.preparation.kind === 'nexusPrescienceAnswer'
|
||
? { type: 'nexusPrescienceAnswer', event: battle.nexusInspection!.event, value: answer }
|
||
: { type: 'prescienceAnswer', value: answer };
|
||
}
|
||
|
||
export function NexusInspectionHistory({ game }: { game: GameView }) {
|
||
const battle = game.battle;
|
||
if (!battle?.nexusInspection || ![battle.nexusInspection.owner, battle.nexusInspection.target].includes(game.me) || !battle.nexusInsights?.length) return null;
|
||
return <section aria-label="Private Nexus inspection history" className="space-y-2">
|
||
<h4>Nexus inspection</h4>
|
||
{battle.nexusInsights.map((insight, index) => <p className="notice" key={`${index}-${insight.field}`}>
|
||
{insight.active ? (battle.nexusInspection!.target === game.me ? 'Your committed element' : 'Current answer') : 'Previous answer'}: {insight.field} = {insight.label}
|
||
{!insight.active && <span className="fine"> · No longer binding</span>}
|
||
</p>)}
|
||
</section>;
|
||
}
|
||
|
||
export function BattlePreparation({
|
||
game,
|
||
send,
|
||
busy,
|
||
}: {
|
||
game: GameView;
|
||
send: (action: Action) => Promise<void>;
|
||
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 (
|
||
<p className="notice">
|
||
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.'}
|
||
</p>
|
||
);
|
||
if (preparation.kind === 'voice')
|
||
return (
|
||
<>
|
||
<h3>The Voice</h3>
|
||
<p className="muted">
|
||
{beneficiary.id === me.id
|
||
? 'Command your opponent'
|
||
: `Assist ${beneficiary.name}`}{' '}
|
||
before Atreides chooses prescience and the combatants seal their
|
||
plans.
|
||
</p>
|
||
<label htmlFor="voice-kind">
|
||
Card type
|
||
<select
|
||
id="voice-kind"
|
||
value={kind}
|
||
onChange={(e) => setKind(e.target.value)}
|
||
>
|
||
{VOICE_KINDS.map((k) => (
|
||
<option key={k} value={k}>
|
||
{battleCardLabel(k)}
|
||
</option>
|
||
))}
|
||
</select>
|
||
</label>
|
||
<label className="decision-checkbox">
|
||
<input
|
||
type="checkbox"
|
||
checked={must}
|
||
onChange={(e) => setMust(e.target.checked)}
|
||
/>
|
||
Require this type (unchecked: forbid)
|
||
</label>
|
||
<Button
|
||
className="game-action"
|
||
disabled={busy}
|
||
onClick={() => act({ type: 'voice', kind, must })}
|
||
>
|
||
Use the Voice
|
||
</Button>
|
||
<Button
|
||
className="game-action"
|
||
disabled={busy}
|
||
onClick={() => act({ type: 'declineBattlePower' })}
|
||
>
|
||
Decline the Voice
|
||
</Button>
|
||
</>
|
||
);
|
||
const prescienceTarget =
|
||
beneficiary.id === b.attacker ? b.defender : b.attacker;
|
||
const noFieldTarget = b.noFieldPlayers.includes(prescienceTarget);
|
||
if (preparation.kind === 'prescience')
|
||
return (
|
||
<>
|
||
<h3>Battle prescience</h3>
|
||
<p className="muted">
|
||
Choose one element of{' '}
|
||
{beneficiary.id === me.id ? 'your' : `${beneficiary.name}’s`}{' '}
|
||
opponent’s plan. Only that element becomes fixed.
|
||
</p>
|
||
{noFieldTarget && (
|
||
<p className="fine">
|
||
A No-Field battle keeps the number dialed hidden from Atreides. You
|
||
can inspect the leader, weapon, or defense.
|
||
</p>
|
||
)}
|
||
{[
|
||
'leader',
|
||
'weapon',
|
||
'defense',
|
||
...(noFieldTarget ? [] : ['dial']),
|
||
].map((field) => (
|
||
<Button
|
||
className="game-action"
|
||
key={field}
|
||
disabled={busy}
|
||
onClick={() => act({ type: 'prescience', field })}
|
||
>
|
||
Reveal {field}
|
||
</Button>
|
||
))}
|
||
<Button
|
||
className="game-action"
|
||
disabled={busy}
|
||
onClick={() => act({ type: 'declineBattlePower' })}
|
||
>
|
||
Decline prescience
|
||
</Button>
|
||
</>
|
||
);
|
||
const field = battlePreparationField(game);
|
||
if (!field) return <p className="notice">This inspection is no longer awaiting an answer.</p>;
|
||
const answerAction = battleInspectionAnswerAction(game, value);
|
||
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 (
|
||
<>
|
||
<h3>Reveal your {field}</h3>
|
||
<p className="muted">
|
||
{beneficiary.name} will see this element. You may still change the rest
|
||
of your plan before sealing it.
|
||
</p>
|
||
{(field === 'weapon' || field === 'defense') && b.harassWithdraw && !b.harassWithdraw.blocked && (
|
||
<p className="fine">
|
||
Harass & Withdraw is neither a weapon nor a defense. Choose None
|
||
for the category it will occupy; its identity stays private until plans are revealed.
|
||
</p>
|
||
)}
|
||
{b.voice && (
|
||
<p className="notice">
|
||
Voice: {b.voice.must ? 'must play' : 'cannot play'}{' '}
|
||
{battleCardLabel(b.voice.kind)}.
|
||
</p>
|
||
)}
|
||
<label htmlFor="prescience-answer">
|
||
{field === 'dial' ? 'Forces dialed' : field}
|
||
</label>
|
||
{field === 'dial' ? (
|
||
<Input
|
||
id="prescience-answer"
|
||
type="number"
|
||
min={0}
|
||
max={game.advanced || me.faction === 'ixians' ? 40 : 20}
|
||
step={game.advanced || me.faction === 'ixians' ? 0.5 : 1}
|
||
value={value}
|
||
onChange={(e) => setValue(e.target.value)}
|
||
/>
|
||
) : (
|
||
<select
|
||
id="prescience-answer"
|
||
value={value}
|
||
onChange={(e) => setValue(e.target.value)}
|
||
>
|
||
<option value="">None</option>
|
||
{choices.map((choice) => (
|
||
<option key={choice.id} value={choice.id}>
|
||
{choice.name}
|
||
</option>
|
||
))}
|
||
</select>
|
||
)}
|
||
{stoneReason && <p className="notice">{stoneReason}</p>}
|
||
<Button
|
||
className="game-action"
|
||
disabled={busy || !!stoneReason || !answerAction}
|
||
onClick={() => { if (!busy && !stoneReason && answerAction) act(answerAction); }}
|
||
>
|
||
Commit this element
|
||
</Button>
|
||
</>
|
||
);
|
||
}
|