/** * @file Transcendence panel component for the second prestige layer. * @copyright nhcarrigan * @license Naomi's Public License * @author Naomi Carrigan */ /* eslint-disable max-lines-per-function -- Complex component with many render paths */ /* eslint-disable complexity -- Many conditional render paths */ /* eslint-disable max-statements -- Transcendence panel manages many local state variables */ /* eslint-disable max-lines -- Transcendence panel with CDN images exceeds line limit */ import { useState, type JSX } from "react"; import { useGame } from "../../context/gameContext.js"; import { TRANSCENDENCE_UPGRADES, TRANSCENDENCE_UPGRADE_CATEGORY_LABELS, } from "../../data/transcendenceUpgrades.js"; import { cdnImage } from "../../utils/cdn.js"; import type { TranscendenceUpgradeCategory } from "@elysium/types"; const echoFormulaConstant = 853; const finalBossId = "the_absolute_one"; /** * Calculates the echo preview for a transcendence. * @param prestigeCount - The current prestige count. * @param echoMetaMultiplier - The echo meta multiplier from upgrades. * @returns The predicted echo reward. */ const calculateEchoPreview = ( prestigeCount: number, echoMetaMultiplier: number, ): number => { const safeCount = Math.max(prestigeCount, 1); return Math.floor( // eslint-disable-next-line stylistic/no-extra-parens -- Required by no-mixed-operators rule (echoFormulaConstant / Math.sqrt(safeCount)) * echoMetaMultiplier, ); }; const categoryOrder: Array = [ "income", "combat", "prestige_threshold", "prestige_runestones", "echo_meta", ]; /** * Renders the transcendence panel with transcendence and echo shop tabs. * @returns The JSX element. */ const TranscendencePanel = (): JSX.Element => { const { state, formatInteger, transcend, buyEchoUpgrade } = useGame(); const [ isPending, setIsPending ] = useState(false); const [ result, setResult ] = useState<{ echoes: number; count: number; } | null>(null); const [ error, setError ] = useState(null); const [ buyingId, setBuyingId ] = useState(null); type TranscendTab = "transcend" | "shop"; const [ activeTab, setActiveTab ] = useState("transcend"); if (state === null) { return (

{"Loading..."}

); } const { bosses, prestige: prestigeData, transcendence } = state; const hasDefeatedFinalBoss = bosses.some((boss) => { return boss.id === finalBossId && boss.status === "defeated"; }); const echoMetaMultiplier = transcendence?.echoMetaMultiplier ?? 1; const echoPreview = calculateEchoPreview( prestigeData.count, echoMetaMultiplier, ); const currentEchoes = transcendence?.echoes ?? 0; const transcendenceCount = transcendence?.count ?? 0; async function handleTranscend(): Promise { setIsPending(true); setError(null); try { const data = await transcend(); setResult({ count: data.newTranscendenceCount, echoes: data.echoes }); } catch (error_: unknown) { setError( error_ instanceof Error ? error_.message : "Transcendence failed", ); } finally { setIsPending(false); } } async function handleBuyUpgrade(upgradeId: string): Promise { setBuyingId(upgradeId); try { await buyEchoUpgrade(upgradeId); } finally { setBuyingId(null); } } const upgradesByCategory = categoryOrder.map((catId) => { const categoryLabels = TRANSCENDENCE_UPGRADE_CATEGORY_LABELS; const label = categoryLabels[catId] ?? catId; const upgrades = TRANSCENDENCE_UPGRADES.filter((upgrade) => { return upgrade.category === catId; }); return { catId, label, upgrades }; }); function handleTranscendClick(): void { void handleTranscend(); } function handleTranscendTabClick(): void { setActiveTab("transcend"); } function handleShopTabClick(): void { setActiveTab("shop"); } return (

{"🌌 Transcendence"}

{activeTab === "transcend" && <>

{"Transcendence is the ultimate reset. It wipes "} {"everything"} {" — resources, prestige, runestones, upgrades, and equipment" + " — but grants "} {"Echoes"} {", a permanent currency that survives all future resets."} {" Echoes power upgrades that permanently amplify every run."}

{"Fewer prestiges = more Echoes."} {" Optimise your run for maximum yield!"}

{transcendenceCount > 0 &&

{"Transcendence count: "} {transcendenceCount}

}

{"Current Echoes: "} {formatInteger(currentEchoes)}

{"Current prestige count: "} {prestigeData.count}

{hasDefeatedFinalBoss ?

{"Echoes on transcendence: "} {"+"} {formatInteger(echoPreview)} {echoMetaMultiplier > 1 && {" (×"} {echoMetaMultiplier.toFixed(2)} {" meta bonus applied)"} }

: null}
{hasDefeatedFinalBoss ? null :

{"🔒 "} {"Defeat The Absolute One"} {" to unlock transcendence."}

{"The Absolute One is the final boss of The Absolute zone," + " requiring Prestige 90 to challenge."}

} {hasDefeatedFinalBoss ?

{"You are ready to transcend. This action is "} {"irreversible"} {"."}

{error === null ? null :

{error}

} {result === null ? null :

{"Transcended! Earned "} {formatInteger(result.echoes)} {" Echoes"} {". This is Transcendence "} {result.count} {". A new cycle begins."}

}
: null} } {activeTab === "shop" &&

{"Balance: "} {formatInteger(currentEchoes)} {" Echoes"}

{"Echo upgrades are "} {"permanent"} {" — they survive all future prestiges and transcendences."}

{upgradesByCategory.map(({ catId, label, upgrades }) => { return (

{label}

{upgrades.map((upgrade) => { const purchased = ( transcendence?.purchasedUpgradeIds ?? [] ).includes(upgrade.id); const canAfford = currentEchoes >= upgrade.cost; const isLoading = buyingId === upgrade.id; function handleBuyClick(): void { void handleBuyUpgrade(upgrade.id); } return (
{upgrade.name}

{upgrade.name}

{upgrade.description}

{purchased ? "✅ Purchased" : `✨ ${formatInteger(upgrade.cost)} Echoes`}

{purchased ? null : }
); })}
); })}
}
); }; export { TranscendencePanel };