Support Sapho ordering for Great Maker votes
Verify and publish checkpoint container / container (push) Successful in 11m14s
Verify and publish checkpoint container / container (push) Successful in 11m14s
This commit is contained in:
1 parent
e81725e4b2
commit
77d02b3231
18 files changed
+798
-21
No files matched your search
@@ -4382,6 +4382,12 @@ function botAdvisorMatchingAllowed(g:GameView,action:Action) {
|
||||
} catch(error) { if(error instanceof AdvisorMatchingError) return false; throw error; }
|
||||
}
|
||||
export function botActions(g: GameView): Action[] {
|
||||
if (g.saphoGreatMakerPriority) {
|
||||
const own = g.players.find(player => player.id === g.me), priority = g.saphoGreatMakerPriority;
|
||||
return (own?.bot || own?.autopilot) && g.status === 'playing' && priority.canPass &&
|
||||
!g.roomControl?.paused && !g.roomControl?.closed && !g.automaticContinuationPending
|
||||
? [{type:'saphoGreatMakerPass', event:priority.event}] : [];
|
||||
}
|
||||
if (g.emperorGuildRatePriority) {
|
||||
const me = g.players.find(player => player.id === g.me);
|
||||
return (me?.bot || me?.autopilot) && g.emperorGuildRatePriority.canContinue &&
|
||||
|
||||
+146
-7
@@ -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,
|
||||
|
||||
@@ -37,7 +37,7 @@ export function greatMakerRideAction(
|
||||
}
|
||||
export function greatMakerBotActions(game: GameView): Action[] {
|
||||
const d = game.decision;
|
||||
if (!d || d.player !== game.me || game.truthtrance) return [];
|
||||
if (!d || d.player !== game.me || game.truthtrance || game.saphoGreatMakerPriority) return [];
|
||||
if (d.kind === 'greatMakerVote')
|
||||
return [
|
||||
{
|
||||
|
||||
+11
-4
@@ -1,3 +1,5 @@
|
||||
import type { SaphoGreatMakerOrder } from './sapho-great-maker';
|
||||
|
||||
export type GreatMaker = {
|
||||
arrival: {
|
||||
territory: string;
|
||||
@@ -14,10 +16,12 @@ export type GreatMaker = {
|
||||
order: string[];
|
||||
votes: { player: string; yes: boolean }[];
|
||||
ridesBefore: string[];
|
||||
/** Present only on fresh vote-order-capable encounters. */
|
||||
saphoOrder?: SaphoGreatMakerOrder;
|
||||
signature: string;
|
||||
};
|
||||
export function greatMakerSignature(frame: GreatMaker): string {
|
||||
return JSON.stringify([
|
||||
const values: unknown[] = [
|
||||
frame.event,
|
||||
frame.turn,
|
||||
frame.pile,
|
||||
@@ -28,7 +32,9 @@ export function greatMakerSignature(frame: GreatMaker): string {
|
||||
frame.votes,
|
||||
frame.ridesBefore,
|
||||
frame.arrival,
|
||||
]);
|
||||
];
|
||||
if (frame.saphoOrder) values.push(frame.saphoOrder);
|
||||
return JSON.stringify(values);
|
||||
}
|
||||
export function validateGreatMaker(
|
||||
frame: GreatMaker,
|
||||
@@ -38,8 +44,9 @@ export function validateGreatMaker(
|
||||
const ids = players.map((player) => player.id);
|
||||
if (
|
||||
!frame ||
|
||||
Object.keys(frame).sort().join(',') !==
|
||||
'arrival,event,index,order,pile,ridesBefore,signature,stage,territory,turn,votes' ||
|
||||
Object.keys(frame).sort().join(',') !== (frame.saphoOrder
|
||||
? 'arrival,event,index,order,pile,ridesBefore,saphoOrder,signature,stage,territory,turn,votes'
|
||||
: 'arrival,event,index,order,pile,ridesBefore,signature,stage,territory,turn,votes') ||
|
||||
typeof frame.event !== 'string' ||
|
||||
!frame.event ||
|
||||
!Number.isSafeInteger(frame.turn) ||
|
||||
|
||||
@@ -516,6 +516,7 @@ export const RULE_TOPICS: RuleTopic[] = [
|
||||
'In a fresh Richese battle, use unreserved Sapho at a clean boundary before both combatants finish final battle actions, including after sealed plans and revealed declarations. Habbanya still precedes ordinary aggressor tie priority. Participants, plans, promises, weapon choices and votes do not swap or replay. Older battles retain their pre-plan opportunity.',
|
||||
'When two or more players declared Truthtrance in a supported clean parent, each queued holder may continue or use their held Sapho to move their entire pending question group first or last. Physical storm order and each holder’s card order stay unchanged. Supported Semuta claim/pass restores the same question queue, including the selected Homeworld, Leader Skills and Discovery profiles. Clean ordinary auction lots also preserve their standing bid and remaining clock. Richese cache Once Around and Silent lots and Advanced Black Market lots preserve their original bidding and funding. Fresh Advanced CHOAM-only Richese games offer Semuta on this Sapho discard and supported definite factual or bid-question Truthtrance discards in those auctions. Other question families and combinations remain unfinished.',
|
||||
'During a clean native Extortion payer decision, use Sapho to take your optional choice first/last among unanswered non-Moritani players. Earlier declines, collected bank5 and the one-payment3 limit remain. The next payer event changes even when that player stays next. You may decline instead of paying.',
|
||||
'During a supported Great Maker vote, a shared public opportunity before each vote lets any remaining voter use Sapho to go first or last, or continue without changing order. Earlier votes and the majority threshold stay unchanged. In supported Semuta games the physical discard response finishes first; a player who recovers Sapho can use it again. The online priority is provisional.',
|
||||
'Before either of two Ecological Testing Station occupants chooses, use Sapho to take your adjustment first or last if that changes the order. Fresh choices with Richese seated give both occupants a shared opportunity to use an available order change or continue; an automated occupant cannot advance the station choice while another player is deciding. Each occupant still adjusts the cumulative storm distance once. Physical storm order and its original source stay unchanged. In supported Semuta games, claim or pass reopens the shared opportunity; an occupant may use a recovered Sapho again before either choice. This online priority is provisional.',
|
||||
'During ordered Advanced Charity, take your remaining turn first or last, then discard Sapho. An accepted current claim provisionally protects that actor while another holder reorders only later unstarted turns. At a clean boundary, the holder may pause its own claimed turn and resume last without repeating the claim or payment. Completed turns stay closed and physical First Player order is unchanged. Basic and older concurrent phases have no ordered scope.',
|
||||
'During ordered Advanced Revival, take your unfinished opportunity first or last, then discard Sapho. If another player has started, provisional queued timing lets that player finish unchanged. At a clean boundary, you may instead pause your own started turn and resume last, retaining used allowances. Pending requests must finish first. Completed turns and already-held positions cannot be repeated. Basic and older concurrent Revival phases have no ordered scope.',
|
||||
|
||||
@@ -0,0 +1,128 @@
|
||||
import { reorderOrderedOpportunity } from './ordered-opportunity';
|
||||
|
||||
/** Public ordering history for the original Great Maker voting encounter. */
|
||||
export type SaphoGreatMakerUse = {
|
||||
event: string;
|
||||
player: string;
|
||||
mode: 'first' | 'last';
|
||||
cursor: number;
|
||||
};
|
||||
export type SaphoGreatMakerOrder = {
|
||||
version: 1;
|
||||
original: string[];
|
||||
uses: SaphoGreatMakerUse[];
|
||||
};
|
||||
export type SaphoGreatMakerContext = {
|
||||
encounter: string;
|
||||
turn: number;
|
||||
stormOrder: readonly string[];
|
||||
queue: readonly string[];
|
||||
cursor: number;
|
||||
order?: SaphoGreatMakerOrder;
|
||||
};
|
||||
export type SaphoGreatMakerRequest = {
|
||||
event: string;
|
||||
player: string;
|
||||
mode: 'first' | 'last';
|
||||
};
|
||||
|
||||
export class SaphoGreatMakerError extends Error {
|
||||
constructor(message: string) {
|
||||
super(message);
|
||||
this.name = 'SaphoGreatMakerError';
|
||||
}
|
||||
}
|
||||
function requireMaker(value: unknown, message: string): asserts value {
|
||||
if (!value) throw new SaphoGreatMakerError(message);
|
||||
}
|
||||
const identifier = (value: unknown): value is string =>
|
||||
typeof value === 'string' && value.trim().length > 0;
|
||||
const count = (value: unknown): value is number =>
|
||||
typeof value === 'number' && Number.isSafeInteger(value) && value >= 0;
|
||||
const ids = (value: unknown): value is readonly string[] =>
|
||||
Array.isArray(value) && value.every(identifier) && new Set(value).size === value.length;
|
||||
const exact = (value: unknown, keys: string): value is Record<string, unknown> =>
|
||||
!!value && typeof value === 'object' && !Array.isArray(value) &&
|
||||
[Object.prototype, null].includes(Object.getPrototypeOf(value)) &&
|
||||
Object.keys(value).sort().join(',') === keys;
|
||||
const same = (left: unknown, right: unknown): boolean => JSON.stringify(left) === JSON.stringify(right);
|
||||
const eventFor = (encounter: string, turn: number, cursor: number, revision: number): string =>
|
||||
`saphoGreatMaker:${JSON.stringify([encounter, turn, cursor, revision])}`;
|
||||
|
||||
/** Construct only when a new recorded ordering is needed; unmodified older
|
||||
* encounters need no added field or changed Great Maker signature. */
|
||||
export function initialSaphoGreatMakerOrder(stormOrder: readonly string[]): SaphoGreatMakerOrder {
|
||||
requireMaker(ids(stormOrder) && stormOrder.length >= 2 && stormOrder.length <= 6,
|
||||
'Great Maker needs its original unique two-to-six-player storm order.');
|
||||
return {version: 1, original: [...stormOrder], uses: []};
|
||||
}
|
||||
|
||||
function applyUse(original: readonly string[], queue: readonly string[], use: SaphoGreatMakerUse): string[] {
|
||||
const remaining = queue.slice(use.cursor);
|
||||
requireMaker(use.mode === 'first' || use.mode === 'last', 'Choose first or last.');
|
||||
requireMaker(identifier(use.player) && remaining.includes(use.player),
|
||||
'Only a player who has not yet voted may change position.');
|
||||
requireMaker(use.mode === 'first' ? remaining[0] !== use.player : remaining.at(-1) !== use.player,
|
||||
'This voter already holds that position.');
|
||||
try {
|
||||
const next = reorderOrderedOpportunity({
|
||||
event: use.event, eligible: original, completed: queue.slice(0, use.cursor),
|
||||
remaining, current: remaining[0] ?? null, currentStarted: false,
|
||||
}, {event: use.event, player: use.player, position: use.mode});
|
||||
return [...next.completed, ...next.remaining];
|
||||
} catch (error) {
|
||||
throw new SaphoGreatMakerError(error instanceof Error ? error.message : 'Invalid Great Maker voter order.');
|
||||
}
|
||||
}
|
||||
|
||||
function validate(context: SaphoGreatMakerContext): string[] {
|
||||
requireMaker(context && typeof context === 'object' && identifier(context.encounter) &&
|
||||
count(context.turn) && context.turn > 0 && ids(context.stormOrder) &&
|
||||
context.stormOrder.length >= 2 && context.stormOrder.length <= 6,
|
||||
'Great Maker needs its original encounter, turn and unique storm order.');
|
||||
const original = [...context.stormOrder];
|
||||
requireMaker(ids(context.queue) && context.queue.length === original.length &&
|
||||
context.queue.every(player => original.includes(player)) &&
|
||||
count(context.cursor) && context.cursor <= context.queue.length,
|
||||
'Great Maker needs its complete voter queue and current vote cursor.');
|
||||
if (context.order === undefined) {
|
||||
requireMaker(same(context.queue, original),
|
||||
'A Great Maker queue without a Sapho record must retain its original storm order.');
|
||||
return original;
|
||||
}
|
||||
const order = context.order;
|
||||
requireMaker(exact(order, 'original,uses,version') && order.version === 1 &&
|
||||
ids(order.original) && same(order.original, original) && Array.isArray(order.uses),
|
||||
'The Sapho vote record must retain its exact original voter order.');
|
||||
let queue = [...original], previousCursor = 0;
|
||||
for (const [revision, use] of order.uses.entries()) {
|
||||
requireMaker(exact(use, 'cursor,event,mode,player') && count(use.cursor) &&
|
||||
use.cursor >= previousCursor && use.cursor <= context.cursor &&
|
||||
use.event === eventFor(context.encounter, context.turn, use.cursor, revision),
|
||||
'Sapho vote history has a stale event, revision or completed voter cursor.');
|
||||
queue = applyUse(original, queue, use);
|
||||
previousCursor = use.cursor;
|
||||
}
|
||||
requireMaker(same(context.queue, queue),
|
||||
'The Great Maker voter queue does not match its original Sapho history.');
|
||||
return original;
|
||||
}
|
||||
|
||||
export function validateSaphoGreatMaker(context: SaphoGreatMakerContext): void {
|
||||
validate(context);
|
||||
}
|
||||
export function saphoGreatMakerEvent(context: SaphoGreatMakerContext): string {
|
||||
validate(context);
|
||||
return eventFor(context.encounter, context.turn, context.cursor, context.order?.uses.length ?? 0);
|
||||
}
|
||||
export function reorderSaphoGreatMaker(
|
||||
context: SaphoGreatMakerContext,
|
||||
request: SaphoGreatMakerRequest,
|
||||
): {queue: string[]; order: SaphoGreatMakerOrder} {
|
||||
const original = validate(context), event = saphoGreatMakerEvent(context);
|
||||
requireMaker(request && typeof request === 'object' && request.event === event,
|
||||
'This Sapho Great Maker opportunity has expired.');
|
||||
const use: SaphoGreatMakerUse = {event, player: request.player, mode: request.mode, cursor: context.cursor};
|
||||
return {queue: applyUse(original, context.queue, use),
|
||||
order: {version: 1, original, uses: [...(context.order?.uses ?? []).map(old => ({...old})), use]}};
|
||||
}
|
||||
+2
-2
@@ -12,13 +12,13 @@ type TurnView = Pick<
|
||||
| 'phaseOpening'
|
||||
| 'automaticContinuationPending'
|
||||
> &
|
||||
Partial<Pick<GameView, 'emperorExtortionPriority' | 'saphoStationPriority' | 'biddingEnd' | 'kullReaction' | 'richeseBetrayalReaction' | 'guildBetrayalReaction' | 'nexusIxianReplacement' | 'nexusIxianBetrayalReaction' | 'nexusHarkonnenBetrayalReaction'>>;
|
||||
Partial<Pick<GameView, 'emperorExtortionPriority' | 'saphoStationPriority' | 'saphoGreatMakerPriority' | 'biddingEnd' | 'kullReaction' | 'richeseBetrayalReaction' | 'guildBetrayalReaction' | 'nexusIxianReplacement' | 'nexusIxianBetrayalReaction' | 'nexusHarkonnenBetrayalReaction'>>;
|
||||
|
||||
/** The single current decision owner for the table banner and seat highlight.
|
||||
* Shared response windows have no single acting seat. Only public view fields
|
||||
* participate; this does not decide which gameplay actions are legal. */
|
||||
export function tableActionOwner(g: TurnView): string | null {
|
||||
if (g.saphoStationPriority || g.emperorExtortionPriority) return null;
|
||||
if (g.saphoStationPriority || g.saphoGreatMakerPriority || g.emperorExtortionPriority) return null;
|
||||
if (g.richeseBetrayalReaction || g.guildBetrayalReaction) return null;
|
||||
if (g.kullReaction && g.status === 'playing')
|
||||
return g.players.some(p => p.id === g.kullReaction!.player)
|
||||
|
||||
Reference in new issue
Block a user