Support Sapho ordering for Great Maker votes
Verify and publish checkpoint container / container (push) Successful in 11m14s

This commit is contained in:
Quintine committed 2026-11-16 21:32:53 +11:00
1 parent e81725e4b2
commit 77d02b3231
18 files changed
+798 -21

No files matched your search

+146 -7
View File
@@ -162,6 +162,7 @@ import { advanceDiscoveryEntry, beginDiscoveryEntryArrival, createDiscoveryEntry
import { createDiscoveryState, validateDiscoveryState, placeDiscovery, rememberDiscoveryFace, revealDiscoveryToken, isDiscoverySpiceCardId, isDiscoveryTokenId, DISCOVERY_SPICE_CARDS, DISCOVERY_CARD_PLACEMENTS, DISCOVERY_TOKEN_BY_ID, JACURUTU_SIETCH, type DiscoveryState } from './discoveries';
import { quoteJacurutuBattleIncome, jacurutuDialSelection, type JacurutuDialOffer } from './discovery-battle';
import { greatMakerSignature, greatMakerMajority, validateGreatMaker, type GreatMaker } from './great-maker';
import { initialSaphoGreatMakerOrder, validateSaphoGreatMaker, saphoGreatMakerEvent, reorderSaphoGreatMaker, SaphoGreatMakerError } from './sapho-great-maker';
import { quoteNexusChoamTrade, validateNexusChoamTrade, nexusChoamTradeSignature, type NexusChoamTrade } from './nexus-choam-trade';
import { quoteNexusChoamInspection, sampleNexusChoamInspection, nexusChoamInspectionSignature, type NexusChoamInspectionReceipt } from './nexus-choam-inspection';
import { quoteNexusMoritaniRetention, nexusMoritaniRetentionSignature, type NexusMoritaniRetentionReceipt } from './nexus-moritani-retention';
@@ -1688,6 +1689,8 @@ export type Game = {
ecologicalStorm?: DiscoveryStorm;
/** Neutral opportunity before either of two Station occupants chooses. */
saphoStationPriority?: { event: string; passed: string[] };
/** Public card-independent ordering opportunity before a Great Maker vote. */
saphoGreatMakerPriority?: { event: string; passed: string[] };
discoveryEnabled?: boolean;
discoveries?: DiscoveryState;
discoveryStash?: DiscoveryStash;
@@ -1836,6 +1839,15 @@ export type Game = {
resume: NonNullable<Game['pendingNullentropy']>['resume'];
stateSignature: string;
}
| {
kind: 'saphoGreatMakerDiscard';
player: string;
card: string;
event: string;
mode: 'first' | 'last';
resume: NonNullable<Game['pendingNullentropy']>['resume'];
stateSignature: string;
}
| {
kind: 'saphoAuctionDiscard';
cyclic?: 'normal' | 'blackMarket';
@@ -6703,6 +6715,16 @@ type SaphoStationDiscardContinuation = Extract<
NonNullable<Game['pendingTreacheryDiscard']>['continuation'],
{ kind: 'saphoStationDiscard' }
>;
type SaphoGreatMakerDiscardContinuation = Extract<
NonNullable<Game['pendingTreacheryDiscard']>['continuation'],
{ kind: 'saphoGreatMakerDiscard' }
>;
function saphoGreatMakerDiscardSignature(g: Game, c: SaphoGreatMakerDiscardContinuation) {
return JSON.stringify({player:c.player,card:c.card,event:c.event,mode:c.mode,
parent:nullentropyParentSignature(g,c.resume,c.event),turn:g.turn,phase:g.phase,
order:g.order,maker:g.greatMaker,spiceSequence:g.spiceSequence,spiceDiscard:g.spiceDiscard,
priority:g.saphoGreatMakerPriority});
}
function saphoStationDiscardSignature(g: Game, c: SaphoStationDiscardContinuation) {
return JSON.stringify({player:c.player, card:c.card, event:c.event, mode:c.mode,
...(c.stationReplayPriority ? {stationReplayPriority:true} : {}),
@@ -8749,6 +8771,11 @@ function treacheryDiscardIntegrity(g: Game) {
semutaOfferSupported(g, c, batch.entries) &&
c.stateSignature === saphoStationDiscardSignature(g, c),
'The used Juice of Sapho no longer matches its Testing Station choice.');
} else if (continuation?.kind === 'saphoGreatMakerDiscard') {
const c = continuation;
requireRule(batch.cause === 'sapho:greatMaker' && semutaOfferSupported(g,c,batch.entries) &&
c.stateSignature === saphoGreatMakerDiscardSignature(g,c),
'The used Juice of Sapho no longer matches its Great Maker vote.');
} else if (continuation?.kind === 'saphoMovementDiscard') {
const c = continuation, entry = batch.entries[0];
requireRule(
@@ -10061,6 +10088,20 @@ function semutaOfferSupported(
continuation: NonNullable<Game['pendingTreacheryDiscard']>['continuation'],
entries: FreshDiscardBatch['entries'],
) {
if (continuation.kind === 'saphoGreatMakerDiscard') {
const frame = g.greatMaker, decision = continuation.resume.decision;
const use = frame?.saphoOrder?.uses.at(-1);
return g.semutaPreview === true && g.discoveryEnabled === true && !!g.discoveries &&
discoveryModeSupported(g) && g.status === 'playing' && g.phase === 1 &&
frame?.stage === 'vote' && use?.event === continuation.event &&
use.player === continuation.player && use.mode === continuation.mode &&
decision?.kind === 'greatMakerVote' && decision.player === frame.order[frame.votes.length] &&
decision.event === frame.event && !g.decision && !g.saphoGreatMakerPriority &&
!g.response && !g.pendingKarama && !g.phaseOpening && !continuation.resume.response &&
!continuation.resume.pendingKarama && !continuation.resume.phaseOpening &&
entries.length === 1 && entries[0].publicFace && entries[0].discardedBy === continuation.player &&
entries[0].card.id === continuation.card && entries[0].card.effect === 'juiceOfSapho';
}
if (continuation.kind === 'saphoStationDiscard') {
const frame = g.ecologicalStorm, decision = continuation.resume.decision, receipt = frame?.sapho;
return g.semutaPreview === true && g.discoveryEnabled === true && !!g.discoveries &&
@@ -10921,6 +10962,12 @@ function finishTreacheryDiscard(g: Game, claim?: { player: string; card: string
if (next.stationReplayPriority && g.ecologicalStorm?.stage === 'choose' &&
g.ecologicalStorm.queue?.choices.length === 0)
g.saphoStationPriority = {event:g.ecologicalStorm.event,passed:[]};
} else if (next.kind === 'saphoGreatMakerDiscard') {
g.response = next.resume.response;
g.decision = next.resume.decision;
g.pendingKarama = next.resume.pendingKarama;
g.phaseOpening = next.resume.phaseOpening;
openSaphoGreatMakerPriority(g);
} else if (next.kind === 'saphoMovementDiscard') {
g.response = next.resume.response;
g.decision = next.resume.decision;
@@ -15439,6 +15486,26 @@ function greatMakerRideOptions(g: Game, owner: string) {
function stampGreatMaker(g: Game) {
g.greatMaker!.signature = greatMakerSignature(g.greatMaker!);
}
function saphoGreatMakerRule<T>(run: () => T): T {
try { return run(); }
catch (error) {
if (error instanceof SaphoGreatMakerError) throw new RuleError(error.message);
throw error;
}
}
function saphoGreatMakerContext(g: Game) {
const frame = g.greatMaker!;
// Completed encounters can outlive their turn and its later storm order.
const stormOrder = frame.stage === 'complete' ? frame.saphoOrder?.original ?? frame.order : g.order;
return {encounter:frame.event,turn:frame.turn,stormOrder,queue:frame.order,
cursor:frame.votes.length,...(frame.saphoOrder ? {order:frame.saphoOrder} : {})};
}
function openSaphoGreatMakerPriority(g: Game) {
const frame = g.greatMaker!;
if (frame.saphoOrder && frame.order.length - frame.votes.length > 1)
g.saphoGreatMakerPriority = {event:saphoGreatMakerRule(() => saphoGreatMakerEvent(saphoGreatMakerContext(g))),passed:[]};
else delete g.saphoGreatMakerPriority;
}
function greatMakerIntegrity(g: Game) {
sneakWormIntegrity(g);
const frame = g.greatMaker, continuation = g.pendingTreacheryDiscard?.continuation;
@@ -15447,11 +15514,21 @@ function greatMakerIntegrity(g: Game) {
g.nexusFremenRideBetrayal?.stage === 'choose' ? { decision: g.nexusFremenRideBetrayal.source, response: null } : null];
const owned = controls.filter(control => control?.decision?.kind === 'greatMakerVote' || control?.decision?.kind === 'greatMakerRide');
if (!frame) {
requireRule(owned.length === 0, 'The Great Maker has lost its original encounter.');
requireRule(owned.length === 0 && !g.saphoGreatMakerPriority, 'The Great Maker has lost its original encounter.');
return;
}
requireRule(g.discoveryEnabled && g.discoveries, 'The Great Maker requires its physical Discovery module.');
nexusRule(() => validateGreatMaker(frame, g.turn, g.players));
saphoGreatMakerRule(() => validateSaphoGreatMaker(saphoGreatMakerContext(g)));
if (g.saphoGreatMakerPriority) {
const priority = g.saphoGreatMakerPriority, remaining = frame.order.slice(frame.votes.length);
requireRule(frame.stage === 'vote' && !!frame.saphoOrder && remaining.length > 1 &&
priority.event === saphoGreatMakerRule(() => saphoGreatMakerEvent(saphoGreatMakerContext(g))) &&
Array.isArray(priority.passed) && priority.passed.length < remaining.length &&
new Set(priority.passed).size === priority.passed.length &&
priority.passed.every(id => remaining.includes(id)),
'The Great Maker order opportunity lost its pending voters.');
}
if (frame.stage === 'complete') {
requireRule(owned.length === 0, 'The completed Great Maker cannot retain another vote or reserve ride.');
return;
@@ -15459,8 +15536,8 @@ function greatMakerIntegrity(g: Game) {
if (frame.arrival) requireRule(validGameLocation(g,frame.arrival.territory,frame.arrival.sector), 'The Great Maker has lost its declared reserve destination.');
const card = g.spiceDiscard[frame.pile][frame.index];
requireRule(g.phase === 1 && frame.turn === g.turn && g.spiceSequence?.pile === frame.pile &&
card && 'worm' in card && card.greatMaker && !card.suppressed &&
frame.order.join('|') === g.order.join('|'), 'The Great Maker has lost its current spice encounter.');
card && 'worm' in card && card.greatMaker && !card.suppressed,
'The Great Maker has lost its current spice encounter.');
if (frame.stage === 'vote' || frame.stage === 'ride') {
const kind = frame.stage === 'vote' ? 'greatMakerVote' : 'greatMakerRide';
const owner = frame.stage === 'vote' ? frame.order[frame.votes.length] : byFaction(g, 'fremen')?.id;
@@ -15500,6 +15577,7 @@ function openGreatMakerVote(g: Game) {
const frame = g.greatMaker!;
frame.stage = 'vote'; stampGreatMaker(g);
g.decision = {kind:'greatMakerVote', player:frame.order[frame.votes.length], event:frame.event};
openSaphoGreatMakerPriority(g);
}
function completeGreatMaker(g: Game) {
g.greatMaker!.stage = 'complete'; stampGreatMaker(g);
@@ -15611,7 +15689,10 @@ function continueSpice(g: Game, injected?: SpiceCard) {
g.greatMaker = {arrival:null,event:crypto.randomUUID(),turn:g.turn,pile:sequence.pile,
index:g.spiceDiscard[sequence.pile].length-1,
territory:previous && 'territory' in previous ? previous.territory : null,
stage:'worm',order:[...g.order],votes:[],ridesBefore:[...g.wormRides],signature:''};
stage:'worm',order:[...g.order],votes:[],ridesBefore:[...g.wormRides],
...(g.expansions.includes('choam') && byFaction(g,'richese') &&
!g.semutaAdvancedOrdinaryPreview && !g.semutaRecruitsPreview
? {saphoOrder:initialSaphoGreatMakerOrder(g.order)} : {}),signature:''};
stampGreatMaker(g);
if (g.greatMaker.territory) beginWorm(g,g.greatMaker.territory);
else openGreatMakerVote(g);
@@ -30900,7 +30981,7 @@ function offerMoritaniDuke(g: Game) {
return true;
}
type SaphoOption = {
scope: 'onceAround' | 'cyclicAuction' | 'movement' | 'battleOrder' | 'extortion' | 'revival' | 'charity' | 'testingStation';
scope: 'onceAround' | 'cyclicAuction' | 'movement' | 'battleOrder' | 'extortion' | 'revival' | 'charity' | 'testingStation' | 'greatMakerVote';
event: string;
mode: 'first' | 'last';
/** Display only; action submission keeps scope/event/mode. */
@@ -31148,7 +31229,7 @@ function saphoCleanWindow(g: Game) {
!g.truthtrance &&
!g.phaseOpening &&
!g.response &&
(!g.decision || saphoExtortionDecision(g) || saphoTestingStationDecision(g)) &&
(!g.decision || saphoExtortionDecision(g) || saphoTestingStationDecision(g) || !!g.saphoGreatMakerPriority) &&
!g.pendingNullentropy &&
!g.pendingRicheseGift &&
!g.pendingExchange &&
@@ -31244,6 +31325,17 @@ function saphoOptions(g: Game, p: Player): SaphoOption[] {
)
return [];
const options: SaphoOption[] = [];
if (g.saphoGreatMakerPriority) {
const frame = g.greatMaker!, priority = g.saphoGreatMakerPriority;
if (!frame.order.slice(frame.votes.length).includes(p.id) || priority.passed.includes(p.id)) return options;
for (const mode of ['first','last'] as const) {
try {
reorderSaphoGreatMaker(saphoGreatMakerContext(g), {event:priority.event,player:p.id,mode});
options.push({scope:'greatMakerVote',event:priority.event,mode});
} catch (error) { if (!(error instanceof SaphoGreatMakerError)) throw error; }
}
return options;
}
if (saphoTestingStationDecision(g)) {
const frame = g.ecologicalStorm!;
if (g.saphoStationPriority &&
@@ -31358,7 +31450,31 @@ function playSapho(g: Game, p: Player, action: Action) {
'This Juice of Sapho opportunity is unavailable, already completed or expired.',
);
recordNativePrintedCardPlay(g, p.id, 'juiceOfSapho');
if (option.scope === 'testingStation') {
if (option.scope === 'greatMakerVote') {
const frame = g.greatMaker!;
const next = saphoGreatMakerRule(() => reorderSaphoGreatMaker(saphoGreatMakerContext(g),
{event:option.event,player:p.id,mode:option.mode}));
frame.order = next.queue;
frame.saphoOrder = next.order;
stampGreatMaker(g);
g.decision = {kind:'greatMakerVote',player:frame.order[frame.votes.length],event:frame.event};
delete g.saphoGreatMakerPriority;
const used = discard(g,p,'richese-juice-of-sapho');
log(g, `${p.name} discarded Juice of Sapho to vote ${option.mode} among the remaining Great Maker voters. Earlier votes and the majority rule remain.`,
{faction:p.faction,name:'Juice of Sapho'});
if (g.semutaPreview) {
const continuation: SaphoGreatMakerDiscardContinuation = {kind:'saphoGreatMakerDiscard',
player:p.id,card:used.id,event:option.event,mode:option.mode,
resume:{response:g.response,decision:g.decision,pendingKarama:g.pendingKarama,phaseOpening:g.phaseOpening},
stateSignature:''};
const entries = [{card:used,discardedBy:p.id,publicFace:true}];
g.decision = null;
requireRule(semutaOfferSupported(g,continuation,entries),
'This Great Maker vote cannot safely resume its Semuta reaction.');
continuation.stateSignature = saphoGreatMakerDiscardSignature(g,continuation);
stageTreacheryDiscard(g,'sapho:greatMaker',entries,continuation);
} else openSaphoGreatMakerPriority(g);
} else if (option.scope === 'testingStation') {
requireRule(saphoTestingStationDecision(g) && g.ecologicalStorm,
'The original Testing Station choice is no longer open.');
const frame = nexusRule(() => reorderDiscoveryStorm(g, g.ecologicalStorm!, {
@@ -45120,6 +45236,26 @@ function applyActionWithInitiator(state: Game, id: string, action: Action, initi
action.scope === 'testingStation' && action.event === priority.event,
'Finish the Testing Station priority before choosing storm movement.');
}
if (state.saphoGreatMakerPriority) {
const priority = state.saphoGreatMakerPriority, frame = state.greatMaker;
greatMakerIntegrity(state);
getPlayer(state, id);
if (action?.type === 'advanceBots') return state;
requireRule(frame?.stage === 'vote' && frame.order.slice(frame.votes.length).includes(id) &&
!priority.passed.includes(id), 'This Great Maker ordering opportunity is not available to you.');
if (action.type === 'saphoGreatMakerPass') {
requireRule(Object.keys(action).sort().join(',') === 'event,type' && action.event === priority.event,
'Continue only the current Great Maker ordering opportunity.');
const game = structuredClone(state);
game.saphoGreatMakerPriority!.passed.push(id);
if (game.saphoGreatMakerPriority!.passed.length === frame.order.length - frame.votes.length)
delete game.saphoGreatMakerPriority;
return game;
}
requireRule(action.type === 'card' && action.card === 'richese-juice-of-sapho' &&
action.scope === 'greatMakerVote' && action.event === priority.event,
'Finish the Great Maker ordering opportunity before voting.');
}
if (action.alliancePromiseEvent !== undefined) {
const guide = projectedAlliancePromiseGuide(state, id);
requireRule(guide && Object.keys(action).sort().join(',') === Object.keys(guide.action).sort().join(',') &&
@@ -51148,6 +51284,9 @@ export function viewGame(state: Game, id: string, now?: number) {
saphoStationPriority: g.saphoStationPriority ? {event:g.saphoStationPriority.event,
canPass:!!g.ecologicalStorm?.queue?.order.includes(id) && !g.saphoStationPriority.passed.includes(id),
waiting:g.saphoStationPriority.passed.includes(id) || !g.ecologicalStorm?.queue?.order.includes(id)} : null,
saphoGreatMakerPriority: g.saphoGreatMakerPriority ? {event:g.saphoGreatMakerPriority.event,
canPass:!!g.greatMaker?.order.slice(g.greatMaker.votes.length).includes(id) && !g.saphoGreatMakerPriority.passed.includes(id),
waiting:g.saphoGreatMakerPriority.passed.includes(id) || !g.greatMaker?.order.slice(g.greatMaker.votes.length).includes(id)} : null,
discoveryEntry: g.discoveryEntry?.stage === 'choose' && g.decision?.kind === 'discoveryEntry' && g.decision.player === id
? {...nexusRule(() => quoteDiscoveryEntry({...g,discoveries:g.discoveries!},g.discoveryEntry!,id)),event:g.decision.event} : null,
greatMaker: g.greatMaker ? { event:g.greatMaker.event, turn:g.greatMaker.turn, stage:g.greatMaker.stage, votes:structuredClone(g.greatMaker.votes), order:[...g.greatMaker.order], ride:greatMakerRideOptions(g,id) } : null,