Files
Dune/game/ecaz-loyalty.ts
Quintine de26aaf029 Implement Advanced Ecaz Loyalty with public card inspection
Before genuine Advanced Ecaz Traitor dealing, randomly set aside one of the five
native Ecaz cards face up for the game. Store its owner and exact identity once;
exclude it from the initial deck, Tleilaxu Face Dancer setup and Nexus replacement
universes. Do not change leader custody or add choices, payment or Karama windows.
Absent markers preserve older already-dealt saves without taking held cards away.
Validate owner, timing and distinct physical custody before actions, normalization
and projection. Expose a detached public card identity, never private deck order.

Show the named card, portrait and enlarged Traitor inspection above the table.
A dedicated Loyalty context explains public set-aside custody and cannot-call
rules; browser review caught and fixed the generic held-Traitor guidance.
Add internal help, checklist, shared Advanced faction text and source documentation.
The official page8 requirement and page16 noKarama entry support the effect;
relative pre-Traitor prediction/skill sequencing is an explicit composition.
Gated Skills/Ecaz and Moritani assassination/Ecaz are not certified.

Twelve new cases plus related regressions cover candidate selection, immutable
invalid-state rejection,2..6 genuine deals, Basic/noEcaz, completed Tleilaxu setup,
Harkonnen/Tleilaxu Nexus draws, full physical census, detached public views, all4
legal AI setups, JSON continuation, legacy custody and public rendering.
Independent review found no material issue after genuine setup/legacy test fixes
and the focused inspector correction.50 related focused cases pass. A mistyped
filename filter failed closed before the corrected union ran successfully.
Types, lint, all 5012 offline tests, production build and 49 HTTP tests
pass on stable source. Earlier type/lint findings were corrected before this run.

Six genuine faction-game samples finish with no rejected actions and repeated
JSON restoration: CHOAM Basic1054/Advanced225 actions, Ecaz Basic91/Advanced245,
combined Basic476/Advanced704. Existing physical Treachery/force custody checks
pass; focused Loyalty tests cover expansion Traitor census. These bounded legal
samples are not strength calibration or complete expansion acceptance.

Browser QA created a fresh Ecaz/Easy Harkonnen ready lobby and initialized its
Advanced setup before dealing using backup and CAS. Bindikk Narvi was public
before choices and remained excluded through actual human Traitor/force setup,
Storm and refresh. The saved human Traitor is Beast Rabban; a pointer action just
after viewport reset differed from its intended Feyd target, so exact-target
pointer acceptance across viewport changes is not claimed. Ordinary source
bindings remain name/ID-specific. One hand card,12spice,14reserves and the pending
Storm dial restore; both public projections agree and saved seat records match.
The Loyalty inspector shows correct card-specific guidance; Escape restores focus.
At390px its panel has no horizontal overflow,16px text and44/48px controls; the
expanded scroll body fits342px. Internal help opens its complete checklist topic.
Normal viewport restored. Screenshot capture timed out; full visual, long-inspector
keyboard and broader module acceptance remain open.

All 1539 pre-existing rooms, 3259 human seat records and
auxiliary rows remain unchanged. SQLite integrity and foreign keys pass.
Only isolated QA/HTTP fixtures add rooms. No server restart, database reset,
migration, recurring automation, AI strategy change or mode/publication gate change.

Private evidence: 20260921-gameplay-review.
Verified source tree: 881bf1912665350086d80be664d479a1b2724146da6ccc9576790c07e0449ee6
2026-09-21 12:43:37 +10:00

39 lines
2.1 KiB
TypeScript

import { leaders } from './cards';
import type { Game } from './engine';
/** A separate physical Traitor Card, face up for the rest of this game. */
export type EcazLoyalty = { player: string; card: string | null };
export function chooseEcazLoyalty(deck: readonly string[], roll: number): string {
const candidates = leaders('ecaz').map(leader => leader.id);
if (!Number.isFinite(roll) || roll < 0 || roll >= 1 ||
new Set(deck).size !== deck.length || candidates.some(card => !deck.includes(card)))
throw new Error('Ecaz Loyalty requires the intact native Traitor inventory and a valid random draw.');
return candidates[Math.floor(roll * candidates.length)];
}
export function withoutEcazLoyalty(deck: readonly string[], loyalty?: EcazLoyalty): string[] {
return deck.filter(card => card !== loyalty?.card);
}
/** Missing markers belong to older games and never remove an already-dealt card. */
export function validateEcazLoyalty(game: Pick<Game, 'ecazLoyalty' | 'advanced' | 'players' | 'status' | 'setupStage' | 'traitorReserve' | 'moritaniAssassinate'>): void {
const loyalty = game.ecazLoyalty;
if (loyalty === undefined) return;
if (!loyalty || !game.advanced || game.status === 'lobby' ||
!game.players.some(player => player.id === loyalty.player && player.faction === 'ecaz'))
throw new Error('Ecaz Loyalty must belong to the native Advanced Ecaz player.');
const circulating = [
...(game.traitorReserve ?? []),
...game.players.flatMap(player => [...player.traitors, ...player.traitorChoices, ...(player.faceDancers ?? []).map(card => card.leader)]),
];
if (loyalty.card === null) {
if (game.status !== 'setup' || !['prediction', 'skillTreachery', 'leaderSkills'].includes(game.setupStage ?? '') || circulating.length)
throw new Error('Ecaz Loyalty must be revealed before initial Traitor dealing.');
return;
}
if (!leaders('ecaz').some(leader => leader.id === loyalty.card) || circulating.includes(loyalty.card) ||
game.moritaniAssassinate?.opportunities.some(receipt => receipt.card === loyalty.card))
throw new Error('The public Ecaz Loyalty card must remain separate from all circulating or retired Traitors.');
}