Offer Semuta after proactive CHOAM Baliset discard
This commit is contained in:
1 parent
faebab9a3a
commit
756af19d18
7 files changed
+300
-16
No files matched your search
@@ -5,6 +5,7 @@ import {
|
||||
createGame,
|
||||
newPlayer,
|
||||
viewGame,
|
||||
normalizeAutomaticGame,
|
||||
type Game,
|
||||
type Action,
|
||||
} from '../game/engine';
|
||||
@@ -12,6 +13,8 @@ import { baseDeck } from '../game/cards';
|
||||
import { TERRITORIES, gameDistance, splitLocation } from '../game/board';
|
||||
import { botActions } from '../game/bots';
|
||||
import { DIFFICULTIES } from '../game/bot-profiles';
|
||||
import { richeseCards } from '../game/richese-cards';
|
||||
import { SEMUTA_DRUG_ID } from '../game/semuta-drug';
|
||||
const p = (g: Game, id: string) => g.players.find((p) => p.id === id)!;
|
||||
const send = (g: Game, id: string, a: Action) => applyAction(g, id, a);
|
||||
function hold(g: Game, id: string, name: string) {
|
||||
@@ -183,6 +186,77 @@ void test('proactive Baliset restricts only the selected player and territory',
|
||||
g.active = 'e';
|
||||
assert.throws(() => move(g), /Baliset prevents/);
|
||||
});
|
||||
void test('clean proactive Baliset discard offers Semuta before one territory restriction', () => {
|
||||
const initial = fixture();
|
||||
initial.players[1] = newPlayer('e', 'Richese', 'richese');
|
||||
p(initial, 'e').forces = { 'red_chasm:7': 3 };
|
||||
p(initial, 'e').reserves = 17;
|
||||
initial.richeseCache = richeseCards();
|
||||
initial.semutaPreview = true;
|
||||
const index = initial.richeseCache.findIndex(card => card.id === SEMUTA_DRUG_ID);
|
||||
assert.ok(index >= 0);
|
||||
const semuta = initial.richeseCache.splice(index, 1)[0];
|
||||
p(initial, 'e').hand.push(semuta);
|
||||
contest(initial, 'b');
|
||||
const card = p(initial, 'c').hand.find(card => card.name === 'Baliset')!.id;
|
||||
const territory = dest(initial).territory;
|
||||
const physical = (state: Game) => [
|
||||
...state.deck, ...state.discard, ...state.richeseCache!,
|
||||
...state.players.flatMap(player => player.hand),
|
||||
].map(card => card.id).sort();
|
||||
const original = physical(initial);
|
||||
const absent = structuredClone(initial);
|
||||
p(absent, 'e').hand = [absent.richeseCache!.splice(0, 1)[0]];
|
||||
absent.richeseCache!.push(semuta);
|
||||
const pending = allow(play(initial)), neutral = allow(play(absent));
|
||||
const event = pending.pendingTreacheryDiscard!.batch.event;
|
||||
assert.equal(pending.pendingTreacheryDiscard?.continuation.kind, 'choamBalisetDiscard');
|
||||
assert.equal(pending.pendingTreacheryDiscard?.reaction?.stage, 'offer');
|
||||
assert.equal(neutral.pendingTreacheryDiscard?.reaction?.stage, 'offer');
|
||||
assert.equal(pending.choamBaliset, undefined);
|
||||
assert.equal(pending.discard.filter(used => used.id === card).length, 1);
|
||||
assert.deepEqual(viewGame(pending, 'c'), viewGame(neutral, 'c'));
|
||||
assert.deepEqual(viewGame(pending, 'b'), viewGame(neutral, 'b'));
|
||||
assert.equal(viewGame(pending, 'e').semutaReaction?.canCommit, true);
|
||||
assert.equal(botActions(viewGame(pending, 'e'))[0]?.type, 'semutaCommit');
|
||||
assert.deepEqual(normalizeAutomaticGame(JSON.parse(JSON.stringify(pending))), pending);
|
||||
for (const change of [
|
||||
(state: Game) => {
|
||||
const c = state.pendingTreacheryDiscard!.continuation;
|
||||
if (c.kind === 'choamBalisetDiscard') c.territory = 'red_chasm';
|
||||
},
|
||||
(state: Game) => {
|
||||
const c = state.pendingTreacheryDiscard!.continuation;
|
||||
if (c.kind === 'choamBalisetDiscard') c.target = 'b';
|
||||
},
|
||||
(state: Game) => { p(state, 'c').forces = {}; },
|
||||
(state: Game) => { state.choamBaliset = [{ turn: state.turn, player: 'e', territory }]; },
|
||||
(state: Game) => { state.pendingTreacheryDiscard!.batch.entries[0].card.name = 'Forgery'; },
|
||||
]) {
|
||||
const corrupt: Game = JSON.parse(JSON.stringify(pending));
|
||||
change(corrupt);
|
||||
const before = JSON.stringify(corrupt);
|
||||
assert.throws(() => send(corrupt, 'e', { type: 'semutaCommit', event }));
|
||||
assert.equal(JSON.stringify(corrupt), before);
|
||||
}
|
||||
let declined: Game = JSON.parse(JSON.stringify(pending));
|
||||
for (const id of ['c', 'b', 'e'])
|
||||
declined = send(declined, id, { type: 'semutaPass', event });
|
||||
const claimed = send(JSON.parse(JSON.stringify(pending)), 'e',
|
||||
{ type: 'semutaCommit', event });
|
||||
for (const state of [declined, claimed]) {
|
||||
assert.equal(state.pendingTreacheryDiscard, null);
|
||||
assert.deepEqual(state.choamBaliset, [{ turn: state.turn, player: 'e', territory }]);
|
||||
assert.equal(viewGame(state, 'e').balisetRestrictions.length, 1);
|
||||
assert.throws(() => move(state), /Baliset prevents/);
|
||||
assert.deepEqual(physical(state), original);
|
||||
assert.throws(() => send(state, 'e', { type: 'semutaCommit', event }));
|
||||
}
|
||||
assert.equal(declined.discard.filter(used => used.id === card).length, 1);
|
||||
assert.equal(p(claimed, 'e').hand.filter(used => used.id === card).length, 1);
|
||||
assert.equal(claimed.discard.filter(used => used.id === semuta.id).length, 1);
|
||||
});
|
||||
|
||||
void test('Baliset permits ordinary shipment into the restricted territory', () => {
|
||||
let g = allow(play(fixture()));
|
||||
g = send(g, 'e', { type: 'ship', amount: 1, ...dest(g) });
|
||||
|
||||
@@ -9,6 +9,7 @@ import { richeseCards } from '../game/richese-cards';
|
||||
import { newRevivalRules } from '../game/revival';
|
||||
import { unitStore } from './fixture-nexus-room-store';
|
||||
import { saphoAggressorGame, aggressorAction } from './fixture-sapho-aggressor';
|
||||
import { TERRITORIES, gameDistance, splitLocation } from '../game/board';
|
||||
import { takeSaphoBattleCard } from './fixture-sapho-battle-order';
|
||||
|
||||
const clock = { now: () => 10000, sleep: async () => {} };
|
||||
@@ -955,6 +956,95 @@ void test('authenticated Kulon Semuta offer restores one movement bonus across r
|
||||
} finally { f.sqlite.close(); }
|
||||
});
|
||||
|
||||
void test('authenticated proactive Baliset Semuta claim restores only the selected movement restriction', async () => {
|
||||
const f = unitStore();
|
||||
try {
|
||||
const made = await f.rooms.createRoom('Semuta Baliset', 'choam', false, ['choam']);
|
||||
const code = made.view.code;
|
||||
const richese = await f.rooms.joinRoom(code, 'Richese', 'richese');
|
||||
const bg = await f.rooms.joinRoom(code, 'BG', 'beneGesserit');
|
||||
const auths = await Promise.all([made.token!, richese.token!, bg.token!]
|
||||
.map(token => f.restart().authenticate(code, token)));
|
||||
const existing = await f.restart().readRoom(code);
|
||||
const g = createGame(code, newPlayer(auths[0].playerId, 'CHOAM', 'choam'), false, ['choam']);
|
||||
g.players.push(newPlayer(auths[1].playerId, 'Richese', 'richese'),
|
||||
newPlayer(auths[2].playerId, 'BG', 'beneGesserit'));
|
||||
Object.assign(g, { status: 'playing', phase: 5, turn: 2, storm: 18,
|
||||
active: auths[1].playerId, order: auths.map(auth => auth.playerId),
|
||||
movementRemaining: auths.map(auth => auth.playerId), deck: baseDeck(),
|
||||
richeseCache: richeseCards(), semutaPreview: true });
|
||||
for (const p of g.players) {
|
||||
p.spice = 10;
|
||||
p.hand = [];
|
||||
p.traitors = p.leaders.length ? [p.leaders[0].id] : [];
|
||||
p.traitorChoices = [];
|
||||
}
|
||||
const semuta = take(g, SEMUTA_DRUG_ID), karama = take(g, 'karama');
|
||||
const index = g.deck.findIndex(card => card.name === 'Baliset');
|
||||
assert.ok(index >= 0);
|
||||
const used = g.deck.splice(index, 1)[0];
|
||||
const key = TERRITORIES.flatMap(t => t.sectors.map(s => `${t.id}:${s}`))
|
||||
.find(key => splitLocation(key).territory !== 'red_chasm' &&
|
||||
splitLocation(key).sector !== 18 &&
|
||||
gameDistance(g, 'red_chasm:7', key,
|
||||
k => splitLocation(k).sector === 18) === 1)!;
|
||||
assert.ok(key);
|
||||
const location = splitLocation(key);
|
||||
g.players[0].hand.push(used);
|
||||
g.players[0].forces = { [key]: 1 };
|
||||
g.players[0].reserves = 19;
|
||||
g.players[1].hand.push(semuta);
|
||||
g.players[1].forces = { 'red_chasm:7': 3 };
|
||||
g.players[1].reserves = 17;
|
||||
g.players[2].hand.push(karama);
|
||||
g.version = existing.version + 1;
|
||||
assert.equal(f.sqlite.prepare('UPDATE rooms SET state=?,version=? WHERE code=? AND version=?')
|
||||
.run(JSON.stringify(g), g.version, code, existing.version).changes, 1);
|
||||
const seats = f.sqlite.prepare('SELECT * FROM seats').all();
|
||||
const act = async (index: number, action: Action) => {
|
||||
const current = await f.restart().readRoom(code);
|
||||
await f.restart().act(code, auths[index], current.version, action, clock);
|
||||
return f.restart().readRoom(code);
|
||||
};
|
||||
let current = await act(0, {
|
||||
type: 'card', mode: 'choam', card: used.id,
|
||||
target: auths[1].playerId, territory: location.territory,
|
||||
});
|
||||
assert.equal(current.response?.kind, 'choamWorthless');
|
||||
for (let i = 0; current.response?.kind === 'choamWorthless' && i < 3; i++) {
|
||||
const index = auths.findIndex(auth =>
|
||||
!viewGame(current, auth.playerId).responseControls?.hasPassed &&
|
||||
!!viewGame(current, auth.playerId).responseControls?.cancelCards.length);
|
||||
assert.ok(index >= 0);
|
||||
current = await act(index, { type: 'passResponse' });
|
||||
}
|
||||
const event = current.pendingTreacheryDiscard!.batch.event;
|
||||
assert.equal(current.pendingTreacheryDiscard?.continuation.kind, 'choamBalisetDiscard');
|
||||
assert.equal(current.pendingTreacheryDiscard?.reaction?.stage, 'offer');
|
||||
assert.equal(current.choamBaliset, undefined);
|
||||
assert.equal(current.discard.filter(card => card.id === used.id).length, 1);
|
||||
await f.restart().continueRoomAutomatic(code, clock);
|
||||
assert.equal((await f.restart().readRoom(code)).version, current.version);
|
||||
assert.equal((await f.restart().readSeatView(code, auths[1])).semutaReaction?.canCommit, true);
|
||||
const claimed = await act(1, { type: 'semutaCommit', event });
|
||||
assert.equal(claimed.pendingTreacheryDiscard, null);
|
||||
assert.deepEqual(claimed.choamBaliset,
|
||||
[{ turn: 2, player: auths[1].playerId, territory: location.territory }]);
|
||||
assert.equal(claimed.players[1].hand.filter(card => card.id === used.id).length, 1);
|
||||
assert.equal(claimed.discard.filter(card => card.id === semuta.id).length, 1);
|
||||
await assert.rejects(f.restart().act(code, auths[1], current.version,
|
||||
{ type: 'semutaCommit', event }, clock));
|
||||
assert.deepEqual(f.sqlite.prepare('SELECT * FROM seats').all(), seats);
|
||||
for (const auth of auths)
|
||||
assert.deepEqual(await f.restart().readSeatView(code, auth), viewGame(claimed, auth.playerId));
|
||||
const before = await f.restart().readRoom(code);
|
||||
await assert.rejects(f.restart().act(code, auths[1], before.version, {
|
||||
type: 'move', from: 'red_chasm:7', amount: 1, ...location,
|
||||
}, clock), /Baliset prevents/);
|
||||
assert.deepEqual(await f.restart().readRoom(code), before);
|
||||
} finally { f.sqlite.close(); }
|
||||
});
|
||||
|
||||
void test('authenticated CHOAM sale retains paid spice and market after a saved Semuta claim', async () => {
|
||||
const f = unitStore();
|
||||
try {
|
||||
|
||||
Reference in new issue
Block a user