Files
Dune/game/recruits.ts
T
Quintine c04cb93830 Connect the Recruits independent-card revival preview
The explicit development initializer now includes the complete three-card Ecaz Treachery variant before genuine Basic/Advanced faction setup. Recruits has owned play/discard controls, full inspection, a public current-rate table, shared authoritative revival quotes, all four AI profiles and persistent exact free-use ledgers. Existing CHOAM/Tleilaxu choices settle before returning forces. Inactive games retain their prior allowance arithmetic.

Clean activation before normal returns or after exactly recorded free returns is connected. Prior-paid/unknown use, later Fremen grants, pending repricing, same-turn recovered-card replay and additional optional modules stay gated. Native unlimited faction advantages remain unlimited. The independent seven-force cap after faction cancellation is explicitly documented as an inference from independent effects, not a direct combined FAQ. Reinforcements and Harass & Withdraw remain unfinished; public starts and publication stay gated.

Independent rules/privacy/persistence review passed. Review fixed auction alias double-counting after a physical card sale, malformed canonical cards, legacy zero-ledger activation, a seat-control validation bypass and an ordinary-start bypass. Focused tests cover readiness and turn expiry as well as authenticated restart, exact free/paid accounting, stale/duplicate requests, competing writes and malformed-save rejection. Types, lint, 4743 offline tests, build and 43 HTTP tests passed with unchanged source.

Eight fixed-seed genuine six-seat samples finish: basic/Easy: 1961 accepted, 0 Recruits plays, 53 JSON restores; basic/Medium: 711 accepted, 0 Recruits plays, 19 JSON restores; basic/Hard: 239 accepted, 0 Recruits plays, 6 JSON restores; basic/Brutal: 1367 accepted, 1 Recruits plays, 36 JSON restores; advanced/Easy: 1402 accepted, 0 Recruits plays, 37 JSON restores; advanced/Medium: 530 accepted, 0 Recruits plays, 14 JSON restores; advanced/Hard: 545 accepted, 1 Recruits plays, 14 JSON restores; advanced/Brutal: 1240 accepted, 1 Recruits plays, 33 JSON restores. Reports retain rejected candidates and earlier harness attempts. All 216 game-source hashes remain identical to the samples; a later presentation-test expectation update changes no game code. Actual card use, custody and periodic/terminal private views are checked; this is bounded playability evidence, not full variant acceptance or AI calibration. A separate conserved browser Revival fixture verifies the full inspector, physical play, public rates, four free returns and active/resolved refresh.

All 902 opening games and original seat/recovery records remain unchanged (936 after checks). All 903 present immediately before broad checks are also preserved. Database integrity and foreign keys pass. The healthy server recovered after the power failure and was reused without restart, reset or recurring automation.

Verified source tree: 1f934f996268b35c8a20d0d617fa962aad878108496fa1a4a05323360757b0e3
2026-09-14 03:44:21 +10:00

98 lines
3.1 KiB
TypeScript

/** A global card effect expires when the authoritative turn changes. */
export type RecruitsEffect = Readonly<{ turn: number }>;
export const RECRUITS_CARD_ID = 'ecaz-recruits' as const;
export type RecruitsPlay = Readonly<{
type: 'card';
card: typeof RECRUITS_CARD_ID;
blocked: string | null;
}>;
export type RecruitsPreview = Readonly<{
active: boolean;
playedTurn?: number;
playedBy?: string;
play: RecruitsPlay | null;
rates: ReadonlyArray<Readonly<{ player: string; freeRate: number; limit: number }>>;
grantRevivalBlocked: string | null;
}>;
/** A single shared control adapter for UI and bots; blocked details stay display-only. */
export function recruitsPlayAction(
preview?: Pick<RecruitsPreview, 'play'> | null,
): { type: 'card'; card: typeof RECRUITS_CARD_ID } | null {
const play = preview?.play;
return play && !play.blocked ? { type: 'card', card: play.card } : null;
}
export type RecruitsScope = Readonly<{
turn: number;
recruits?: RecruitsEffect | null;
}>;
/**
* Resolved facts, measured in physical forces, never battle strength.
* The caller resolves faction, ally, prevention and Homeworld interactions.
* freeAllowanceUsed is deliberately separate from total revived: the sources
* do not settle whether earlier paid revivals consume a newly raised free rate.
* freeRateCap is explicit because the ordinary Fremen cap example does not
* decide every interaction with an unlimited-revival faction.
*/
export type RecruitsRevivalFacts = Readonly<{
currentFreeRate: number;
currentLimit: number;
revived: number;
freeAllowanceUsed: number;
freeRateCap: number;
freeBlocked?: boolean;
revivalBlocked?: boolean;
}>;
export type RecruitsRevivalAllowance = Readonly<{
active: boolean;
freeRate: number;
limit: number;
freeRemaining: number;
remaining: number;
}>;
/**
* Pure resolved-facts arithmetic, not runtime-certified Recruits activation.
* It does not play/discard a card, reopen revival, refund spice, alter a pending
* quote, choose free elite units, or relax an elite unit's separate revival cap.
* Existing unlimited physical limits (currently 20) survive the ordinary raise.
*/
export function recruitsRevivalAllowance(
scope: RecruitsScope,
facts: RecruitsRevivalFacts,
): RecruitsRevivalAllowance {
for (const key of [
'currentFreeRate',
'currentLimit',
'revived',
'freeAllowanceUsed',
'freeRateCap',
] as const)
if (!Number.isSafeInteger(facts[key]) || facts[key] < 0)
throw new RangeError(`${key} must be a nonnegative integer force count.`);
const active = scope.recruits?.turn === scope.turn;
const limit = active ? Math.max(7, facts.currentLimit) : facts.currentLimit;
const freeRate = facts.freeBlocked
? 0
: Math.min(
facts.currentFreeRate * (active ? 2 : 1),
facts.freeRateCap,
limit,
);
const remaining = facts.revivalBlocked
? 0
: Math.max(0, limit - facts.revived);
return {
active,
freeRate,
limit,
remaining,
freeRemaining: Math.min(
remaining,
Math.max(0, freeRate - facts.freeAllowanceUsed),
),
};
}