feat: add lifetime stats to player profile

Introduce six lifetime stat fields (gold, clicks, bosses, quests,
adventurers, achievements) that accumulate across all prestige and
transcendence resets and are never cleared.

- schema: add six new Float fields to the Player model
- prestige route: capture current-run totals and increment lifetime
  fields before resetting per-run counters to zero
- profile route: return lifetime fields as the All Time section data;
  add four new ProfileSettings toggles for visibility control
- ProfilePage: display lifetime bosses/quests/adventurers/achievements
  in All Time section; remove GameProvider dependency by importing
  formatNumber directly (fixes crash on public profile pages)
- EditProfileModal: add four new All Time stat toggles
- types: update Player, ProfileSettings, and PublicProfileResponse
This commit is contained in:
2026-03-07 02:08:41 -08:00
committed by Naomi Carrigan
parent 3cded34f4b
commit 298e1f4604
9 changed files with 213 additions and 39 deletions
+6
View File
@@ -62,6 +62,12 @@ authRouter.get("/callback", async (context) => {
lastSavedAt: player.lastSavedAt,
totalGoldEarned: player.totalGoldEarned,
totalClicks: player.totalClicks,
lifetimeGoldEarned: player.lifetimeGoldEarned,
lifetimeClicks: player.lifetimeClicks,
lifetimeBossesDefeated: player.lifetimeBossesDefeated,
lifetimeQuestsCompleted: player.lifetimeQuestsCompleted,
lifetimeAdventurersRecruited: player.lifetimeAdventurersRecruited,
lifetimeAchievementsUnlocked: player.lifetimeAchievementsUnlocked,
};
const initialState = INITIAL_GAME_STATE(playerShape, playerShape.characterName);
+14
View File
@@ -63,6 +63,12 @@ prestigeRouter.post("/", async (context) => {
},
};
// Capture current-run stats to accumulate into lifetime totals before resetting
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 },
@@ -73,8 +79,16 @@ prestigeRouter.post("/", async (context) => {
where: { discordId },
data: {
characterName,
// Reset current-run counters
totalGoldEarned: 0,
totalClicks: 0,
// Accumulate into lifetime totals — never reset
lifetimeGoldEarned: { increment: state.player.totalGoldEarned },
lifetimeClicks: { increment: state.player.totalClicks },
lifetimeBossesDefeated: { increment: runBossesDefeated },
lifetimeQuestsCompleted: { increment: runQuestsCompleted },
lifetimeAdventurersRecruited: { increment: runAdventurersRecruited },
lifetimeAchievementsUnlocked: { increment: runAchievementsUnlocked },
lastSavedAt: now,
},
});
+25 -5
View File
@@ -22,8 +22,14 @@ const parseProfileSettings = (raw: unknown): ProfileSettings => {
return {
showTotalGold: obj.showTotalGold !== false,
showTotalClicks: obj.showTotalClicks !== false,
showPrestige: obj.showPrestige !== false,
showLifetimeBossesDefeated: obj.showLifetimeBossesDefeated !== false,
showLifetimeQuestsCompleted: obj.showLifetimeQuestsCompleted !== false,
showLifetimeAdventurersRecruited: obj.showLifetimeAdventurersRecruited !== false,
showLifetimeAchievementsUnlocked: obj.showLifetimeAchievementsUnlocked !== false,
showGuildFounded: obj.showGuildFounded !== false,
showCurrentGold: obj.showCurrentGold !== false,
showCurrentClicks: obj.showCurrentClicks !== false,
showPrestige: obj.showPrestige !== false,
showBossesDefeated: obj.showBossesDefeated !== false,
showQuestsCompleted: obj.showQuestsCompleted !== false,
showAdventurersRecruited: obj.showAdventurersRecruited !== false,
@@ -63,14 +69,22 @@ profileRouter.get("/:discordId", async (context) => {
avatar: player.avatar ?? null,
bio: player.bio ?? "",
profileSettings,
createdAt: player.createdAt,
// All Time stats — cumulative across all runs, never reset
totalGoldEarned: player.lifetimeGoldEarned,
totalClicks: player.lifetimeClicks,
lifetimeBossesDefeated: player.lifetimeBossesDefeated,
lifetimeQuestsCompleted: player.lifetimeQuestsCompleted,
lifetimeAdventurersRecruited: player.lifetimeAdventurersRecruited,
lifetimeAchievementsUnlocked: player.lifetimeAchievementsUnlocked,
// Current Run stats — from live GameState, reset on prestige & transcendence
currentRunGold: state?.player.totalGoldEarned ?? 0,
currentRunClicks: state?.player.totalClicks ?? 0,
prestigeCount,
totalGoldEarned: player.totalGoldEarned,
totalClicks: player.totalClicks,
bossesDefeated,
questsCompleted,
adventurersRecruited,
achievementsUnlocked,
createdAt: player.createdAt,
});
});
@@ -86,8 +100,14 @@ profileRouter.put("/", authMiddleware, async (context) => {
const profileSettings: ProfileSettings = {
showTotalGold: body.profileSettings?.showTotalGold !== false,
showTotalClicks: body.profileSettings?.showTotalClicks !== false,
showPrestige: body.profileSettings?.showPrestige !== false,
showLifetimeBossesDefeated: body.profileSettings?.showLifetimeBossesDefeated !== false,
showLifetimeQuestsCompleted: body.profileSettings?.showLifetimeQuestsCompleted !== false,
showLifetimeAdventurersRecruited: body.profileSettings?.showLifetimeAdventurersRecruited !== false,
showLifetimeAchievementsUnlocked: body.profileSettings?.showLifetimeAchievementsUnlocked !== false,
showGuildFounded: body.profileSettings?.showGuildFounded !== false,
showCurrentGold: body.profileSettings?.showCurrentGold !== false,
showCurrentClicks: body.profileSettings?.showCurrentClicks !== false,
showPrestige: body.profileSettings?.showPrestige !== false,
showBossesDefeated: body.profileSettings?.showBossesDefeated !== false,
showQuestsCompleted: body.profileSettings?.showQuestsCompleted !== false,
showAdventurersRecruited: body.profileSettings?.showAdventurersRecruited !== false,