Offer Semuta on clean early-ended Ornithopter discard
This commit is contained in:
1 parent
0e9945e333
commit
2ec0422b79
8 files changed
+170
-38
No files matched your search
@@ -212,3 +212,54 @@ void test('a completed paid Box discard can be claimed before resumption without
|
||||
assert.deepEqual(viewGame(reload(claimed), p.id), viewGame(claimed, p.id));
|
||||
assert.deepEqual(normalizeAutomaticGame(reload(claimed)), reload(claimed));
|
||||
});
|
||||
|
||||
void test('a retired Ornithopter can be claimed after one flight group without replaying movement', () => {
|
||||
const { g, semuta, hajr } = fixture();
|
||||
player(g, 'a').hand = [];
|
||||
g.deck.push(hajr);
|
||||
const ornithopter = take(g, 'richese-ornithopter');
|
||||
player(g, 'a').hand.push(ornithopter);
|
||||
player(g, 'a').forces = { 'imperial_basin:10': 3 };
|
||||
player(g, 'a').reserves = 17;
|
||||
player(g, 'a').shipped = true;
|
||||
const original = inventory(g);
|
||||
const first = applyAction(g, 'a', {
|
||||
type: 'move', movementCard: ornithopter.id, ornithopter: 'twoGroups',
|
||||
forces: { 'imperial_basin:10': 1 }, territory: 'arrakeen', sector: 10,
|
||||
});
|
||||
assert.equal(first.ornithopter?.completed, 1);
|
||||
assert.equal(first.discard.some(card => card.id === ornithopter.id), false);
|
||||
const pending = applyAction(first, 'a', { type: 'endMovement' });
|
||||
assert.equal(pending.ornithopter, null);
|
||||
assert.equal(pending.pendingTreacheryDiscard?.continuation.kind, 'ornithopterDiscard');
|
||||
assert.equal(pending.pendingTreacheryDiscard?.reaction?.stage, 'offer');
|
||||
assert.equal(pending.discard.filter(card => card.id === ornithopter.id).length, 1);
|
||||
assert.equal(pending.active, 'a');
|
||||
assert.deepEqual(pending.movementRemaining, ['a', 'r', 'e']);
|
||||
const event = pending.pendingTreacheryDiscard!.batch.event;
|
||||
assert.equal(viewGame(pending, 'r').semutaReaction?.canCommit, true);
|
||||
assert.equal(viewGame(pending, 'a').semutaReaction?.canCommit, false);
|
||||
assert.deepEqual(normalizeAutomaticGame(reload(pending)), reload(pending));
|
||||
let declined = reload(pending);
|
||||
for (const id of ['e', 'a', 'r'])
|
||||
declined = applyAction(declined, id, { type: 'semutaPass', event });
|
||||
assert.equal(declined.pendingTreacheryDiscard, null);
|
||||
assert.equal(declined.active, 'r');
|
||||
assert.deepEqual(declined.movementRemaining, ['r', 'e']);
|
||||
assert.equal(declined.discard.filter(card => card.id === ornithopter.id).length, 1);
|
||||
const claimed = applyAction(reload(pending), 'r', botActions(viewGame(pending, 'r'))[0]!);
|
||||
assert.equal(claimed.pendingTreacheryDiscard, null);
|
||||
assert.equal(claimed.active, 'r');
|
||||
assert.deepEqual(claimed.movementRemaining, ['r', 'e']);
|
||||
assert.equal(player(claimed, 'a').moved, 1);
|
||||
assert.equal(player(claimed, 'a').forces['arrakeen:10'], 1);
|
||||
assert.equal(player(claimed, 'a').forces['imperial_basin:10'], 2);
|
||||
assert.equal(player(claimed, 'r').hand.filter(card => card.id === ornithopter.id).length, 1);
|
||||
assert.equal(claimed.discard.filter(card => card.id === semuta.id).length, 1);
|
||||
assert.equal(claimed.discard.some(card => card.id === ornithopter.id), false);
|
||||
assert.deepEqual(inventory(claimed), original);
|
||||
for (const p of claimed.players)
|
||||
assert.deepEqual(viewGame(reload(claimed), p.id), viewGame(claimed, p.id));
|
||||
assert.deepEqual(normalizeAutomaticGame(reload(claimed)), reload(claimed));
|
||||
assert.throws(() => applyAction(claimed, 'r', { type: 'semutaCommit', event }));
|
||||
});
|
||||
@@ -129,5 +129,50 @@ void test('authenticated ordinary and paid-Box discards preserve one Semuta clai
|
||||
assert.deepEqual(f.sqlite.prepare('SELECT * FROM seats').all(), originalSeats);
|
||||
for (const auth of auths)
|
||||
assert.deepEqual(await f.restart().readSeatView(code, auth), viewGame(claimedBox, auth.playerId));
|
||||
|
||||
const flight = structuredClone(claimedBox);
|
||||
const reusableSemuta = take(flight, SEMUTA_DRUG_ID);
|
||||
const ornithopter = take(flight, 'richese-ornithopter');
|
||||
seat(flight, ids[0]).hand.push(reusableSemuta);
|
||||
seat(flight, ids[1]).hand.push(ornithopter);
|
||||
const pilot = seat(flight, ids[1]);
|
||||
pilot.reserves += Object.values(pilot.forces).reduce((sum, n) => sum + n, 0) - 3;
|
||||
pilot.forces = { 'imperial_basin:10': 3 };
|
||||
pilot.shipped = true;
|
||||
pilot.moved = 0;
|
||||
flight.hajr = [];
|
||||
Object.assign(flight, { turn: 4, phase: 5, active: ids[1], storm: 18,
|
||||
ready: [], decision: null, response: null, phaseOpening: null,
|
||||
stormPending: null, movementRemaining: [ids[1], ids[0], ids[2]] });
|
||||
flight.version = claimedBox.version + 1;
|
||||
assert.equal(f.sqlite.prepare('UPDATE rooms SET state=?,version=? WHERE code=? AND version=?')
|
||||
.run(JSON.stringify(flight), flight.version, code, claimedBox.version).changes, 1);
|
||||
const moved = await act(1, { type: 'move', movementCard: ornithopter.id,
|
||||
ornithopter: 'twoGroups', forces: { 'imperial_basin:10': 1 },
|
||||
territory: 'arrakeen', sector: 10 });
|
||||
assert.equal(moved.ornithopter?.completed, 1);
|
||||
const retired = await act(1, { type: 'endMovement' });
|
||||
const flightEvent = retired.pendingTreacheryDiscard?.batch.event;
|
||||
assert.equal(retired.pendingTreacheryDiscard?.reaction?.stage, 'offer');
|
||||
assert.ok(flightEvent);
|
||||
assert.equal(retired.active, ids[1]);
|
||||
await f.restart().continueRoomAutomatic(code, clock);
|
||||
assert.equal((await f.restart().readRoom(code)).version, retired.version);
|
||||
const flightOwner = await f.restart().readSeatView(code, auths[0]);
|
||||
const flightObserver = await f.restart().readSeatView(code, auths[2]);
|
||||
assert.equal(flightOwner.semutaReaction?.canCommit, true);
|
||||
assert.equal(flightObserver.semutaReaction?.canCommit, false);
|
||||
const flown = await act(0, { type: 'semutaCommit', event: flightEvent });
|
||||
assert.equal(flown.pendingTreacheryDiscard, null);
|
||||
assert.equal(flown.active, ids[0]);
|
||||
assert.deepEqual(flown.movementRemaining, [ids[0], ids[2]]);
|
||||
assert.equal(seat(flown, ids[1]).moved, 1);
|
||||
assert.equal(seat(flown, ids[1]).forces['arrakeen:10'], 1);
|
||||
assert.equal(seat(flown, ids[0]).hand.filter(card => card.id === ornithopter.id).length, 1);
|
||||
assert.equal(flown.discard.filter(card => card.id === SEMUTA_DRUG_ID).length, 1);
|
||||
assert.equal(flown.discard.some(card => card.id === ornithopter.id), false);
|
||||
assert.deepEqual(f.sqlite.prepare('SELECT * FROM seats').all(), originalSeats);
|
||||
for (const auth of auths)
|
||||
assert.deepEqual(await f.restart().readSeatView(code, auth), viewGame(flown, auth.playerId));
|
||||
} finally { f.sqlite.close(); }
|
||||
});
|
||||
Reference in new issue
Block a user