feat: initial prototype — core game systems (#30)
Security Scan and Upload / Security & DefectDojo Upload (push) Successful in 1m1s
CI / Lint, Build & Test (push) Successful in 1m6s

## Summary

This PR represents the full v1 prototype, implementing the core game systems for Elysium.

- Full idle/clicker RPG loop: resource collection, crafting, boss fights, exploration, and quests
- Adventurer hiring with batch size selector and progressive tier cost scaling
- Prestige, transcendence, and apotheosis systems with auto-prestige support
- Character sheet, titles, leaderboards, companion system, and daily login bonuses
- Auto-quest and auto-boss toggles
- Discord webhook notifications on prestige/transcendence/apotheosis
- Discord role awarded on apotheosis
- Responsive design and overarching story/lore system
- In-game sound effects and browser notifications for key events
- Support link button in the resource bar
- Full test coverage (100% on `apps/api` and `packages/types`)
- CI pipeline: lint → build → test

## Closes

Closes #1
Closes #2
Closes #3
Closes #4
Closes #5
Closes #6
Closes #7
Closes #8
Closes #9
Closes #10
Closes #11
Closes #12
Closes #13
Closes #14
Closes #16
Closes #19
Closes #20
Closes #21
Closes #22
Closes #23
Closes #24
Closes #25
Closes #26
Closes #27
Closes #29

 This issue was created with help from Hikari~ 🌸

Co-authored-by: Naomi Carrigan <commits@nhcarrigan.com>
Reviewed-on: #30
Co-authored-by: Hikari <hikari@nhcarrigan.com>
Co-committed-by: Hikari <hikari@nhcarrigan.com>
This commit was merged in pull request #30.
This commit is contained in:
2026-03-08 15:53:39 -07:00
committed by Naomi Carrigan
parent c69e155de3
commit 29c817230d
172 changed files with 50706 additions and 0 deletions
+127
View File
@@ -0,0 +1,127 @@
/**
* @file Leaderboard routes for retrieving ranked player statistics.
* @copyright nhcarrigan
* @license Naomi's Public License
* @author Naomi Carrigan
*/
/* eslint-disable max-lines-per-function -- Route handler requires many steps */
/* eslint-disable complexity -- Leaderboard handler has inherent complexity */
import { Hono } from "hono";
import { gameTitles } from "../data/titles.js";
import { prisma } from "../db/client.js";
import type { HonoEnvironment } from "../types/hono.js";
import type { GameState } from "@elysium/types";
const leaderboardRouter = new Hono<HonoEnvironment>();
const validCategories = new Set([
"totalGold",
"bossesDefeated",
"questsCompleted",
"achievementsUnlocked",
"prestigeCount",
"transcendenceCount",
"apotheosisCount",
]);
const gameStateCategories = new Set([
"prestigeCount",
"transcendenceCount",
"apotheosisCount",
]);
/**
* Parses the showOnLeaderboards flag from a player's profile settings blob.
* @param raw - The raw profile settings value from the database.
* @returns True if the player should appear on leaderboards, false otherwise.
*/
const parseShowOnLeaderboards = (raw: unknown): boolean => {
if (raw !== null && typeof raw === "object" && !Array.isArray(raw)) {
/* eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- Runtime profile shape */
return (raw as Record<string, unknown>).showOnLeaderboards !== false;
}
return true;
};
/**
* Resolves the display title name for a given title ID.
* @param titleId - The player's active title ID.
* @returns The human-readable title name, or empty string if no title.
*/
const resolveTitleName = (titleId: string | null): string => {
if (titleId === null || titleId === "") {
return "";
}
return gameTitles.find((title) => {
return title.id === titleId;
})?.name ?? titleId;
};
leaderboardRouter.get("/", async(context) => {
const category = context.req.query("category") ?? "totalGold";
const limitRaw = Number(context.req.query("limit") ?? "100");
const limit = Math.min(Math.max(1, limitRaw), 100);
if (!validCategories.has(category)) {
return context.json({ error: "Invalid category" }, 400);
}
const [ players, gameStates ] = await Promise.all([
prisma.player.findMany(),
gameStateCategories.has(category)
? prisma.gameState.findMany()
: Promise.resolve([]),
]);
const stateMap = new Map(
gameStates.map((gs) => {
/* eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- Prisma returns JsonValue */
return [ gs.discordId, gs.state as unknown as GameState ];
}),
);
const entries = players.
filter((player) => {
return parseShowOnLeaderboards(player.profileSettings);
}).
map((player) => {
let value = 0;
if (category === "totalGold") {
value = player.lifetimeGoldEarned;
} else if (category === "bossesDefeated") {
value = player.lifetimeBossesDefeated;
} else if (category === "questsCompleted") {
value = player.lifetimeQuestsCompleted;
} else if (category === "achievementsUnlocked") {
value = player.lifetimeAchievementsUnlocked;
} else {
const state = stateMap.get(player.discordId);
if (category === "prestigeCount") {
value = state?.prestige.count ?? 0;
} else if (category === "transcendenceCount") {
value = state?.transcendence?.count ?? 0;
} else if (category === "apotheosisCount") {
value = state?.apotheosis?.count ?? 0;
}
}
return {
activeTitle: resolveTitleName(player.activeTitle),
avatar: player.avatar ?? null,
characterName: player.characterName,
discordId: player.discordId,
username: player.username,
value: value,
};
}).
sort((a, b) => {
return b.value - a.value;
}).
slice(0, limit).
map((entry, index) => {
return { ...entry, rank: index + 1 };
});
return context.json({ category, entries });
});
export { leaderboardRouter };