/** * @file Apotheosis service handling eligibility checks and state building. * @copyright nhcarrigan * @license Naomi's Public License * @author Naomi Carrigan */ import { initialGameState } from "../data/initialState.js"; import { defaultTranscendenceUpgrades, } from "../data/transcendenceUpgrades.js"; import type { ApotheosisData, GameState } from "@elysium/types"; /** * Total number of echo upgrades — all must be purchased to unlock Apotheosis. */ const totalEchoUpgrades = defaultTranscendenceUpgrades.length; /** * Returns true when the player is eligible to achieve Apotheosis: * all Transcendence echo upgrades must be purchased. * @param state - The current game state. * @returns Whether the player is eligible for Apotheosis. */ const isEligibleForApotheosis = (state: GameState): boolean => { const purchasedIds = state.transcendence?.purchasedUpgradeIds ?? []; return ( purchasedIds.length >= totalEchoUpgrades && defaultTranscendenceUpgrades.every((u) => { return purchasedIds.includes(u.id); }) ); }; /** * Builds the updated game state after Apotheosis — the ultimate nuclear reset. * Wipes absolutely everything including prestige and transcendence. * Only codex lore entries and the apotheosis count itself are preserved. * @param currentState - The current game state before apotheosis. * @param characterName - The character name to carry over. * @returns The updated game state and apotheosis data. */ const buildPostApotheosisState = ( currentState: GameState, characterName: string, ): { updatedApotheosisData: ApotheosisData; updatedState: GameState } => { const apotheosisCount = (currentState.apotheosis?.count ?? 0) + 1; const updatedApotheosisData: ApotheosisData = { count: apotheosisCount }; const freshState = initialGameState(currentState.player, characterName); const updatedState: GameState = { ...freshState, lastTickAt: Date.now(), // Codex lore persists through all resets — players keep their discovered entries ...currentState.codex ? { codex: currentState.codex } : {}, // Apotheosis data is eternal — never wiped by any reset apotheosis: updatedApotheosisData, // Story chapter progress is permanent — survives all resets ...currentState.story ? { story: currentState.story } : {}, }; return { updatedApotheosisData, updatedState }; }; export { buildPostApotheosisState, isEligibleForApotheosis };