Connect Harkonnen Nexus to Ecaz Occupy
Verify and publish checkpoint container / container (push) Successful in 11m17s
Verify and publish checkpoint container / container (push) Successful in 11m17s
This commit is contained in:
1 parent
007508185e
commit
a2e7029a72
12 files changed
+529
-19
No files matched your search
@@ -77,7 +77,9 @@ void test('a group declaration rejects retargeted battle, leader, identity and r
|
||||
|
||||
void test('group declaration is unavailable in unsupported profiles or ambiguous group battles', () => {
|
||||
const game = source();
|
||||
for (const patch of [{advanced:true}, {expansions:['ix']}, {homeworlds:{}},
|
||||
const advanced = createTraitorDeclaration({...game, advanced:true}, 'h');
|
||||
assert.equal(advanced.beneficiary, 'a');
|
||||
for (const patch of [{expansions:['ix']}, {homeworlds:{}},
|
||||
{nexusCards:{}}, {leaderSkills:{}}, {techTokens:{}}, {strongholdCards:{}},
|
||||
{ecazTreachery:true}, {discoveryEnabled:true}]) {
|
||||
assert.throws(() => createTraitorDeclaration({...game, ...patch}, 'h'));
|
||||
|
||||
@@ -0,0 +1,136 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import { test } from 'node:test';
|
||||
import { applyAction, createGame, joinGame, newPlayer, viewGame, type Action, type Game } from '../game/engine';
|
||||
import { TERRITORIES } from '../game/board';
|
||||
import { traitorDeck } from '../game/traitors';
|
||||
import { validateNexusTraitorSnapshot } from '../game/nexus-traitor-exchange';
|
||||
import { nextHarkonnenBetrayalNativeStep, settleHarkonnenBetrayalNativeCounters } from './fixture-nexus-harkonnen-betrayal';
|
||||
|
||||
const act = (game: Game, actor: string, action: Action) => applyAction(game, actor, action);
|
||||
function player(game: Game, id: string) {
|
||||
const seat = game.players.find(p => p.id === id);
|
||||
assert.ok(seat);
|
||||
return seat;
|
||||
}
|
||||
function step(game: Game): Game {
|
||||
const next = nextHarkonnenBetrayalNativeStep(game);
|
||||
try { return act(game, next.actor, next.action); }
|
||||
catch (error) { throw Error(`Native Moritani step ${game.turn}/${game.phase}/${game.decision?.kind} ${JSON.stringify(next)}: ${String(error)}`); }
|
||||
}
|
||||
function advance(game: Game, until: (game: Game) => boolean): Game {
|
||||
for (let i = 0; i < 1800; i++) {
|
||||
if (until(game)) return game;
|
||||
assert.notEqual(game.status, 'finished', 'Unexpected victory during the staged battle');
|
||||
game = step(game);
|
||||
}
|
||||
throw Error(`Moritani journey stalled at ${game.status}/${game.turn}/${game.phase}/${game.decision?.kind}`);
|
||||
}
|
||||
function checkTraitors(game: Game): void {
|
||||
validateNexusTraitorSnapshot({ reserve: game.traitorReserve!, players: game.players.map(({id, faction, traitors, faceDancers}) =>
|
||||
({ id, faction, traitors, ...(faceDancers ? { faceDancers } : {}) })) }, traitorDeck(game.players));
|
||||
}
|
||||
/** Exchange an existing dealt card with its actual owner or reserve; never add a card. */
|
||||
function hold(game: Game, id: string, identity: string): void {
|
||||
const owner = player(game, id);
|
||||
if (owner.traitors.includes(identity)) return;
|
||||
const old = owner.traitors[0]; assert.ok(old);
|
||||
const other = game.players.find(p => p.id !== id && p.traitors.includes(identity));
|
||||
if (other) other.traitors[other.traitors.indexOf(identity)] = old;
|
||||
else {
|
||||
const index = game.traitorReserve!.indexOf(identity); assert.ok(index >= 0);
|
||||
game.traitorReserve![index] = old;
|
||||
}
|
||||
owner.traitors[0] = identity;
|
||||
}
|
||||
|
||||
/** Fresh public Advanced setup; only unopened Nexus/Spice ordering, conserved
|
||||
* dealt Traitor swaps and one reserve force on each side are staged. The real
|
||||
* second-turn Nexus closes, Moritani receives its face, and normal controls
|
||||
* choose the battle, seal plans, vote and resolve it. Harkonnen's strength-6
|
||||
* Feyd beats Moritani's strength-1 Vando with both forces undialed. */
|
||||
function beforeCall(): Game {
|
||||
let game = createGame('MORITANIREVEAL', newPlayer('m', 'Moritani', 'moritani'), true, ['ecaz']);
|
||||
for (const [id, faction] of [['h', 'harkonnen'], ['g', 'guild'], ['a', 'atreides']] as const)
|
||||
joinGame(game, newPlayer(id, faction, faction));
|
||||
game = act(game, 'm', {type:'moduleOption', module:'nexusCards', enabled:true});
|
||||
for (const seat of game.players) game = act(game, seat.id, {type:'ready'});
|
||||
game = act(game, 'm', {type:'start', advancedPreview:true});
|
||||
assert.equal(game.nexusHarkonnenBetrayalPreview, true);
|
||||
game = advance(game, g => g.status === 'playing');
|
||||
assert.equal(game.moritaniAssassinatePreview, true);
|
||||
hold(game, 'm', 'harkonnen-1');
|
||||
hold(game, 'h', 'moritani-4');
|
||||
checkTraitors(game);
|
||||
const nexus = game.nexusCards!.cards!, index = nexus.deck.indexOf('harkonnen');
|
||||
assert.ok(index >= 0);
|
||||
nexus.deck.unshift(nexus.deck.splice(index, 1)[0]);
|
||||
for (let pos = 0; pos < 2; pos++) {
|
||||
const i = game.spiceDeck.findIndex((card, n) => n >= pos && 'territory' in card); assert.ok(i >= pos);
|
||||
game.spiceDeck.splice(pos, 0, game.spiceDeck.splice(i, 1)[0]);
|
||||
}
|
||||
game = advance(game, g => g.turn === 2 && g.phase === 1 && !g.response && !g.decision);
|
||||
const worm = game.spiceDeck.findIndex(card => 'worm' in card && !card.greatMaker && !card.suppressed); assert.ok(worm >= 0);
|
||||
game.spiceDeck.unshift(game.spiceDeck.splice(worm, 1)[0]);
|
||||
game = advance(game, g => g.nexus && !g.spiceWindow && !g.spiceResolution && !g.response && !g.decision);
|
||||
game = act(game, 'h', {type:'alliance', target:'g'});
|
||||
game = act(game, 'g', {type:'alliance', target:'h'});
|
||||
game = advance(game, g => g.nexusCards?.phase?.stage === 'drawing');
|
||||
assert.ok(game.nexusCards!.phase!.eligible.includes('m'));
|
||||
game = act(game, 'm', {type:'nexusCardChoice', turn:game.turn, card:null, choice:'draw', ownRedraws:0});
|
||||
assert.equal(game.nexusCards!.cards!.hands.m, 'harkonnen');
|
||||
game = advance(game, g => g.phase === 5 && !g.response && !g.decision && !g.pendingGuildBetrayal);
|
||||
const territory = TERRITORIES.find(t => t.type === 'sand' && !t.sectors.includes(game.storm) &&
|
||||
game.players.every(p => !Object.keys(p.forces).some(key => key.startsWith(`${t.id}:`))));
|
||||
assert.ok(territory);
|
||||
for (const id of ['h', 'm']) {
|
||||
const seat = player(game, id); assert.ok(seat.reserves > 0);
|
||||
seat.reserves--; seat.forces[`${territory.id}:${territory.sectors[0]}`] = 1;
|
||||
}
|
||||
game = advance(game, g => g.phase === 6 && !!g.active && !g.phaseOpening && !g.response && !g.decision);
|
||||
const chooser = game.active!; assert.ok(['h', 'm'].includes(chooser));
|
||||
game = act(game, chooser, {type:'chooseBattle', territory:territory.id, target:chooser === 'h' ? 'm' : 'h'});
|
||||
game = advance(game, g => !!g.battle && !g.response && !g.decision && !g.battle.preparation &&
|
||||
(!g.battle.preLeader || g.battle.preLeader.closed));
|
||||
for (const id of [game.battle!.attacker, game.battle!.defender])
|
||||
game = act(game, id, {type:'battlePlan', dial:0, leader:id === 'h' ? 'harkonnen-0' : 'moritani-4'});
|
||||
assert.equal(game.battle!.revealed, true);
|
||||
return advance(game, g => !g.response && !g.decision);
|
||||
}
|
||||
|
||||
void test('a publicly revealed Harkonnen traitor canceled by Nexus still prevents Moritani assassination', () => {
|
||||
let game = beforeCall();
|
||||
const battleEvent = game.battle!.event;
|
||||
game = act(game, 'h', {type:'traitorCall', call:true});
|
||||
game = settleHarkonnenBetrayalNativeCounters(game);
|
||||
const reaction = viewGame(game, 'm').nexusHarkonnenBetrayalReaction; assert.ok(reaction?.canUse);
|
||||
assert.equal(reaction.identity, 'moritani-4');
|
||||
assert.ok(player(game, 'h').revealedTraitors?.includes('moritani-4'), 'The original call reveals the physical Traitor');
|
||||
game = act(game, 'm', {type:'nexusHarkonnenBetrayalUse', event:reaction.event});
|
||||
assert.equal(game.battle!.traitorCalls.h, false);
|
||||
assert.equal(game.pendingNexusHarkonnenReplacement?.status, 'due');
|
||||
for (let i = 0; i < 500 && game.turn === 2 && game.phase !== 8; i++) {
|
||||
assert.notEqual(game.decision?.kind, 'moritaniAssassinate', 'A canceled call does not make its revealed Traitor unseen');
|
||||
game = step(game);
|
||||
}
|
||||
assert.equal(game.phase, 8);
|
||||
assert.equal(game.lastBattleContext?.event, battleEvent);
|
||||
assert.equal(game.lastBattleContext?.result, 'normal');
|
||||
assert.equal(game.lastBattleContext?.winner, 'h');
|
||||
assert.deepEqual(game.moritaniAssassinate!.opportunities, []);
|
||||
assert.equal(game.nexusHarkonnenReplacementHistory!.length, 1);
|
||||
checkTraitors(game);
|
||||
});
|
||||
|
||||
void test('the same normal Moritani loss without a traitor reveal offers assassination', () => {
|
||||
let game = beforeCall();
|
||||
game = act(game, 'h', {type:'traitorCall', call:false});
|
||||
game = advance(game, g => g.decision?.kind === 'moritaniAssassinate');
|
||||
assert.equal(game.lastBattleContext?.result, 'normal');
|
||||
assert.equal(game.lastBattleContext?.winner, 'h');
|
||||
const offer = viewGame(game, 'm').moritaniAssassinate?.pending;
|
||||
assert.ok(offer);
|
||||
assert.ok(offer.cards.some(card => card.card === 'harkonnen-1'));
|
||||
assert.equal(game.nexusCards!.cards!.hands.m, 'harkonnen');
|
||||
assert.equal(game.pendingNexusHarkonnenReplacement, null);
|
||||
checkTraitors(game);
|
||||
});
|
||||
@@ -0,0 +1,47 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import test from 'node:test';
|
||||
import { leaders, treacheryDeck } from '../game/cards';
|
||||
import { NEXUS_FACTIONS, type NexusPlayer } from '../game/nexus-cards';
|
||||
import {
|
||||
closeHarkonnenBetrayalSource, createHarkonnenBetrayalSource, initialHarkonnenBetrayalCursor,
|
||||
validateHarkonnenBetrayalHistory, validateHarkonnenBetrayalSource,
|
||||
type HarkonnenBetrayalAuthority, type HarkonnenBetrayalContext,
|
||||
} from '../game/nexus-harkonnen-betrayal';
|
||||
import { createTraitorDeclaration } from '../game/traitor-declarations';
|
||||
import { traitorDeck } from '../game/traitors';
|
||||
|
||||
/** A source using the exact old two-plan context, including its original
|
||||
* physical snapshot and source constructor. This is helper compatibility, not
|
||||
* evidence of a resumed room or an independently reproduced Basic battle. */
|
||||
void test('the prior two-plan Harkonnen source remains readable and closable', () => {
|
||||
const players: NexusPlayer[] = [
|
||||
{id:'e', faction:'ecaz', ally:'g'},
|
||||
{id:'g', faction:'guild', ally:'e'},
|
||||
{id:'h', faction:'harkonnen', ally:null},
|
||||
{id:'a', faction:'atreides', ally:null},
|
||||
];
|
||||
const universe = traitorDeck(players.map(p => ({leaders:leaders(p.faction)})));
|
||||
const held = 'ecaz-0';
|
||||
const ctx: HarkonnenBetrayalContext = {
|
||||
status:'playing', phase:6, turn:2, advanced:false, sequence:0, expansions:['ecaz'],
|
||||
players, universe, physicalCards:treacheryDeck(['ecaz']),
|
||||
cards:{version:1, deck:NEXUS_FACTIONS.filter(id => id !== 'harkonnen'), discard:[],
|
||||
hands:Object.fromEntries(players.map(p => [p.id, p.id === 'a' ? 'harkonnen' : null]))},
|
||||
traitors:{reserve:universe.filter(id => id !== held),
|
||||
players:players.map(p => ({id:p.id, faction:p.faction, traitors:p.id === 'h' ? [held] : []}))},
|
||||
battle:{event:'old-basic-occupy-battle', attacker:'h', defender:'e',
|
||||
plans:{h:{leader:'harkonnen-0'}, e:{leader:held}}, heroLeaderIds:[]},
|
||||
};
|
||||
const declaration = createTraitorDeclaration({...ctx.battle,
|
||||
players:players.map(p => ({...p, traitors:p.id === 'h' ? [held] : []}))}, 'h');
|
||||
const authority: HarkonnenBetrayalAuthority = {provider:'h', declaration,
|
||||
nativeWindow:'direct', nativeContext:'original-native-context', nativeRequired:[], nativePassed:[]};
|
||||
const source = createHarkonnenBetrayalSource(ctx, authority, 'original-battle-parent');
|
||||
assert.equal(Object.hasOwn(source.battle, 'ecazOccupy'), false);
|
||||
const restored = JSON.parse(JSON.stringify(source)) as typeof source;
|
||||
validateHarkonnenBetrayalSource(ctx, restored, authority, 'original-battle-parent');
|
||||
const closed = closeHarkonnenBetrayalSource(restored, 'use', 'a', initialHarkonnenBetrayalCursor());
|
||||
validateHarkonnenBetrayalHistory([closed.receipt], closed.cursor, universe);
|
||||
assert.equal(closed.receipt.source.declaration.identity, held);
|
||||
assert.equal(closed.receipt.outcome, 'use');
|
||||
});
|
||||
@@ -0,0 +1,114 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import test from 'node:test';
|
||||
import { leaders, treacheryDeck } from '../game/cards';
|
||||
import { quoteEcazOccupyBattle } from '../game/ecaz-occupy-battle';
|
||||
import { NEXUS_FACTIONS, type NexusPlayer } from '../game/nexus-cards';
|
||||
import {
|
||||
closeHarkonnenBetrayalSource,
|
||||
createHarkonnenBetrayalSource,
|
||||
initialHarkonnenBetrayalCursor,
|
||||
validateHarkonnenBetrayalHistory,
|
||||
validateHarkonnenBetrayalSource,
|
||||
type HarkonnenBetrayalAuthority,
|
||||
type HarkonnenBetrayalContext,
|
||||
} from '../game/nexus-harkonnen-betrayal';
|
||||
import { createTraitorDeclaration } from '../game/traitor-declarations';
|
||||
import { traitorDeck } from '../game/traitors';
|
||||
|
||||
/** The original public alliance, actual traitor custody and complete Occupy
|
||||
* quote are retained in each source; no runtime battle is claimed here. */
|
||||
function fixture(side: 'ecaz-leads' | 'harkonnen-leads' | 'opposing' | 'external-ally') {
|
||||
const together = side === 'ecaz-leads' || side === 'harkonnen-leads';
|
||||
const external = side === 'external-ally';
|
||||
const players: NexusPlayer[] = [
|
||||
{ id: 'e', faction: 'ecaz', ally: together ? 'h' : 'g' },
|
||||
{ id: 'h', faction: 'harkonnen', ally: together ? 'e' : external ? 'a' : null },
|
||||
{ id: 'g', faction: 'guild', ally: together ? null : 'e' },
|
||||
{ id: 'a', faction: 'atreides', ally: external ? 'h' : null },
|
||||
...(external ? [{ id: 'f', faction: 'fremen' as const, ally: null }] : []),
|
||||
];
|
||||
const ally = together ? players[1] : players[2];
|
||||
const lead = side === 'harkonnen-leads' ? 'h' : 'e';
|
||||
const opposing = together ? 'g' : external ? 'a' : 'h';
|
||||
const identity = together ? 'guild-0' : 'ecaz-1';
|
||||
const holder = external ? 'f' : 'a';
|
||||
const ecazLoyalty = { player: 'e', card: 'ecaz-0' };
|
||||
const universe = traitorDeck(players.map(player => ({ leaders: leaders(player.faction) })))
|
||||
.filter(card => card !== ecazLoyalty.card);
|
||||
const forces = { normal: 4, elite: 0, eliteStrength: 2 as const, freeSupport: false };
|
||||
const occupy = quoteEcazOccupyBattle({ advanced: true, battleOrderActor: opposing,
|
||||
ecaz: { id: 'e', faction: 'ecaz', ally: ally.id, forces },
|
||||
ally: { id: ally.id, faction: ally.faction, ally: 'e', forces },
|
||||
lead, canceled: false });
|
||||
const ctx: HarkonnenBetrayalContext = {
|
||||
status: 'playing', phase: 6, turn: 2, advanced: true, sequence: 0,
|
||||
expansions: ['ecaz'], players, ecazLoyalty, universe,
|
||||
physicalCards: treacheryDeck(['ecaz']),
|
||||
cards: { version: 1, deck: NEXUS_FACTIONS.filter(card => card !== 'harkonnen'),
|
||||
discard: [], hands: Object.fromEntries(players.map(player => [player.id,
|
||||
player.id === holder ? 'harkonnen' : null])) },
|
||||
traitors: { reserve: universe.filter(card => card !== identity),
|
||||
players: players.map(player => ({ id: player.id, faction: player.faction,
|
||||
traitors: player.id === 'h' ? [identity] : [] })) },
|
||||
battle: { event: 'occupy-battle', attacker: lead, defender: opposing,
|
||||
plans: { [lead]: { leader: lead === 'h' ? 'harkonnen-0' : 'ecaz-1' },
|
||||
[opposing]: { leader: opposing === 'g' ? 'guild-0' : opposing === 'a' ? 'atreides-0' : 'harkonnen-0' } },
|
||||
heroLeaderIds: [], ecazOccupy: occupy },
|
||||
};
|
||||
const declaration = createTraitorDeclaration({ ...ctx.battle, players: players.map(player => ({ ...player,
|
||||
traitors: ctx.traitors.players.find(seat => seat.id === player.id)!.traitors })) }, 'h');
|
||||
const native: HarkonnenBetrayalAuthority = { provider: 'h', declaration,
|
||||
nativeWindow: external ? 'harkonnenTraitor' : 'direct', nativeContext: 'original-native-source',
|
||||
nativeRequired: external ? ['e'] : [], nativePassed: external ? ['e'] : [] };
|
||||
return { ctx, native, holder, identity };
|
||||
}
|
||||
|
||||
for (const side of ['ecaz-leads', 'harkonnen-leads', 'opposing', 'external-ally'] as const)
|
||||
void test(`Occupy ${side} preserves the canonical Harkonnen declaration and physical source`, () => {
|
||||
const { ctx, native, holder, identity } = fixture(side);
|
||||
const before = structuredClone(ctx);
|
||||
const source = createHarkonnenBetrayalSource(ctx, native, 'battle-parent');
|
||||
assert.equal(source.declaration.identity, identity);
|
||||
assert.equal(source.battle.ecazOccupy?.lead, ctx.battle.ecazOccupy?.lead);
|
||||
assert.equal(source.eligible, holder);
|
||||
validateHarkonnenBetrayalSource(ctx, source, native, 'battle-parent');
|
||||
const { receipt, cursor } = closeHarkonnenBetrayalSource(source, 'use', holder,
|
||||
initialHarkonnenBetrayalCursor());
|
||||
validateHarkonnenBetrayalHistory([receipt], cursor, ctx.universe);
|
||||
assert.deepEqual(ctx, before);
|
||||
});
|
||||
|
||||
void test('Occupy co-side calls never invent an allied Karama counter', () => {
|
||||
const { ctx, native } = fixture('ecaz-leads');
|
||||
assert.equal(native.declaration.beneficiary, 'e');
|
||||
assert.equal(native.declaration.voter, 'h');
|
||||
assert.throws(() => createHarkonnenBetrayalSource(ctx,
|
||||
{ ...native, nativeWindow: 'harkonnenTraitor' }, 'battle-parent'));
|
||||
assert.throws(() => createHarkonnenBetrayalSource(ctx,
|
||||
{ ...native, nativeRequired: ['a'], nativePassed: ['a'] }, 'battle-parent'));
|
||||
});
|
||||
|
||||
void test('Occupy external Harkonnen ally retains the completed native counter', () => {
|
||||
const { ctx, native } = fixture('external-ally');
|
||||
assert.throws(() => createHarkonnenBetrayalSource(ctx,
|
||||
{ ...native, nativeWindow: 'direct', nativeRequired: [], nativePassed: [] }, 'battle-parent'));
|
||||
assert.throws(() => createHarkonnenBetrayalSource(ctx,
|
||||
{ ...native, nativePassed: [] }, 'battle-parent'));
|
||||
});
|
||||
|
||||
void test('Occupy source rejects changed derived profile, rules band or original alliance', () => {
|
||||
const { ctx, native } = fixture('ecaz-leads');
|
||||
const source = createHarkonnenBetrayalSource(ctx, native, 'battle-parent');
|
||||
for (const altered of [
|
||||
{ ...ctx.battle.ecazOccupy!, fixedEcazDial: ctx.battle.ecazOccupy!.fixedEcazDial + 1 },
|
||||
{ ...ctx.battle.ecazOccupy!, forceOwner: 'e' },
|
||||
{ ...ctx.battle.ecazOccupy!, advanced: false },
|
||||
]) {
|
||||
const changed = { ...ctx, battle: { ...ctx.battle, ecazOccupy: altered } };
|
||||
assert.throws(() => createHarkonnenBetrayalSource(changed, native, 'battle-parent'));
|
||||
assert.throws(() => validateHarkonnenBetrayalSource(changed, source, native, 'battle-parent'));
|
||||
}
|
||||
const changedAlliance = { ...ctx, players: ctx.players.map(player => player.id === 'h'
|
||||
? { ...player, ally: null } : player) };
|
||||
assert.throws(() => createHarkonnenBetrayalSource(changedAlliance, native, 'battle-parent'));
|
||||
});
|
||||
@@ -0,0 +1,146 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import { test } from 'node:test';
|
||||
import { applyAction, createGame, joinGame, newPlayer, viewGame, type Action, type Game } from '../game/engine';
|
||||
import { TERRITORIES } from '../game/board';
|
||||
import { traitorDeck } from '../game/traitors';
|
||||
import { withoutEcazLoyalty } from '../game/ecaz-loyalty';
|
||||
import { validateNexusTraitorSnapshot } from '../game/nexus-traitor-exchange';
|
||||
import { nextHarkonnenBetrayalNativeStep, settleHarkonnenBetrayalNativeCounters } from './fixture-nexus-harkonnen-betrayal';
|
||||
|
||||
const act = (game: Game, actor: string, action: Action) => applyAction(game, actor, action);
|
||||
const seat = (game: Game, id: string) => { const player = game.players.find(p => p.id === id); assert.ok(player); return player; };
|
||||
|
||||
function step(game: Game): Game {
|
||||
const next = nextHarkonnenBetrayalNativeStep(game);
|
||||
try { return act(game, next.actor, next.action); }
|
||||
catch (error) { throw Error(`Native Occupy/Nexus ${game.turn}/${game.phase}/${game.decision?.kind} ${JSON.stringify(next)}: ${String(error)}`); }
|
||||
}
|
||||
function advance(game: Game, until: (game: Game) => boolean): Game {
|
||||
for (let i = 0; i < 1800; i++) {
|
||||
if (until(game)) return game;
|
||||
assert.notEqual(game.status, 'finished');
|
||||
game = step(game);
|
||||
}
|
||||
throw Error(`Native Occupy/Nexus stalled at ${game.status}/${game.turn}/${game.phase}/${game.decision?.kind}`);
|
||||
}
|
||||
function inventory(game: Game): string[] {
|
||||
return [...game.deck, ...game.discard, ...(game.auction?.cards.slice(game.auction.index) ?? []),
|
||||
...game.players.flatMap(player => player.hand)].map(card => card.id).sort();
|
||||
}
|
||||
function traitors(game: Game): void {
|
||||
validateNexusTraitorSnapshot({ reserve: game.traitorReserve!, players: game.players.map(({ id, faction, traitors, faceDancers }) =>
|
||||
({ id, faction, traitors, ...(faceDancers ? { faceDancers } : {}) })) },
|
||||
withoutEcazLoyalty(traitorDeck(game.players), game.ecazLoyalty));
|
||||
}
|
||||
/** Swap one original held or reserve card; never create a Traitor identity. */
|
||||
function stageTraitor(game: Game, identity: string): void {
|
||||
const owner = seat(game, 'h');
|
||||
if (owner.traitors.includes(identity)) return;
|
||||
const previous = owner.traitors[0]; assert.ok(previous);
|
||||
const holder = game.players.find(player => player.id !== 'h' && player.traitors.includes(identity));
|
||||
if (holder) holder.traitors[holder.traitors.indexOf(identity)] = previous;
|
||||
else {
|
||||
const index = game.traitorReserve!.indexOf(identity); assert.ok(index >= 0);
|
||||
game.traitorReserve![index] = previous;
|
||||
}
|
||||
owner.traitors[0] = identity;
|
||||
}
|
||||
|
||||
/** Actual public Advanced E3 setup, natural second-turn Nexus, reciprocal
|
||||
* alliance, Nexus draw, native Occupy lead, sealed plans and traitor call.
|
||||
* Only unopened Nexus/Spice deck order, one conserved held Traitor exchange
|
||||
* and one existing reserve force per battle participant are staged. */
|
||||
function fixture(side: 'ally' | 'opponent', lead: 'ecaz' | 'ally') {
|
||||
let game = createGame('HARKOCCUPY', newPlayer('e', 'Ecaz', 'ecaz'), true, ['ecaz']);
|
||||
for (const [id, faction] of [['h', 'harkonnen'], ['g', 'guild'], ['a', 'atreides']] as const)
|
||||
joinGame(game, newPlayer(id, faction, faction));
|
||||
game = act(game, 'e', { type: 'moduleOption', module: 'nexusCards', enabled: true });
|
||||
for (const p of game.players) game = act(game, p.id, { type: 'ready' });
|
||||
game = act(game, 'e', { type: 'start', advancedPreview: true });
|
||||
assert.equal(game.nexusHarkonnenBetrayalPreview, true);
|
||||
game = advance(game, state => state.status === 'playing');
|
||||
const cards = inventory(game); traitors(game);
|
||||
const nexus = game.nexusCards!.cards!, face = nexus.deck.indexOf('harkonnen'); assert.ok(face >= 0);
|
||||
nexus.deck.unshift(nexus.deck.splice(face, 1)[0]);
|
||||
for (let pos = 0; pos < 2; pos++) {
|
||||
const index = game.spiceDeck.findIndex((card, n) => n >= pos && 'territory' in card); assert.ok(index >= pos);
|
||||
game.spiceDeck.splice(pos, 0, game.spiceDeck.splice(index, 1)[0]);
|
||||
}
|
||||
game = advance(game, state => state.turn === 2 && state.phase === 1 && !state.response && !state.decision);
|
||||
const worm = game.spiceDeck.findIndex(card => 'worm' in card && !card.greatMaker && !card.suppressed); assert.ok(worm >= 0);
|
||||
game.spiceDeck.unshift(game.spiceDeck.splice(worm, 1)[0]);
|
||||
game = advance(game, state => state.nexus && !state.spiceWindow && !state.spiceResolution && !state.response && !state.decision);
|
||||
const ally = side === 'ally' ? 'h' : 'g';
|
||||
const opponent = side === 'ally' ? 'a' : 'h';
|
||||
const holder = side === 'ally' ? 'g' : 'a';
|
||||
game = act(game, 'e', { type: 'alliance', target: ally });
|
||||
game = act(game, ally, { type: 'alliance', target: 'e' });
|
||||
game = advance(game, state => state.nexusCards?.phase?.stage === 'drawing');
|
||||
assert.ok(game.nexusCards!.phase!.eligible.includes(holder));
|
||||
game = act(game, holder, { type: 'nexusCardChoice', turn: game.turn, card: null, choice: 'draw', ownRedraws: 0 });
|
||||
assert.equal(game.nexusCards!.cards!.hands[holder], 'harkonnen');
|
||||
game = advance(game, state => state.phase === 5 && !state.response && !state.decision);
|
||||
const territory = TERRITORIES.find(t => t.type === 'sand' && !t.sectors.includes(game.storm) &&
|
||||
game.players.every(p => !Object.keys(p.forces).some(key => key.startsWith(`${t.id}:`)))); assert.ok(territory);
|
||||
for (const id of ['e', ally, opponent]) {
|
||||
const p = seat(game, id); assert.ok(p.reserves > 0); p.reserves--;
|
||||
p.forces[`${territory.id}:${territory.sectors[0]}`] = 1;
|
||||
}
|
||||
game = advance(game, state => state.phase === 6 && !!state.active && !state.phaseOpening && !state.response && !state.decision);
|
||||
const choice = viewGame(game, game.active!).battleChoices.find(item => item.territory === territory.id); assert.ok(choice);
|
||||
game = act(game, choice.chooser, { type: 'chooseBattle', territory: territory.id,
|
||||
target: choice.attacker === choice.chooser ? choice.defender : choice.attacker });
|
||||
const decision = game.decision;
|
||||
assert.ok(decision?.kind === 'ecazBattleLead');
|
||||
game = act(game, 'e', { type: 'decision', event: decision.event, lead: lead === 'ecaz' ? 'e' : ally });
|
||||
// Public Nexus setup may retain ordinary pre-leader or other native battle
|
||||
// decisions after the Occupy lead and counter. Drive each original window;
|
||||
// the standalone Occupy helper assumes those windows are already absent.
|
||||
game = advance(game, state => !!state.battle && !state.response && !state.decision &&
|
||||
!state.battle.preparation && (!state.battle.preLeader || state.battle.preLeader.closed));
|
||||
assert.ok(game.battle?.ecazOccupy);
|
||||
const actor = lead === 'ecaz' ? 'e' : ally;
|
||||
const target = side === 'ally' ? opponent : actor;
|
||||
const identity = seat(game, target).leaders.find(leader => !leader.dead && !leader.usedAt &&
|
||||
leader.id !== game.ecazLoyalty?.card)!.id;
|
||||
stageTraitor(game, identity); traitors(game);
|
||||
const profile = viewGame(game, actor).battle!.ecazOccupy!.profile!;
|
||||
for (const id of [game.battle!.attacker, game.battle!.defender]) {
|
||||
const leader = id === target ? identity : seat(game, id).leaders.find(l => !l.dead && !l.usedAt)!.id;
|
||||
game = act(game, id, { type: 'battlePlan', dial: id === actor ? profile.fixedEcazDial : 0, leader });
|
||||
}
|
||||
assert.equal(game.battle!.revealed, true);
|
||||
game = advance(game, state => !state.response && !state.decision);
|
||||
game = act(game, 'h', { type: 'traitorCall', call: true });
|
||||
game = settleHarkonnenBetrayalNativeCounters(game);
|
||||
const reaction = viewGame(game, holder).nexusHarkonnenBetrayalReaction;
|
||||
assert.ok(reaction, 'A genuine Occupy Harkonnen call must offer the held Nexus.');
|
||||
assert.equal(reaction.identity, identity);
|
||||
assert.equal(reaction.target, target);
|
||||
assert.equal(reaction.beneficiary, side === 'ally' ? actor : 'h');
|
||||
assert.equal(reaction.canUse, true);
|
||||
assert.deepEqual(inventory(game), cards); traitors(game);
|
||||
return { game, holder, identity, event: reaction.event, cards };
|
||||
}
|
||||
|
||||
for (const side of ['ally', 'opponent'] as const) for (const lead of ['ecaz', 'ally'] as const)
|
||||
for (const use of [false, true])
|
||||
void test(`Advanced Ecaz Occupy, Harkonnen ${side}, ${lead} lead: native Nexus ${use ? 'Use' : 'Pass'}`, () => {
|
||||
const f = fixture(side, lead); let game = f.game;
|
||||
if (use) game = act(game, f.holder, { type: 'nexusHarkonnenBetrayalUse', event: f.event });
|
||||
else for (const id of game.pendingNexusHarkonnenBetrayal!.required)
|
||||
game = act(game, id, { type: 'nexusHarkonnenBetrayalPass', event: f.event });
|
||||
assert.equal(game.pendingNexusHarkonnenBetrayal, null);
|
||||
assert.equal(game.battle!.traitorCalls.h, !use);
|
||||
assert.equal(seat(game, 'h').traitors.includes(f.identity), !use);
|
||||
assert.equal(game.pendingNexusHarkonnenReplacement?.status ?? null, use ? 'due' : null);
|
||||
assert.equal(game.nexusCards!.cards!.hands[f.holder], use ? null : 'harkonnen');
|
||||
assert.deepEqual(inventory(game), f.cards); traitors(game);
|
||||
const top = game.traitorReserve![0];
|
||||
game = advance(game, state => state.phase === 8 && !state.pendingNexusHarkonnenReplacement && !state.phaseOpening);
|
||||
assert.equal(game.lastBattleContext!.result, use ? 'normal' : 'traitor');
|
||||
assert.equal(game.nexusHarkonnenReplacementHistory!.length, use ? 1 : 0);
|
||||
if (use) assert.equal(game.nexusHarkonnenReplacementHistory![0].drawn, top);
|
||||
assert.equal(seat(game, 'h').traitors.length, 4);
|
||||
assert.deepEqual(inventory(game), f.cards); traitors(game);
|
||||
});
|
||||
Reference in new issue
Block a user