Offer Semuta after clean BG Charity Karama cost
This commit is contained in:
1 parent
6de75a7d78
commit
ebfae0f803
10 files changed
+201
-48
No files matched your search
@@ -151,6 +151,40 @@ void test('prior-turn CHOAM Charity receipt does not block a fresh Karama Semuta
|
||||
assert.equal(resumed.players[0].spice, 0);
|
||||
});
|
||||
|
||||
void test('clean BG charity Karama cancellation offers Semuta without awarding extra charity', () => {
|
||||
let g = fixture(true);
|
||||
g.players[1] = newPlayer('e', 'Richese', 'richese');
|
||||
g.richeseCache = richeseCards();
|
||||
g.semutaPreview = true;
|
||||
const semuta = g.richeseCache.findIndex(c => c.id === SEMUTA_DRUG_ID);
|
||||
assert.ok(semuta >= 0);
|
||||
g.players[0].hand.push(g.richeseCache.splice(semuta, 1)[0]);
|
||||
g = allow(ready(g));
|
||||
contest(g);
|
||||
g.players[2].spice = 12;
|
||||
g = applyAction(g, 'b', { type: 'charity' });
|
||||
assert.equal(g.response?.kind, 'bgCharity');
|
||||
assert.equal(viewGame(g, 'b').players[2].charityClaimed, true);
|
||||
const beforeSpice = g.players.map(p => p.spice);
|
||||
g = cancel(g);
|
||||
const event = g.pendingTreacheryDiscard!.batch.event;
|
||||
assert.equal(g.pendingTreacheryDiscard?.reaction?.stage, 'offer');
|
||||
assert.equal(g.response, null);
|
||||
assert.equal(viewGame(g, 'c').semutaReaction?.canCommit, true);
|
||||
assert.equal(viewGame(g, 'b').semutaReaction?.canCommit, false);
|
||||
let declined: Game = JSON.parse(JSON.stringify(g));
|
||||
for (const id of ['c', 'e', 'b'])
|
||||
declined = applyAction(declined, id, { type: 'semutaPass', event });
|
||||
assert.equal(declined.pendingTreacheryDiscard, null);
|
||||
assert.deepEqual(declined.players.map(p => p.spice), beforeSpice);
|
||||
const claimed = applyAction(JSON.parse(JSON.stringify(g)), 'c', { type: 'semutaCommit', event });
|
||||
assert.equal(claimed.pendingTreacheryDiscard, null);
|
||||
assert.deepEqual(claimed.players.map(p => p.spice), beforeSpice);
|
||||
assert.equal(claimed.players[0].hand.filter(c => c.effect === 'karama').length, 1);
|
||||
assert.equal(claimed.discard.filter(c => c.id === SEMUTA_DRUG_ID).length, 1);
|
||||
assert.equal(viewGame(claimed, 'b').players[2].charityClaimed, true);
|
||||
});
|
||||
|
||||
void test('CHOAM receives two spice per faction, including itself, only after its opening response', () => {
|
||||
const initial = contest(fixture());
|
||||
let g = ready(initial);
|
||||
|
||||
@@ -847,3 +847,76 @@ void test('authenticated printed Karama cost suspends CHOAM Inflation placement
|
||||
assert.deepEqual(await f.restart().readSeatView(code, auth), viewGame(claimed, auth.playerId));
|
||||
} finally { f.sqlite.close(); }
|
||||
});
|
||||
|
||||
void test('authenticated BG Charity Karama cost restores one canceled extra allowance', async () => {
|
||||
const f = unitStore();
|
||||
try {
|
||||
const made = await f.rooms.createRoom('Semuta BG Charity', 'choam', true, ['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);
|
||||
let g = createGame(code, newPlayer(auths[0].playerId, 'CHOAM', 'choam'), true, ['choam']);
|
||||
g.players.push(newPlayer(auths[1].playerId, 'Richese', 'richese'),
|
||||
newPlayer(auths[2].playerId, 'BG', 'beneGesserit'));
|
||||
Object.assign(g, {
|
||||
status: 'playing', phase: 1, nexus: true,
|
||||
order: g.players.map(p => p.id), deck: baseDeck(),
|
||||
richeseCache: richeseCards(), semutaPreview: true,
|
||||
});
|
||||
for (const player of g.players) {
|
||||
player.spice = 0;
|
||||
player.hand = [];
|
||||
player.traitors = player.leaders.length ? [player.leaders[0].id] : [];
|
||||
player.traitorChoices = [];
|
||||
}
|
||||
const karama = take(g, 'karama');
|
||||
g.players[1].hand.push(karama);
|
||||
const semuta = take(g, SEMUTA_DRUG_ID);
|
||||
g.players[0].hand.push(semuta);
|
||||
for (const player of g.players)
|
||||
g = applyAction(g, player.id, { type: 'ready' });
|
||||
while (g.decision?.kind === 'choamMarket')
|
||||
g = applyAction(g, g.decision.player, { type: 'decision', done: true });
|
||||
while (g.response) {
|
||||
const owner = g.players.find(p => {
|
||||
const controls = viewGame(g, p.id).responseControls;
|
||||
return controls?.cancelCards.length && !controls.hasPassed;
|
||||
});
|
||||
assert.ok(owner);
|
||||
g = applyAction(g, owner.id, { type: 'passResponse' });
|
||||
}
|
||||
assert.deepEqual(g.choamCharity, { turn: 1, canceled: false });
|
||||
g.players[2].spice = 12;
|
||||
g = applyAction(g, auths[2].playerId, { type: 'charity' });
|
||||
assert.equal(g.response?.kind, 'bgCharity');
|
||||
const balances = g.players.map(p => p.spice);
|
||||
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 before = await f.restart().readRoom(code);
|
||||
await f.restart().act(code, auths[index], before.version, action, clock);
|
||||
return f.restart().readRoom(code);
|
||||
};
|
||||
const pending = await act(1, { type: 'card', card: karama.id, mode: 'cancel' });
|
||||
assert.equal(pending.pendingTreacheryDiscard?.reaction?.stage, 'offer');
|
||||
const event = pending.pendingTreacheryDiscard!.batch.event;
|
||||
await f.restart().continueRoomAutomatic(code, clock);
|
||||
assert.equal((await f.restart().readRoom(code)).version, pending.version);
|
||||
assert.equal((await f.restart().readSeatView(code, auths[0])).semutaReaction?.canCommit, true);
|
||||
assert.equal((await f.restart().readSeatView(code, auths[2])).semutaReaction?.canCommit, false);
|
||||
const claimed = await act(0, { type: 'semutaCommit', event });
|
||||
assert.equal(claimed.pendingTreacheryDiscard, null);
|
||||
assert.deepEqual(claimed.players.map(p => p.spice), balances);
|
||||
assert.equal(claimed.players[0].hand.filter(card => card.id === karama.id).length, 1);
|
||||
assert.equal(claimed.discard.filter(card => card.id === SEMUTA_DRUG_ID).length, 1);
|
||||
assert.equal(viewGame(claimed, auths[2].playerId).players[2].charityClaimed, true);
|
||||
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));
|
||||
} finally { f.sqlite.close(); }
|
||||
});
|
||||
Reference in new issue
Block a user