Allow Advanced Emperor gifts during Guild rate responses
Verify and publish checkpoint container / container (push) Successful in 11m3s
Verify and publish checkpoint container / container (push) Successful in 11m3s
This commit is contained in:
1 parent
b3843bf18e
commit
5e7f7b45e4
14 files changed
+475
-6
No files matched your search
+101
-2
@@ -1254,6 +1254,8 @@ type SpiceBankerIncomePayment = {
|
||||
};
|
||||
|
||||
export type ResponseWindow = {
|
||||
/** Original Guild-rate response parked while an allied gift is resolved. */
|
||||
emperorGuildRateGift?: { event: string; response: ResponseWindow; signature: string };
|
||||
/** The original public Guild timing decision remains live during this gift. */
|
||||
emperorGuildTimingGift?: { event: string; signature: string };
|
||||
/** The original Extortion payment decision remains live during this gift. */
|
||||
@@ -2396,6 +2398,7 @@ export type Game = {
|
||||
moritaniExtortion?: ExtortionState;
|
||||
/** Public release of the human Emperor's optional gift opportunity. */
|
||||
emperorExtortionGiftRelease?: { event: string; emperor: string; recipient: string };
|
||||
emperorGuildRateGiftRelease?: { event: string; emperor: string };
|
||||
grummanCollection?: GrummanCollection;
|
||||
pendingMoritaniPlacement?: {
|
||||
token: string;
|
||||
@@ -30836,6 +30839,59 @@ function emperorGuildTimingGiftIntegrity(g: Game) {
|
||||
if (g.pendingKarama?.use.kind === 'cancel')
|
||||
validateEmperorGuildTimingGift(g, g.pendingKarama.use.response);
|
||||
}
|
||||
function emperorGuildRateGiftPublicEligible(g: Game, p: Player): boolean {
|
||||
const response = g.response;
|
||||
const event = response?.guildRateEvent ?? response?.guildTransportEvent;
|
||||
return g.status === 'playing' && g.advanced && g.phase === 5 && g.expansions.length === 0 &&
|
||||
g.players.every(seat => ['atreides','beneGesserit','emperor','fremen','guild','harkonnen'].includes(seat.faction)) &&
|
||||
!g.techTokens && !g.strongholdCards && !g.leaderSkills && !g.homeworlds && !g.nexusCards &&
|
||||
!g.discoveryEnabled && !g.sandtrout && !g.coalitionPreview && !g.coalitionState && !g.phaseOpening && !g.decision &&
|
||||
!g.truthtrance && !g.pendingKarama && !g.pendingTreacheryDiscard && !g.pendingKull &&
|
||||
!g.pendingRicheseGift && !g.pendingNullentropy && !g.pendingEmperorAuctionGift &&
|
||||
!g.pendingArrivalOverlap && !g.pendingAmbassador &&
|
||||
response?.kind === 'guildRate' && typeof event === 'string' && !!event &&
|
||||
(!!g.pendingShipment !== !!g.pendingGuildTransport) && p.faction === 'emperor' && !!p.ally &&
|
||||
g.players.some(seat => seat.id === p.ally && seat.ally === p.id);
|
||||
}
|
||||
function emperorGuildRatePriority(g: Game): {event:string; emperor:string; recipient:string} | null {
|
||||
const emperor = byFaction(g, 'emperor');
|
||||
if (!emperor || !emperorGuildRateGiftPublicEligible(g, emperor) || !emperor.ally) return null;
|
||||
const event = g.response!.guildRateEvent ?? g.response!.guildTransportEvent!;
|
||||
if (g.emperorGuildRateGiftRelease?.event === event && g.emperorGuildRateGiftRelease.emperor === emperor.id) return null;
|
||||
return {event, emperor:emperor.id, recipient:emperor.ally};
|
||||
}
|
||||
function emperorGuildRateGiftMaximum(g: Game, p: Player): number {
|
||||
if (livePledgePromises(g.pledgePromises ?? [], p.id, g.turn, g.phase).length) return 0;
|
||||
const shipment = g.pendingShipment, transport = g.pendingGuildTransport;
|
||||
const pending = shipment?.player === p.id ? shipment.cost - shipment.allyPayment :
|
||||
transport?.player === p.id ? transport.cost - transport.allyPayment : 0;
|
||||
return Math.max(0, emperorAuctionGiftMaximum(g, p) - pending);
|
||||
}
|
||||
function emperorGuildRateGiftQuote(g: Game, p: Player): {recipient:string; maximum:number} | null {
|
||||
if (!emperorGuildRateGiftPublicEligible(g, p) || !p.ally) return null;
|
||||
const maximum = emperorGuildRateGiftMaximum(g, p);
|
||||
return maximum > 0 ? {recipient:p.ally, maximum} : null;
|
||||
}
|
||||
function emperorGuildRateGiftSignature(g: Game, parent: ResponseWindow, owner:string, recipient:string, amount:number): string {
|
||||
return JSON.stringify([g.turn,g.phase,g.active,g.order,g.pendingShipment,g.pendingGuildTransport,parent,owner,recipient,amount]);
|
||||
}
|
||||
function validateEmperorGuildRateGift(g: Game, response: ResponseWindow) {
|
||||
const parent = response.emperorGuildRateGift;
|
||||
if (!parent) return;
|
||||
const owner = g.players.find(player => player.id === response.owner);
|
||||
const recipient = g.players.find(player => player.id === response.recipient);
|
||||
requireRule(response.kind === 'emperorGift' && owner?.faction === 'emperor' && recipient &&
|
||||
owner.ally === recipient.id && recipient.ally === owner.id && parent.response.kind === 'guildRate' &&
|
||||
parent.event === (parent.response.guildRateEvent ?? parent.response.guildTransportEvent) && !!parent.event &&
|
||||
typeof response.amount === 'number' && Number.isSafeInteger(response.amount) && response.amount > 0 &&
|
||||
response.amount <= emperorGuildRateGiftMaximum(g, owner) &&
|
||||
parent.signature === emperorGuildRateGiftSignature(g,parent.response,owner.id,recipient.id,response.amount),
|
||||
'The Emperor gift lost its original Guild-rate response.');
|
||||
}
|
||||
function emperorGuildRateGiftIntegrity(g: Game) {
|
||||
if (g.response) validateEmperorGuildRateGift(g, g.response);
|
||||
if (g.pendingKarama?.use.kind === 'cancel') validateEmperorGuildRateGift(g, g.pendingKarama.use.response);
|
||||
}
|
||||
function emperorPhaseOpeningGiftSignature(g: Game, opening: {passed: string[]; initialize: boolean}, owner: string, recipient: string, amount: number): string {
|
||||
return JSON.stringify([g.turn, g.phase, g.active, g.order, g.ready, g.amalWindowOpen ?? false,
|
||||
opening, owner, recipient, amount]);
|
||||
@@ -38886,6 +38942,7 @@ function finishResponse(g: Game, canceled: boolean, settlement?: BureaucratSettl
|
||||
karamaConversionIntegrity(g);
|
||||
currentFactionPayment(g);
|
||||
const response = g.response!;
|
||||
validateEmperorGuildRateGift(g, response);
|
||||
validateEmperorGuildTimingGift(g, response);
|
||||
validateEmperorExtortionGift(g, response);
|
||||
validateEmperorPhaseOpeningGift(g, response);
|
||||
@@ -40066,6 +40123,7 @@ function finishResponse(g: Game, canceled: boolean, settlement?: BureaucratSettl
|
||||
);
|
||||
}
|
||||
if (response.emperorPhaseOpeningGift) g.phaseOpening = structuredClone(response.emperorPhaseOpeningGift.opening);
|
||||
if (response.emperorGuildRateGift) g.response = structuredClone(response.emperorGuildRateGift.response);
|
||||
if (response.emperorAuctionGiftEvent) {
|
||||
requireRule(g.pendingEmperorAuctionGift?.event === response.emperorAuctionGiftEvent,
|
||||
'The Emperor gift lost its original auction opportunity.');
|
||||
@@ -40798,10 +40856,12 @@ function savedNoFieldResponses(g: Game): ResponseWindow[] {
|
||||
continuation && 'resume' in continuation ? continuation.resume : null,
|
||||
g.pendingKull?.stage === 'counter' ? g.pendingKull.resume : null,
|
||||
continuation?.kind === 'kullCounterDiscard' ? continuation.frame.resume : null];
|
||||
return contexts.flatMap(context => {
|
||||
const responses = contexts.flatMap(context => {
|
||||
const karama = context && 'pendingKarama' in context ? context.pendingKarama as Game['pendingKarama'] : null;
|
||||
return [context?.response, karama?.use.kind === 'cancel' ? karama.use.response : null];
|
||||
}).filter((response): response is ResponseWindow => !!response);
|
||||
return responses.flatMap(response => response.emperorGuildRateGift
|
||||
? [response, response.emperorGuildRateGift.response] : [response]);
|
||||
}
|
||||
/** Bind both private stages, also while a card effect has saved their controls. */
|
||||
function leaderSkillNoFieldIntegrity(g: Game): boolean {
|
||||
@@ -43830,6 +43890,15 @@ function applyActionWithInitiator(state: Game, id: string, action: Action, initi
|
||||
emperorExtortionGiftIntegrity(state);
|
||||
emperorAuctionGiftIntegrity(state);
|
||||
emperorGuildTimingGiftIntegrity(state);
|
||||
emperorGuildRateGiftIntegrity(state);
|
||||
const rateGiftResponse = state.response?.emperorGuildRateGift ||
|
||||
(state.pendingKarama?.use.kind === 'cancel' && state.pendingKarama.use.response.emperorGuildRateGift);
|
||||
if (rateGiftResponse && action?.type !== 'advanceBots')
|
||||
requireRule(action?.type === 'passResponse' || action?.type === 'card' && action.mode === 'cancel',
|
||||
'Resolve the Emperor gift response before another action.');
|
||||
if (emperorGuildRatePriority(state) && action?.type !== 'advanceBots')
|
||||
requireRule(action?.type === 'emperorGift' || action?.type === 'emperorGuildRateContinue',
|
||||
'Wait for the Emperor to share spice or continue.');
|
||||
const phaseGiftResponse = state.response?.emperorPhaseOpeningGift ||
|
||||
(state.pendingKarama?.use.kind === 'cancel' && state.pendingKarama.use.response.emperorPhaseOpeningGift);
|
||||
if (phaseGiftResponse && action?.type !== 'advanceBots')
|
||||
@@ -44743,6 +44812,7 @@ function settleAutomaticContinuations(g: Game) {
|
||||
if (g.pendingHomeworldOccupiedPercentage || g.pendingHomeworldOccupiedBonus && !g.decision) return;
|
||||
if (response?.kind === 'ixAuction' && g.homeworldOccupationPreview &&
|
||||
quoteOccupiedBiddingAuthority(g, 'ixAuction').blocked) return;
|
||||
if (response && emperorGuildRatePriority(g)) return;
|
||||
if (response) {
|
||||
if (
|
||||
!(
|
||||
@@ -44800,6 +44870,7 @@ export function normalizeAutomaticGame(state: Game): Game {
|
||||
emperorExtortionGiftIntegrity(state);
|
||||
emperorAuctionGiftIntegrity(state);
|
||||
emperorGuildTimingGiftIntegrity(state);
|
||||
emperorGuildRateGiftIntegrity(state);
|
||||
twoPlayerControllersIntegrity(state);
|
||||
factionDraftIntegrity(state);
|
||||
factionSwapIntegrity(state);
|
||||
@@ -45661,8 +45732,29 @@ function applyActionInner(
|
||||
} };
|
||||
return g;
|
||||
}
|
||||
if (t === 'emperorGuildRateContinue') {
|
||||
const priority = emperorGuildRatePriority(g);
|
||||
requireRule(priority && priority.emperor === id && action.event === priority.event &&
|
||||
Object.keys(action).sort().join(',') === 'event,type',
|
||||
'Continue only your current Emperor Guild-rate opportunity.');
|
||||
g.emperorGuildRateGiftRelease = {event:priority.event, emperor:id};
|
||||
return g;
|
||||
}
|
||||
if (t === 'emperorGift' && g.response?.kind === 'guildRate') {
|
||||
const quote = emperorGuildRateGiftQuote(g, p);
|
||||
requireRule(quote && Object.keys(action).sort().join(',') === 'amount,type',
|
||||
'This Guild-rate gift is unavailable or no longer current.');
|
||||
const amount = integer(action.amount, 1, quote.maximum, 'Spice');
|
||||
const parent = structuredClone(g.response);
|
||||
const event = parent.guildRateEvent ?? parent.guildTransportEvent!;
|
||||
g.emperorGuildRateGiftRelease = {event, emperor:id};
|
||||
g.response = {kind:'emperorGift', owner:id, recipient:quote.recipient, amount, elite:0, passed:[],
|
||||
emperorGuildRateGift:{event,response:parent,signature:emperorGuildRateGiftSignature(g,parent,id,quote.recipient,amount)}};
|
||||
return g;
|
||||
}
|
||||
if (g.response) {
|
||||
const response = g.response;
|
||||
requireRule(!emperorGuildRatePriority(g), 'Wait for the Emperor to share spice or continue.');
|
||||
if (response.kind === 'fremenMovement') pendingFremenMovement(g, response);
|
||||
if (t === 'passResponse') {
|
||||
requireRule(
|
||||
@@ -49478,6 +49570,7 @@ export function viewGame(state: Game, id: string, now?: number) {
|
||||
emperorExtortionGiftIntegrity(state);
|
||||
emperorAuctionGiftIntegrity(state);
|
||||
emperorGuildTimingGiftIntegrity(state);
|
||||
emperorGuildRateGiftIntegrity(state);
|
||||
twoPlayerControllersIntegrity(state);
|
||||
factionDraftIntegrity(state);
|
||||
factionSwapIntegrity(state);
|
||||
@@ -50546,6 +50639,7 @@ export function viewGame(state: Game, id: string, now?: number) {
|
||||
? { amount: undefined }
|
||||
: {}),
|
||||
...(g.response.emperorGuildTimingGift ? { emperorGuildTimingGift: undefined } : {}),
|
||||
...(g.response.emperorGuildRateGift ? { emperorGuildRateGift: undefined } : {}),
|
||||
...(g.response.emperorExtortionGift ? { emperorExtortionGift: undefined } : {}),
|
||||
...(g.response.emperorPhaseOpeningGift ? { emperorPhaseOpeningGift: undefined } : {}),
|
||||
...(g.response.emperorAuctionGiftEvent ? { emperorAuctionGiftEvent: undefined } : {}),
|
||||
@@ -50554,7 +50648,7 @@ export function viewGame(state: Game, id: string, now?: number) {
|
||||
paymentIncome: currentFactionPayment(g),
|
||||
responseControls: g.pendingRicheseBetrayal || g.pendingKull?.stage === 'offer' ? undefined : g.response
|
||||
? {
|
||||
cancelCards: responseCancelCards(g, me, g.response),
|
||||
cancelCards: emperorGuildRatePriority(g) ? [] : responseCancelCards(g, me, g.response),
|
||||
hasPassed: g.response.passed.includes(id),
|
||||
}
|
||||
: undefined,
|
||||
@@ -50615,6 +50709,11 @@ export function viewGame(state: Game, id: string, now?: number) {
|
||||
: 0,
|
||||
},
|
||||
emperorGuildTimingGift: emperorGuildTimingGiftQuote(g, me),
|
||||
emperorGuildRateGift: emperorGuildRateGiftQuote(g, me),
|
||||
emperorGuildRatePriority: (() => {
|
||||
const priority = emperorGuildRatePriority(g);
|
||||
return priority ? {event:priority.event, recipient:priority.recipient, canContinue:priority.emperor === id} : null;
|
||||
})(),
|
||||
emperorExtortionGift: emperorExtortionGiftQuote(g, me),
|
||||
emperorExtortionPriority: (() => {
|
||||
const priority = emperorExtortionPriority(g);
|
||||
|
||||
Reference in new issue
Block a user