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
261 lines
7.6 KiB
TypeScript
261 lines
7.6 KiB
TypeScript
import type { Game, Player } from './engine';
|
|
import { faction, type FactionId } from './catalog';
|
|
import { isAuditorLeader } from './choam-auditor';
|
|
import { homeworldLowBonus } from './homeworld-benefits';
|
|
import { recruitsRevivalAllowance } from './recruits';
|
|
type RevivalRateContext = Pick<
|
|
Game,
|
|
| 'advanced'
|
|
| 'players'
|
|
| 'homeworlds'
|
|
| 'revivalRules'
|
|
| 'freeRevival'
|
|
| 'turn'
|
|
| 'recruits'
|
|
>;
|
|
export type RevivalRules = {
|
|
expanded: string[];
|
|
choamBlocked?: boolean;
|
|
freeBlocked?: string[];
|
|
limitBlocked: boolean;
|
|
fullPrice: boolean;
|
|
allyDiscount: string | null;
|
|
discountBlocked: boolean;
|
|
earlyBlocked: string[];
|
|
};
|
|
export const newRevivalRules = (): RevivalRules => ({
|
|
expanded: [],
|
|
limitBlocked: false,
|
|
fullPrice: false,
|
|
allyDiscount: null,
|
|
discountBlocked: false,
|
|
earlyBlocked: [],
|
|
});
|
|
export function forceRevivalLimit(
|
|
g: Pick<Game, 'revivalRules'>,
|
|
p: Pick<Player, 'id' | 'faction'>,
|
|
) {
|
|
if (p.faction === 'choam' && !g.revivalRules?.choamBlocked) return 20;
|
|
if (g.revivalRules?.limitBlocked) return 3;
|
|
if (p.faction === 'tleilaxu') return 20;
|
|
return g.revivalRules?.expanded.includes(p.id) ? 5 : 3;
|
|
}
|
|
export function revivalDiscount(
|
|
g: Pick<Game, 'players' | 'revivalRules'>,
|
|
p: Pick<Player, 'id' | 'faction'>,
|
|
) {
|
|
if (p.faction === 'tleilaxu') return !g.revivalRules?.fullPrice;
|
|
return (
|
|
!g.revivalRules?.discountBlocked &&
|
|
g.revivalRules?.allyDiscount === p.id &&
|
|
g.players.some((t) => t.faction === 'tleilaxu' && t.ally === p.id)
|
|
);
|
|
}
|
|
export function freeRevivalRate(
|
|
g: RevivalRateContext,
|
|
p: Pick<Player, 'id' | 'faction'>,
|
|
) {
|
|
return g.revivalRules?.freeBlocked?.includes(p.id)
|
|
? 0
|
|
: (g.freeRevival.includes(p.id) ? 3 : faction(p.faction).revival) +
|
|
homeworldLowBonus(g, p.id);
|
|
}
|
|
/** E3's explicit four-free Fremen rate may exceed the ordinary three-return cap;
|
|
* the extra free rate never creates an additional paid allowance. */
|
|
export function normalForceRevivalLimit(
|
|
g: RevivalRateContext,
|
|
p: Pick<Player, 'id' | 'faction' | 'revived' | 'freeForcesRevived'>,
|
|
) {
|
|
return normalRevivalAllowance(g, p).limit;
|
|
}
|
|
export function normalRevivalAllowance(
|
|
g: RevivalRateContext,
|
|
p: Pick<Player, 'id' | 'faction' | 'revived' | 'freeForcesRevived'>,
|
|
) {
|
|
const currentFreeRate = freeRevivalRate(g, p);
|
|
return recruitsRevivalAllowance(g, {
|
|
currentFreeRate,
|
|
currentLimit: Math.max(forceRevivalLimit(g, p), currentFreeRate),
|
|
revived: p.revived,
|
|
// A Recruits activation is rejected when this ledger is absent and use is
|
|
// nonzero. The fallback preserves old-room behavior while the card is idle.
|
|
freeAllowanceUsed:
|
|
g.recruits?.turn === g.turn ? (p.freeForcesRevived ?? p.revived) : p.revived,
|
|
freeRateCap: 20,
|
|
});
|
|
}
|
|
export function freeRevivalRemaining(
|
|
g: RevivalRateContext,
|
|
p: Pick<Player, 'id' | 'faction' | 'revived' | 'freeForcesRevived'>,
|
|
) {
|
|
return normalRevivalAllowance(g, p).freeRemaining;
|
|
}
|
|
export function forceRevivalQuote(
|
|
g: RevivalRateContext,
|
|
p: Pick<Player, 'id' | 'faction' | 'revived' | 'freeForcesRevived'>,
|
|
amount: number,
|
|
elite = 0,
|
|
freeElite?: number,
|
|
) {
|
|
const free = Math.min(amount, freeRevivalRemaining(g, p));
|
|
return forceRevivalPrice(
|
|
p.faction,
|
|
amount,
|
|
elite,
|
|
free,
|
|
!!revivalDiscount(g, p),
|
|
freeElite,
|
|
!!g.revivalRules?.choamBlocked,
|
|
);
|
|
}
|
|
|
|
/** Normal force returns only; Emperor-funded extra revivals and card effects are separate. */
|
|
export function forceRevivalRemaining(
|
|
g: RevivalRateContext,
|
|
p: Pick<Player, 'id' | 'faction' | 'revived' | 'freeForcesRevived' | 'tanks'>,
|
|
) {
|
|
return Math.max(
|
|
0,
|
|
Math.min(
|
|
p.tanks,
|
|
normalForceRevivalLimit(g, p) - p.revived,
|
|
// GF9 November 2020 FAQ p. 5 permits paid Fremen revivals with Tleilaxu in play.
|
|
// Selecting expansion cards alone does not provide that faction's permission.
|
|
p.faction === 'fremen' &&
|
|
!g.players.some((player) => player.faction === 'tleilaxu')
|
|
? freeRevivalRemaining(g, p)
|
|
: Infinity,
|
|
),
|
|
);
|
|
}
|
|
export function normalRevivalCycle(
|
|
p: Pick<Player, 'leaders' | 'revivalCycle'>,
|
|
) {
|
|
return p.leaders.every((l) => l.dead || l.capturedBy || l.gholaBy)
|
|
? Math.min(...p.leaders.map((l) => (l.dead ? l.deaths : l.deaths + 1)))
|
|
: p.revivalCycle;
|
|
}
|
|
|
|
/** Native leader options for the existing ordinary cycle and Tleilaxu self-service.
|
|
* Shared discs are deliberately separate: Ecaz's six-disc cycle is not implemented here.
|
|
* This is a pure quote; committing an action, not reading a view, advances the cycle.
|
|
*/
|
|
export function leaderRevivalOptions(g: Game, p: Player) {
|
|
const cycle = normalRevivalCycle(p);
|
|
const enabled = g.phase === 4 && !revivalPrevented(g, p.id);
|
|
const discount = revivalDiscount(g, p);
|
|
const leaders = p.leaders.flatMap((leader) => {
|
|
if (!enabled || !leader.dead || leader.capturedBy || leader.gholaBy)
|
|
return [];
|
|
// Auditor's first return expressly waives the all-in-Tanks prerequisite.
|
|
// Repeat-death and sixth-disc cycle interpretations remain separately unverified.
|
|
const auditorFirstReturn =
|
|
g.advanced &&
|
|
p.faction === 'choam' &&
|
|
isAuditorLeader(leader) &&
|
|
leader.deaths === 1;
|
|
const normal =
|
|
!p.leaderRevived &&
|
|
(auditorFirstReturn || (cycle > 0 && leader.deaths === cycle));
|
|
if (
|
|
!normal &&
|
|
(p.faction !== 'tleilaxu' ||
|
|
g.revivalRules?.earlyBlocked.includes(`${p.id}:${leader.id}`))
|
|
)
|
|
return [];
|
|
const cost = discount ? Math.ceil(leader.strength / 2) : leader.strength;
|
|
return [
|
|
{
|
|
id: leader.id,
|
|
name: leader.name,
|
|
normalCost: leader.strength,
|
|
cost,
|
|
early: !normal,
|
|
affordable: p.spice >= cost,
|
|
},
|
|
];
|
|
});
|
|
const kwisatzCost = discount ? 1 : 2;
|
|
const kwisatz =
|
|
enabled &&
|
|
g.advanced &&
|
|
p.faction === 'atreides' &&
|
|
p.kwisatz?.dead &&
|
|
!p.leaderRevived &&
|
|
cycle >= (p.kwisatz.revivalCycle ?? 1)
|
|
? { cost: kwisatzCost, affordable: p.spice >= kwisatzCost }
|
|
: null;
|
|
return { cycle, leaders, kwisatz };
|
|
}
|
|
export type PendingRevival = {
|
|
player: string;
|
|
kind: 'forces' | 'leader' | 'kwisatz' | 'foreignGhola';
|
|
payer?: string;
|
|
emperorExtra?: boolean;
|
|
amount?: number;
|
|
elite?: number;
|
|
leader?: string;
|
|
normalCost: number;
|
|
cost: number;
|
|
free: number;
|
|
checks: (
|
|
| 'choamRevival'
|
|
| 'revivalLimit'
|
|
| 'revivalDiscount'
|
|
| 'earlyRevival'
|
|
| 'foreignGhola'
|
|
)[];
|
|
};
|
|
|
|
export function revivalPrevented(
|
|
g: Pick<Game, 'turn' | 'phase' | 'revivalPrevention'>,
|
|
player: string,
|
|
) {
|
|
return (
|
|
g.phase === 4 &&
|
|
g.revivalPrevention?.turn === g.turn &&
|
|
g.revivalPrevention.player === player
|
|
);
|
|
}
|
|
|
|
export function eliteRevivalRemaining(
|
|
p: Pick<Player, 'faction' | 'elites'>,
|
|
advanced = true,
|
|
) {
|
|
return !advanced || p.faction === 'ixians'
|
|
? (p.elites?.tanks ?? 0)
|
|
: Math.min(p.elites?.tanks ?? 0, Math.max(0, 1 - (p.elites?.revived ?? 0)));
|
|
}
|
|
export function paidForceRevivalCost(
|
|
p: Pick<Player, 'faction'>,
|
|
amount: number,
|
|
elite = 0,
|
|
) {
|
|
return amount * 2 + (p.faction === 'ixians' ? elite : 0);
|
|
}
|
|
|
|
export function forceRevivalPrice(
|
|
faction: FactionId,
|
|
amount: number,
|
|
elite: number,
|
|
free: number,
|
|
discount: boolean,
|
|
freeElite?: number,
|
|
choamBlocked = false,
|
|
) {
|
|
const freeCyborgs =
|
|
faction === 'ixians' ? (freeElite ?? Math.min(free, elite)) : 0;
|
|
const normalCost = paidForceRevivalCost(
|
|
{ faction },
|
|
amount - free,
|
|
faction === 'ixians' ? elite - freeCyborgs : 0,
|
|
);
|
|
const factionCost =
|
|
faction === 'choam' && !choamBlocked ? amount - free : normalCost;
|
|
return {
|
|
free,
|
|
normalCost,
|
|
cost: discount ? Math.ceil(factionCost / 2) : factionCost,
|
|
};
|
|
}
|