Offer Semuta after completed CHOAM card sales
This commit is contained in:
1 parent
9bfc3ec037
commit
4c07e1bbd1
8 files changed
+333
-16
No files matched your search
@@ -4,6 +4,7 @@ import {
|
||||
applyAction,
|
||||
createGame,
|
||||
newPlayer,
|
||||
normalizeAutomaticGame,
|
||||
viewGame,
|
||||
RuleError,
|
||||
type Game,
|
||||
@@ -13,6 +14,8 @@ import { saleOptions } from '../game/choam-market';
|
||||
import { createTechTokens } from '../game/tech-tokens';
|
||||
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';
|
||||
function fixture() {
|
||||
const g = createGame('MARKET22', newPlayer('c', 'CHOAM', 'choam'), false, [
|
||||
'choam',
|
||||
@@ -129,6 +132,117 @@ void test('Worthless sale reveals its card but only discards and pays after the
|
||||
assert.equal(g.phase, 2);
|
||||
assert.deepEqual(live(g), live(initial));
|
||||
});
|
||||
void test('clean CHOAM sale offers Semuta after committed income before the market resumes', () => {
|
||||
const g = fixture();
|
||||
g.players[1] = newPlayer('e', 'Richese', 'richese');
|
||||
g.players[1].spice = 20;
|
||||
g.richeseCache = richeseCards();
|
||||
g.semutaPreview = true;
|
||||
const index = g.richeseCache.findIndex(card => card.id === SEMUTA_DRUG_ID);
|
||||
assert.ok(index >= 0);
|
||||
const semuta = g.richeseCache.splice(index, 1)[0];
|
||||
g.players[1].hand.push(semuta);
|
||||
contest(g, 1, 'b');
|
||||
const sold = hold(g, 'c', 'Baliset');
|
||||
const original = live(g);
|
||||
const absent = structuredClone(g);
|
||||
absent.players[1].hand = [absent.richeseCache!.splice(0, 1)[0]];
|
||||
absent.richeseCache!.push(semuta);
|
||||
const offered = (state: Game) => allow(sell(ready(state), sold.id));
|
||||
const pending = offered(g), neutral = offered(absent);
|
||||
const event = pending.pendingTreacheryDiscard!.batch.event;
|
||||
assert.equal(pending.pendingTreacheryDiscard?.continuation.kind, 'choamSaleDiscard');
|
||||
assert.equal(pending.pendingTreacheryDiscard?.reaction?.stage, 'offer');
|
||||
assert.equal(neutral.pendingTreacheryDiscard?.reaction?.stage, 'offer');
|
||||
assert.equal(pending.choamMarket?.sale, undefined);
|
||||
assert.equal(pending.decision, null);
|
||||
assert.equal(pending.players[0].spice, 22);
|
||||
assert.equal(pending.players[0].hand.some(card => card.id === sold.id), false);
|
||||
assert.equal(pending.discard.filter(card => card.id === sold.id).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.deepEqual(normalizeAutomaticGame(JSON.parse(JSON.stringify(pending))), pending);
|
||||
for (const change of [
|
||||
(state: Game) => {
|
||||
const next = state.pendingTreacheryDiscard!.continuation;
|
||||
if (next.kind === 'choamSaleDiscard') next.price = 3;
|
||||
},
|
||||
(state: Game) => { state.players[0].spice += 2; },
|
||||
(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(() => applyAction(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 = applyAction(declined, id, { type: 'semutaPass', event });
|
||||
const claimed = applyAction(JSON.parse(JSON.stringify(pending)), 'e',
|
||||
botActions(viewGame(pending, 'e'))[0]!);
|
||||
for (const state of [declined, claimed]) {
|
||||
assert.equal(state.pendingTreacheryDiscard, null);
|
||||
assert.equal(state.decision?.kind, 'choamMarket');
|
||||
assert.equal(state.players[0].spice, 22);
|
||||
assert.deepEqual(live(state), original);
|
||||
assert.throws(() => applyAction(state, 'e', { type: 'semutaCommit', event }));
|
||||
}
|
||||
assert.equal(declined.discard.filter(card => card.id === sold.id).length, 1);
|
||||
assert.equal(claimed.players[1].hand.filter(card => card.id === sold.id).length, 1);
|
||||
assert.equal(claimed.discard.filter(card => card.id === semuta.id).length, 1);
|
||||
const resumed = done(claimed);
|
||||
assert.equal(resumed.choamMarket, null);
|
||||
assert.equal(resumed.phase, 3);
|
||||
});
|
||||
void test('CHOAM duplicate sale retains its witness and three spice through Semuta', () => {
|
||||
const g = fixture();
|
||||
g.players[1] = newPlayer('e', 'Richese', 'richese');
|
||||
g.players[1].spice = 20;
|
||||
g.richeseCache = richeseCards();
|
||||
g.semutaPreview = true;
|
||||
const semutaIndex = g.richeseCache.findIndex(card => card.id === SEMUTA_DRUG_ID);
|
||||
const semuta = g.richeseCache.splice(semutaIndex, 1)[0];
|
||||
g.players[1].hand.push(semuta);
|
||||
contest(g, 1, 'b');
|
||||
const sold = hold(g, 'c', 'Snooper'), witness = hold(g, 'c', 'Snooper');
|
||||
const pending = allow(sell(ready(g), sold.id, witness.id));
|
||||
const continuation = pending.pendingTreacheryDiscard?.continuation;
|
||||
assert.equal(continuation?.kind, 'choamSaleDiscard');
|
||||
if (continuation?.kind === 'choamSaleDiscard') {
|
||||
assert.equal(continuation.witness, witness.id);
|
||||
assert.equal(continuation.price, 3);
|
||||
}
|
||||
assert.equal(pending.players[0].spice, 23);
|
||||
assert.deepEqual(pending.players[0].hand.map(card => card.id), [witness.id]);
|
||||
const event = pending.pendingTreacheryDiscard!.batch.event;
|
||||
const claimed = applyAction(pending, 'e', { type: 'semutaCommit', event });
|
||||
assert.equal(claimed.players[0].spice, 23);
|
||||
assert.deepEqual(claimed.players[0].hand.map(card => card.id), [witness.id]);
|
||||
assert.equal(claimed.players[1].hand.filter(card => card.id === sold.id).length, 1);
|
||||
assert.equal(claimed.discard.filter(card => card.id === semuta.id).length, 1);
|
||||
assert.equal(claimed.decision?.kind, 'choamMarket');
|
||||
});
|
||||
void test('canceled CHOAM sale creates no Semuta event or bank income', () => {
|
||||
const g = fixture();
|
||||
g.players[1] = newPlayer('e', 'Richese', 'richese');
|
||||
g.richeseCache = richeseCards();
|
||||
g.semutaPreview = true;
|
||||
const semutaIndex = g.richeseCache.findIndex(card => card.id === SEMUTA_DRUG_ID);
|
||||
g.players[1].hand.push(g.richeseCache.splice(semutaIndex, 1)[0]);
|
||||
contest(g, 1, 'b');
|
||||
const sold = hold(g, 'c', 'Baliset');
|
||||
const declaration = sell(ready(g), sold.id);
|
||||
const karama = declaration.players[2].hand.find(card => card.effect === 'karama')!;
|
||||
const canceled = applyAction(declaration, 'b',
|
||||
{ type: 'card', card: karama.id, mode: 'cancel' });
|
||||
assert.ok(!canceled.pendingTreacheryDiscard);
|
||||
assert.equal(canceled.players[0].spice, 20);
|
||||
assert.equal(canceled.players[0].hand.filter(card => card.id === sold.id).length, 1);
|
||||
assert.equal(canceled.choamMarket?.sale, undefined);
|
||||
assert.equal(canceled.decision?.kind, 'choamMarket');
|
||||
});
|
||||
void test('surplus sales keep one exact duplicate and permit selling several surplus copies', () => {
|
||||
let g = fixture();
|
||||
const cards = [
|
||||
|
||||
@@ -808,6 +808,83 @@ void test('authenticated private Ixian ally discard waits for Semuta before its
|
||||
} finally { f.sqlite.close(); }
|
||||
});
|
||||
|
||||
void test('authenticated CHOAM sale retains paid spice and market after a saved Semuta claim', async () => {
|
||||
const f = unitStore();
|
||||
try {
|
||||
const made = await f.rooms.createRoom('Semuta Sale', '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);
|
||||
let 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: 2, order: auths.map(auth => auth.playerId),
|
||||
deck: baseDeck(), richeseCache: richeseCards(), semutaPreview: true,
|
||||
choamCharity: { turn: 1, canceled: false } });
|
||||
for (const p of g.players) {
|
||||
p.spice = 20;
|
||||
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 sold = g.deck.splice(index, 1)[0];
|
||||
g.players[0].hand.push(sold);
|
||||
g.players[1].hand.push(semuta);
|
||||
g.players[2].hand.push(karama);
|
||||
for (const p of g.players)
|
||||
g = applyAction(g, p.id, { type: 'ready' });
|
||||
assert.equal(g.decision?.kind, 'choamMarket');
|
||||
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: 'decision', mode: 'sell', card: sold.id });
|
||||
assert.equal(current.response?.kind, 'choamSale');
|
||||
for (let i = 0; current.response?.kind === 'choamSale' && 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?.reaction?.stage, 'offer');
|
||||
assert.equal(current.players[0].spice, 22);
|
||||
assert.equal(current.choamMarket?.sale, undefined);
|
||||
assert.equal(current.decision, null);
|
||||
await f.restart().continueRoomAutomatic(code, clock);
|
||||
assert.equal((await f.restart().readRoom(code)).version, current.version);
|
||||
const ownerView = await f.restart().readSeatView(code, auths[1]);
|
||||
assert.equal(ownerView.semutaReaction?.canCommit, true);
|
||||
assert.deepEqual((await f.restart().readSeatView(code, auths[0])).semutaReaction?.candidates, []);
|
||||
const claimed = await act(1, { type: 'semutaCommit', event });
|
||||
assert.equal(claimed.pendingTreacheryDiscard, null);
|
||||
assert.equal(claimed.decision?.kind, 'choamMarket');
|
||||
assert.equal(claimed.players[0].spice, 22);
|
||||
assert.equal(claimed.players[1].hand.filter(card => card.id === sold.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 resumed = await act(0, { type: 'decision', done: true });
|
||||
assert.equal(resumed.phase, 3);
|
||||
assert.equal(resumed.players[0].spice, 22);
|
||||
} finally { f.sqlite.close(); }
|
||||
});
|
||||
|
||||
void test('authenticated printed Karama auction payment resumes one saved Richese cache offer', async () => {
|
||||
const f = unitStore();
|
||||
try {
|
||||
|
||||
Reference in new issue
Block a user