import type { ApotheosisData, GameState } from "@elysium/types"; import { INITIAL_GAME_STATE } from "../data/initialState.js"; import { DEFAULT_TRANSCENDENCE_UPGRADES } from "../data/transcendenceUpgrades.js"; /** Total number of echo upgrades — all must be purchased to unlock Apotheosis */ const TOTAL_ECHO_UPGRADES = DEFAULT_TRANSCENDENCE_UPGRADES.length; /** * Returns true when the player is eligible to achieve Apotheosis: * all Transcendence echo upgrades must be purchased. */ export const isEligibleForApotheosis = (state: GameState): boolean => { const purchasedIds = state.transcendence?.purchasedUpgradeIds ?? []; return purchasedIds.length >= TOTAL_ECHO_UPGRADES && DEFAULT_TRANSCENDENCE_UPGRADES.every((u) => purchasedIds.includes(u.id)); }; /** * Builds the new 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. */ export const buildPostApotheosisState = ( currentState: GameState, characterName: string, ): { newState: GameState; newApotheosisData: ApotheosisData } => { const newCount = (currentState.apotheosis?.count ?? 0) + 1; const newApotheosisData: ApotheosisData = { count: newCount }; const freshState = INITIAL_GAME_STATE(currentState.player, characterName); const newState: 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: newApotheosisData, }; return { newState, newApotheosisData }; };