generated from nhcarrigan/template
feat: add transcendence second prestige layer
Implements the full Transcendence system — the ultimate endgame mechanic, unlocked by defeating The Absolute One (requires Prestige 90). Nuclear reset model: wipes resources, prestige, runestones, upgrades, equipment, bosses, quests, zones, and achievements. Codex entries and lifetime profile stats are preserved. Transcendence data is permanent and accumulates across all future resets. Echo formula: floor(853 / sqrt(prestigeCount)) × echoMetaMultiplier Fewer prestiges = more Echoes, rewarding optimised play. 15 Echo upgrades across 5 categories: - Income multipliers (×1.25 → ×5): 5 tiers, cost 5–80 echoes - Combat multipliers (×1.25 → ×2): 3 tiers, cost 5–35 echoes - Prestige threshold reductions (×0.9, ×0.8): cost 8–20 echoes - Prestige runestone multipliers (×1.5, ×2): cost 8–20 echoes - Echo meta multipliers (×1.25 → ×2): cost 10–50 echoes New files: Transcendence.ts types, transcendence service, route, data files (API + web), TranscendencePanel.tsx component. Modified: GameState, Api, types/index, prestige service (carries transcendence through resets, applies echo multipliers), boss route (echoCombatMultiplier), game.ts anti-cheat (echo cap), tick.ts (echoIncomeMultiplier), GameContext, API client, GameLayout (new tab), ResourceBar (transcendence badge alongside prestige badge), styles.css, AboutPanel, IDEAS.md.
This commit is contained in:
@@ -0,0 +1,133 @@
|
||||
import type { TranscendenceUpgrade } from "@elysium/types";
|
||||
|
||||
export const DEFAULT_TRANSCENDENCE_UPGRADES: TranscendenceUpgrade[] = [
|
||||
// ── Income multipliers ──────────────────────────────────────────────────────
|
||||
{
|
||||
id: "echo_income_1",
|
||||
name: "Whisper of Power",
|
||||
description: "The echoes of past runs linger, amplifying your guild's income by 25%.",
|
||||
category: "income",
|
||||
cost: 5,
|
||||
multiplier: 1.25,
|
||||
},
|
||||
{
|
||||
id: "echo_income_2",
|
||||
name: "Resonance",
|
||||
description: "Your transcendent experience resonates through your guild, boosting income by 50%.",
|
||||
category: "income",
|
||||
cost: 10,
|
||||
multiplier: 1.5,
|
||||
},
|
||||
{
|
||||
id: "echo_income_3",
|
||||
name: "Harmonic Surge",
|
||||
description: "The harmony of multiple timelines surges through your guild, doubling its income.",
|
||||
category: "income",
|
||||
cost: 20,
|
||||
multiplier: 2.0,
|
||||
},
|
||||
{
|
||||
id: "echo_income_4",
|
||||
name: "Ethereal Overflow",
|
||||
description: "Ethereal energy overflows from your transcendence, tripling your guild's income.",
|
||||
category: "income",
|
||||
cost: 40,
|
||||
multiplier: 3.0,
|
||||
},
|
||||
{
|
||||
id: "echo_income_5",
|
||||
name: "Infinite Chorus",
|
||||
description: "The infinite chorus of every run you've ever played amplifies your guild fivefold.",
|
||||
category: "income",
|
||||
cost: 80,
|
||||
multiplier: 5.0,
|
||||
},
|
||||
|
||||
// ── Combat multipliers ──────────────────────────────────────────────────────
|
||||
{
|
||||
id: "echo_combat_1",
|
||||
name: "Battle-Hardened",
|
||||
description: "Memories of countless battles harden your adventurers, increasing party DPS by 25%.",
|
||||
category: "combat",
|
||||
cost: 5,
|
||||
multiplier: 1.25,
|
||||
},
|
||||
{
|
||||
id: "echo_combat_2",
|
||||
name: "Veteran's Edge",
|
||||
description: "Veterans of transcendence know how to fight smarter, boosting party DPS by 50%.",
|
||||
category: "combat",
|
||||
cost: 15,
|
||||
multiplier: 1.5,
|
||||
},
|
||||
{
|
||||
id: "echo_combat_3",
|
||||
name: "Transcendent Warrior",
|
||||
description: "Your warriors carry the strength of every fallen timeline, doubling party DPS.",
|
||||
category: "combat",
|
||||
cost: 35,
|
||||
multiplier: 2.0,
|
||||
},
|
||||
|
||||
// ── Prestige threshold reductions ──────────────────────────────────────────
|
||||
{
|
||||
id: "echo_prestige_threshold_1",
|
||||
name: "Accelerated Path",
|
||||
description: "Experience from past lives shortens the road to prestige — threshold reduced by 10%.",
|
||||
category: "prestige_threshold",
|
||||
cost: 8,
|
||||
multiplier: 0.9,
|
||||
},
|
||||
{
|
||||
id: "echo_prestige_threshold_2",
|
||||
name: "Shortcut Through Time",
|
||||
description: "You've walked this path so many times you know every shortcut — threshold reduced by 20%.",
|
||||
category: "prestige_threshold",
|
||||
cost: 20,
|
||||
multiplier: 0.8,
|
||||
},
|
||||
|
||||
// ── Prestige runestone multipliers ─────────────────────────────────────────
|
||||
{
|
||||
id: "echo_prestige_runestones_1",
|
||||
name: "Runic Attunement",
|
||||
description: "Transcendent insight attunes you to the runestones, earning 50% more per prestige.",
|
||||
category: "prestige_runestones",
|
||||
cost: 8,
|
||||
multiplier: 1.5,
|
||||
},
|
||||
{
|
||||
id: "echo_prestige_runestones_2",
|
||||
name: "Master Runesmith",
|
||||
description: "You have mastered the art of runestone crafting, doubling your prestige runestone yield.",
|
||||
category: "prestige_runestones",
|
||||
cost: 20,
|
||||
multiplier: 2.0,
|
||||
},
|
||||
|
||||
// ── Echo meta multipliers ───────────────────────────────────────────────────
|
||||
{
|
||||
id: "echo_meta_1",
|
||||
name: "Resonant Awakening",
|
||||
description: "Your transcendence resonates deeper, amplifying future echo yields by 25%.",
|
||||
category: "echo_meta",
|
||||
cost: 10,
|
||||
multiplier: 1.25,
|
||||
},
|
||||
{
|
||||
id: "echo_meta_2",
|
||||
name: "Transcendent Loop",
|
||||
description: "Each loop of existence makes the next more powerful — future echo yields +50%.",
|
||||
category: "echo_meta",
|
||||
cost: 25,
|
||||
multiplier: 1.5,
|
||||
},
|
||||
{
|
||||
id: "echo_meta_3",
|
||||
name: "Infinite Spiral",
|
||||
description: "You have mastered the infinite spiral of transcendence, doubling all future echo yields.",
|
||||
category: "echo_meta",
|
||||
cost: 50,
|
||||
multiplier: 2.0,
|
||||
},
|
||||
];
|
||||
@@ -7,6 +7,7 @@ import { authRouter } from "./routes/auth.js";
|
||||
import { bossRouter } from "./routes/boss.js";
|
||||
import { gameRouter } from "./routes/game.js";
|
||||
import { prestigeRouter } from "./routes/prestige.js";
|
||||
import { transcendenceRouter } from "./routes/transcendence.js";
|
||||
import { profileRouter } from "./routes/profile.js";
|
||||
|
||||
const app = new Hono();
|
||||
@@ -26,6 +27,7 @@ app.route("/auth", authRouter);
|
||||
app.route("/game", gameRouter);
|
||||
app.route("/boss", bossRouter);
|
||||
app.route("/prestige", prestigeRouter);
|
||||
app.route("/transcendence", transcendenceRouter);
|
||||
app.route("/profile", profileRouter);
|
||||
|
||||
app.get("/health", (context) => context.json({ status: "ok" }));
|
||||
|
||||
@@ -59,7 +59,8 @@ const calculatePartyStats = (
|
||||
partyMaxHp += adventurer.level * 50 * adventurer.count;
|
||||
}
|
||||
|
||||
partyDPS *= equipmentCombatMultiplier * setCombatMultiplier;
|
||||
const echoCombatMultiplier = state.transcendence?.echoCombatMultiplier ?? 1;
|
||||
partyDPS *= equipmentCombatMultiplier * setCombatMultiplier * echoCombatMultiplier;
|
||||
|
||||
return { partyDPS, partyMaxHp };
|
||||
};
|
||||
|
||||
@@ -290,7 +290,19 @@ const validateAndSanitize = (incoming: GameState, previous: GameState): GameStat
|
||||
const prestige =
|
||||
incoming.prestige.count < previous.prestige.count ? previous.prestige : incoming.prestige;
|
||||
|
||||
return { ...incoming, resources, bosses, quests, achievements, prestige };
|
||||
// Echoes are only granted server-side via transcendence and can only decrease between
|
||||
// saves (spent on echo upgrades). Cap at the previous value to block inflation.
|
||||
const cappedEchoes = Math.min(
|
||||
incoming.transcendence?.echoes ?? 0,
|
||||
previous.transcendence?.echoes ?? 0,
|
||||
);
|
||||
const transcendenceSpread = incoming.transcendence
|
||||
? { transcendence: { ...incoming.transcendence, echoes: cappedEchoes } }
|
||||
: previous.transcendence
|
||||
? { transcendence: previous.transcendence }
|
||||
: {};
|
||||
|
||||
return { ...incoming, resources, bosses, quests, achievements, prestige, ...transcendenceSpread };
|
||||
};
|
||||
|
||||
export const gameRouter = new Hono<HonoEnv>();
|
||||
|
||||
@@ -0,0 +1,140 @@
|
||||
import type { BuyEchoUpgradeRequest, GameState, TranscendenceRequest } from "@elysium/types";
|
||||
import { Hono } from "hono";
|
||||
import type { HonoEnv } from "../types/hono.js";
|
||||
import { prisma } from "../db/client.js";
|
||||
import { authMiddleware } from "../middleware/auth.js";
|
||||
import { DEFAULT_TRANSCENDENCE_UPGRADES } from "../data/transcendenceUpgrades.js";
|
||||
import {
|
||||
buildPostTranscendenceState,
|
||||
computeTranscendenceMultipliers,
|
||||
isEligibleForTranscendence,
|
||||
} from "../services/transcendence.js";
|
||||
|
||||
export const transcendenceRouter = new Hono<HonoEnv>();
|
||||
|
||||
transcendenceRouter.use("*", authMiddleware);
|
||||
|
||||
transcendenceRouter.post("/", async (context) => {
|
||||
const discordId = context.get("discordId") as string;
|
||||
const body = await context.req.json<TranscendenceRequest>();
|
||||
|
||||
const characterName = body.characterName?.trim();
|
||||
if (!characterName) {
|
||||
return context.json({ error: "characterName is required" }, 400);
|
||||
}
|
||||
|
||||
const record = await prisma.gameState.findUnique({ where: { discordId } });
|
||||
if (!record) {
|
||||
return context.json({ error: "No save found" }, 404);
|
||||
}
|
||||
|
||||
const state = record.state as unknown as GameState;
|
||||
|
||||
if (!isEligibleForTranscendence(state)) {
|
||||
return context.json(
|
||||
{ error: "Not eligible for transcendence — defeat The Absolute One first" },
|
||||
400,
|
||||
);
|
||||
}
|
||||
|
||||
const { newState, newTranscendenceData, echoesEarned } = buildPostTranscendenceState(
|
||||
state,
|
||||
characterName,
|
||||
);
|
||||
|
||||
// Capture current-run stats before the nuclear reset
|
||||
const runBossesDefeated = state.bosses.filter((b) => b.status === "defeated").length;
|
||||
const runQuestsCompleted = state.quests.filter((q) => q.status === "completed").length;
|
||||
const runAdventurersRecruited = state.adventurers.reduce((sum, a) => sum + a.count, 0);
|
||||
const runAchievementsUnlocked = (state.achievements ?? []).filter((a) => a.unlockedAt !== null).length;
|
||||
|
||||
const now = Date.now();
|
||||
await prisma.gameState.update({
|
||||
where: { discordId },
|
||||
data: { state: newState as object, updatedAt: now },
|
||||
});
|
||||
|
||||
await prisma.player.update({
|
||||
where: { discordId },
|
||||
data: {
|
||||
characterName,
|
||||
// Reset current-run counters (same as prestige)
|
||||
totalGoldEarned: 0,
|
||||
totalClicks: 0,
|
||||
// Accumulate into lifetime totals
|
||||
lifetimeGoldEarned: { increment: state.player.totalGoldEarned },
|
||||
lifetimeClicks: { increment: state.player.totalClicks },
|
||||
lifetimeBossesDefeated: { increment: runBossesDefeated },
|
||||
lifetimeQuestsCompleted: { increment: runQuestsCompleted },
|
||||
lifetimeAdventurersRecruited: { increment: runAdventurersRecruited },
|
||||
lifetimeAchievementsUnlocked: { increment: runAchievementsUnlocked },
|
||||
lastSavedAt: now,
|
||||
},
|
||||
});
|
||||
|
||||
return context.json({
|
||||
echoes: echoesEarned,
|
||||
newTranscendenceCount: newTranscendenceData.count,
|
||||
});
|
||||
});
|
||||
|
||||
transcendenceRouter.post("/buy-upgrade", async (context) => {
|
||||
const discordId = context.get("discordId") as string;
|
||||
const body = await context.req.json<BuyEchoUpgradeRequest>();
|
||||
|
||||
const { upgradeId } = body;
|
||||
if (!upgradeId) {
|
||||
return context.json({ error: "upgradeId is required" }, 400);
|
||||
}
|
||||
|
||||
const upgrade = DEFAULT_TRANSCENDENCE_UPGRADES.find((u) => u.id === upgradeId);
|
||||
if (!upgrade) {
|
||||
return context.json({ error: "Unknown echo upgrade" }, 404);
|
||||
}
|
||||
|
||||
const record = await prisma.gameState.findUnique({ where: { discordId } });
|
||||
if (!record) {
|
||||
return context.json({ error: "No save found" }, 404);
|
||||
}
|
||||
|
||||
const state = record.state as unknown as GameState;
|
||||
|
||||
if (!state.transcendence) {
|
||||
return context.json({ error: "No transcendence data found" }, 400);
|
||||
}
|
||||
|
||||
const { purchasedUpgradeIds, echoes } = state.transcendence;
|
||||
|
||||
if (purchasedUpgradeIds.includes(upgradeId)) {
|
||||
return context.json({ error: "Upgrade already purchased" }, 400);
|
||||
}
|
||||
|
||||
if (echoes < upgrade.cost) {
|
||||
return context.json({ error: "Not enough echoes" }, 400);
|
||||
}
|
||||
|
||||
const newEchoes = echoes - upgrade.cost;
|
||||
const newPurchasedIds = [...purchasedUpgradeIds, upgradeId];
|
||||
const newMultipliers = computeTranscendenceMultipliers(newPurchasedIds);
|
||||
|
||||
const newState: GameState = {
|
||||
...state,
|
||||
transcendence: {
|
||||
...state.transcendence,
|
||||
echoes: newEchoes,
|
||||
purchasedUpgradeIds: newPurchasedIds,
|
||||
...newMultipliers,
|
||||
},
|
||||
};
|
||||
|
||||
await prisma.gameState.update({
|
||||
where: { discordId },
|
||||
data: { state: newState as object, updatedAt: Date.now() },
|
||||
});
|
||||
|
||||
return context.json({
|
||||
echoesRemaining: newEchoes,
|
||||
purchasedUpgradeIds: newPurchasedIds,
|
||||
...newMultipliers,
|
||||
});
|
||||
});
|
||||
@@ -16,11 +16,13 @@ const MILESTONE_RUNESTONES_PER_INTERVAL = 25;
|
||||
* Calculates the gold threshold required for the next prestige.
|
||||
* Formula: BASE * SCALE_FACTOR^prestigeCount — each prestige makes the next threshold harder.
|
||||
*/
|
||||
export const calculatePrestigeThreshold = (prestigeCount: number): number =>
|
||||
BASE_PRESTIGE_GOLD_THRESHOLD * Math.pow(THRESHOLD_SCALE_FACTOR, prestigeCount);
|
||||
export const calculatePrestigeThreshold = (prestigeCount: number, thresholdMultiplier = 1): number =>
|
||||
BASE_PRESTIGE_GOLD_THRESHOLD * Math.pow(THRESHOLD_SCALE_FACTOR, prestigeCount) * thresholdMultiplier;
|
||||
|
||||
export const isEligibleForPrestige = (state: GameState): boolean =>
|
||||
state.player.totalGoldEarned >= calculatePrestigeThreshold(state.prestige.count);
|
||||
export const isEligibleForPrestige = (state: GameState): boolean => {
|
||||
const thresholdMultiplier = state.transcendence?.echoPrestigeThresholdMultiplier ?? 1;
|
||||
return state.player.totalGoldEarned >= calculatePrestigeThreshold(state.prestige.count, thresholdMultiplier);
|
||||
};
|
||||
|
||||
const getCategoryMultiplier = (
|
||||
purchasedUpgradeIds: string[],
|
||||
@@ -52,12 +54,13 @@ export const calculateRunestones = (
|
||||
totalGoldEarned: number,
|
||||
prestigeCount: number,
|
||||
purchasedUpgradeIds: string[],
|
||||
echoRunestoneMultiplier = 1,
|
||||
): number => {
|
||||
const threshold = calculatePrestigeThreshold(prestigeCount);
|
||||
const base =
|
||||
Math.floor(Math.sqrt(totalGoldEarned / threshold)) * RUNESTONES_PER_PRESTIGE_LEVEL;
|
||||
const runestoneMult = getCategoryMultiplier(purchasedUpgradeIds, "runestones");
|
||||
return Math.floor(base * runestoneMult);
|
||||
return Math.floor(base * runestoneMult * echoRunestoneMultiplier);
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -85,10 +88,12 @@ export const buildPostPrestigeState = (
|
||||
currentState: GameState,
|
||||
characterName: string,
|
||||
): { newState: GameState; newPrestigeData: PrestigeData; runestonesEarned: number; milestoneRunestones: number } => {
|
||||
const echoRunestoneMultiplier = currentState.transcendence?.echoPrestigeRunestoneMultiplier ?? 1;
|
||||
const runestonesEarned = calculateRunestones(
|
||||
currentState.player.totalGoldEarned,
|
||||
currentState.prestige.count,
|
||||
currentState.prestige.purchasedUpgradeIds,
|
||||
echoRunestoneMultiplier,
|
||||
);
|
||||
const newPrestigeCount = currentState.prestige.count + 1;
|
||||
const { purchasedUpgradeIds } = currentState.prestige;
|
||||
@@ -113,6 +118,8 @@ export const buildPostPrestigeState = (
|
||||
lastTickAt: Date.now(),
|
||||
// Codex lore persists across prestiges — players keep their discovered entries
|
||||
...(currentState.codex ? { codex: currentState.codex } : {}),
|
||||
// Transcendence data is permanent — never wiped by prestige
|
||||
...(currentState.transcendence ? { transcendence: currentState.transcendence } : {}),
|
||||
};
|
||||
|
||||
return { newState, newPrestigeData, runestonesEarned, milestoneRunestones };
|
||||
|
||||
@@ -0,0 +1,84 @@
|
||||
import type { GameState, TranscendenceData, TranscendenceUpgradeCategory } from "@elysium/types";
|
||||
import { INITIAL_GAME_STATE } from "../data/initialState.js";
|
||||
import { DEFAULT_TRANSCENDENCE_UPGRADES } from "../data/transcendenceUpgrades.js";
|
||||
|
||||
/** ID of the boss that must be defeated to unlock transcendence */
|
||||
const FINAL_BOSS_ID = "the_absolute_one";
|
||||
|
||||
/** Base constant used in the echo yield formula */
|
||||
const ECHO_FORMULA_CONSTANT = 853;
|
||||
|
||||
const getCategoryMultiplier = (
|
||||
purchasedIds: string[],
|
||||
category: TranscendenceUpgradeCategory,
|
||||
): number =>
|
||||
DEFAULT_TRANSCENDENCE_UPGRADES
|
||||
.filter((u) => u.category === category && purchasedIds.includes(u.id))
|
||||
.reduce((mult, u) => mult * u.multiplier, 1);
|
||||
|
||||
export const computeTranscendenceMultipliers = (
|
||||
purchasedUpgradeIds: string[],
|
||||
): Omit<TranscendenceData, "count" | "echoes" | "purchasedUpgradeIds"> => ({
|
||||
echoIncomeMultiplier: getCategoryMultiplier(purchasedUpgradeIds, "income"),
|
||||
echoCombatMultiplier: getCategoryMultiplier(purchasedUpgradeIds, "combat"),
|
||||
echoPrestigeThresholdMultiplier: getCategoryMultiplier(purchasedUpgradeIds, "prestige_threshold"),
|
||||
echoPrestigeRunestoneMultiplier: getCategoryMultiplier(purchasedUpgradeIds, "prestige_runestones"),
|
||||
echoMetaMultiplier: getCategoryMultiplier(purchasedUpgradeIds, "echo_meta"),
|
||||
});
|
||||
|
||||
/**
|
||||
* Returns true when the player is eligible to transcend:
|
||||
* they must have defeated the final boss at least once.
|
||||
*/
|
||||
export const isEligibleForTranscendence = (state: GameState): boolean =>
|
||||
state.bosses.some((b) => b.id === FINAL_BOSS_ID && b.status === "defeated");
|
||||
|
||||
/**
|
||||
* Calculates echo yield for a transcendence.
|
||||
* Formula: floor(CONSTANT / sqrt(prestigeCount)) × echoMetaMultiplier
|
||||
* Fewer prestiges = more echoes (rewards efficient play).
|
||||
* Minimum prestige count of 1 is enforced to avoid division by zero.
|
||||
*/
|
||||
export const calculateEchoes = (
|
||||
prestigeCount: number,
|
||||
echoMetaMultiplier: number,
|
||||
): number => {
|
||||
const safeCount = Math.max(prestigeCount, 1);
|
||||
return Math.floor((ECHO_FORMULA_CONSTANT / Math.sqrt(safeCount)) * echoMetaMultiplier);
|
||||
};
|
||||
|
||||
/**
|
||||
* Builds the new game state after a transcendence (nuclear reset).
|
||||
* Wipes everything except codex, dailyChallenges, and transcendence data.
|
||||
*/
|
||||
export const buildPostTranscendenceState = (
|
||||
currentState: GameState,
|
||||
characterName: string,
|
||||
): { newState: GameState; newTranscendenceData: TranscendenceData; echoesEarned: number } => {
|
||||
const previousTranscendence = currentState.transcendence;
|
||||
const echoMetaMultiplier = previousTranscendence?.echoMetaMultiplier ?? 1;
|
||||
|
||||
const echoesEarned = calculateEchoes(currentState.prestige.count, echoMetaMultiplier);
|
||||
const previousEchoes = previousTranscendence?.echoes ?? 0;
|
||||
const newCount = (previousTranscendence?.count ?? 0) + 1;
|
||||
const newPurchasedIds = previousTranscendence?.purchasedUpgradeIds ?? [];
|
||||
|
||||
const newTranscendenceData: TranscendenceData = {
|
||||
count: newCount,
|
||||
echoes: previousEchoes + echoesEarned,
|
||||
purchasedUpgradeIds: newPurchasedIds,
|
||||
...computeTranscendenceMultipliers(newPurchasedIds),
|
||||
};
|
||||
|
||||
const freshState = INITIAL_GAME_STATE(currentState.player, characterName);
|
||||
const newState: GameState = {
|
||||
...freshState,
|
||||
lastTickAt: Date.now(),
|
||||
// Codex lore persists through all resets
|
||||
...(currentState.codex ? { codex: currentState.codex } : {}),
|
||||
// Transcendence data is permanent
|
||||
transcendence: newTranscendenceData,
|
||||
};
|
||||
|
||||
return { newState, newTranscendenceData, echoesEarned };
|
||||
};
|
||||
Reference in New Issue
Block a user