Support staged group Fremen revival grants
Verify and publish checkpoint container / container (push) Canceled after 0s

This commit is contained in:
Quintine committed 2026-10-28 23:37:46 +11:00
1 parent 9081249574
commit d8d2e7207b
9 files changed
+277 -15

No files matched your search

+46 -7
View File
@@ -1,4 +1,5 @@
import type { Game } from './engine';
import { coalitionOf, CoalitionAllianceError } from './coalition-alliance';
export type FremenRevivalGrantSource = {
turn: number;
@@ -9,7 +10,8 @@ export type FremenRevivalGrantSource = {
export type FremenRevivalGrantContext = Pick<
Game,
'status' | 'phase' | 'turn' | 'players' | 'freeRevival' | 'revivalRules' | 'recruits'
>;
> & Partial<Pick<Game, 'coalitionState' | 'advanced' | 'expansions' | 'homeworlds' |
'nexusCards' | 'leaderSkills' | 'techTokens' | 'strongholdCards' | 'ecazTreachery' | 'discoveryEnabled'>>;
export class FremenRevivalGrantError extends Error {
constructor(message: string) {
@@ -23,12 +25,30 @@ const id = (value: unknown): value is string =>
const count = (value: unknown): value is number =>
Number.isSafeInteger(value) && (value as number) >= 0;
/** Match the unexposed Basic classic group profile; other profiles retain the
* existing mutual-pair path until their interactions are connected. */
function groupRecipients(g: FremenRevivalGrantContext, owner: string): string[] | null {
if (!g.coalitionState || g.status !== 'playing' || g.advanced !== false ||
!Array.isArray(g.expansions) || g.expansions.length || g.homeworlds || g.nexusCards ||
g.leaderSkills || g.techTokens || g.strongholdCards || g.ecazTreachery || g.discoveryEnabled ||
!g.players.every(player => ['atreides', 'beneGesserit', 'emperor', 'fremen', 'guild', 'harkonnen'].includes(player.faction)))
return null;
try {
const group = coalitionOf(g.players, g.coalitionState, owner);
return group?.members.length === 3 ? group.members.filter(member => member !== owner) : null;
} catch (error) {
if (error instanceof CoalitionAllianceError) throw new FremenRevivalGrantError(error.message);
throw error;
}
}
/** Permission only. The engine owns the response and commits or denies this
* source once; normal revival quotes retain rates, prior usage and payment.
* No busy gate belongs here because settlement validates its own response. */
export function fremenRevivalGrantBlock(
g: FremenRevivalGrantContext,
owner: string,
selectedRecipient?: string,
): string | null {
if (g.status !== 'playing' || g.phase !== 4 || !count(g.turn) || g.turn < 1)
return 'Grant Fremen allied free revival during the current Revival phase.';
@@ -39,10 +59,13 @@ export function fremenRevivalGrantBlock(
if (owners.length !== 1 || fremen.faction !== 'fremen' ||
g.players.filter(player => player.faction === 'fremen').length !== 1)
return 'The grant needs the current native Fremen owner.';
const recipients = g.players.filter(player => player.id === fremen.ally);
const group = groupRecipients(g, owner);
const recipientId = group ? selectedRecipient : fremen.ally;
const recipients = g.players.filter(player => player.id === recipientId);
const recipient = recipients[0];
if (!id(fremen.ally) || recipients.length !== 1 ||
recipient.id === owner || recipient.ally !== owner)
if (!id(recipientId) || recipients.length !== 1 || recipient.id === owner ||
(group ? !group.includes(recipientId) : recipient.ally !== owner ||
(selectedRecipient !== undefined && selectedRecipient !== fremen.ally)))
return 'The grant needs the Fremen owner’s current mutual ally.';
if (!Array.isArray(g.freeRevival))
return 'The current Fremen revival permissions are invalid.';
@@ -67,11 +90,12 @@ export function fremenRevivalGrantBlock(
export function quoteFremenRevivalGrant(
g: FremenRevivalGrantContext,
owner: string,
recipient?: string,
): FremenRevivalGrantSource {
const blocked = fremenRevivalGrantBlock(g, owner);
const blocked = fremenRevivalGrantBlock(g, owner, recipient);
if (blocked) throw new FremenRevivalGrantError(blocked);
const fremen = g.players.find(player => player.id === owner)!;
return { turn: g.turn, owner, recipient: fremen.ally! };
return { turn: g.turn, owner, recipient: groupRecipients(g, owner) ? recipient! : fremen.ally! };
}
/** Bind the original relationship and turn before either response outcome.
@@ -85,11 +109,26 @@ export function validateFremenRevivalGrant(
!count(source.turn) || source.turn !== g.turn ||
!id(source.owner) || !id(source.recipient))
throw new FremenRevivalGrantError('The Fremen allied revival grant has lost its original source.');
const current = quoteFremenRevivalGrant(g, source.owner);
const current = quoteFremenRevivalGrant(g, source.owner, source.recipient);
if (current.recipient !== source.recipient)
throw new FremenRevivalGrantError('The Fremen allied revival grant no longer matches its original ally.');
}
/** Separate owner-only projection avoids changing the established pair API. */
export function projectFremenGroupRevivalGrant(
g: FremenRevivalGrantContext,
viewer: string,
): Array<{recipient: string; granted: boolean; blocked: string | null}> | null {
if (!id(viewer) || !Array.isArray(g.players) ||
g.players.filter(player => player.id === viewer && player.faction === 'fremen').length !== 1)
return null;
const recipients = groupRecipients(g, viewer);
if (!recipients) return null;
return recipients.map(recipient => ({recipient,
granted: Array.isArray(g.freeRevival) && g.freeRevival.includes(recipient),
blocked: fremenRevivalGrantBlock(g, viewer, recipient)}));
}
/** Owner-only status. No wallet, Tanks, prior counts or quoted free amount is
* projected; the existing normal revival panel owns numerical allowances. */
export function projectFremenRevivalGrant(