9 Commits

Author SHA1 Message Date
naomi b604a4aa5c release: v0.1.1
Security Scan and Upload / Security & DefectDojo Upload (push) Successful in 1m7s
CI / Lint, Build & Test (push) Successful in 1m8s
2026-03-08 20:23:22 -07:00
hikari e10eabc8b5 fix: save character name correctly and show story on character sheet
CI / Lint, Build & Test (push) Successful in 1m9s
Security Scan and Upload / Security & DefectDojo Upload (push) Successful in 1m9s
- Load route syncs characterName from Player record so profile updates
  are reflected immediately on next load
- Save route preserves Player record's characterName so auto-saves
  cannot overwrite profile updates
- Public profile response now includes completedChapters
- Character sheet panel displays completed story chapters with outcome
- Removed stale CSS for old achievement/codex toast classes
2026-03-08 20:19:40 -07:00
hikari c3d79e0c11 feat: add third-person choice descriptions to public character sheet
CI / Lint, Build & Test (push) Failing after 57s
Security Scan and Upload / Security & DefectDojo Upload (push) Successful in 1m15s
Each story choice now has a concise third-person description used on
the public character page, keeping narrative spoilers out of the
profile view whilst still conveying the character's path.
2026-03-08 20:15:26 -07:00
hikari 6e2cb45553 fix: delay boss lore toasts until battle animation reveals result
Security Scan and Upload / Security & DefectDojo Upload (push) Successful in 1m3s
CI / Lint, Build & Test (push) Successful in 1m6s
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-08 19:18:46 -07:00
hikari 5a065998b6 fix: delay boss notifications until reveal and animate hp bar colours
Security Scan and Upload / Security & DefectDojo Upload (push) Successful in 1m3s
CI / Lint, Build & Test (push) Successful in 1m5s
- Move bossVictory sound and notification from gameContext into BattleModal,
  fired at the 5.2s reveal timeout so the animation plays before the spoiler
- Replace CSS width transition with a setInterval tick (50ms steps over 5s)
  so bossHpPercent and partyHpPercent update incrementally during the animation
- Both bars now use a shared getHpColour helper: green >50%, yellow 25-50%,
  red <25%, causing colour to shift naturally as the bar visually drains
2026-03-08 19:07:04 -07:00
hikari f9c925b9fc feat: unify toast styles and add quest/milestone toast notifications
Security Scan and Upload / Security & DefectDojo Upload (push) Successful in 1m3s
CI / Lint, Build & Test (push) Successful in 1m5s
- Merge .codex-toast and .achievement-toast into a single .game-toast class
- Fix storyToast inner class names and replace <button> wrapper with <div>
- Add QuestCompleteToast and QuestFailedToast components
- Add MilestoneToast for prestige, transcendence, and apotheosis events
- Move shared toast container to gameLayout so all toasts stack in one column
- Wire quest detection in GameContext to store full Quest objects for toast names
- Trigger prestige toast from both auto-prestige and manual prestige panel
2026-03-08 18:47:42 -07:00
hikari 290c06de83 fix: correct combat power calculation in quest panel
CI / Lint, Build & Test (push) Failing after 49s
Security Scan and Upload / Security & DefectDojo Upload (push) Successful in 2m18s
2026-03-08 16:02:49 -07:00
naomi 205b4136ce release: v0.1.0
CI / Lint, Build & Test (push) Successful in 1m8s
Security Scan and Upload / Security & DefectDojo Upload (push) Successful in 1m11s
2026-03-08 15:55:47 -07:00
hikari 29c817230d 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>
2026-03-08 15:53:39 -07:00
208 changed files with 39798 additions and 8686 deletions
+14 -3
View File
@@ -18,6 +18,11 @@ jobs:
- name: Check dependency pins - name: Check dependency pins
uses: naomi-lgbt/dependency-pin-check@main uses: naomi-lgbt/dependency-pin-check@main
with:
dev-dependencies: true
peer-dependencies: true
optional-dependencies: true
language: javascript
- name: Set up Node.js - name: Set up Node.js
uses: actions/setup-node@v4 uses: actions/setup-node@v4
@@ -32,6 +37,12 @@ jobs:
- name: Install dependencies - name: Install dependencies
run: pnpm install --frozen-lockfile run: pnpm install --frozen-lockfile
- name: Generate Prisma client
run: pnpm --filter @elysium/api exec prisma generate
- name: Build (types package)
run: pnpm --filter @elysium/types build
- name: Lint (types package) - name: Lint (types package)
run: pnpm --filter @elysium/types lint run: pnpm --filter @elysium/types lint
@@ -41,15 +52,15 @@ jobs:
- name: Lint (web) - name: Lint (web)
run: pnpm --filter @elysium/web lint run: pnpm --filter @elysium/web lint
- name: Build (types package)
run: pnpm --filter @elysium/types build
- name: Build (API) - name: Build (API)
run: pnpm --filter @elysium/api build run: pnpm --filter @elysium/api build
- name: Build (web) - name: Build (web)
run: pnpm --filter @elysium/web build run: pnpm --filter @elysium/web build
- name: Test (types package)
run: pnpm --filter @elysium/types test
- name: Test (API) - name: Test (API)
run: pnpm --filter @elysium/api test run: pnpm --filter @elysium/api test
+8 -1
View File
@@ -1,5 +1,12 @@
# Elysium Project Notes # Elysium Project Notes
## CI Requirements
**Never commit without first confirming the full pipeline passes locally:**
1. `pnpm lint` — zero errors, zero warnings
2. `pnpm build` — all packages build cleanly
3. `pnpm test` — all tests pass with 100% coverage on `apps/api` and `packages/types`
## About Page ## About Page
The About page (`apps/web/src/components/game/AboutPanel.tsx`) contains a **How to Play** guide that should be kept up to date as new features are added to the game. When implementing new game systems, zones, mechanics, or significant UI features, update the `HOW_TO_PLAY` array in `AboutPanel.tsx` to include a description of the new feature. The About page (`apps/web/src/components/game/aboutPanel.tsx`) contains a **How to Play** guide that should be kept up to date as new features are added to the game. When implementing new game systems, zones, mechanics, or significant UI features, update the `HOW_TO_PLAY` array in `aboutPanel.tsx` to include a description of the new feature.
-49
View File
@@ -1,49 +0,0 @@
# Elysium — Content Ideas
A running list of planned features and content additions. Strike through items as they're completed!
---
## 🌟 New Systems
- [x] **Offline earnings** — When returning to the game, earn a percentage of what you'd have earned offline (cap at ~812 hours). Upgradeable via the prestige shop to increase the % and the time cap. Essential for an idle game!
- [ ] **Second prestige layer (Transcendence)** — Unlocked after ~10 prestiges. Sacrifice all runestones for a new currency ("Echoes"?). Echoes are permanent account-wide currency that persist across prestiges. Has its own upgrade tree with truly game-changing bonuses. Gives endgame players a long-term goal.
- [x] **Daily challenges** — Three rotating objectives each day (e.g. kill X boss, earn X gold this run, complete X quests). Reward bonus crystals. Encourages daily logins even when idling comfortably.
- [x] **Boss first-kill bounties** — Defeating a boss for the very first time grants a one-time runestone bonus. Rewards exploration and makes conquering a new zone feel extra satisfying.
- [x] **Auto-prestige toggle** — Unlockable via the prestige shop. Automatically prestiges the moment the threshold is reached. Late-game convenience that dedicated players will love.
---
## 📦 Content Additions
- [x] **Equipment set bonuses** — Group existing equipment into named sets (e.g. "Shadow Infiltrator"). Wearing 2/3/4 pieces of a set grants escalating bonuses. Adds strategic depth without requiring lots of new items.
- [ ] **The Codex / Lore Book** — Defeating bosses and completing quests unlocks lore entries about the world. Pure flavour, but gives the world depth and a collection mechanic. Show a ✨ notification when new lore unlocks.
- [x] **Milestone prestige bonuses** — Every 5th prestige, earn a free prestige upgrade or a large runestone windfall. Gives players mini-goals within the prestige loop.
---
## 📊 UI / Statistics
- [x] **Statistics panel** — All-time totals: gold earned across all runs, total prestiges, bosses defeated, quests completed, time played. Idle game players love seeing big numbers about their big numbers.
- [x] **Last cloud save date + Force cloud save button** — Display when the last cloud save occurred (always visible, e.g. in the ResourceBar). Include a manual "Force Save" button for peace of mind.
---
## 💜 Priority Order (Suggested)
1. ~~Offline earnings~~
2. ~~Statistics panel~~
3. ~~Daily challenges~~
4. ~~Boss first-kill bounties~~
5. ~~Milestone prestige bonuses~~
6. ~~Equipment set bonuses~~
7. ~~Auto-prestige toggle~~
8. The Codex / Lore Book (flavour, lower priority)
9. Second prestige layer / Transcendence (big feature, save for later)
+2 -2
View File
@@ -1,3 +1,3 @@
import { NaomisConfig } from "@nhcarrigan/eslint-config"; import config from "@nhcarrigan/eslint-config";
export default [...NaomisConfig]; export default [...config];
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "@elysium/api", "name": "@elysium/api",
"version": "0.0.0", "version": "0.1.1",
"private": true, "private": true,
"type": "module", "type": "module",
"main": "./prod/src/index.js", "main": "./prod/src/index.js",
+20 -5
View File
@@ -13,13 +13,28 @@ model Player {
username String username String
discriminator String discriminator String
avatar String? avatar String?
characterName String @default("") characterName String @default("")
bio String @default("") pronouns String @default("")
profileSettings Json? characterRace String @default("")
characterClass String @default("")
bio String @default("")
guildName String @default("")
guildDescription String @default("")
profileSettings Json?
unlockedTitles Json?
activeTitle String @default("")
createdAt Float createdAt Float
lastSavedAt Float lastSavedAt Float
totalGoldEarned Float @default(0) totalGoldEarned Float @default(0)
totalClicks Float @default(0) totalClicks Float @default(0)
lifetimeGoldEarned Float @default(0)
lifetimeClicks Float @default(0)
lifetimeBossesDefeated Float @default(0)
lifetimeQuestsCompleted Float @default(0)
lifetimeAdventurersRecruited Float @default(0)
lifetimeAchievementsUnlocked Float @default(0)
lastLoginDate String?
loginStreak Int @default(1)
} }
model GameState { model GameState {
+6
View File
@@ -4,3 +4,9 @@ DISCORD_REDIRECT_URI="op://Environment Variables - Naomi/Elysium/discord redirec
JWT_SECRET="op://Environment Variables - Naomi/Elysium/jwt secret" JWT_SECRET="op://Environment Variables - Naomi/Elysium/jwt secret"
DATABASE_URL="op://Environment Variables - Naomi/Elysium/mongo url" DATABASE_URL="op://Environment Variables - Naomi/Elysium/mongo url"
ANTI_CHEAT_SECRET="op://Environment Variables - Naomi/Elysium/anti cheat secret" ANTI_CHEAT_SECRET="op://Environment Variables - Naomi/Elysium/anti cheat secret"
PORT="op://Environment Variables - Naomi/Elysium/port"
CORS_ORIGIN="op://Environment Variables - Naomi/Elysium/origin"
DISCORD_MILESTONE_WEBHOOK="op://Environment Variables - Naomi/Elysium/discord milestone webhook"
DISCORD_BOT_TOKEN="op://Environment Variables - Naomi/Elysium/discord bot token"
DISCORD_GUILD_ID="op://Environment Variables - Naomi/Elysium/discord guild id"
DISCORD_APOTHEOSIS_ROLE_ID="op://Environment Variables - Naomi/Elysium/discord apotheosis role id"
+236 -229
View File
@@ -1,359 +1,366 @@
/**
* @file Game data definitions.
* @copyright nhcarrigan
* @license Naomi's Public License
* @author Naomi Carrigan
*/
/* eslint-disable max-lines -- Data file */
import type { Achievement } from "@elysium/types"; import type { Achievement } from "@elysium/types";
export const DEFAULT_ACHIEVEMENTS: Achievement[] = [ export const defaultAchievements: Array<Achievement> = [
// Click milestones // Click milestones
{ {
id: "first_click", condition: { amount: 1, type: "totalClicks" },
name: "First Strike",
description: "Click the Guild Hall for the first time.", description: "Click the Guild Hall for the first time.",
icon: "👆", icon: "👆",
condition: { type: "totalClicks", amount: 1 }, id: "first_click",
reward: { crystals: 5 }, name: "First Strike",
unlockedAt: null, reward: { crystals: 5 },
unlockedAt: null,
}, },
{ {
id: "click_enthusiast", condition: { amount: 100, type: "totalClicks" },
name: "Click Enthusiast",
description: "Click the Guild Hall 100 times.", description: "Click the Guild Hall 100 times.",
icon: "🖱️", icon: "🖱️",
condition: { type: "totalClicks", amount: 100 }, id: "click_enthusiast",
reward: { crystals: 25 }, name: "Click Enthusiast",
unlockedAt: null, reward: { crystals: 25 },
unlockedAt: null,
}, },
{ {
id: "click_master", condition: { amount: 1000, type: "totalClicks" },
name: "Click Master",
description: "Click the Guild Hall 1,000 times.", description: "Click the Guild Hall 1,000 times.",
icon: "⚡", icon: "⚡",
condition: { type: "totalClicks", amount: 1_000 }, id: "click_master",
reward: { crystals: 100 }, name: "Click Master",
unlockedAt: null, reward: { crystals: 100 },
unlockedAt: null,
}, },
{ {
id: "click_legend", condition: { amount: 10_000, type: "totalClicks" },
name: "Click Legend",
description: "Click the Guild Hall 10,000 times.", description: "Click the Guild Hall 10,000 times.",
icon: "🌩️", icon: "🌩️",
condition: { type: "totalClicks", amount: 10_000 }, id: "click_legend",
reward: { crystals: 300 }, name: "Click Legend",
unlockedAt: null, reward: { crystals: 300 },
unlockedAt: null,
}, },
// Gold milestones // Gold milestones
{ {
id: "first_gold", condition: { amount: 100, type: "totalGoldEarned" },
name: "First Gold",
description: "Earn your first 100 gold.", description: "Earn your first 100 gold.",
icon: "🪙", icon: "🪙",
condition: { type: "totalGoldEarned", amount: 100 }, id: "first_gold",
reward: { crystals: 5 }, name: "First Gold",
unlockedAt: null, reward: { crystals: 5 },
unlockedAt: null,
}, },
{ {
id: "wealthy", condition: { amount: 10_000, type: "totalGoldEarned" },
name: "Wealthy",
description: "Earn 10,000 gold in total.", description: "Earn 10,000 gold in total.",
icon: "💰", icon: "💰",
condition: { type: "totalGoldEarned", amount: 10_000 }, id: "wealthy",
reward: { crystals: 25 }, name: "Wealthy",
unlockedAt: null, reward: { crystals: 25 },
unlockedAt: null,
}, },
{ {
id: "rich", condition: { amount: 1_000_000, type: "totalGoldEarned" },
name: "Rich",
description: "Earn 1,000,000 gold in total.", description: "Earn 1,000,000 gold in total.",
icon: "👑", icon: "👑",
condition: { type: "totalGoldEarned", amount: 1_000_000 }, id: "rich",
reward: { crystals: 100 }, name: "Rich",
unlockedAt: null, reward: { crystals: 100 },
unlockedAt: null,
}, },
{ {
id: "billionaire", condition: { amount: 1_000_000_000, type: "totalGoldEarned" },
name: "Billionaire",
description: "Earn 1,000,000,000 gold in total.", description: "Earn 1,000,000,000 gold in total.",
icon: "🏦", icon: "🏦",
condition: { type: "totalGoldEarned", amount: 1_000_000_000 }, id: "billionaire",
reward: { crystals: 500 }, name: "Billionaire",
unlockedAt: null, reward: { crystals: 500 },
unlockedAt: null,
}, },
{ {
id: "trillionaire", condition: { amount: 1_000_000_000_000, type: "totalGoldEarned" },
name: "Trillionaire",
description: "Earn 1,000,000,000,000 gold in total.", description: "Earn 1,000,000,000,000 gold in total.",
icon: "💎", icon: "💎",
condition: { type: "totalGoldEarned", amount: 1_000_000_000_000 }, id: "trillionaire",
reward: { crystals: 2_000 }, name: "Trillionaire",
unlockedAt: null, reward: { crystals: 2000 },
unlockedAt: null,
}, },
// Quest milestones // Quest milestones
{ {
id: "first_quest", condition: { amount: 1, type: "questsCompleted" },
name: "Adventurous Spirit",
description: "Complete your first quest.", description: "Complete your first quest.",
icon: "📜", icon: "📜",
condition: { type: "questsCompleted", amount: 1 }, id: "first_quest",
reward: { crystals: 10 }, name: "Adventurous Spirit",
unlockedAt: null, reward: { crystals: 10 },
unlockedAt: null,
}, },
{ {
id: "quest_veteran", condition: { amount: 5, type: "questsCompleted" },
name: "Quest Veteran",
description: "Complete 5 quests.", description: "Complete 5 quests.",
icon: "📚", icon: "📚",
condition: { type: "questsCompleted", amount: 5 }, id: "quest_veteran",
reward: { crystals: 50 }, name: "Quest Veteran",
unlockedAt: null, reward: { crystals: 50 },
unlockedAt: null,
}, },
{ {
id: "quest_master", condition: { amount: 15, type: "questsCompleted" },
name: "Quest Master",
description: "Complete 15 quests.", description: "Complete 15 quests.",
icon: "🗺️", icon: "🗺️",
condition: { type: "questsCompleted", amount: 15 }, id: "quest_master",
reward: { crystals: 200 }, name: "Quest Master",
unlockedAt: null, reward: { crystals: 200 },
unlockedAt: null,
}, },
// Boss milestones // Boss milestones
{ {
id: "boss_slayer", condition: { amount: 1, type: "bossesDefeated" },
name: "Boss Slayer",
description: "Defeat your first boss.", description: "Defeat your first boss.",
icon: "⚔️", icon: "⚔️",
condition: { type: "bossesDefeated", amount: 1 }, id: "boss_slayer",
reward: { crystals: 25 }, name: "Boss Slayer",
unlockedAt: null, reward: { crystals: 25 },
unlockedAt: null,
}, },
{ {
id: "boss_veteran", condition: { amount: 5, type: "bossesDefeated" },
name: "Boss Veteran",
description: "Defeat 5 bosses.", description: "Defeat 5 bosses.",
icon: "🗡️", icon: "🗡️",
condition: { type: "bossesDefeated", amount: 5 }, id: "boss_veteran",
reward: { crystals: 150 }, name: "Boss Veteran",
unlockedAt: null, reward: { crystals: 150 },
unlockedAt: null,
}, },
{ {
id: "legendary_hunter", condition: { amount: 10, type: "bossesDefeated" },
name: "Legendary Hunter",
description: "Defeat 10 bosses.", description: "Defeat 10 bosses.",
icon: "🏆", icon: "🏆",
condition: { type: "bossesDefeated", amount: 10 }, id: "legendary_hunter",
reward: { crystals: 500 }, name: "Legendary Hunter",
unlockedAt: null, reward: { crystals: 500 },
unlockedAt: null,
}, },
{ {
id: "devourer_slayer", condition: { amount: 18, type: "bossesDefeated" },
name: "World Saver",
description: "Defeat all 18 bosses, including the Devourer of Worlds.", description: "Defeat all 18 bosses, including the Devourer of Worlds.",
icon: "🌟", icon: "🌟",
condition: { type: "bossesDefeated", amount: 18 }, id: "devourer_slayer",
reward: { crystals: 2_000 }, name: "World Saver",
unlockedAt: null, reward: { crystals: 2000 },
unlockedAt: null,
}, },
// Adventurer milestones // Adventurer milestones
{ {
id: "guild_master", condition: { amount: 50, type: "adventurerTotal" },
name: "Guild Master",
description: "Recruit a total of 50 adventurers.", description: "Recruit a total of 50 adventurers.",
icon: "🏰", icon: "🏰",
condition: { type: "adventurerTotal", amount: 50 }, id: "guild_master",
reward: { crystals: 50 }, name: "Guild Master",
unlockedAt: null, reward: { crystals: 50 },
unlockedAt: null,
}, },
{ {
id: "army_commander", condition: { amount: 500, type: "adventurerTotal" },
name: "Army Commander",
description: "Recruit a total of 500 adventurers.", description: "Recruit a total of 500 adventurers.",
icon: "🛡️", icon: "🛡️",
condition: { type: "adventurerTotal", amount: 500 }, id: "army_commander",
reward: { crystals: 200 }, name: "Army Commander",
unlockedAt: null, reward: { crystals: 200 },
unlockedAt: null,
}, },
{ {
id: "army_legend", condition: { amount: 5000, type: "adventurerTotal" },
name: "Legendary Commander",
description: "Recruit a total of 5,000 adventurers.", description: "Recruit a total of 5,000 adventurers.",
icon: "⚜️", icon: "⚜️",
condition: { type: "adventurerTotal", amount: 5_000 }, id: "army_legend",
reward: { crystals: 750 }, name: "Legendary Commander",
unlockedAt: null, reward: { crystals: 750 },
unlockedAt: null,
}, },
// Prestige milestones // Prestige milestones
{ {
id: "first_prestige", condition: { amount: 1, type: "prestigeCount" },
name: "Born Again",
description: "Prestige for the first time.", description: "Prestige for the first time.",
icon: "⭐", icon: "⭐",
condition: { type: "prestigeCount", amount: 1 }, id: "first_prestige",
reward: { crystals: 100 }, name: "Born Again",
unlockedAt: null, reward: { crystals: 100 },
unlockedAt: null,
}, },
// Collection milestones // Collection milestones
{ {
id: "collector", condition: { amount: 4, type: "equipmentOwned" },
name: "Collector",
description: "Acquire your first piece of boss-dropped equipment.", description: "Acquire your first piece of boss-dropped equipment.",
icon: "🎒", icon: "🎒",
condition: { type: "equipmentOwned", amount: 4 }, id: "collector",
reward: { crystals: 10 }, name: "Collector",
unlockedAt: null, reward: { crystals: 10 },
unlockedAt: null,
}, },
{ {
id: "arsenal", condition: { amount: 12, type: "equipmentOwned" },
name: "Arsenal",
description: "Own 12 pieces of equipment.", description: "Own 12 pieces of equipment.",
icon: "🗃️", icon: "🗃️",
condition: { type: "equipmentOwned", amount: 12 }, id: "arsenal",
reward: { crystals: 200 }, name: "Arsenal",
unlockedAt: null, reward: { crystals: 200 },
unlockedAt: null,
}, },
{ {
id: "well_armed", condition: { amount: 25, type: "equipmentOwned" },
name: "Well Armed",
description: "Own 25 pieces of equipment.", description: "Own 25 pieces of equipment.",
icon: "⚔️", icon: "⚔️",
condition: { type: "equipmentOwned", amount: 25 }, id: "well_armed",
reward: { crystals: 1_000 }, name: "Well Armed",
unlockedAt: null, reward: { crystals: 1000 },
unlockedAt: null,
}, },
{ {
id: "fully_equipped", condition: { amount: 40, type: "equipmentOwned" },
name: "Fully Equipped",
description: "Own 40 pieces of equipment.", description: "Own 40 pieces of equipment.",
icon: "🛡️", icon: "🛡️",
condition: { type: "equipmentOwned", amount: 40 }, id: "fully_equipped",
reward: { crystals: 10_000 }, name: "Fully Equipped",
unlockedAt: null, reward: { crystals: 10_000 },
unlockedAt: null,
}, },
// Higher click milestones // Higher click milestones
{ {
id: "click_obsessed", condition: { amount: 100_000, type: "totalClicks" },
name: "Click Obsessed",
description: "Click the Guild Hall 100,000 times.", description: "Click the Guild Hall 100,000 times.",
icon: "💥", icon: "💥",
condition: { type: "totalClicks", amount: 100_000 }, id: "click_obsessed",
reward: { crystals: 1_000 }, name: "Click Obsessed",
unlockedAt: null, reward: { crystals: 1000 },
unlockedAt: null,
}, },
{ {
id: "click_deity", condition: { amount: 1_000_000, type: "totalClicks" },
name: "Click Deity",
description: "Click the Guild Hall 1,000,000 times.", description: "Click the Guild Hall 1,000,000 times.",
icon: "☄️", icon: "☄️",
condition: { type: "totalClicks", amount: 1_000_000 }, id: "click_deity",
reward: { crystals: 5_000 }, name: "Click Deity",
unlockedAt: null, reward: { crystals: 5000 },
unlockedAt: null,
}, },
// Endgame gold milestones // Endgame gold milestones
{ {
id: "quadrillionaire", condition: { amount: 1e15, type: "totalGoldEarned" },
name: "Quadrillionaire",
description: "Earn 1 quadrillion gold in total.", description: "Earn 1 quadrillion gold in total.",
icon: "✨", icon: "✨",
condition: { type: "totalGoldEarned", amount: 1e15 }, id: "quadrillionaire",
reward: { crystals: 10_000 }, name: "Quadrillionaire",
unlockedAt: null, reward: { crystals: 10_000 },
unlockedAt: null,
}, },
{ {
id: "void_hoarder", condition: { amount: 1e18, type: "totalGoldEarned" },
name: "Void Hoarder",
description: "Earn 1 quintillion gold in total.", description: "Earn 1 quintillion gold in total.",
icon: "🌀", icon: "🌀",
condition: { type: "totalGoldEarned", amount: 1e18 }, id: "void_hoarder",
reward: { crystals: 50_000 }, name: "Void Hoarder",
unlockedAt: null, reward: { crystals: 50_000 },
unlockedAt: null,
}, },
// Higher quest milestones // Higher quest milestones
{ {
id: "quest_champion", condition: { amount: 30, type: "questsCompleted" },
name: "Quest Champion",
description: "Complete 30 quests.", description: "Complete 30 quests.",
icon: "🏅", icon: "🏅",
condition: { type: "questsCompleted", amount: 30 }, id: "quest_champion",
reward: { crystals: 1_000 }, name: "Quest Champion",
unlockedAt: null, reward: { crystals: 1000 },
unlockedAt: null,
}, },
{ {
id: "quest_grandmaster", condition: { amount: 50, type: "questsCompleted" },
name: "Quest Grandmaster",
description: "Complete 50 quests.", description: "Complete 50 quests.",
icon: "🎖️", icon: "🎖️",
condition: { type: "questsCompleted", amount: 50 }, id: "quest_grandmaster",
reward: { crystals: 5_000 }, name: "Quest Grandmaster",
unlockedAt: null, reward: { crystals: 5000 },
unlockedAt: null,
}, },
{ {
id: "quest_eternal", condition: { amount: 72, type: "questsCompleted" },
name: "Quest Eternal",
description: "Complete all 72 quests across the known multiverse.", description: "Complete all 72 quests across the known multiverse.",
icon: "🌌", icon: "🌌",
condition: { type: "questsCompleted", amount: 72 }, id: "quest_eternal",
reward: { crystals: 25_000 }, name: "Quest Eternal",
unlockedAt: null, reward: { crystals: 25_000 },
unlockedAt: null,
}, },
// Higher boss milestones // Higher boss milestones
{ {
id: "boss_champion", condition: { amount: 20, type: "bossesDefeated" },
name: "Champion of the Realm",
description: "Defeat 20 bosses.", description: "Defeat 20 bosses.",
icon: "🦁", icon: "🦁",
condition: { type: "bossesDefeated", amount: 20 }, id: "boss_champion",
reward: { crystals: 1_000 }, name: "Champion of the Realm",
unlockedAt: null, reward: { crystals: 1000 },
unlockedAt: null,
}, },
{ {
id: "boss_grandmaster", condition: { amount: 30, type: "bossesDefeated" },
name: "Grandmaster Hunter",
description: "Defeat 30 bosses.", description: "Defeat 30 bosses.",
icon: "🔱", icon: "🔱",
condition: { type: "bossesDefeated", amount: 30 }, id: "boss_grandmaster",
reward: { crystals: 5_000 }, name: "Grandmaster Hunter",
unlockedAt: null, reward: { crystals: 5000 },
unlockedAt: null,
}, },
{ {
id: "boss_eternal", condition: { amount: 60, type: "bossesDefeated" },
name: "Eternal Vanquisher",
description: "Defeat all 60 bosses across every plane of existence.", description: "Defeat all 60 bosses across every plane of existence.",
icon: "💀", icon: "💀",
condition: { type: "bossesDefeated", amount: 60 }, id: "boss_eternal",
reward: { crystals: 50_000 }, name: "Eternal Vanquisher",
unlockedAt: null, reward: { crystals: 50_000 },
unlockedAt: null,
}, },
// Higher adventurer milestones // Higher adventurer milestones
{ {
id: "army_titan", condition: { amount: 50_000, type: "adventurerTotal" },
name: "Titan Commander",
description: "Recruit a total of 50,000 adventurers.", description: "Recruit a total of 50,000 adventurers.",
icon: "⚡", icon: "⚡",
condition: { type: "adventurerTotal", amount: 50_000 }, id: "army_titan",
reward: { crystals: 5_000 }, name: "Titan Commander",
unlockedAt: null, reward: { crystals: 5000 },
unlockedAt: null,
}, },
// Higher prestige milestones // Higher prestige milestones
{ {
id: "prestige_veteran", condition: { amount: 5, type: "prestigeCount" },
name: "Veteran of Ages",
description: "Prestige 5 times.", description: "Prestige 5 times.",
icon: "🌟", icon: "🌟",
condition: { type: "prestigeCount", amount: 5 }, id: "prestige_veteran",
reward: { crystals: 1_000 }, name: "Veteran of Ages",
unlockedAt: null, reward: { crystals: 1000 },
unlockedAt: null,
}, },
{ {
id: "prestige_master", condition: { amount: 10, type: "prestigeCount" },
name: "Master of Cycles",
description: "Prestige 10 times.", description: "Prestige 10 times.",
icon: "💫", icon: "💫",
condition: { type: "prestigeCount", amount: 10 }, id: "prestige_master",
reward: { crystals: 5_000 }, name: "Master of Cycles",
unlockedAt: null, reward: { crystals: 5000 },
unlockedAt: null,
}, },
{ {
id: "prestige_legend", condition: { amount: 25, type: "prestigeCount" },
name: "Legend of Eternity",
description: "Prestige 25 times.", description: "Prestige 25 times.",
icon: "🌠", icon: "🌠",
condition: { type: "prestigeCount", amount: 25 }, id: "prestige_legend",
reward: { crystals: 25_000 }, name: "Legend of Eternity",
unlockedAt: null, reward: { crystals: 25_000 },
unlockedAt: null,
}, },
]; ];
+298 -259
View File
@@ -1,356 +1,395 @@
/**
* @file Game data definitions.
* @copyright nhcarrigan
* @license Naomi's Public License
* @author Naomi Carrigan
*/
/* eslint-disable max-lines -- Data file */
import type { Adventurer } from "@elysium/types"; import type { Adventurer } from "@elysium/types";
export const DEFAULT_ADVENTURERS: Adventurer[] = [ export const defaultAdventurers: Array<Adventurer> = [
{ {
id: "peasant", baseCost: 10,
name: "Peasant", class: "warrior",
class: "warrior", combatPower: 1,
level: 1, count: 0,
goldPerSecond: 0.1,
essencePerSecond: 0, essencePerSecond: 0,
combatPower: 1, goldPerSecond: 0.1,
count: 0, id: "peasant",
unlocked: true, level: 1,
name: "Peasant",
unlocked: true,
}, },
{ {
id: "militia", baseCost: 100,
name: "Militia", class: "warrior",
class: "warrior", combatPower: 3,
level: 2, count: 0,
goldPerSecond: 0.5,
essencePerSecond: 0, essencePerSecond: 0,
combatPower: 3, goldPerSecond: 0.5,
count: 0, id: "militia",
unlocked: false, level: 2,
name: "Militia",
unlocked: false,
}, },
{ {
id: "apprentice", baseCost: 750,
name: "Apprentice Mage", class: "mage",
class: "mage", combatPower: 8,
level: 3, count: 0,
goldPerSecond: 1.5,
essencePerSecond: 0.01, essencePerSecond: 0.01,
combatPower: 8, goldPerSecond: 1.5,
count: 0, id: "apprentice",
unlocked: false, level: 3,
name: "Apprentice Mage",
unlocked: false,
}, },
{ {
id: "scout", baseCost: 5000,
name: "Scout", class: "rogue",
class: "rogue", combatPower: 20,
level: 4, count: 0,
goldPerSecond: 4,
essencePerSecond: 0.02, essencePerSecond: 0.02,
combatPower: 20, goldPerSecond: 4,
count: 0, id: "scout",
unlocked: false, level: 4,
name: "Scout",
unlocked: false,
}, },
{ {
id: "acolyte", baseCost: 35_000,
name: "Acolyte", class: "cleric",
class: "cleric", combatPower: 50,
level: 5, count: 0,
goldPerSecond: 10,
essencePerSecond: 0.05, essencePerSecond: 0.05,
combatPower: 50, goldPerSecond: 10,
count: 0, id: "acolyte",
unlocked: false, level: 5,
name: "Acolyte",
unlocked: false,
}, },
{ {
id: "ranger", baseCost: 250_000,
name: "Ranger", class: "ranger",
class: "ranger", combatPower: 120,
level: 6, count: 0,
goldPerSecond: 25,
essencePerSecond: 0.1, essencePerSecond: 0.1,
combatPower: 120, goldPerSecond: 25,
count: 0, id: "ranger",
unlocked: false, level: 6,
name: "Ranger",
unlocked: false,
}, },
{ {
id: "knight", baseCost: 1_750_000,
name: "Knight", class: "warrior",
class: "warrior", combatPower: 300,
level: 7, count: 0,
goldPerSecond: 75,
essencePerSecond: 0.2, essencePerSecond: 0.2,
combatPower: 300, goldPerSecond: 75,
count: 0, id: "knight",
unlocked: false, level: 7,
name: "Knight",
unlocked: false,
}, },
{ {
id: "archmage", baseCost: 12_000_000,
name: "Archmage", class: "mage",
class: "mage", combatPower: 800,
level: 8, count: 0,
goldPerSecond: 200,
essencePerSecond: 0.5, essencePerSecond: 0.5,
combatPower: 800, goldPerSecond: 200,
count: 0, id: "archmage",
unlocked: false, level: 8,
name: "Archmage",
unlocked: false,
}, },
{ {
id: "paladin", baseCost: 85_000_000,
name: "Paladin", class: "paladin",
class: "paladin", combatPower: 2000,
level: 9, count: 0,
goldPerSecond: 600,
essencePerSecond: 1, essencePerSecond: 1,
combatPower: 2000, goldPerSecond: 600,
count: 0, id: "paladin",
unlocked: false, level: 9,
name: "Paladin",
unlocked: false,
}, },
{ {
id: "dragon_rider", baseCost: 600_000_000,
name: "Dragon Rider", class: "ranger",
class: "ranger", combatPower: 6000,
level: 10, count: 0,
goldPerSecond: 2000,
essencePerSecond: 3, essencePerSecond: 3,
combatPower: 6000, goldPerSecond: 2000,
count: 0, id: "dragon_rider",
unlocked: false, level: 10,
name: "Dragon Rider",
unlocked: false,
}, },
{ {
id: "shadow_assassin", baseCost: 4_000_000_000,
name: "Shadow Assassin", class: "rogue",
class: "rogue", combatPower: 18_000,
level: 11, count: 0,
goldPerSecond: 5_000,
essencePerSecond: 6, essencePerSecond: 6,
combatPower: 18_000, goldPerSecond: 5000,
count: 0, id: "shadow_assassin",
unlocked: false, level: 11,
name: "Shadow Assassin",
unlocked: false,
}, },
{ {
id: "arcane_scholar", baseCost: 28_000_000_000,
name: "Arcane Scholar", class: "mage",
class: "mage", combatPower: 45_000,
level: 12, count: 0,
goldPerSecond: 14_000,
essencePerSecond: 15, essencePerSecond: 15,
combatPower: 45_000, goldPerSecond: 14_000,
count: 0, id: "arcane_scholar",
unlocked: false, level: 12,
name: "Arcane Scholar",
unlocked: false,
}, },
{ {
id: "void_walker", baseCost: 200_000_000_000,
name: "Void Walker", class: "rogue",
class: "rogue", combatPower: 130_000,
level: 13, count: 0,
goldPerSecond: 40_000,
essencePerSecond: 35, essencePerSecond: 35,
combatPower: 130_000, goldPerSecond: 40_000,
count: 0, id: "void_walker",
unlocked: false, level: 13,
name: "Void Walker",
unlocked: false,
}, },
{ {
id: "celestial_guard", baseCost: 1_400_000_000_000,
name: "Celestial Guard", class: "paladin",
class: "paladin", combatPower: 400_000,
level: 14, count: 0,
goldPerSecond: 120_000,
essencePerSecond: 100, essencePerSecond: 100,
combatPower: 400_000, goldPerSecond: 120_000,
count: 0, id: "celestial_guard",
unlocked: false, level: 14,
name: "Celestial Guard",
unlocked: false,
}, },
{ {
id: "divine_champion", baseCost: 10_000_000_000_000,
name: "Divine Champion", class: "warrior",
class: "warrior", combatPower: 1_200_000,
level: 15, count: 0,
goldPerSecond: 400_000,
essencePerSecond: 300, essencePerSecond: 300,
combatPower: 1_200_000, goldPerSecond: 400_000,
count: 0, id: "divine_champion",
unlocked: false, level: 15,
name: "Divine Champion",
unlocked: false,
}, },
{ {
id: "seraph_knight", baseCost: 70_000_000_000_000,
name: "Seraph Knight", class: "paladin",
class: "paladin", combatPower: 4_000_000,
level: 16, count: 0,
goldPerSecond: 1_200_000,
essencePerSecond: 800, essencePerSecond: 800,
combatPower: 4_000_000, goldPerSecond: 1_200_000,
count: 0, id: "seraph_knight",
unlocked: false, level: 16,
name: "Seraph Knight",
unlocked: false,
}, },
{ {
id: "abyss_diver", baseCost: 500_000_000_000_000,
name: "Abyss Diver", class: "rogue",
class: "rogue", combatPower: 12_000_000,
level: 17, count: 0,
goldPerSecond: 3_500_000, essencePerSecond: 2000,
essencePerSecond: 2_000, goldPerSecond: 3_500_000,
combatPower: 12_000_000, id: "abyss_diver",
count: 0, level: 17,
unlocked: false, name: "Abyss Diver",
unlocked: false,
}, },
{ {
id: "infernal_warden", baseCost: 3_500_000_000_000_000,
name: "Infernal Warden", class: "warrior",
class: "warrior", combatPower: 35_000_000,
level: 18, count: 0,
goldPerSecond: 10_000_000, essencePerSecond: 5000,
essencePerSecond: 5_000, goldPerSecond: 10_000_000,
combatPower: 35_000_000, id: "infernal_warden",
count: 0, level: 18,
unlocked: false, name: "Infernal Warden",
unlocked: false,
}, },
{ {
id: "crystal_sage", baseCost: 25_000_000_000_000_000,
name: "Crystal Sage", class: "mage",
class: "mage", combatPower: 100_000_000,
level: 19, count: 0,
goldPerSecond: 30_000_000,
essencePerSecond: 12_000, essencePerSecond: 12_000,
combatPower: 100_000_000, goldPerSecond: 30_000_000,
count: 0, id: "crystal_sage",
unlocked: false, level: 19,
name: "Crystal Sage",
unlocked: false,
}, },
{ {
id: "void_sentinel", baseCost: 175_000_000_000_000_000,
name: "Void Sentinel", class: "rogue",
class: "rogue", combatPower: 300_000_000,
level: 20, count: 0,
goldPerSecond: 90_000_000,
essencePerSecond: 30_000, essencePerSecond: 30_000,
combatPower: 300_000_000, goldPerSecond: 90_000_000,
count: 0, id: "void_sentinel",
unlocked: false, level: 20,
name: "Void Sentinel",
unlocked: false,
}, },
{ {
id: "eternal_champion", baseCost: 1_200_000_000_000_000_000,
name: "Eternal Champion", class: "warrior",
class: "warrior", combatPower: 900_000_000,
level: 21, count: 0,
goldPerSecond: 270_000_000,
essencePerSecond: 80_000, essencePerSecond: 80_000,
combatPower: 900_000_000, goldPerSecond: 270_000_000,
count: 0, id: "eternal_champion",
unlocked: false, level: 21,
name: "Eternal Champion",
unlocked: false,
}, },
{ {
id: "aether_weaver", baseCost: 8_500_000_000_000_000_000,
name: "Aether Weaver", class: "mage",
class: "mage", combatPower: 2_700_000_000,
level: 22, count: 0,
goldPerSecond: 800_000_000,
essencePerSecond: 220_000, essencePerSecond: 220_000,
combatPower: 2_700_000_000, goldPerSecond: 800_000_000,
count: 0, id: "aether_weaver",
unlocked: false, level: 22,
name: "Aether Weaver",
unlocked: false,
}, },
{ {
id: "titan_warrior", baseCost: 60_000_000_000_000_000_000,
name: "Titan Warrior", class: "warrior",
class: "warrior", combatPower: 8_000_000_000,
level: 23, count: 0,
goldPerSecond: 2_500_000_000,
essencePerSecond: 600_000, essencePerSecond: 600_000,
combatPower: 8_000_000_000, goldPerSecond: 2_500_000_000,
count: 0, id: "titan_warrior",
unlocked: false, level: 23,
name: "Titan Warrior",
unlocked: false,
}, },
{ {
id: "nexus_sage", baseCost: 420_000_000_000_000_000_000,
name: "Nexus Sage", class: "mage",
class: "mage", combatPower: 24_000_000_000,
level: 24, count: 0,
goldPerSecond: 7_500_000_000,
essencePerSecond: 1_600_000, essencePerSecond: 1_600_000,
combatPower: 24_000_000_000, goldPerSecond: 7_500_000_000,
count: 0, id: "nexus_sage",
unlocked: false, level: 24,
name: "Nexus Sage",
unlocked: false,
}, },
{ {
id: "cosmos_knight", baseCost: 3_000_000_000_000_000_000_000,
name: "Cosmos Knight", class: "paladin",
class: "paladin", combatPower: 72_000_000_000,
level: 25, count: 0,
goldPerSecond: 22_000_000_000,
essencePerSecond: 4_500_000, essencePerSecond: 4_500_000,
combatPower: 72_000_000_000, goldPerSecond: 22_000_000_000,
count: 0, id: "cosmos_knight",
unlocked: false, level: 25,
name: "Cosmos Knight",
unlocked: false,
}, },
{ {
id: "astral_sovereign", baseCost: 21_000_000_000_000_000_000_000,
name: "Astral Sovereign", class: "warrior",
class: "warrior", combatPower: 200_000_000_000,
level: 26, count: 0,
goldPerSecond: 65_000_000_000,
essencePerSecond: 12_000_000, essencePerSecond: 12_000_000,
combatPower: 200_000_000_000, goldPerSecond: 65_000_000_000,
count: 0, id: "astral_sovereign",
unlocked: false, level: 26,
name: "Astral Sovereign",
unlocked: false,
}, },
{ {
id: "primordial_mage", baseCost: 150_000_000_000_000_000_000_000,
name: "Primordial Mage", class: "mage",
class: "mage", combatPower: 600_000_000_000,
level: 27, count: 0,
goldPerSecond: 200_000_000_000,
essencePerSecond: 35_000_000, essencePerSecond: 35_000_000,
combatPower: 600_000_000_000, goldPerSecond: 200_000_000_000,
count: 0, id: "primordial_mage",
unlocked: false, level: 27,
name: "Primordial Mage",
unlocked: false,
}, },
{ {
id: "reality_warden", baseCost: 1_000_000_000_000_000_000_000_000,
name: "Reality Warden", class: "paladin",
class: "paladin", combatPower: 1_800_000_000_000,
level: 28, count: 0,
goldPerSecond: 600_000_000_000,
essencePerSecond: 100_000_000, essencePerSecond: 100_000_000,
combatPower: 1_800_000_000_000, goldPerSecond: 600_000_000_000,
count: 0, id: "reality_warden",
unlocked: false, level: 28,
name: "Reality Warden",
unlocked: false,
}, },
{ {
id: "infinity_ranger", baseCost: 7_000_000_000_000_000_000_000_000,
name: "Infinity Ranger", class: "ranger",
class: "ranger", combatPower: 5_500_000_000_000,
level: 29, count: 0,
goldPerSecond: 1_800_000_000_000,
essencePerSecond: 300_000_000, essencePerSecond: 300_000_000,
combatPower: 5_500_000_000_000, goldPerSecond: 1_800_000_000_000,
count: 0, id: "infinity_ranger",
unlocked: false, level: 29,
name: "Infinity Ranger",
unlocked: false,
}, },
{ {
id: "oblivion_paladin", baseCost: 50_000_000_000_000_000_000_000_000,
name: "Oblivion Paladin", class: "paladin",
class: "paladin", combatPower: 16_000_000_000_000,
level: 30, count: 0,
goldPerSecond: 5_500_000_000_000,
essencePerSecond: 850_000_000, essencePerSecond: 850_000_000,
combatPower: 16_000_000_000_000, goldPerSecond: 5_500_000_000_000,
count: 0, id: "oblivion_paladin",
unlocked: false, level: 30,
name: "Oblivion Paladin",
unlocked: false,
}, },
{ {
id: "transcendent_rogue", baseCost: 350_000_000_000_000_000_000_000_000,
name: "Transcendent Rogue", class: "rogue",
class: "rogue", combatPower: 50_000_000_000_000,
level: 31, count: 0,
goldPerSecond: 16_000_000_000_000,
essencePerSecond: 2_500_000_000, essencePerSecond: 2_500_000_000,
combatPower: 50_000_000_000_000, goldPerSecond: 16_000_000_000_000,
count: 0, id: "transcendent_rogue",
unlocked: false, level: 31,
name: "Transcendent Rogue",
unlocked: false,
}, },
{ {
id: "omniversal_champion", baseCost: 2_500_000_000_000_000_000_000_000_000,
name: "Omniversal Champion", class: "warrior",
class: "warrior", combatPower: 150_000_000_000_000,
level: 32, count: 0,
goldPerSecond: 50_000_000_000_000,
essencePerSecond: 7_000_000_000, essencePerSecond: 7_000_000_000,
combatPower: 150_000_000_000_000, goldPerSecond: 50_000_000_000_000,
count: 0, id: "omniversal_champion",
unlocked: false, level: 32,
name: "Omniversal Champion",
unlocked: false,
}, },
]; ];
File diff suppressed because it is too large Load Diff
+60 -14
View File
@@ -1,25 +1,71 @@
/**
* @file Game data definitions.
* @copyright nhcarrigan
* @license Naomi's Public License
* @author Naomi Carrigan
*/
import type { DailyChallengeType } from "@elysium/types"; import type { DailyChallengeType } from "@elysium/types";
interface DailyChallengeTemplate { interface DailyChallengeTemplate {
type: DailyChallengeType; type: DailyChallengeType;
label: string; label: string;
target: number; target: number;
rewardCrystals: number; rewardCrystals: number;
} }
export const DAILY_CHALLENGE_TEMPLATES: DailyChallengeTemplate[] = [ export const dailyChallengeTemplates: Array<DailyChallengeTemplate> = [
// Clicks — always requires active play // Clicks — always requires active play
{ type: "clicks", label: "Click 500 times", target: 500, rewardCrystals: 50 }, { label: "Click 500 times", rewardCrystals: 50, target: 500, type: "clicks" },
{ type: "clicks", label: "Click 1,000 times", target: 1_000, rewardCrystals: 100 }, {
{ type: "clicks", label: "Click 5,000 times", target: 5_000, rewardCrystals: 300 }, label: "Click 1,000 times",
rewardCrystals: 100,
target: 1000,
type: "clicks",
},
{
label: "Click 5,000 times",
rewardCrystals: 300,
target: 5000,
type: "clicks",
},
// Boss defeats — requires active combat // Boss defeats — requires active combat
{ type: "bossesDefeated", label: "Defeat 1 boss", target: 1, rewardCrystals: 75 }, {
{ type: "bossesDefeated", label: "Defeat 3 bosses", target: 3, rewardCrystals: 200 }, label: "Defeat 1 boss",
{ type: "bossesDefeated", label: "Defeat 5 bosses", target: 5, rewardCrystals: 400 }, rewardCrystals: 75,
target: 1,
type: "bossesDefeated",
},
{
label: "Defeat 3 bosses",
rewardCrystals: 200,
target: 3,
type: "bossesDefeated",
},
{
label: "Defeat 5 bosses",
rewardCrystals: 400,
target: 5,
type: "bossesDefeated",
},
// Quest completions — requires starting quests // Quest completions — requires starting quests
{ type: "questsCompleted", label: "Complete 3 quests", target: 3, rewardCrystals: 100 }, {
{ type: "questsCompleted", label: "Complete 5 quests", target: 5, rewardCrystals: 200 }, label: "Complete 3 quests",
{ type: "questsCompleted", label: "Complete 10 quests", target: 10, rewardCrystals: 400 }, rewardCrystals: 100,
target: 3,
type: "questsCompleted",
},
{
label: "Complete 5 quests",
rewardCrystals: 200,
target: 5,
type: "questsCompleted",
},
{
label: "Complete 10 quests",
rewardCrystals: 400,
target: 10,
type: "questsCompleted",
},
// Prestige — the big one // Prestige — the big one
{ type: "prestige", label: "Prestige once", target: 1, rewardCrystals: 750 }, { label: "Prestige once", rewardCrystals: 750, target: 1, type: "prestige" },
]; ];
File diff suppressed because it is too large Load Diff
+54 -37
View File
@@ -1,94 +1,111 @@
/**
* @file Game data definitions.
* @copyright nhcarrigan
* @license Naomi's Public License
* @author Naomi Carrigan
*/
/* eslint-disable stylistic/max-len -- Data content */
/* eslint-disable @typescript-eslint/naming-convention -- Numeric keys required by EquipmentSet type */
import type { EquipmentSet } from "@elysium/types"; import type { EquipmentSet } from "@elysium/types";
export const DEFAULT_EQUIPMENT_SETS: EquipmentSet[] = [ export const defaultEquipmentSets: Array<EquipmentSet> = [
{ {
id: "iron_vanguard",
name: "Iron Vanguard",
description: "The armaments of a seasoned guild soldier — proven steel, reliable gold.",
pieces: ["iron_sword", "chainmail", "mages_focus"],
bonuses: { bonuses: {
2: { goldMultiplier: 1.1 }, 2: { goldMultiplier: 1.1 },
3: { combatMultiplier: 1.1 }, 3: { combatMultiplier: 1.1 },
}, },
description:
"The armaments of a seasoned guild soldier — proven steel, reliable gold.",
id: "iron_vanguard",
name: "Iron Vanguard",
pieces: [ "iron_sword", "chainmail", "mages_focus" ],
}, },
{ {
id: "shadow_infiltrator",
name: "Shadow Infiltrator",
description: "Gear forged from the Shadow Marshes themselves — unseen, unstoppable.",
pieces: ["shadow_dagger", "void_shroud", "void_compass"],
bonuses: { bonuses: {
2: { goldMultiplier: 1.15 }, 2: { goldMultiplier: 1.15 },
3: { clickMultiplier: 1.2 }, 3: { clickMultiplier: 1.2 },
}, },
description:
"Gear forged from the Shadow Marshes themselves — unseen, unstoppable.",
id: "shadow_infiltrator",
name: "Shadow Infiltrator",
pieces: [ "shadow_dagger", "void_shroud", "void_compass" ],
}, },
{ {
id: "volcanic_forger",
name: "Volcanic Forger",
description: "Weapons and armour tempered in the depths of the Volcanic Reaches.",
pieces: ["flame_lance", "volcanic_plate", "crystal_shard"],
bonuses: { bonuses: {
2: { combatMultiplier: 1.15 }, 2: { combatMultiplier: 1.15 },
3: { goldMultiplier: 1.15 }, 3: { goldMultiplier: 1.15 },
}, },
description:
"Weapons and armour tempered in the depths of the Volcanic Reaches.",
id: "volcanic_forger",
name: "Volcanic Forger",
pieces: [ "flame_lance", "volcanic_plate", "crystal_shard" ],
}, },
{ {
id: "celestial_guardian",
name: "Celestial Guardian",
description: "Relics of the Celestial Reaches — divine power made manifest.",
pieces: ["seraph_wing", "celestial_armour", "angels_halo"],
bonuses: { bonuses: {
2: { combatMultiplier: 1.2 }, 2: { combatMultiplier: 1.2 },
3: { goldMultiplier: 1.2 }, 3: { goldMultiplier: 1.2 },
}, },
description:
"Relics of the Celestial Reaches — divine power made manifest.",
id: "celestial_guardian",
name: "Celestial Guardian",
pieces: [ "seraph_wing", "celestial_armour", "angels_halo" ],
}, },
{ {
id: "abyssal_predator",
name: "Abyssal Predator",
description: "Trophies reclaimed from the deepest trenches of the Abyssal Reaches.",
pieces: ["depth_blade", "pressure_plate", "leviathan_eye"],
bonuses: { bonuses: {
2: { goldMultiplier: 1.2 }, 2: { goldMultiplier: 1.2 },
3: { clickMultiplier: 1.25 }, 3: { clickMultiplier: 1.25 },
}, },
description:
"Trophies reclaimed from the deepest trenches of the Abyssal Reaches.",
id: "abyssal_predator",
name: "Abyssal Predator",
pieces: [ "depth_blade", "pressure_plate", "leviathan_eye" ],
}, },
{ {
id: "infernal_conqueror",
name: "Infernal Conqueror",
description: "Forged in the heart of the Infernal Court from the essence of the defeated.",
pieces: ["hellfire_edge", "demon_hide", "soul_gem"],
bonuses: { bonuses: {
2: { combatMultiplier: 1.25 }, 2: { combatMultiplier: 1.25 },
3: { goldMultiplier: 1.25 }, 3: { goldMultiplier: 1.25 },
}, },
description:
"Forged in the heart of the Infernal Court from the essence of the defeated.",
id: "infernal_conqueror",
name: "Infernal Conqueror",
pieces: [ "hellfire_edge", "demon_hide", "soul_gem" ],
}, },
{ {
id: "crystal_domain",
name: "Crystal Domain",
description: "Instruments of the Crystalline Spire — reality refracted into absolute efficiency.",
pieces: ["prism_blade", "faceted_armour", "prism_eye"],
bonuses: { bonuses: {
2: { clickMultiplier: 1.25 }, 2: { clickMultiplier: 1.25 },
3: { goldMultiplier: 1.25 }, 3: { goldMultiplier: 1.25 },
}, },
description:
"Instruments of the Crystalline Spire — reality refracted into absolute efficiency.",
id: "crystal_domain",
name: "Crystal Domain",
pieces: [ "prism_blade", "faceted_armour", "prism_eye" ],
}, },
{ {
id: "void_emperor",
name: "Void Emperor",
description: "The regalia of the Void Sanctum's lord — power carved from absolute nothingness.",
pieces: ["void_annihilator", "eternal_shroud", "void_heart_gem"],
bonuses: { bonuses: {
2: { goldMultiplier: 1.3 }, 2: { goldMultiplier: 1.3 },
3: { combatMultiplier: 1.3 }, 3: { combatMultiplier: 1.3 },
}, },
description:
"The regalia of the Void Sanctum's lord — power carved from absolute nothingness.",
id: "void_emperor",
name: "Void Emperor",
pieces: [ "void_annihilator", "eternal_shroud", "void_heart_gem" ],
}, },
{ {
id: "eternal_throne",
name: "Eternal Throne",
description: "The armaments of the Eternal Throne — weapons and armour that have endured all of time.",
pieces: ["throne_blade", "eternal_armour", "eternity_stone"],
bonuses: { bonuses: {
2: { combatMultiplier: 1.35, goldMultiplier: 1.25 }, 2: { combatMultiplier: 1.35, goldMultiplier: 1.25 },
3: { clickMultiplier: 1.35 }, 3: { clickMultiplier: 1.35 },
}, },
description:
"The armaments of the Eternal Throne — weapons and armour that have endured all of time.",
id: "eternal_throne",
name: "Eternal Throne",
pieces: [ "throne_blade", "eternal_armour", "eternity_stone" ],
}, },
]; ];
File diff suppressed because it is too large Load Diff
+102 -36
View File
@@ -1,40 +1,106 @@
import type { GameState, Player, PrestigeData } from "@elysium/types"; /**
import { DEFAULT_ACHIEVEMENTS } from "./achievements.js"; * @file Initial game state data.
import { DEFAULT_ADVENTURERS } from "./adventurers.js"; * @copyright nhcarrigan
import { DEFAULT_BOSSES } from "./bosses.js"; * @license Naomi's Public License
import { DEFAULT_EQUIPMENT } from "./equipment.js"; * @author Naomi Carrigan
import { DEFAULT_QUESTS } from "./quests.js"; */
import { DEFAULT_UPGRADES } from "./upgrades.js"; import { defaultAchievements } from "./achievements.js";
import { DEFAULT_ZONES } from "./zones.js"; import { defaultAdventurers } from "./adventurers.js";
import { defaultBosses } from "./bosses.js";
import { defaultEquipment } from "./equipment.js";
import { defaultExplorations } from "./explorations.js";
import { defaultQuests } from "./quests.js";
import { currentSchemaVersion } from "./schemaVersion.js";
import { defaultUpgrades } from "./upgrades.js";
import { defaultZones } from "./zones.js";
import type {
ApotheosisData,
ExplorationState,
GameState,
Player,
PrestigeData,
TranscendenceData,
} from "@elysium/types";
export const INITIAL_PRESTIGE: PrestigeData = { const initialPrestige: PrestigeData = {
count: 0, count: 0,
runestones: 0,
productionMultiplier: 1, productionMultiplier: 1,
purchasedUpgradeIds: [], purchasedUpgradeIds: [],
runestones: 0,
}; };
export const INITIAL_GAME_STATE = (player: Player, characterName: string): GameState => ({ const initialTranscendence: TranscendenceData = {
player: { count: 0,
...player, echoCombatMultiplier: 1,
characterName, echoIncomeMultiplier: 1,
totalGoldEarned: 0, echoMetaMultiplier: 1,
totalClicks: 0, echoPrestigeRunestoneMultiplier: 1,
}, echoPrestigeThresholdMultiplier: 1,
resources: { echoes: 0,
gold: 0, purchasedUpgradeIds: [],
essence: 0, };
crystals: 0,
runestones: 0, const initialApotheosis: ApotheosisData = {
}, count: 0,
adventurers: structuredClone(DEFAULT_ADVENTURERS), };
upgrades: structuredClone(DEFAULT_UPGRADES),
quests: structuredClone(DEFAULT_QUESTS), const initialExploration: ExplorationState = {
bosses: structuredClone(DEFAULT_BOSSES), areas: defaultExplorations.map((area) => {
equipment: structuredClone(DEFAULT_EQUIPMENT), return {
achievements: structuredClone(DEFAULT_ACHIEVEMENTS), id: area.id,
prestige: INITIAL_PRESTIGE, status:
zones: structuredClone(DEFAULT_ZONES), area.zoneId === "verdant_vale"
baseClickPower: 1, ? ("available" as const)
lastTickAt: Date.now(), : ("locked" as const),
}); };
}),
craftedClickMultiplier: 1,
craftedCombatMultiplier: 1,
craftedEssenceMultiplier: 1,
craftedGoldMultiplier: 1,
craftedRecipeIds: [],
materials: [],
};
/**
* Builds an initial game state for a new player.
* @param player - The player data from Discord OAuth.
* @param characterName - The character name chosen by the player.
* @returns A fresh GameState object.
*/
const initialGameState = (
player: Player,
characterName: string,
): GameState => {
return {
achievements: structuredClone(defaultAchievements),
adventurers: structuredClone(defaultAdventurers),
apotheosis: { ...initialApotheosis },
baseClickPower: 1,
bosses: structuredClone(defaultBosses),
companions: { activeCompanionId: null, unlockedCompanionIds: [] },
equipment: structuredClone(defaultEquipment),
exploration: structuredClone(initialExploration),
lastTickAt: Date.now(),
player: {
...player,
characterName: characterName,
totalClicks: 0,
totalGoldEarned: 0,
},
prestige: initialPrestige,
quests: structuredClone(defaultQuests),
resources: {
crystals: 0,
essence: 0,
gold: 0,
runestones: 0,
},
schemaVersion: currentSchemaVersion,
transcendence: { ...initialTranscendence },
upgrades: structuredClone(defaultUpgrades),
zones: structuredClone(defaultZones),
};
};
export { initialExploration, initialGameState };
+25
View File
@@ -0,0 +1,25 @@
/**
* @file Login bonus reward data.
* @copyright nhcarrigan
* @license Naomi's Public License
* @author Naomi Carrigan
*/
export interface DayReward {
day: number;
goldBase: number;
crystals?: number;
}
/**
* Rewards for days 17 of a login streak. The cycle repeats every 7 days
* with a multiplier equal to the week number (week 1 = ×1, week 2 = ×2, etc.).
*/
export const dailyRewards: Array<DayReward> = [
{ day: 1, goldBase: 500 },
{ day: 2, goldBase: 1000 },
{ day: 3, goldBase: 2500 },
{ day: 4, goldBase: 5000 },
{ day: 5, goldBase: 10_000 },
{ day: 6, goldBase: 25_000 },
{ crystals: 5, day: 7, goldBase: 50_000 },
];
+479
View File
@@ -0,0 +1,479 @@
/**
* @file Game data definitions.
* @copyright nhcarrigan
* @license Naomi's Public License
* @author Naomi Carrigan
*/
/* eslint-disable max-lines -- Data file */
/* eslint-disable stylistic/max-len -- Data content */
import type { Material } from "@elysium/types";
export const defaultMaterials: Array<Material> = [
// Zone 1: verdant_vale
{
description:
"Sticky resin tapped from ancient heartwood trees. Smells faintly of spring rain and something older beneath.",
id: "verdant_sap",
name: "Verdant Sap",
rarity: "common",
zoneId: "verdant_vale",
},
{
description:
"A translucent gem found buried near the roots of old-growth trees. Pulses with gentle life energy when held.",
id: "forest_crystal",
name: "Forest Crystal",
rarity: "uncommon",
zoneId: "verdant_vale",
},
{
description:
"Bark from a tree that has stood since before the kingdom. Harder than iron and warmer to the touch than it has any right to be.",
id: "elder_bark",
name: "Elder Bark",
rarity: "rare",
zoneId: "verdant_vale",
},
// Zone 2: shattered_ruins
{
description:
"Fine powder ground from fallen masonry. Still carries traces of the civilisation it once was — if you know how to read the patterns.",
id: "ruin_dust",
name: "Ruin Dust",
rarity: "common",
zoneId: "shattered_ruins",
},
{
description:
"A shard of enchanted stonework. The enchantment is broken, but something lingers in the grain of the stone, waiting.",
id: "cursed_fragment",
name: "Cursed Fragment",
rarity: "uncommon",
zoneId: "shattered_ruins",
},
{
description:
"A fragment of scale shed during the elder dragon's long reign over the ruins. Resistant to fire and magic alike.",
id: "dragonscale_chip",
name: "Dragonscale Chip",
rarity: "rare",
zoneId: "shattered_ruins",
},
// Zone 3: frozen_peaks
{
description:
"Ice from a glacier that has not moved in ten thousand years. Impossibly cold and perfectly clear, with something almost visible within.",
id: "glacial_ice",
name: "Glacial Ice",
rarity: "common",
zoneId: "frozen_peaks",
},
{
description:
"A crystal that formed inside the glacier itself over millennia. It never melts, not even near fire.",
id: "frost_crystal",
name: "Frost Crystal",
rarity: "uncommon",
zoneId: "frozen_peaks",
},
{
description:
"A fragment of the reality tear. It hums with wrongness that the fingers instinctively recognise before the mind does.",
id: "void_shard",
name: "Void Shard",
rarity: "rare",
zoneId: "frozen_peaks",
},
// Zone 4: shadow_marshes
{
description:
"Roots from the strangler plants that thrive in the fog-choked depths. Toxic without extensive preparation. Worth it, usually.",
id: "marsh_root",
name: "Marsh Root",
rarity: "common",
zoneId: "shadow_marshes",
},
{
description:
"Distilled darkness, caught in a vial before it could dissipate. Heavy and cold, and absolutely lightless.",
id: "shadow_essence",
name: "Shadow Essence",
rarity: "uncommon",
zoneId: "shadow_marshes",
},
{
description:
"Bone from something that died in the marsh so long ago it has become part of it. The curse runs deep through the marrow.",
id: "cursed_bone",
name: "Cursed Bone",
rarity: "rare",
zoneId: "shadow_marshes",
},
// Zone 5: volcanic_depths
{
description:
"Cooled lava that retained its internal heat. Warm to the touch even centuries after solidifying from whatever it once was.",
id: "magma_stone",
name: "Magma Stone",
rarity: "common",
zoneId: "volcanic_depths",
},
{
description:
"A crystal grown in the heart of a cooling magma chamber. Burns without being consumed, endlessly.",
id: "ember_crystal",
name: "Ember Crystal",
rarity: "uncommon",
zoneId: "volcanic_depths",
},
{
description:
"Ore from a seam that the fire elementals guard jealously. What it forges into is extraordinary by any measure.",
id: "legendary_ore",
name: "Legendary Ore",
rarity: "rare",
zoneId: "volcanic_depths",
},
// Zone 6: astral_void
{
description:
"Particulate matter from dying stars, collected from the void between worlds. Glitters even in total darkness.",
id: "stardust",
name: "Stardust",
rarity: "common",
zoneId: "astral_void",
},
{
description:
"Filaments of solidified probability. Handle with care — they remember every possible future they passed through.",
id: "astral_thread",
name: "Astral Thread",
rarity: "uncommon",
zoneId: "astral_void",
},
{
description:
"A crystal that formed in the spaces between spaces. Technically exists in several places simultaneously. Don't think too hard about it.",
id: "void_crystal",
name: "Void Crystal",
rarity: "rare",
zoneId: "astral_void",
},
// Zone 7: celestial_reaches
{
description:
"Residue from the celestial host's passing. Warm as sunlight and infinitely patient, as if waiting for something to happen.",
id: "celestial_dust",
name: "Celestial Dust",
rarity: "common",
zoneId: "celestial_reaches",
},
{
description:
"A chip of something the celestials discarded as imperfect. By mortal standards, it is extraordinary beyond measure.",
id: "divine_fragment",
name: "Divine Fragment",
rarity: "uncommon",
zoneId: "celestial_reaches",
},
{
description:
"A crystallised harmonic from the celestial choir. Resonates with a sound felt in the chest rather than heard with the ears.",
id: "choir_shard",
name: "Choir Shard",
rarity: "rare",
zoneId: "celestial_reaches",
},
// Zone 8: abyssal_trench
{
description:
"Coral from the deepest trenches where no light reaches and no warmth remains. Black as the water around it.",
id: "trench_coral",
name: "Trench Coral",
rarity: "common",
zoneId: "abyssal_trench",
},
{
description:
"A gem compressed by aeons of unimaginable pressure at the bottom of all things. Impossibly dense for its size.",
id: "pressure_gem",
name: "Pressure Gem",
rarity: "uncommon",
zoneId: "abyssal_trench",
},
{
description:
"A tooth from whatever has been waiting in the trench since before your world was made. It is very large.",
id: "ancient_tooth",
name: "Ancient Tooth",
rarity: "rare",
zoneId: "abyssal_trench",
},
// Zone 9: infernal_court
{
description:
"Sulphur residue from the court's perpetual fires. The smell never fully fades, no matter how carefully it is stored.",
id: "brimstone_flake",
name: "Brimstone Flake",
rarity: "common",
zoneId: "infernal_court",
},
{
description:
"Extracted from the court's refuse. Corrosive, powerful, and deeply unpleasant in every measurable way.",
id: "demon_ichor",
name: "Demon Ichor",
rarity: "uncommon",
zoneId: "infernal_court",
},
{
description:
"What remains after a soul has been fully processed by the court. Carries faint echoes of what it was before.",
id: "soul_residue",
name: "Soul Residue",
rarity: "rare",
zoneId: "infernal_court",
},
// Zone 10: crystalline_spire
{
description:
"Ground from the spire's outer facets. Each particle contains a compressed possibility that has not yet resolved.",
id: "prism_dust",
name: "Prism Dust",
rarity: "common",
zoneId: "crystalline_spire",
},
{
description:
"A fragment of the spire's core intelligence. Still running calculations on something that may or may not have an answer.",
id: "calculation_shard",
name: "Calculation Shard",
rarity: "uncommon",
zoneId: "crystalline_spire",
},
{
description:
"A crystal that contains a future that never happened. Treat carefully. The future remembers being possible.",
id: "possibility_crystal",
name: "Possibility Crystal",
rarity: "rare",
zoneId: "crystalline_spire",
},
// Zone 11: void_sanctum
{
description:
"Matter that exists in the space between spaces. Lacks most standard properties in ways that should not be possible.",
id: "null_matter",
name: "Null Matter",
rarity: "common",
zoneId: "void_sanctum",
},
{
description:
"A shard of the call that drew your guild here. Still resonant, still reaching toward something none of you can name.",
id: "resonance_fragment",
name: "Resonance Fragment",
rarity: "uncommon",
zoneId: "void_sanctum",
},
{
description:
"From the heart of the sanctum itself. What it does is undefined. What it is cannot be satisfactorily described.",
id: "sanctum_core",
name: "Sanctum Core",
rarity: "rare",
zoneId: "void_sanctum",
},
// Zone 12: eternal_throne
{
description:
"Residue from the base of the eternal throne. Old beyond any measurement that applies to things your guild understands.",
id: "throne_dust",
name: "Throne Dust",
rarity: "common",
zoneId: "eternal_throne",
},
{
description:
"A chip from one of the throne's crown-like spires. Authority made into something your hands can hold.",
id: "crown_fragment",
name: "Crown Fragment",
rarity: "uncommon",
zoneId: "eternal_throne",
},
{
description:
"From the throne's arm. Carries the weight of every decision ever made here, compressed into splinter-form.",
id: "eternity_splinter",
name: "Eternity Splinter",
rarity: "rare",
zoneId: "eternal_throne",
},
// Zone 13: primordial_chaos
{
description:
"A solidified moment of chaos. Still undecided about its own properties, which change depending on how you look at it.",
id: "chaos_fragment",
name: "Chaos Fragment",
rarity: "common",
zoneId: "primordial_chaos",
},
{
description:
"A fragment from when something was being made here. What was being made is unclear. Something important, probably.",
id: "creation_shard",
name: "Creation Shard",
rarity: "uncommon",
zoneId: "primordial_chaos",
},
{
description:
"The raw stuff of creation, before it became anything specific. Handle with care. It wants to become things.",
id: "primordial_essence",
name: "Primordial Essence",
rarity: "rare",
zoneId: "primordial_chaos",
},
// Zone 14: infinite_expanse
{
description:
"Gathered from somewhere in the expanse. Direction is uncertain. Distance from the collection point is uncertain.",
id: "expanse_dust",
name: "Expanse Dust",
rarity: "common",
zoneId: "infinite_expanse",
},
{
description:
"A crystal that contains compressed distance. It weighs more than its size suggests. Much more. Do not drop it.",
id: "distance_crystal",
name: "Distance Crystal",
rarity: "uncommon",
zoneId: "infinite_expanse",
},
{
description:
"A fragment of the expanse's edge, which the expanse does not technically have. This should not exist. It does anyway.",
id: "infinity_shard",
name: "Infinity Shard",
rarity: "rare",
zoneId: "infinite_expanse",
},
// Zone 15: reality_forge
{
description:
"Ash from the forge's fires. Contains fragments of unrealised realities that never quite made it to existence.",
id: "forge_ash",
name: "Forge Ash",
rarity: "common",
zoneId: "reality_forge",
},
{
description:
"A worn tool left by whatever worked here before your universe existed. Still functional in ways that are difficult to explain.",
id: "creation_tool",
name: "Creation Tool",
rarity: "uncommon",
zoneId: "reality_forge",
},
{
description:
"A flawed reality, discarded by the forge as below standard. Still contains everything a universe needs.",
id: "reality_shard",
name: "Reality Shard",
rarity: "rare",
zoneId: "reality_forge",
},
// Zone 16: cosmic_maelstrom
{
description:
"Debris from a galaxy that got too close to the maelstrom. Compressed to a size your guild can actually carry.",
id: "maelstrom_debris",
name: "Maelstrom Debris",
rarity: "common",
zoneId: "cosmic_maelstrom",
},
{
description:
"A crystal that formed at the intersection of several fundamental forces that should never have been in the same place.",
id: "force_crystal",
name: "Force Crystal",
rarity: "uncommon",
zoneId: "cosmic_maelstrom",
},
{
description:
"A fragment from the maelstrom's eye. Impossibly calm. Whatever is at the centre has been there since the beginning.",
id: "cosmic_fragment",
name: "Cosmic Fragment",
rarity: "rare",
zoneId: "cosmic_maelstrom",
},
// Zone 17: primeval_sanctum
{
description:
"Dust from the oldest place. Has been here since before the concept of 'here' had been invented.",
id: "ancient_dust",
name: "Ancient Dust",
rarity: "common",
zoneId: "primeval_sanctum",
},
{
description:
"A shard of something that remembers the moment before the first moment. The memory is in the material itself.",
id: "memory_shard",
name: "Memory Shard",
rarity: "uncommon",
zoneId: "primeval_sanctum",
},
{
description:
"An artefact from the first thing to exist in this place. What it did is unknown. That it mattered is beyond doubt.",
id: "primeval_relic",
name: "Primeval Relic",
rarity: "rare",
zoneId: "primeval_sanctum",
},
// Zone 18: the_absolute
{
description:
"A fragment of the final truth. It is difficult to look at directly, and impossible to look away from once you start.",
id: "absolute_fragment",
name: "Absolute Fragment",
rarity: "common",
zoneId: "the_absolute",
},
{
description:
"From the edge of everything. On one side: everything. On the other: nothing. This is from the very boundary between them.",
id: "boundary_shard",
name: "Boundary Shard",
rarity: "uncommon",
zoneId: "the_absolute",
},
{
description:
"The last crystal. After this, there are no more. It knows this. You can tell from the way it sits in your hand.",
id: "omega_crystal",
name: "Omega Crystal",
rarity: "rare",
zoneId: "the_absolute",
},
];
+132 -107
View File
@@ -1,216 +1,241 @@
/**
* @file Game data definitions.
* @copyright nhcarrigan
* @license Naomi's Public License
* @author Naomi Carrigan
*/
/* eslint-disable stylistic/max-len -- Data content */
import type { PrestigeUpgrade } from "@elysium/types"; import type { PrestigeUpgrade } from "@elysium/types";
export const DEFAULT_PRESTIGE_UPGRADES: PrestigeUpgrade[] = [ export const defaultPrestigeUpgrades: Array<PrestigeUpgrade> = [
// ── Global Income Tiers ─────────────────────────────────────────────────── // ── Global Income Tiers ───────────────────────────────────────────────────
{ {
id: "income_1",
name: "Runestone Blessing I",
description: "The first runestone awakens dormant power in your guild. All production ×1.25.",
category: "income", category: "income",
description:
"The first runestone awakens dormant power in your guild. All production ×1.25.",
id: "income_1",
multiplier: 1.25,
name: "Runestone Blessing I",
runestonesCost: 10, runestonesCost: 10,
multiplier: 1.25,
}, },
{ {
id: "income_2",
name: "Runestone Blessing II",
description: "Deeper runestone resonance amplifies your workforce. All production ×1.5.",
category: "income", category: "income",
description:
"Deeper runestone resonance amplifies your workforce. All production ×1.5.",
id: "income_2",
multiplier: 1.5,
name: "Runestone Blessing II",
runestonesCost: 25, runestonesCost: 25,
multiplier: 1.5,
}, },
{ {
id: "income_3", category: "income",
name: "Runestone Blessing III", description: "The runes sing with accumulated wisdom. All production ×2.",
description: "The runes sing with accumulated wisdom. All production ×2.", id: "income_3",
category: "income", multiplier: 2,
name: "Runestone Blessing III",
runestonesCost: 60, runestonesCost: 60,
multiplier: 2,
}, },
{ {
id: "income_4",
name: "Runic Surge I",
description: "Runestone energy surges through your guild's operations. All production ×3.",
category: "income", category: "income",
description:
"Runestone energy surges through your guild's operations. All production ×3.",
id: "income_4",
multiplier: 3,
name: "Runic Surge I",
runestonesCost: 150, runestonesCost: 150,
multiplier: 3,
}, },
{ {
id: "income_5",
name: "Runic Surge II",
description: "The surge intensifies, pushing limits thought impossible. All production ×5.",
category: "income", category: "income",
description:
"The surge intensifies, pushing limits thought impossible. All production ×5.",
id: "income_5",
multiplier: 5,
name: "Runic Surge II",
runestonesCost: 350, runestonesCost: 350,
multiplier: 5,
}, },
{ {
id: "income_6",
name: "Runic Surge III",
description: "An overwhelming tide of runic energy floods your operations. All production ×10.",
category: "income", category: "income",
description:
"An overwhelming tide of runic energy floods your operations. All production ×10.",
id: "income_6",
multiplier: 10,
name: "Runic Surge III",
runestonesCost: 800, runestonesCost: 800,
multiplier: 10,
}, },
{ {
id: "income_7", category: "income",
name: "Ancient Inscription I",
description: description:
"You decipher ancient runic inscriptions that unlock vast potential. All production ×25.", "You decipher ancient runic inscriptions that unlock vast potential. All production ×25.",
category: "income", id: "income_7",
runestonesCost: 2_000, multiplier: 25,
multiplier: 25, name: "Ancient Inscription I",
runestonesCost: 2000,
}, },
{ {
id: "income_8",
name: "Ancient Inscription II",
description: "Deeper inscriptions reveal secrets of primordial power. All production ×50.",
category: "income", category: "income",
runestonesCost: 5_000, description:
multiplier: 50, "Deeper inscriptions reveal secrets of primordial power. All production ×50.",
id: "income_8",
multiplier: 50,
name: "Ancient Inscription II",
runestonesCost: 5000,
}, },
{ {
id: "income_9",
name: "Ancient Inscription III",
description: "The full inscription blazes with world-shaping power. All production ×100.",
category: "income", category: "income",
description:
"The full inscription blazes with world-shaping power. All production ×100.",
id: "income_9",
multiplier: 100,
name: "Ancient Inscription III",
runestonesCost: 12_000, runestonesCost: 12_000,
multiplier: 100,
}, },
{ {
id: "income_10", category: "income",
name: "Eternal Rune I",
description: description:
"The oldest runes, carved before memory began, yield their secrets at last. All production ×500.", "The oldest runes, carved before memory began, yield their secrets at last. All production ×500.",
category: "income", id: "income_10",
multiplier: 500,
name: "Eternal Rune I",
runestonesCost: 30_000, runestonesCost: 30_000,
multiplier: 500,
}, },
{ {
id: "income_11", category: "income",
name: "Eternal Rune II",
description: description:
"Eternal runes resonate with the heartbeat of creation itself. All production ×1,000.", "Eternal runes resonate with the heartbeat of creation itself. All production ×1,000.",
category: "income", id: "income_11",
multiplier: 1000,
name: "Eternal Rune II",
runestonesCost: 80_000, runestonesCost: 80_000,
multiplier: 1_000,
}, },
// ── Click Power ─────────────────────────────────────────────────────────── // ── Click Power ───────────────────────────────────────────────────────────
{ {
id: "click_power_1",
name: "Runic Strike I",
description: "Infuse your personal strikes with runestone energy. Click power ×2.",
category: "click", category: "click",
description:
"Infuse your personal strikes with runestone energy. Click power ×2.",
id: "click_power_1",
multiplier: 2,
name: "Runic Strike I",
runestonesCost: 15, runestonesCost: 15,
multiplier: 2,
}, },
{ {
id: "click_power_2",
name: "Runic Strike II",
description: "Your strikes crackle with compounded runic force. Click power ×5.",
category: "click", category: "click",
description:
"Your strikes crackle with compounded runic force. Click power ×5.",
id: "click_power_2",
multiplier: 5,
name: "Runic Strike II",
runestonesCost: 75, runestonesCost: 75,
multiplier: 5,
}, },
{ {
id: "click_power_3",
name: "Runic Strike III",
description: "Every click channels the weight of all your past lives. Click power ×20.",
category: "click", category: "click",
description:
"Every click channels the weight of all your past lives. Click power ×20.",
id: "click_power_3",
multiplier: 20,
name: "Runic Strike III",
runestonesCost: 400, runestonesCost: 400,
multiplier: 20,
}, },
{ {
id: "click_power_4",
name: "World-Breaker Click",
description: "A single click now carries the force of a falling empire. Click power ×100.",
category: "click", category: "click",
runestonesCost: 2_500, description:
multiplier: 100, "A single click now carries the force of a falling empire. Click power ×100.",
id: "click_power_4",
multiplier: 100,
name: "World-Breaker Click",
runestonesCost: 2500,
}, },
// ── Essence Production ──────────────────────────────────────────────────── // ── Essence Production ────────────────────────────────────────────────────
{ {
id: "essence_1",
name: "Essence Attunement I",
description: "Runestone resonance amplifies your essence gathering. Essence production ×2.",
category: "essence", category: "essence",
description:
"Runestone resonance amplifies your essence gathering. Essence production ×2.",
id: "essence_1",
multiplier: 2,
name: "Essence Attunement I",
runestonesCost: 20, runestonesCost: 20,
multiplier: 2,
}, },
{ {
id: "essence_2",
name: "Essence Attunement II",
description: "Deep attunement draws essence from previously invisible sources. Essence production ×5.",
category: "essence", category: "essence",
description:
"Deep attunement draws essence from previously invisible sources. Essence production ×5.",
id: "essence_2",
multiplier: 5,
name: "Essence Attunement II",
runestonesCost: 120, runestonesCost: 120,
multiplier: 5,
}, },
{ {
id: "essence_3",
name: "Essence Attunement III",
description: "Your guild breathes essence as naturally as air. Essence production ×20.",
category: "essence", category: "essence",
description:
"Your guild breathes essence as naturally as air. Essence production ×20.",
id: "essence_3",
multiplier: 20,
name: "Essence Attunement III",
runestonesCost: 700, runestonesCost: 700,
multiplier: 20,
}, },
{ {
id: "essence_4",
name: "Essence Attunement IV",
description: "Essence flows in torrents from every corner of every world. Essence production ×100.",
category: "essence", category: "essence",
runestonesCost: 4_000, description:
multiplier: 100, "Essence flows in torrents from every corner of every world. Essence production ×100.",
id: "essence_4",
multiplier: 100,
name: "Essence Attunement IV",
runestonesCost: 4000,
}, },
// ── Crystal Production ──────────────────────────────────────────────────── // ── Crystal Production ────────────────────────────────────────────────────
{ {
id: "crystal_1",
name: "Crystal Resonance I",
description: "Runestones vibrate in harmony with crystal structures. Crystal rewards ×2.",
category: "crystals", category: "crystals",
description:
"Runestones vibrate in harmony with crystal structures. Crystal rewards ×2.",
id: "crystal_1",
multiplier: 2,
name: "Crystal Resonance I",
runestonesCost: 30, runestonesCost: 30,
multiplier: 2,
}, },
{ {
id: "crystal_2",
name: "Crystal Resonance II",
description: "The resonance deepens, shattering crystal barriers. Crystal rewards ×5.",
category: "crystals", category: "crystals",
description:
"The resonance deepens, shattering crystal barriers. Crystal rewards ×5.",
id: "crystal_2",
multiplier: 5,
name: "Crystal Resonance II",
runestonesCost: 200, runestonesCost: 200,
multiplier: 5,
}, },
{ {
id: "crystal_3",
name: "Crystal Resonance III",
description: "Pure resonance crystallises reality into abundance. Crystal rewards ×25.",
category: "crystals", category: "crystals",
runestonesCost: 1_200, description:
multiplier: 25, "Pure resonance crystallises reality into abundance. Crystal rewards ×25.",
id: "crystal_3",
multiplier: 25,
name: "Crystal Resonance III",
runestonesCost: 1200,
}, },
// ── Utility Unlocks ─────────────────────────────────────────────────────── // ── Utility Unlocks ───────────────────────────────────────────────────────
{ {
id: "auto_prestige", category: "utility",
name: "Autonomous Ascension",
description: description:
"Unlock the Auto-Prestige toggle. When enabled, you will automatically ascend the moment you reach the prestige threshold — using your current character name.", "Unlock the Auto-Prestige toggle. When enabled, you will automatically ascend the moment you reach the prestige threshold — using your current character name.",
category: "utility", id: "auto_prestige",
multiplier: 1,
name: "Autonomous Ascension",
runestonesCost: 100, runestonesCost: 100,
multiplier: 1,
}, },
// ── Runestone Meta-Upgrade ──────────────────────────────────────────────── // ── Runestone Meta-Upgrade ────────────────────────────────────────────────
{ {
id: "runestone_gain_1", category: "runestones",
name: "Runic Legacy",
description: description:
"Your runestone attunement grows with each prestige. Earn 25% more runestones from future prestiges.", "Your runestone attunement grows with each prestige. Earn 25% more runestones from future prestiges.",
category: "runestones", id: "runestone_gain_1",
multiplier: 1.25,
name: "Runic Legacy",
runestonesCost: 50, runestonesCost: 50,
multiplier: 1.25,
}, },
{ {
id: "runestone_gain_2", category: "runestones",
name: "Eternal Legacy",
description: description:
"Your legend transcends individual lifetimes. Earn 50% more runestones from future prestiges.", "Your legend transcends individual lifetimes. Earn 50% more runestones from future prestiges.",
category: "runestones", id: "runestone_gain_2",
multiplier: 1.5,
name: "Eternal Legacy",
runestonesCost: 500, runestonesCost: 500,
multiplier: 1.5,
}, },
]; ];
File diff suppressed because it is too large Load Diff
+479
View File
@@ -0,0 +1,479 @@
/**
* @file Game data definitions.
* @copyright nhcarrigan
* @license Naomi's Public License
* @author Naomi Carrigan
*/
/* eslint-disable max-lines -- Data file */
/* eslint-disable stylistic/max-len -- Data content */
import type { CraftingRecipe } from "@elysium/types";
export const defaultRecipes: Array<CraftingRecipe> = [
// Zone 1: verdant_vale
{
bonus: { type: "gold_income", value: 1.05 },
description:
"Sap from ancient heartwood trees, refined and bound with forest crystal. The resulting tincture accelerates the flow of wealth through your guild in ways the alchemists cannot fully explain.",
id: "heartwood_tincture",
name: "Heartwood Tincture",
requiredMaterials: [
{ materialId: "verdant_sap", quantity: 5 },
{ materialId: "forest_crystal", quantity: 3 },
],
zoneId: "verdant_vale",
},
{
bonus: { type: "combat_power", value: 1.08 },
description:
"A ward fashioned from bark older than the kingdom. Its presence on the battlefield is not merely physical — something ancient watches through it.",
id: "elder_bark_shield",
name: "Elder Bark Shield",
requiredMaterials: [
{ materialId: "elder_bark", quantity: 2 },
{ materialId: "verdant_sap", quantity: 8 },
],
zoneId: "verdant_vale",
},
// Zone 2: shattered_ruins
{
bonus: { type: "essence_income", value: 1.05 },
description:
"The ruin dust and cursed fragments, carefully worked into a binding that borrows the essence-drawing power of the fallen civilisation's final enchantments.",
id: "runic_binding",
name: "Runic Binding",
requiredMaterials: [
{ materialId: "ruin_dust", quantity: 8 },
{ materialId: "cursed_fragment", quantity: 4 },
],
zoneId: "shattered_ruins",
},
{
bonus: { type: "gold_income", value: 1.08 },
description:
"A charm set with a chip of the elder dragon's scale. The dragon would be furious if he knew. He would also be impressed.",
id: "dragon_scale_charm",
name: "Dragon Scale Charm",
requiredMaterials: [
{ materialId: "dragonscale_chip", quantity: 2 },
{ materialId: "ruin_dust", quantity: 10 },
],
zoneId: "shattered_ruins",
},
// Zone 3: frozen_peaks
{
bonus: { type: "click_power", value: 1.08 },
description:
"Glacial ice ground and shaped into a lens that clarifies and focuses. Holding it, your guild's actions become sharper, more precise, more effective per motion.",
id: "glacial_lens",
name: "Glacial Lens",
requiredMaterials: [
{ materialId: "glacial_ice", quantity: 8 },
{ materialId: "frost_crystal", quantity: 4 },
],
zoneId: "frozen_peaks",
},
{
bonus: { type: "gold_income", value: 1.1 },
description:
"The void shard set in frost crystal, creating something that should not be possible: a stable window into the spaces between spaces. Profitable beyond what physics suggests.",
id: "void_fragment_amulet",
name: "Void Fragment Amulet",
requiredMaterials: [
{ materialId: "void_shard", quantity: 2 },
{ materialId: "frost_crystal", quantity: 6 },
],
zoneId: "frozen_peaks",
},
// Zone 4: shadow_marshes
{
bonus: { type: "essence_income", value: 1.08 },
description:
"Marsh roots processed with shadow essence into a refined compound that somehow makes the essence of things flow more freely toward your guild hall.",
id: "shadow_extract",
name: "Shadow Extract",
requiredMaterials: [
{ materialId: "marsh_root", quantity: 8 },
{ materialId: "shadow_essence", quantity: 4 },
],
zoneId: "shadow_marshes",
},
{
bonus: { type: "combat_power", value: 1.1 },
description:
"The cursed bone and shadow essence combined into a focus that doesn't so much help your party fight as make things afraid of them before the battle begins.",
id: "cursed_focus",
name: "Cursed Focus",
requiredMaterials: [
{ materialId: "cursed_bone", quantity: 2 },
{ materialId: "shadow_essence", quantity: 6 },
],
zoneId: "shadow_marshes",
},
// Zone 5: volcanic_depths
{
bonus: { type: "gold_income", value: 1.1 },
description:
"A seal forged in the volcanic depths, using the eternal heat of the magma stone and ember crystal to create something that burns wealth into existence continuously.",
id: "magma_core_seal",
name: "Magma Core Seal",
requiredMaterials: [
{ materialId: "magma_stone", quantity: 8 },
{ materialId: "ember_crystal", quantity: 4 },
],
zoneId: "volcanic_depths",
},
{
bonus: { type: "combat_power", value: 1.12 },
description:
"The legendary ore, smelted in the volcanic forges with magma stone as fuel. What emerges is something the fire elementals recognise — and fear slightly.",
id: "elemental_ore_ingot",
name: "Elemental Ore Ingot",
requiredMaterials: [
{ materialId: "legendary_ore", quantity: 2 },
{ materialId: "magma_stone", quantity: 10 },
],
zoneId: "volcanic_depths",
},
// Zone 6: astral_void
{
bonus: { type: "click_power", value: 1.12 },
description:
"Stardust arranged along astral threads into a map of the void that somehow, impossibly, shows your guild where to press and how to press it for maximum effect.",
id: "star_chart",
name: "Star Chart",
requiredMaterials: [
{ materialId: "stardust", quantity: 10 },
{ materialId: "astral_thread", quantity: 4 },
],
zoneId: "astral_void",
},
{
bonus: { type: "gold_income", value: 1.12 },
description:
"A void crystal suspended in a matrix of stardust — something that exists in several places simultaneously and draws gold from all of them at once.",
id: "void_crystal_matrix",
name: "Void Crystal Matrix",
requiredMaterials: [
{ materialId: "void_crystal", quantity: 2 },
{ materialId: "stardust", quantity: 12 },
],
zoneId: "astral_void",
},
// Zone 7: celestial_reaches
{
bonus: { type: "essence_income", value: 1.12 },
description:
"Celestial dust and divine fragments ground into a lens that sees the essence in all things and draws a portion of it — gently, as the celestials would prefer.",
id: "celestial_lens",
name: "Celestial Lens",
requiredMaterials: [
{ materialId: "celestial_dust", quantity: 10 },
{ materialId: "divine_fragment", quantity: 4 },
],
zoneId: "celestial_reaches",
},
{
bonus: { type: "gold_income", value: 1.15 },
description:
"A choir shard set in divine fragments, still humming with the celestial harmonic. The resonance makes gold flow in its direction — not compelled, simply invited.",
id: "choir_resonator",
name: "Choir Resonator",
requiredMaterials: [
{ materialId: "choir_shard", quantity: 2 },
{ materialId: "divine_fragment", quantity: 6 },
],
zoneId: "celestial_reaches",
},
// Zone 8: abyssal_trench
{
bonus: { type: "combat_power", value: 1.15 },
description:
"Trench coral and pressure gem combined under conditions that should have destroyed both. The result is something that survived conditions nothing should survive, which is ideal for combat.",
id: "pressure_forged_core",
name: "Pressure-Forged Core",
requiredMaterials: [
{ materialId: "trench_coral", quantity: 10 },
{ materialId: "pressure_gem", quantity: 4 },
],
zoneId: "abyssal_trench",
},
{
bonus: { type: "click_power", value: 1.15 },
description:
"A talisman set with the ancient tooth, suspended in trench coral carvings. Your party fights differently with this at their chest. More deliberately. More completely.",
id: "ancient_fang_talisman",
name: "Ancient Fang Talisman",
requiredMaterials: [
{ materialId: "ancient_tooth", quantity: 2 },
{ materialId: "trench_coral", quantity: 12 },
],
zoneId: "abyssal_trench",
},
// Zone 9: infernal_court
{
bonus: { type: "gold_income", value: 1.15 },
description:
"A seal of infernal court authority, forged from brimstone and ichor. The court doesn't know you have this. It's better that way. It does make trade extremely efficient.",
id: "court_seal",
name: "Court Seal",
requiredMaterials: [
{ materialId: "brimstone_flake", quantity: 10 },
{ materialId: "demon_ichor", quantity: 5 },
],
zoneId: "infernal_court",
},
{
bonus: { type: "essence_income", value: 1.15 },
description:
"Soul residue and demon ichor worked into a catalyst that draws the essence from everything around it — gently, without drawing the court's attention. Usually.",
id: "soul_bound_catalyst",
name: "Soul-Bound Catalyst",
requiredMaterials: [
{ materialId: "soul_residue", quantity: 2 },
{ materialId: "demon_ichor", quantity: 8 },
],
zoneId: "infernal_court",
},
// Zone 10: crystalline_spire
{
bonus: { type: "click_power", value: 1.18 },
description:
"Prism dust and calculation shards assembled into an array that the spire's intelligence would call elegant, if it had aesthetic preferences, which it might.",
id: "prism_array",
name: "Prism Array",
requiredMaterials: [
{ materialId: "prism_dust", quantity: 10 },
{ materialId: "calculation_shard", quantity: 4 },
],
zoneId: "crystalline_spire",
},
{
bonus: { type: "gold_income", value: 1.18 },
description:
"A possibility crystal contained within a calculation shard framework. It runs through every possible outcome of every guild action and finds the one with the highest gold yield.",
id: "possibility_engine",
name: "Possibility Engine",
requiredMaterials: [
{ materialId: "possibility_crystal", quantity: 2 },
{ materialId: "calculation_shard", quantity: 6 },
],
zoneId: "crystalline_spire",
},
// Zone 11: void_sanctum
{
bonus: { type: "combat_power", value: 1.18 },
description:
"Null matter and resonance fragments assembled into something that generates a field where the laws governing how hard things are to kill become negotiable.",
id: "null_field_generator",
name: "Null Field Generator",
requiredMaterials: [
{ materialId: "null_matter", quantity: 10 },
{ materialId: "resonance_fragment", quantity: 4 },
],
zoneId: "void_sanctum",
},
{
bonus: { type: "essence_income", value: 1.18 },
description:
"A sanctum core and resonance fragments shaped into a key to something. The essence flows through it like it was designed to carry essence, which it may have been.",
id: "sanctum_key",
name: "Sanctum Key",
requiredMaterials: [
{ materialId: "sanctum_core", quantity: 2 },
{ materialId: "resonance_fragment", quantity: 6 },
],
zoneId: "void_sanctum",
},
// Zone 12: eternal_throne
{
bonus: { type: "gold_income", value: 1.2 },
description:
"Throne dust pressed into throne dust-lacquered crown fragments, shaped into a circlet. Wearing it — metaphorically — makes gold accumulate with the inevitability of authority.",
id: "crown_circlet",
name: "Crown Circlet",
requiredMaterials: [
{ materialId: "throne_dust", quantity: 10 },
{ materialId: "crown_fragment", quantity: 4 },
],
zoneId: "eternal_throne",
},
{
bonus: { type: "combat_power", value: 1.2 },
description:
"An eternity splinter set into crown fragments, shaped into a ring. What it binds is unclear. Whatever it is, it makes your party significantly harder to kill.",
id: "eternity_bound_ring",
name: "Eternity-Bound Ring",
requiredMaterials: [
{ materialId: "eternity_splinter", quantity: 2 },
{ materialId: "crown_fragment", quantity: 6 },
],
zoneId: "eternal_throne",
},
// Zone 13: primordial_chaos
{
bonus: { type: "click_power", value: 1.2 },
description:
"Chaos fragments and creation shards arranged into a lens that hasn't decided what it wants to focus on yet, which somehow makes every click land harder than it should.",
id: "chaos_lens",
name: "Chaos Lens",
requiredMaterials: [
{ materialId: "chaos_fragment", quantity: 10 },
{ materialId: "creation_shard", quantity: 4 },
],
zoneId: "primordial_chaos",
},
{
bonus: { type: "gold_income", value: 1.22 },
description:
"Primordial essence held in a creation shard framework. It hums constantly. Gold flows toward it with the enthusiasm of something that wants to become something.",
id: "creation_core",
name: "Creation Core",
requiredMaterials: [
{ materialId: "primordial_essence", quantity: 2 },
{ materialId: "creation_shard", quantity: 6 },
],
zoneId: "primordial_chaos",
},
// Zone 14: infinite_expanse
{
bonus: { type: "essence_income", value: 1.2 },
description:
"Expanse dust wound around distance crystals into a coil that draws essence from distances too vast to measure, compressing it into something your guild can actually use.",
id: "distance_coil",
name: "Distance Coil",
requiredMaterials: [
{ materialId: "expanse_dust", quantity: 10 },
{ materialId: "distance_crystal", quantity: 4 },
],
zoneId: "infinite_expanse",
},
{
bonus: { type: "gold_income", value: 1.22 },
description:
"An infinity shard mounted in a distance crystal frame. The prism reflects gold from an infinite number of directions simultaneously. The math works out favourably.",
id: "infinity_prism",
name: "Infinity Prism",
requiredMaterials: [
{ materialId: "infinity_shard", quantity: 2 },
{ materialId: "distance_crystal", quantity: 6 },
],
zoneId: "infinite_expanse",
},
// Zone 15: reality_forge
{
bonus: { type: "combat_power", value: 1.22 },
description:
"Forge ash smelted with creation tools into an ingot of compressed reality. Your party hits harder when carrying it. Reality does not enjoy being concentrated like this.",
id: "reality_ingot",
name: "Reality Ingot",
requiredMaterials: [
{ materialId: "forge_ash", quantity: 10 },
{ materialId: "creation_tool", quantity: 4 },
],
zoneId: "reality_forge",
},
{
bonus: { type: "click_power", value: 1.22 },
description:
"A reality shard carefully shaped with creation tools into something that could, theoretically, become a universe. Instead it makes your clicks unreasonably effective.",
id: "universe_seed",
name: "Universe Seed",
requiredMaterials: [
{ materialId: "reality_shard", quantity: 2 },
{ materialId: "creation_tool", quantity: 6 },
],
zoneId: "reality_forge",
},
// Zone 16: cosmic_maelstrom
{
bonus: { type: "gold_income", value: 1.25 },
description:
"Maelstrom debris and force crystals ground into a lens at the intersection of fundamental forces. Gold flows toward it with the same inevitability that galaxies flow toward gravity.",
id: "force_lens",
name: "Force Lens",
requiredMaterials: [
{ materialId: "maelstrom_debris", quantity: 10 },
{ materialId: "force_crystal", quantity: 4 },
],
zoneId: "cosmic_maelstrom",
},
{
bonus: { type: "essence_income", value: 1.22 },
description:
"A cosmic fragment suspended in a force crystal matrix — a piece of the maelstrom's impossible calm, holding the eye of the storm. Essence accumulates in its vicinity.",
id: "maelstrom_eye",
name: "Maelstrom Eye",
requiredMaterials: [
{ materialId: "cosmic_fragment", quantity: 2 },
{ materialId: "force_crystal", quantity: 6 },
],
zoneId: "cosmic_maelstrom",
},
// Zone 17: primeval_sanctum
{
bonus: { type: "combat_power", value: 1.25 },
description:
"Ancient dust and memory shards arranged into something that remembers how to fight before fighting was invented. Your party benefits from this instinct enormously.",
id: "ancient_memory_array",
name: "Ancient Memory Array",
requiredMaterials: [
{ materialId: "ancient_dust", quantity: 10 },
{ materialId: "memory_shard", quantity: 4 },
],
zoneId: "primeval_sanctum",
},
{
bonus: { type: "click_power", value: 1.25 },
description:
"The primeval relic, set into a memory shard framework. What function it originally served is unknowable. In your guild's hands, it makes every action more deliberate and more powerful.",
id: "first_artefact",
name: "First Artefact",
requiredMaterials: [
{ materialId: "primeval_relic", quantity: 2 },
{ materialId: "memory_shard", quantity: 6 },
],
zoneId: "primeval_sanctum",
},
// Zone 18: the_absolute
{
bonus: { type: "gold_income", value: 1.3 },
description:
"Absolute fragments and boundary shards ground into a lens that sees to the end of all things — and in seeing, draws the wealth inherent in finality toward your guild.",
id: "final_truth_lens",
name: "Final Truth Lens",
requiredMaterials: [
{ materialId: "absolute_fragment", quantity: 10 },
{ materialId: "boundary_shard", quantity: 4 },
],
zoneId: "the_absolute",
},
{
bonus: { type: "combat_power", value: 1.3 },
description:
"The last omega crystal, set at the convergence of boundary shards in the precise arrangement of an ending. What it does to combat is what endings do to everything: make it final.",
id: "omega_convergence",
name: "Omega Convergence",
requiredMaterials: [
{ materialId: "omega_crystal", quantity: 2 },
{ materialId: "boundary_shard", quantity: 6 },
],
zoneId: "the_absolute",
},
];
+11
View File
@@ -0,0 +1,11 @@
/**
* @file Schema version tracking for game state.
* @copyright nhcarrigan
* @license Naomi's Public License
* @author Naomi Carrigan
*/
/**
* The current game state schema version. Bump this whenever a breaking change is made to GameState.
*/
export const currentSchemaVersion = 1;
+141
View File
@@ -0,0 +1,141 @@
/**
* @file Game title definitions.
* @copyright nhcarrigan
* @license Naomi's Public License
* @author Naomi Carrigan
*/
import type { Title } from "@elysium/types";
export const gameTitles: Array<Title> = [
// Quest milestones
{
condition: { amount: 1, type: "questsCompleted" },
description: "Complete your first quest.",
id: "the_adventurous",
name: "The Adventurous",
},
{
condition: { amount: 100, type: "questsCompleted" },
description: "Complete 100 quests in a single run.",
id: "the_persistent",
name: "The Persistent",
},
// Boss milestones
{
condition: { amount: 1, type: "bossesDefeated" },
description: "Defeat your first boss.",
id: "boss_slayer",
name: "Boss Slayer",
},
{
condition: { amount: 10, type: "bossesDefeated" },
description: "Defeat 10 bosses in a single run.",
id: "dungeon_master",
name: "Dungeon Master",
},
// Gold milestones
{
condition: { amount: 1_000_000, type: "totalGoldEarned" },
description: "Earn 1,000,000 gold in a single run.",
id: "the_wealthy",
name: "The Wealthy",
},
{
condition: { amount: 1_000_000_000, type: "totalGoldEarned" },
description: "Earn 1,000,000,000 gold in a single run.",
id: "the_rich",
name: "The Rich",
},
// Click milestones
{
condition: { amount: 10_000, type: "totalClicks" },
description: "Click the Guild Hall 10,000 times in a single run.",
id: "click_maniac",
name: "Click Maniac",
},
// Adventurer milestones
{
condition: { amount: 100, type: "adventurerTotal" },
description: "Recruit 100 adventurers.",
id: "commander",
name: "Commander",
},
{
condition: { amount: 1000, type: "adventurerTotal" },
description: "Recruit 1,000 adventurers.",
id: "warlord",
name: "Warlord",
},
// Social
{
condition: { type: "guildFounded" },
description: "Give your guild a name.",
id: "guild_founder",
name: "Guild Founder",
},
// Prestige milestones
{
condition: { amount: 1, type: "prestigeCount" },
description: "Achieve your first Prestige.",
id: "the_undying",
name: "The Undying",
},
{
condition: { amount: 5, type: "prestigeCount" },
description: "Achieve 5 Prestiges.",
id: "battle_hardened",
name: "Battle Hardened",
},
{
condition: { amount: 25, type: "prestigeCount" },
description: "Achieve 25 Prestiges.",
id: "legend",
name: "Legend",
},
// Transcendence milestones
{
condition: { amount: 1, type: "transcendenceCount" },
description: "Achieve your first Transcendence.",
id: "transcendent",
name: "Transcendent",
},
{
condition: { amount: 5, type: "transcendenceCount" },
description: "Achieve 5 Transcendences.",
id: "beyond_mortal",
name: "Beyond Mortal",
},
// Apotheosis milestones
{
condition: { amount: 1, type: "apotheosisCount" },
description: "Achieve your first Apotheosis.",
id: "apotheosised",
name: "Apotheosised",
},
{
condition: { amount: 5, type: "apotheosisCount" },
description: "Achieve 5 Apotheoses.",
id: "ascendant",
name: "Ascendant",
},
// Achievement milestone
{
condition: { amount: 40, type: "achievementsUnlocked" },
description: "Unlock all achievements.",
id: "completionist",
name: "Completionist",
},
// Longevity
{
condition: { amount: 30, type: "playedDays" },
description: "Play Elysium for 30 days.",
id: "veteran",
name: "Veteran",
},
{
condition: { amount: 365, type: "playedDays" },
description: "Play Elysium for a full year.",
id: "timeless",
name: "Timeless",
},
];
+155
View File
@@ -0,0 +1,155 @@
/**
* @file Game data definitions.
* @copyright nhcarrigan
* @license Naomi's Public License
* @author Naomi Carrigan
*/
/* eslint-disable stylistic/max-len -- Data content */
import type { TranscendenceUpgrade } from "@elysium/types";
export const defaultTranscendenceUpgrades: Array<TranscendenceUpgrade> = [
// ── Income multipliers ──────────────────────────────────────────────────────
{
category: "income",
cost: 5,
description:
"The echoes of past runs linger, amplifying your guild's income by 25%.",
id: "echo_income_1",
multiplier: 1.25,
name: "Whisper of Power",
},
{
category: "income",
cost: 10,
description:
"Your transcendent experience resonates through your guild, boosting income by 50%.",
id: "echo_income_2",
multiplier: 1.5,
name: "Resonance",
},
{
category: "income",
cost: 20,
description:
"The harmony of multiple timelines surges through your guild, doubling its income.",
id: "echo_income_3",
multiplier: 2,
name: "Harmonic Surge",
},
{
category: "income",
cost: 40,
description:
"Ethereal energy overflows from your transcendence, tripling your guild's income.",
id: "echo_income_4",
multiplier: 3,
name: "Ethereal Overflow",
},
{
category: "income",
cost: 80,
description:
"The infinite chorus of every run you've ever played amplifies your guild fivefold.",
id: "echo_income_5",
multiplier: 5,
name: "Infinite Chorus",
},
// ── Combat multipliers ──────────────────────────────────────────────────────
{
category: "combat",
cost: 5,
description:
"Memories of countless battles harden your adventurers, increasing party DPS by 25%.",
id: "echo_combat_1",
multiplier: 1.25,
name: "Battle-Hardened",
},
{
category: "combat",
cost: 15,
description:
"Veterans of transcendence know how to fight smarter, boosting party DPS by 50%.",
id: "echo_combat_2",
multiplier: 1.5,
name: "Veteran's Edge",
},
{
category: "combat",
cost: 35,
description:
"Your warriors carry the strength of every fallen timeline, doubling party DPS.",
id: "echo_combat_3",
multiplier: 2,
name: "Transcendent Warrior",
},
// ── Prestige threshold reductions ──────────────────────────────────────────
{
category: "prestige_threshold",
cost: 8,
description:
"Experience from past lives shortens the road to prestige — threshold reduced by 10%.",
id: "echo_prestige_threshold_1",
multiplier: 0.9,
name: "Accelerated Path",
},
{
category: "prestige_threshold",
cost: 20,
description:
"You've walked this path so many times you know every shortcut — threshold reduced by 20%.",
id: "echo_prestige_threshold_2",
multiplier: 0.8,
name: "Shortcut Through Time",
},
// ── Prestige runestone multipliers ─────────────────────────────────────────
{
category: "prestige_runestones",
cost: 8,
description:
"Transcendent insight attunes you to the runestones, earning 50% more per prestige.",
id: "echo_prestige_runestones_1",
multiplier: 1.5,
name: "Runic Attunement",
},
{
category: "prestige_runestones",
cost: 20,
description:
"You have mastered the art of runestone crafting, doubling your prestige runestone yield.",
id: "echo_prestige_runestones_2",
multiplier: 2,
name: "Master Runesmith",
},
// ── Echo meta multipliers ───────────────────────────────────────────────────
{
category: "echo_meta",
cost: 10,
description:
"Your transcendence resonates deeper, amplifying future echo yields by 25%.",
id: "echo_meta_1",
multiplier: 1.25,
name: "Resonant Awakening",
},
{
category: "echo_meta",
cost: 25,
description:
"Each loop of existence makes the next more powerful — future echo yields +50%.",
id: "echo_meta_2",
multiplier: 1.5,
name: "Transcendent Loop",
},
{
category: "echo_meta",
cost: 50,
description:
"You have mastered the infinite spiral of transcendence, doubling all future echo yields.",
id: "echo_meta_3",
multiplier: 2,
name: "Infinite Spiral",
},
];
File diff suppressed because it is too large Load Diff
+98 -91
View File
@@ -1,184 +1,191 @@
/**
* @file Game data definitions.
* @copyright nhcarrigan
* @license Naomi's Public License
* @author Naomi Carrigan
*/
/* eslint-disable stylistic/max-len -- Data content */
import type { Zone } from "@elysium/types"; import type { Zone } from "@elysium/types";
export const DEFAULT_ZONES: Zone[] = [ export const defaultZones: Array<Zone> = [
{ {
id: "verdant_vale",
name: "The Verdant Vale",
description: description:
"Rolling green hills and ancient forests stretch to the horizon. This is where your guild takes its first steps — trade roads in need of clearing, goblin camps to rout, and an undead queen stirring in the north.", "Rolling green hills and ancient forests stretch to the horizon. This is where your guild takes its first steps — trade roads in need of clearing, goblin camps to rout, and an undead queen stirring in the north.",
emoji: "🌿", emoji: "🌿",
status: "unlocked", id: "verdant_vale",
unlockBossId: null, name: "The Verdant Vale",
status: "unlocked",
unlockBossId: null,
unlockQuestId: null, unlockQuestId: null,
}, },
{ {
id: "shattered_ruins",
name: "The Shattered Ruins",
description: description:
"The remnants of a civilisation long lost to war and dragonfire. Crumbling towers and cursed lakes hide treasures — and an elder dragon who claims these lands as his own.", "The remnants of a civilisation long lost to war and dragonfire. Crumbling towers and cursed lakes hide treasures — and an elder dragon who claims these lands as his own.",
emoji: "🏛️", emoji: "🏛️",
status: "locked", id: "shattered_ruins",
unlockBossId: "forest_giant", name: "The Shattered Ruins",
status: "locked",
unlockBossId: "forest_giant",
unlockQuestId: "ancient_ruins", unlockQuestId: "ancient_ruins",
}, },
{ {
id: "frozen_peaks",
name: "The Frozen Peaks",
description: description:
"At the edge of the world, where the sun barely rises and the cold is a living thing, a tear in reality has drawn something ancient and terrible. Only the mightiest guilds dare tread here.", "At the edge of the world, where the sun barely rises and the cold is a living thing, a tear in reality has drawn something ancient and terrible. Only the mightiest guilds dare tread here.",
emoji: "❄️", emoji: "❄️",
status: "locked", id: "frozen_peaks",
unlockBossId: "elder_dragon", name: "The Frozen Peaks",
status: "locked",
unlockBossId: "elder_dragon",
unlockQuestId: "dragon_lair", unlockQuestId: "dragon_lair",
}, },
{ {
id: "shadow_marshes",
name: "The Shadow Marshes",
description: description:
"A vast, fog-choked wetland where the sun never fully rises. Dark magic seeps from the earth itself, and things far older than the kingdom lurk beneath the murky waters.", "A vast, fog-choked wetland where the sun never fully rises. Dark magic seeps from the earth itself, and things far older than the kingdom lurk beneath the murky waters.",
emoji: "🌑", emoji: "🌑",
status: "locked", id: "shadow_marshes",
unlockBossId: "void_titan", name: "The Shadow Marshes",
status: "locked",
unlockBossId: "void_titan",
unlockQuestId: "storm_citadel", unlockQuestId: "storm_citadel",
}, },
{ {
id: "volcanic_depths",
name: "The Volcanic Depths",
description: description:
"A chain of active volcanoes whose caverns plunge deep into the earth's molten heart. Legendary forges burn here, tended by fire elementals who serve no master — yet.", "A chain of active volcanoes whose caverns plunge deep into the earth's molten heart. Legendary forges burn here, tended by fire elementals who serve no master — yet.",
emoji: "🌋", emoji: "🌋",
status: "locked", id: "volcanic_depths",
unlockBossId: "mud_kraken", name: "The Volcanic Depths",
status: "locked",
unlockBossId: "mud_kraken",
unlockQuestId: "plague_ruins", unlockQuestId: "plague_ruins",
}, },
{ {
id: "astral_void",
name: "The Astral Void",
description: description:
"Beyond the veil of the mortal world lies a realm of pure possibility and absolute terror. Stars are born and die here in moments, and the beings that call this place home have never known mortality.", "Beyond the veil of the mortal world lies a realm of pure possibility and absolute terror. Stars are born and die here in moments, and the beings that call this place home have never known mortality.",
emoji: "🌌", emoji: "🌌",
status: "locked", id: "astral_void",
unlockBossId: "phoenix_lord", name: "The Astral Void",
status: "locked",
unlockBossId: "phoenix_lord",
unlockQuestId: "the_forge", unlockQuestId: "the_forge",
}, },
{ {
id: "celestial_reaches",
name: "The Celestial Reaches",
description: description:
"Beyond the astral void, where reality gives way to pure divinity. The celestial host holds court here in towers of light older than stars, but their idea of order is as alien and terrifying as the chaos below.", "Beyond the astral void, where reality gives way to pure divinity. The celestial host holds court here in towers of light older than stars, but their idea of order is as alien and terrifying as the chaos below.",
emoji: "✨", emoji: "✨",
status: "locked", id: "celestial_reaches",
unlockBossId: "the_devourer", name: "The Celestial Reaches",
status: "locked",
unlockBossId: "the_devourer",
unlockQuestId: "the_end", unlockQuestId: "the_end",
}, },
{ {
id: "abyssal_trench",
name: "The Abyssal Trench",
description: description:
"At the bottom of all things, where no light reaches and pressure could crush continents, something old and patient waits. It has been waiting since before your world was made — and it has never been interrupted.", "At the bottom of all things, where no light reaches and pressure could crush continents, something old and patient waits. It has been waiting since before your world was made — and it has never been interrupted.",
emoji: "🌊", emoji: "🌊",
status: "locked", id: "abyssal_trench",
unlockBossId: "the_first_light", name: "The Abyssal Trench",
status: "locked",
unlockBossId: "the_first_light",
unlockQuestId: "celestial_archive", unlockQuestId: "celestial_archive",
}, },
{ {
id: "infernal_court",
name: "The Infernal Court",
description: description:
"The courts of the underworld, where demon lords scheme across aeons. Power here is measured in souls and suffering — your guild deals in neither, but you will have to speak their language before this is over.", "The courts of the underworld, where demon lords scheme across aeons. Power here is measured in souls and suffering — your guild deals in neither, but you will have to speak their language before this is over.",
emoji: "👿", emoji: "👿",
status: "locked", id: "infernal_court",
unlockBossId: "elder_abomination", name: "The Infernal Court",
status: "locked",
unlockBossId: "elder_abomination",
unlockQuestId: "abyssal_chronicle", unlockQuestId: "abyssal_chronicle",
}, },
{ {
id: "crystalline_spire",
name: "The Crystalline Spire",
description: description:
"A tower of living crystal that pierces every boundary between planes. Its facets reflect possibilities that have never existed and futures that cannot be. The intelligence at its core has been calculating since before this universe existed.", "A tower of living crystal that pierces every boundary between planes. Its facets reflect possibilities that have never existed and futures that cannot be. The intelligence at its core has been calculating since before this universe existed.",
emoji: "💎", emoji: "💎",
status: "locked", id: "crystalline_spire",
unlockBossId: "the_fallen", name: "The Crystalline Spire",
status: "locked",
unlockBossId: "the_fallen",
unlockQuestId: "infernal_codex", unlockQuestId: "infernal_codex",
}, },
{ {
id: "void_sanctum",
name: "The Void Sanctum",
description: description:
"Not a place but a state of being — the space between the spaces between things. Existence grows thin here. Your guild is the first to find it, drawn by a power that should not be able to call to anything that lives.", "Not a place but a state of being — the space between the spaces between things. Existence grows thin here. Your guild is the first to find it, drawn by a power that should not be able to call to anything that lives.",
emoji: "🌀", emoji: "🌀",
status: "locked", id: "void_sanctum",
unlockBossId: "crystal_sovereign", name: "The Void Sanctum",
status: "locked",
unlockBossId: "crystal_sovereign",
unlockQuestId: "the_prism_vault", unlockQuestId: "the_prism_vault",
}, },
{ {
id: "eternal_throne",
name: "The Eternal Throne",
description: description:
"The seat of ultimate power at the centre of all creation. Whoever sits here has sat here since the beginning. They have watched countless guilds rise and fall across uncounted ages. Your guild has come to take the throne. It does not yield.", "The seat of ultimate power at the centre of all creation. Whoever sits here has sat here since the beginning. They have watched countless guilds rise and fall across uncounted ages. Your guild has come to take the throne. It does not yield.",
emoji: "👑", emoji: "👑",
status: "locked", id: "eternal_throne",
unlockBossId: "void_emperor", name: "The Eternal Throne",
status: "locked",
unlockBossId: "void_emperor",
unlockQuestId: "heart_of_void", unlockQuestId: "heart_of_void",
}, },
{ {
id: "primordial_chaos",
name: "The Primordial Chaos",
description: description:
"Beyond the throne lies the raw stuff of creation itself — not a place but an ongoing argument between existence and non-existence that has never been resolved. Your guild enters the argument.", "Beyond the throne lies the raw stuff of creation itself — not a place but an ongoing argument between existence and non-existence that has never been resolved. Your guild enters the argument.",
emoji: "🌪️", emoji: "🌪️",
status: "locked", id: "primordial_chaos",
unlockBossId: "the_apex", name: "The Primordial Chaos",
status: "locked",
unlockBossId: "the_apex",
unlockQuestId: "eternal_dominion", unlockQuestId: "eternal_dominion",
}, },
{ {
id: "infinite_expanse",
name: "The Infinite Expanse",
description: description:
"A realm without edges, without centre, without reference — where distance is a concept that does not apply and your guild must define their own coordinates to navigate at all. Everything here is further than it looks.", "A realm without edges, without centre, without reference — where distance is a concept that does not apply and your guild must define their own coordinates to navigate at all. Everything here is further than it looks.",
emoji: "♾️", emoji: "♾️",
status: "locked", id: "infinite_expanse",
unlockBossId: "primordial_titan", name: "The Infinite Expanse",
status: "locked",
unlockBossId: "primordial_titan",
unlockQuestId: "chaos_chronicle", unlockQuestId: "chaos_chronicle",
}, },
{ {
id: "reality_forge",
name: "The Reality Forge",
description: description:
"The workshop where the original universe was hammered into shape — still hot, still humming, still producing realities as a byproduct of its idle operation. The things that work here have never stopped.", "The workshop where the original universe was hammered into shape — still hot, still humming, still producing realities as a byproduct of its idle operation. The things that work here have never stopped.",
emoji: "⚒️", emoji: "⚒️",
status: "locked", id: "reality_forge",
unlockBossId: "expanse_sovereign", name: "The Reality Forge",
status: "locked",
unlockBossId: "expanse_sovereign",
unlockQuestId: "expanse_codex", unlockQuestId: "expanse_codex",
}, },
{ {
id: "cosmic_maelstrom",
name: "The Cosmic Maelstrom",
description: description:
"A confluence of every force in existence, spinning in patterns that reduce galaxies to debris. Your guild navigates currents of energy that, on a good day, merely shatter planets.", "A confluence of every force in existence, spinning in patterns that reduce galaxies to debris. Your guild navigates currents of energy that, on a good day, merely shatter planets.",
emoji: "🌀", emoji: "🌀",
status: "locked", id: "cosmic_maelstrom",
unlockBossId: "reality_architect", name: "The Cosmic Maelstrom",
status: "locked",
unlockBossId: "reality_architect",
unlockQuestId: "forge_chronicle", unlockQuestId: "forge_chronicle",
}, },
{ {
id: "primeval_sanctum",
name: "The Primeval Sanctum",
description: description:
"The oldest place that has ever existed — older than time, older than space, older than the concept of age itself. It holds something that remembers the moment before the first moment.", "The oldest place that has ever existed — older than time, older than space, older than the concept of age itself. It holds something that remembers the moment before the first moment.",
emoji: "🗿", emoji: "🗿",
status: "locked", id: "primeval_sanctum",
unlockBossId: "cosmic_annihilator", name: "The Primeval Sanctum",
status: "locked",
unlockBossId: "cosmic_annihilator",
unlockQuestId: "maelstrom_codex", unlockQuestId: "maelstrom_codex",
}, },
{ {
id: "the_absolute",
name: "The Absolute",
description: description:
"There is nothing beyond this. Not because nothing has been found — because nothing exists to find. The Absolute is the final truth: the end of all things that are and the beginning of all things that never were. Your guild stands at the edge of everything.", "There is nothing beyond this. Not because nothing has been found — because nothing exists to find. The Absolute is the final truth: the end of all things that are and the beginning of all things that never were. Your guild stands at the edge of everything.",
emoji: "⚫", emoji: "⚫",
status: "locked", id: "the_absolute",
unlockBossId: "primeval_god", name: "The Absolute",
status: "locked",
unlockBossId: "primeval_god",
unlockQuestId: "sanctum_chronicle", unlockQuestId: "sanctum_chronicle",
}, },
]; ];
+6
View File
@@ -1,3 +1,9 @@
/**
* @file Prisma database client singleton.
* @copyright nhcarrigan
* @license Naomi's Public License
* @author Naomi Carrigan
*/
import { PrismaClient } from "@prisma/client"; import { PrismaClient } from "@prisma/client";
export const prisma = new PrismaClient(); export const prisma = new PrismaClient();
+27 -9
View File
@@ -1,13 +1,24 @@
/**
* @file Entry point for the Elysium API server.
* @copyright nhcarrigan
* @license Naomi's Public License
* @author Naomi Carrigan
*/
import { serve } from "@hono/node-server"; import { serve } from "@hono/node-server";
import { Hono } from "hono"; import { Hono } from "hono";
import { cors } from "hono/cors"; import { cors } from "hono/cors";
import { logger } from "hono/logger"; import { logger } from "hono/logger";
import { aboutRouter } from "./routes/about.js"; import { aboutRouter } from "./routes/about.js";
import { apotheosisRouter } from "./routes/apotheosis.js";
import { authRouter } from "./routes/auth.js"; import { authRouter } from "./routes/auth.js";
import { bossRouter } from "./routes/boss.js"; import { bossRouter } from "./routes/boss.js";
import { craftRouter } from "./routes/craft.js";
import { exploreRouter } from "./routes/explore.js";
import { gameRouter } from "./routes/game.js"; import { gameRouter } from "./routes/game.js";
import { leaderboardRouter } from "./routes/leaderboards.js";
import { prestigeRouter } from "./routes/prestige.js"; import { prestigeRouter } from "./routes/prestige.js";
import { profileRouter } from "./routes/profile.js"; import { profileRouter } from "./routes/profile.js";
import { transcendenceRouter } from "./routes/transcendence.js";
const app = new Hono(); const app = new Hono();
@@ -15,9 +26,9 @@ app.use("*", logger());
app.use( app.use(
"*", "*",
cors({ cors({
origin: process.env["CORS_ORIGIN"] ?? "http://localhost:5173", allowHeaders: [ "Authorization", "Content-Type" ],
allowHeaders: ["Authorization", "Content-Type"], allowMethods: [ "GET", "POST", "PUT", "DELETE", "OPTIONS" ],
allowMethods: ["GET", "POST", "PUT", "DELETE", "OPTIONS"], origin: process.env.CORS_ORIGIN ?? "http://localhost:5173",
}), }),
); );
@@ -25,13 +36,20 @@ app.route("/about", aboutRouter);
app.route("/auth", authRouter); app.route("/auth", authRouter);
app.route("/game", gameRouter); app.route("/game", gameRouter);
app.route("/boss", bossRouter); app.route("/boss", bossRouter);
app.route("/explore", exploreRouter);
app.route("/craft", craftRouter);
app.route("/prestige", prestigeRouter); app.route("/prestige", prestigeRouter);
app.route("/transcendence", transcendenceRouter);
app.route("/apotheosis", apotheosisRouter);
app.route("/leaderboards", leaderboardRouter);
app.route("/profile", profileRouter); app.route("/profile", profileRouter);
app.get("/health", (context) => context.json({ status: "ok" })); app.get("/health", (context) => {
return context.json({ status: "ok" });
const port = Number(process.env["PORT"] ?? 3001); });
serve({ fetch: app.fetch, port }, () => { const port = Number(process.env.PORT ?? 3001);
console.log(`Elysium API running on port ${port}`);
serve({ fetch: app.fetch, port: port }, () => {
process.stdout.write(`Elysium API running on port ${String(port)}\n`);
}); });
+29 -11
View File
@@ -1,14 +1,31 @@
import type { MiddlewareHandler } from "hono"; /**
import type { HonoEnv } from "../types/hono.js"; * @file Authentication middleware for validating JWT tokens.
import { verifyToken } from "../services/jwt.js"; * @copyright nhcarrigan
* @license Naomi's Public License
* @author Naomi Carrigan
*/
export const authMiddleware: MiddlewareHandler<HonoEnv> = async (context, next) => { import { verifyToken } from "../services/jwt.js";
import type { HonoEnvironment } from "../types/hono.js";
import type { MiddlewareHandler } from "hono";
/**
* Validates the Authorization Bearer token on each request and attaches the discordId to context.
* @param context - The Hono context object.
* @param next - The next middleware handler.
* @returns A JSON error response if authentication fails, otherwise calls next.
*/
export const authMiddleware: MiddlewareHandler<HonoEnvironment> = async(
context,
next,
) => {
const authorization = context.req.header("Authorization"); const authorization = context.req.header("Authorization");
if (!authorization?.startsWith("Bearer ")) { if (authorization?.startsWith("Bearer ") !== true) {
context.status(401); return context.json(
context.json({ error: "Missing or invalid Authorization header" }); { error: "Missing or invalid Authorization header" },
return; 401,
);
} }
const token = authorization.slice(7); const token = authorization.slice(7);
@@ -16,9 +33,10 @@ export const authMiddleware: MiddlewareHandler<HonoEnv> = async (context, next)
try { try {
const payload = verifyToken(token); const payload = verifyToken(token);
context.set("discordId", payload.discordId); context.set("discordId", payload.discordId);
await next();
} catch { } catch {
context.status(401); return context.json({ error: "Invalid or expired token" }, 401);
context.json({ error: "Invalid or expired token" });
} }
// eslint-disable-next-line @typescript-eslint/no-confusing-void-expression -- Need the consistent return!
return await next();
}; };
+35 -24
View File
@@ -1,46 +1,57 @@
import { readFileSync } from "node:fs"; /**
import { dirname, join } from "node:path"; * @file About route providing API version and release information.
import { fileURLToPath } from "node:url"; * @copyright nhcarrigan
* @license Naomi's Public License
* @author Naomi Carrigan
*/
/* eslint-disable stylistic/max-len -- URL cannot be shortened */
/* eslint-disable require-atomic-updates -- Simple cache; race condition is acceptable */
import { Hono } from "hono"; import { Hono } from "hono";
import type { AboutResponse, GiteaRelease } from "@elysium/types"; import type { AboutResponse, GiteaRelease } from "@elysium/types";
const __dirname = dirname(fileURLToPath(import.meta.url)); // eslint-disable-next-line capitalized-comments -- v8 ignore
const { version: API_VERSION } = JSON.parse( /* v8 ignore next -- @preserve */
readFileSync(join(__dirname, "../../package.json"), "utf-8"), const apiVersion = process.env.npm_package_version ?? "unknown";
) as { version: string };
const GITEA_RELEASES_URL = const giteaReleasesUrl = "https://git.nhcarrigan.com/api/v1/repos/nhcarrigan/elysium/releases";
"https://git.nhcarrigan.com/api/v1/repos/nhcarrigan-ideation/elysium/releases"; const cacheTtlMs = 5 * 60 * 1000;
const CACHE_TTL_MS = 5 * 60 * 1000;
let releasesCache: GiteaRelease[] = []; interface ReleasesCache {
let cacheTimestamp = 0; data: Array<GiteaRelease>;
timestamp: number;
}
const fetchReleases = async (): Promise<GiteaRelease[]> => { let releasesCache: ReleasesCache = { data: [], timestamp: 0 };
const fetchReleases = async(): Promise<Array<GiteaRelease>> => {
const now = Date.now(); const now = Date.now();
if (releasesCache.length > 0 && now - cacheTimestamp < CACHE_TTL_MS) { if (releasesCache.data.length > 0 && now - releasesCache.timestamp < cacheTtlMs) {
return releasesCache; return releasesCache.data;
} }
try { try {
const response = await fetch(GITEA_RELEASES_URL); const response = await fetch(giteaReleasesUrl);
if (!response.ok) { if (!response.ok) {
return releasesCache; return releasesCache.data;
} }
releasesCache = (await response.json()) as GiteaRelease[]; const rawData: unknown = await response.json();
cacheTimestamp = now; /* eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- External API response */
return releasesCache; const data = rawData as Array<GiteaRelease>;
releasesCache = { data: data, timestamp: now };
return releasesCache.data;
} catch { } catch {
return releasesCache; return releasesCache.data;
} }
}; };
export const aboutRouter = new Hono(); const aboutRouter = new Hono();
aboutRouter.get("/", async (context) => { aboutRouter.get("/", async(context) => {
const releases = await fetchReleases(); const releases = await fetchReleases();
const body: AboutResponse = { const body: AboutResponse = {
apiVersion: API_VERSION, apiVersion,
releases, releases,
}; };
return context.json(body); return context.json(body);
}); });
export { aboutRouter };
+118
View File
@@ -0,0 +1,118 @@
/**
* @file Apotheosis route handling the apotheosis reset mechanic.
* @copyright nhcarrigan
* @license Naomi's Public License
* @author Naomi Carrigan
*/
/* eslint-disable max-lines-per-function -- Route handler requires many steps */
/* eslint-disable stylistic/max-len -- Description string cannot be shortened */
import { Hono } from "hono";
import { prisma } from "../db/client.js";
import { authMiddleware } from "../middleware/auth.js";
import {
buildPostApotheosisState,
isEligibleForApotheosis,
} from "../services/apotheosis.js";
import {
grantApotheosisRole,
postMilestoneWebhook,
} from "../services/webhook.js";
import type { HonoEnvironment } from "../types/hono.js";
import type { GameState } from "@elysium/types";
const apotheosisRouter = new Hono<HonoEnvironment>();
apotheosisRouter.use("*", authMiddleware);
apotheosisRouter.post("/", async(context) => {
const discordId = context.get("discordId");
const record = await prisma.gameState.findUnique({ where: { discordId } });
if (!record) {
return context.json({ error: "No save found" }, 404);
}
const rawState: unknown = record.state;
/* eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- Prisma returns JsonValue; cast to GameState */
const state = rawState as GameState;
if (!isEligibleForApotheosis(state)) {
return context.json(
{
error:
"Not eligible for Apotheosis — purchase all Transcendence upgrades first",
},
400,
);
}
// Capture current-run stats before the nuclear reset
// eslint-disable-next-line capitalized-comments -- v8 ignore
/* v8 ignore next 9 -- @preserve */
const runBossesDefeated = state.bosses.filter((b) => {
return b.status === "defeated";
}).length;
const runQuestsCompleted = state.quests.filter((q) => {
return q.status === "completed";
}).length;
const runAdventurersRecruited = state.adventurers.reduce((sum, a) => {
return sum + a.count;
}, 0);
// eslint-disable-next-line capitalized-comments -- v8 ignore
/* v8 ignore next 3 -- @preserve */
const runAchievementsUnlocked = state.achievements.filter((a) => {
return a.unlockedAt !== null;
}).length;
const { updatedState, updatedApotheosisData } = buildPostApotheosisState(
state,
state.player.characterName,
);
const now = Date.now();
await prisma.gameState.update({
/* eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- Prisma requires object */
data: { state: updatedState as object, updatedAt: now },
where: { discordId },
});
await prisma.player.update({
data: {
characterName: state.player.characterName,
lastSavedAt: now,
lifetimeAchievementsUnlocked: { increment: runAchievementsUnlocked },
lifetimeAdventurersRecruited: { increment: runAdventurersRecruited },
lifetimeBossesDefeated: { increment: runBossesDefeated },
lifetimeClicks: { increment: state.player.totalClicks },
// Accumulate into lifetime totals
lifetimeGoldEarned: { increment: state.player.totalGoldEarned },
lifetimeQuestsCompleted: { increment: runQuestsCompleted },
totalClicks: 0,
// Reset current-run counters
totalGoldEarned: 0,
},
where: { discordId },
});
void grantApotheosisRole(discordId);
void postMilestoneWebhook(discordId, "apotheosis", {
apotheosis: updatedApotheosisData.count,
prestige: updatedState.prestige.count,
// eslint-disable-next-line capitalized-comments -- v8 ignore
/* v8 ignore next -- @preserve */
transcendence: updatedState.transcendence?.count ?? 0,
});
return context.json({ apotheosisCount: updatedApotheosisData.count });
});
export { apotheosisRouter };
+64 -32
View File
@@ -1,15 +1,23 @@
import type { Player } from "@elysium/types"; /**
* @file Authentication routes for Discord OAuth.
* @copyright nhcarrigan
* @license Naomi's Public License
* @author Naomi Carrigan
*/
/* eslint-disable max-lines-per-function -- Auth callback requires many steps */
/* eslint-disable max-statements -- Auth callback requires many statements */
import { Hono } from "hono"; import { Hono } from "hono";
import { initialGameState } from "../data/initialState.js";
import { prisma } from "../db/client.js"; import { prisma } from "../db/client.js";
import { INITIAL_GAME_STATE } from "../data/initialState.js";
import { import {
buildOAuthUrl, buildOAuthUrl,
exchangeCode, exchangeCode,
fetchDiscordUser, fetchDiscordUser,
} from "../services/discord.js"; } from "../services/discord.js";
import { signToken } from "../services/jwt.js"; import { signToken } from "../services/jwt.js";
import type { Player } from "@elysium/types";
export const authRouter = new Hono(); const authRouter = new Hono();
authRouter.get("/url", (context) => { authRouter.get("/url", (context) => {
try { try {
@@ -20,10 +28,10 @@ authRouter.get("/url", (context) => {
} }
}); });
authRouter.get("/callback", async (context) => { authRouter.get("/callback", async(context) => {
const code = context.req.query("code"); const code = context.req.query("code");
if (!code) { if (code === undefined || code === "") {
return context.json({ error: "Missing code parameter" }, 400); return context.json({ error: "Missing code parameter" }, 400);
} }
@@ -40,58 +48,82 @@ authRouter.get("/callback", async (context) => {
if (!existing) { if (!existing) {
const player = await prisma.player.create({ const player = await prisma.player.create({
data: { data: {
discordId: discordUser.id, avatar: discordUser.avatar,
username: discordUser.username, characterName: discordUser.username,
discriminator: discordUser.discriminator, createdAt: now,
avatar: discordUser.avatar, discordId: discordUser.id,
characterName: discordUser.username, discriminator: discordUser.discriminator,
createdAt: now, lastSavedAt: now,
lastSavedAt: now, totalClicks: 0,
totalGoldEarned: 0, totalGoldEarned: 0,
totalClicks: 0, username: discordUser.username,
}, },
}); });
const playerShape: Player = { const playerShape: Player = {
discordId: player.discordId, avatar: player.avatar ?? null,
username: player.username, characterName: player.characterName,
discriminator: player.discriminator, createdAt: player.createdAt,
avatar: player.avatar ?? null, discordId: player.discordId,
characterName: player.characterName, discriminator: player.discriminator,
createdAt: player.createdAt, lastSavedAt: player.lastSavedAt,
lastSavedAt: player.lastSavedAt, lifetimeAchievementsUnlocked: player.lifetimeAchievementsUnlocked,
totalGoldEarned: player.totalGoldEarned, lifetimeAdventurersRecruited: player.lifetimeAdventurersRecruited,
totalClicks: player.totalClicks, lifetimeBossesDefeated: player.lifetimeBossesDefeated,
lifetimeClicks: player.lifetimeClicks,
lifetimeGoldEarned: player.lifetimeGoldEarned,
lifetimeQuestsCompleted: player.lifetimeQuestsCompleted,
totalClicks: player.totalClicks,
totalGoldEarned: player.totalGoldEarned,
username: player.username,
}; };
const initialState = INITIAL_GAME_STATE(playerShape, playerShape.characterName); const freshState = initialGameState(
playerShape,
playerShape.characterName,
);
await prisma.gameState.create({ await prisma.gameState.create({
data: { data: {
discordId: player.discordId, discordId: player.discordId,
state: initialState as unknown as never, /* eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- Prisma requires never type */
state: freshState as unknown as never,
updatedAt: now, updatedAt: now,
}, },
}); });
const jwtToken = signToken(player.discordId); const jwtToken = signToken(player.discordId);
const clientUrl = process.env["CORS_ORIGIN"] ?? "http://localhost:5173";
return context.redirect(`${clientUrl}/auth/callback?token=${jwtToken}&isNew=true`); // eslint-disable-next-line capitalized-comments -- v8 ignore
/* v8 ignore next -- @preserve */
const clientUrl = process.env.CORS_ORIGIN ?? "http://localhost:5173";
return context.redirect(
`${clientUrl}/auth/callback?token=${jwtToken}&isNew=true`,
);
} }
const updated = await prisma.player.update({ const updated = await prisma.player.update({
where: { discordId: discordUser.id },
data: { data: {
username: discordUser.username, avatar: discordUser.avatar,
discriminator: discordUser.discriminator, discriminator: discordUser.discriminator,
avatar: discordUser.avatar, username: discordUser.username,
}, },
where: { discordId: discordUser.id },
}); });
const jwtToken = signToken(updated.discordId); const jwtToken = signToken(updated.discordId);
const clientUrl = process.env["CORS_ORIGIN"] ?? "http://localhost:5173";
return context.redirect(`${clientUrl}/auth/callback?token=${jwtToken}&isNew=false`); // eslint-disable-next-line capitalized-comments -- v8 ignore
/* v8 ignore next -- @preserve */
const clientUrl = process.env.CORS_ORIGIN ?? "http://localhost:5173";
return context.redirect(
`${clientUrl}/auth/callback?token=${jwtToken}&isNew=false`,
);
} catch { } catch {
const clientUrl = process.env["CORS_ORIGIN"] ?? "http://localhost:5173"; // eslint-disable-next-line capitalized-comments -- v8 ignore
/* v8 ignore next -- @preserve */
const clientUrl = process.env.CORS_ORIGIN ?? "http://localhost:5173";
return context.redirect(`${clientUrl}/auth/callback?error=auth_failed`); return context.redirect(`${clientUrl}/auth/callback?error=auth_failed`);
} }
}); });
export { authRouter };
+209 -91
View File
@@ -1,14 +1,28 @@
import type { BossChallengeResponse, GameState } from "@elysium/types"; /**
import { computeSetBonuses } from "@elysium/types"; * @file Boss challenge route handling combat mechanics.
* @copyright nhcarrigan
* @license Naomi's Public License
* @author Naomi Carrigan
*/
/* eslint-disable max-lines-per-function -- Boss handler requires many steps */
/* eslint-disable max-statements -- Boss handler requires many statements */
/* eslint-disable complexity -- Boss handler has inherent complexity */
/* eslint-disable stylistic/max-len -- Long lines in combat logic */
import {
computeSetBonuses,
getActiveCompanionBonus,
type BossChallengeResponse,
type GameState,
} from "@elysium/types";
import { Hono } from "hono"; import { Hono } from "hono";
import type { HonoEnv } from "../types/hono.js"; import { defaultBosses } from "../data/bosses.js";
import { defaultEquipmentSets } from "../data/equipmentSets.js";
import { prisma } from "../db/client.js"; import { prisma } from "../db/client.js";
import { DEFAULT_BOSSES } from "../data/bosses.js";
import { DEFAULT_EQUIPMENT_SETS } from "../data/equipmentSets.js";
import { authMiddleware } from "../middleware/auth.js"; import { authMiddleware } from "../middleware/auth.js";
import { updateChallengeProgress } from "../services/dailyChallenges.js"; import { updateChallengeProgress } from "../services/dailyChallenges.js";
import type { HonoEnvironment } from "../types/hono.js";
export const bossRouter = new Hono<HonoEnv>(); const bossRouter = new Hono<HonoEnvironment>();
bossRouter.use("*", authMiddleware); bossRouter.use("*", authMiddleware);
@@ -18,56 +32,99 @@ const calculatePartyStats = (
let globalMultiplier = 1; let globalMultiplier = 1;
for (const upgrade of state.upgrades) { for (const upgrade of state.upgrades) {
if (upgrade.purchased && upgrade.target === "global") { if (upgrade.purchased && upgrade.target === "global") {
globalMultiplier *= upgrade.multiplier; globalMultiplier = globalMultiplier * upgrade.multiplier;
} }
} }
// eslint-disable-next-line stylistic/no-mixed-operators -- prestige count * factor is clear
const prestigeMultiplier = 1 + state.prestige.count * 0.1; const prestigeMultiplier = 1 + state.prestige.count * 0.1;
// Apply equipped weapon's combat bonus // Apply equipped weapon's combat bonus
const equipmentCombatMultiplier = (state.equipment ?? []) // eslint-disable-next-line capitalized-comments -- v8 ignore
.filter((e) => e.equipped && e.bonus.combatMultiplier != null) /* v8 ignore next 7 -- @preserve */
.reduce((mult, e) => mult * (e.bonus.combatMultiplier ?? 1), 1); const equipmentCombatMultiplier = state.equipment.
filter((item) => {
return item.equipped && item.bonus.combatMultiplier !== undefined;
}).
reduce((mult, item) => {
return mult * (item.bonus.combatMultiplier ?? 1);
}, 1);
const equippedItemIds = (state.equipment ?? []).filter((e) => e.equipped).map((e) => e.id); // eslint-disable-next-line capitalized-comments -- v8 ignore
const setCombatMultiplier = computeSetBonuses(equippedItemIds, DEFAULT_EQUIPMENT_SETS).combatMultiplier; /* v8 ignore next 7 -- @preserve */
const equippedItemIds = state.equipment.
filter((item) => {
return item.equipped;
}).
map((item) => {
return item.id;
});
const { combatMultiplier: setCombatMultiplier } = computeSetBonuses(
equippedItemIds,
defaultEquipmentSets,
);
let partyDPS = 0; let partyDPS = 0;
let partyMaxHp = 0; let partyMaxHp = 0;
for (const adventurer of state.adventurers) { for (const adventurer of state.adventurers) {
if (adventurer.count === 0) continue; if (adventurer.count === 0) {
continue;
}
let adventurerMultiplier = 1; let adventurerMultiplier = 1;
for (const upgrade of state.upgrades) { for (const upgrade of state.upgrades) {
if ( if (
upgrade.purchased && upgrade.purchased
upgrade.target === "adventurer" && && upgrade.target === "adventurer"
upgrade.adventurerId === adventurer.id && upgrade.adventurerId === adventurer.id
) { ) {
adventurerMultiplier *= upgrade.multiplier; adventurerMultiplier = adventurerMultiplier * upgrade.multiplier;
} }
} }
partyDPS += const adventurerContribution
adventurer.combatPower * = adventurer.combatPower
adventurer.count * * adventurer.count
adventurerMultiplier * * adventurerMultiplier
globalMultiplier * * globalMultiplier
prestigeMultiplier; * prestigeMultiplier;
partyDPS = partyDPS + adventurerContribution;
partyMaxHp += adventurer.level * 50 * adventurer.count; const adventurerHp = adventurer.level * 50 * adventurer.count;
partyMaxHp = partyMaxHp + adventurerHp;
} }
partyDPS *= equipmentCombatMultiplier * setCombatMultiplier; // eslint-disable-next-line capitalized-comments -- v8 ignore
/* v8 ignore next 12 -- @preserve */
const echoCombatMultiplier = state.transcendence?.echoCombatMultiplier ?? 1;
const craftedCombatMultiplier
= state.exploration?.craftedCombatMultiplier ?? 1;
const companionBonus = getActiveCompanionBonus(
state.companions?.activeCompanionId ?? null,
state.companions?.unlockedCompanionIds ?? [],
);
const companionCombatMult
= companionBonus?.type === "bossDamage"
? 1 + companionBonus.value
: 1;
partyDPS = partyDPS
* equipmentCombatMultiplier
* setCombatMultiplier
* echoCombatMultiplier
* craftedCombatMultiplier
* companionCombatMult;
return { partyDPS, partyMaxHp }; return { partyDPS, partyMaxHp };
}; };
bossRouter.post("/challenge", async (context) => { bossRouter.post("/challenge", async(context) => {
const discordId = context.get("discordId") as string; const discordId = context.get("discordId");
const body = await context.req.json<{ bossId: string }>(); const body = await context.req.json<{ bossId: string }>();
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions -- Runtime body validation
if (!body.bossId) { if (!body.bossId) {
return context.json({ error: "Invalid request body" }, 400); return context.json({ error: "Invalid request body" }, 400);
} }
@@ -78,8 +135,12 @@ bossRouter.post("/challenge", async (context) => {
return context.json({ error: "No save found" }, 404); return context.json({ error: "No save found" }, 404);
} }
const state = record.state as unknown as GameState; const rawState: unknown = record.state;
const boss = state.bosses.find((b) => b.id === body.bossId); /* eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- Prisma returns JsonValue; cast to GameState */
const state = rawState as GameState;
const boss = state.bosses.find((b) => {
return b.id === body.bossId;
});
if (!boss) { if (!boss) {
return context.json({ error: "Boss not found" }, 404); return context.json({ error: "Boss not found" }, 404);
@@ -95,7 +156,12 @@ bossRouter.post("/challenge", async (context) => {
const { partyDPS, partyMaxHp } = calculatePartyStats(state); const { partyDPS, partyMaxHp } = calculatePartyStats(state);
if (partyDPS === 0 || partyMaxHp === 0 || !isFinite(partyDPS) || !isFinite(partyMaxHp)) { if (
partyDPS === 0
|| partyMaxHp === 0
|| !Number.isFinite(partyDPS)
|| !Number.isFinite(partyMaxHp)
) {
return context.json( return context.json(
{ error: "Your party has no adventurers ready to fight" }, { error: "Your party has no adventurers ready to fight" },
400, 400,
@@ -110,44 +176,53 @@ bossRouter.post("/challenge", async (context) => {
const won = timeToKillBoss <= timeToKillParty; const won = timeToKillBoss <= timeToKillParty;
// eslint-disable-next-line @typescript-eslint/init-declarations -- Conditionally assigned in if/else branches
let partyHpRemaining: number; let partyHpRemaining: number;
// eslint-disable-next-line @typescript-eslint/init-declarations -- Conditionally assigned in if/else branches
let bossHpAtBattleEnd: number; let bossHpAtBattleEnd: number;
let bossNewHp: number; // eslint-disable-next-line @typescript-eslint/init-declarations -- Conditionally assigned in if/else branches
let bossUpdatedHp: number;
// eslint-disable-next-line @typescript-eslint/init-declarations -- Conditionally assigned based on win/loss
let rewards: BossChallengeResponse["rewards"]; let rewards: BossChallengeResponse["rewards"];
// eslint-disable-next-line @typescript-eslint/init-declarations -- Conditionally assigned based on win/loss
let casualties: BossChallengeResponse["casualties"]; let casualties: BossChallengeResponse["casualties"];
if (won) { if (won) {
bossHpAtBattleEnd = 0; bossHpAtBattleEnd = 0;
bossNewHp = 0; bossUpdatedHp = 0;
partyHpRemaining = Math.max( const bossDamageDealt = bossDPS * timeToKillBoss;
0, partyHpRemaining = Math.max(0, partyMaxHp - bossDamageDealt);
partyMaxHp - bossDPS * timeToKillBoss,
);
boss.status = "defeated"; boss.status = "defeated";
boss.currentHp = 0; boss.currentHp = 0;
state.resources.gold += boss.goldReward; state.resources.gold = state.resources.gold + boss.goldReward;
state.resources.essence += boss.essenceReward; state.resources.essence = state.resources.essence + boss.essenceReward;
state.resources.crystals += boss.crystalReward; state.resources.crystals = state.resources.crystals + boss.crystalReward;
state.player.totalGoldEarned += boss.goldReward; state.player.totalGoldEarned = state.player.totalGoldEarned + boss.goldReward;
for (const upgradeId of boss.upgradeRewards) { for (const upgradeId of boss.upgradeRewards) {
const upgrade = state.upgrades.find((u) => u.id === upgradeId); const upgrade = state.upgrades.find((u) => {
return u.id === upgradeId;
});
if (upgrade) { if (upgrade) {
upgrade.unlocked = true; upgrade.unlocked = true;
} }
} }
// Grant equipment rewards — auto-equip if the slot is currently empty // Grant equipment rewards — auto-equip if the slot is currently empty
const equipmentRewards = boss.equipmentRewards ?? []; // eslint-disable-next-line capitalized-comments -- v8 ignore
for (const equipmentId of equipmentRewards) { /* v8 ignore next 14 -- @preserve */
const equipment = (state.equipment ?? []).find((e) => e.id === equipmentId); for (const equipmentId of boss.equipmentRewards) {
const equipment = state.equipment.find((item) => {
return item.id === equipmentId;
});
if (equipment) { if (equipment) {
equipment.owned = true; equipment.owned = true;
const slotAlreadyEquipped = (state.equipment ?? []).some(
(e) => e.type === equipment.type && e.equipped, const slotAlreadyEquipped = state.equipment.some((item) => {
); return item.type === equipment.type && item.equipped;
});
if (!slotAlreadyEquipped) { if (!slotAlreadyEquipped) {
equipment.equipped = true; equipment.equipped = true;
} }
@@ -155,62 +230,94 @@ bossRouter.post("/challenge", async (context) => {
} }
// Unlock next boss in the same zone (zone-based sequential progression) // Unlock next boss in the same zone (zone-based sequential progression)
const zoneBosses = state.bosses.filter((b) => b.zoneId === boss.zoneId); const zoneBosses = state.bosses.filter((b) => {
const zoneIndex = zoneBosses.findIndex((b) => b.id === body.bossId); return b.zoneId === boss.zoneId;
const nextZoneBoss = zoneBosses[zoneIndex + 1]; });
if (nextZoneBoss && nextZoneBoss.prestigeRequirement <= state.prestige.count) { const zoneIndex = zoneBosses.findIndex((b) => {
const nextBossInState = state.bosses.find((b) => b.id === nextZoneBoss.id); return b.id === body.bossId;
if (nextBossInState) nextBossInState.status = "available"; });
const [ nextZoneBoss ] = zoneBosses.slice(zoneIndex + 1);
if (
nextZoneBoss
&& nextZoneBoss.prestigeRequirement <= state.prestige.count
) {
const nextBossInState = state.bosses.find((b) => {
return b.id === nextZoneBoss.id;
});
if (nextBossInState) {
nextBossInState.status = "available";
}
} }
// Unlock any zone whose unlock conditions are now both satisfied /*
// (final boss defeated AND final quest completed) * Unlock any zone whose unlock conditions are now both satisfied
for (const zone of (state.zones ?? [])) { * (final boss defeated AND final quest completed)
if (zone.status === "unlocked") continue; */
if (zone.unlockBossId !== body.bossId) continue; // eslint-disable-next-line capitalized-comments -- v8 ignore
/* v8 ignore next -- @preserve */
for (const zone of state.zones) {
if (zone.status === "unlocked") {
continue;
}
if (zone.unlockBossId !== body.bossId) {
continue;
}
// Boss condition just became satisfied — check the quest condition too // Boss condition just became satisfied — check the quest condition too
const questSatisfied = const questSatisfied
zone.unlockQuestId == null || = zone.unlockQuestId === null
state.quests.some((q) => q.id === zone.unlockQuestId && q.status === "completed"); || state.quests.some((q) => {
if (!questSatisfied) continue; return q.id === zone.unlockQuestId && q.status === "completed";
});
if (!questSatisfied) {
continue;
}
zone.status = "unlocked"; zone.status = "unlocked";
const newZoneBosses = state.bosses.filter((b) => b.zoneId === zone.id); const updatedZoneBosses = state.bosses.filter((b) => {
const firstNewBoss = newZoneBosses[0]; return b.zoneId === zone.id;
if (firstNewBoss && firstNewBoss.prestigeRequirement <= state.prestige.count) { });
firstNewBoss.status = "available"; const [ firstUpdatedBoss ] = updatedZoneBosses;
if (
firstUpdatedBoss
&& firstUpdatedBoss.prestigeRequirement <= state.prestige.count
) {
firstUpdatedBoss.status = "available";
} }
} }
// Update daily boss challenge progress // Update daily boss challenge progress
if (state.dailyChallenges) { if (state.dailyChallenges) {
const { updatedChallenges, crystalsAwarded } = updateChallengeProgress( const { crystalsAwarded, updatedChallenges } = updateChallengeProgress(
state.dailyChallenges, state.dailyChallenges,
"bossesDefeated", "bossesDefeated",
1, 1,
); );
state.dailyChallenges = updatedChallenges; state.dailyChallenges = updatedChallenges;
state.resources.crystals += crystalsAwarded; state.resources.crystals = state.resources.crystals + crystalsAwarded;
} }
// First-kill bounty — look up authoritative bounty from static data // First-kill bounty — look up authoritative bounty from static data
const staticBoss = DEFAULT_BOSSES.find((b) => b.id === body.bossId); const staticBoss = defaultBosses.find((b) => {
return b.id === body.bossId;
});
// eslint-disable-next-line capitalized-comments -- v8 ignore
/* v8 ignore next -- @preserve */
const bountyRunestones = staticBoss?.bountyRunestones ?? 0; const bountyRunestones = staticBoss?.bountyRunestones ?? 0;
state.prestige.runestones += bountyRunestones; state.prestige.runestones = state.prestige.runestones + bountyRunestones;
rewards = { rewards = {
gold: boss.goldReward, bountyRunestones: bountyRunestones,
essence: boss.essenceReward, crystals: boss.crystalReward,
crystals: boss.crystalReward, equipmentIds: boss.equipmentRewards,
upgradeIds: boss.upgradeRewards, essence: boss.essenceReward,
equipmentIds: equipmentRewards, gold: boss.goldReward,
bountyRunestones, upgradeIds: boss.upgradeRewards,
}; };
} else { } else {
bossHpAtBattleEnd = Math.max( const partyDamageDealt = partyDPS * timeToKillParty;
0, bossHpAtBattleEnd = Math.max(0, bossHpBefore - partyDamageDealt);
bossHpBefore - partyDPS * timeToKillParty, bossUpdatedHp = boss.maxHp;
);
bossNewHp = boss.maxHp;
partyHpRemaining = 0; partyHpRemaining = 0;
boss.status = "available"; boss.status = "available";
@@ -223,34 +330,45 @@ bossRouter.post("/challenge", async (context) => {
casualties = []; casualties = [];
for (const adventurer of state.adventurers) { for (const adventurer of state.adventurers) {
if (adventurer.count === 0) continue; if (adventurer.count === 0) {
continue;
}
const killed = Math.floor(adventurer.count * casualtyFraction); const killed = Math.floor(adventurer.count * casualtyFraction);
if (killed > 0) { if (killed > 0) {
adventurer.count = Math.max(1, adventurer.count - killed); adventurer.count = Math.max(1, adventurer.count - killed);
casualties.push({ adventurerId: adventurer.id, killed }); casualties.push({ adventurerId: adventurer.id, killed: killed });
} }
} }
} }
const now = Date.now(); const now = Date.now();
await prisma.gameState.update({ await prisma.gameState.update({
/* eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- Prisma requires object */
data: { state: state as object, updatedAt: now },
where: { discordId }, where: { discordId },
data: { state: state as object, updatedAt: now },
}); });
const bossMaxHp = boss.maxHp;
const bossNewHp = bossUpdatedHp;
const response: BossChallengeResponse = { const response: BossChallengeResponse = {
won,
partyDPS,
bossDPS, bossDPS,
bossHpBefore,
bossMaxHp: boss.maxHp,
bossHpAtBattleEnd, bossHpAtBattleEnd,
bossHpBefore,
bossMaxHp,
bossNewHp, bossNewHp,
partyMaxHp, partyDPS,
partyHpRemaining, partyHpRemaining,
partyMaxHp,
won,
}; };
if (rewards !== undefined) response.rewards = rewards; if (rewards !== undefined) {
if (casualties !== undefined) response.casualties = casualties; response.rewards = rewards;
}
if (casualties !== undefined) {
response.casualties = casualties;
}
return context.json(response); return context.json(response);
}); });
export { bossRouter };
+156
View File
@@ -0,0 +1,156 @@
/**
* @file Crafting route handling recipe crafting mechanics.
* @copyright nhcarrigan
* @license Naomi's Public License
* @author Naomi Carrigan
*/
/* eslint-disable max-lines-per-function -- Route handler requires many steps */
/* eslint-disable max-statements -- Route handler requires many statements */
/* eslint-disable complexity -- Route handler has inherent complexity */
import { Hono } from "hono";
import { defaultRecipes } from "../data/recipes.js";
import { prisma } from "../db/client.js";
import { authMiddleware } from "../middleware/auth.js";
import type { HonoEnvironment } from "../types/hono.js";
import type {
CraftRecipeRequest,
CraftRecipeResponse,
GameState,
} from "@elysium/types";
const craftRouter = new Hono<HonoEnvironment>();
craftRouter.use("*", authMiddleware);
const recomputeCraftedMultipliers = (
craftedRecipeIds: Array<string>,
): {
craftedGoldMultiplier: number;
craftedEssenceMultiplier: number;
craftedClickMultiplier: number;
craftedCombatMultiplier: number;
} => {
return {
craftedClickMultiplier: defaultRecipes.filter((r) => {
return craftedRecipeIds.includes(r.id) && r.bonus.type === "click_power";
}).reduce((mult, r) => {
// eslint-disable-next-line capitalized-comments -- v8 ignore
/* v8 ignore next -- @preserve */
return mult * r.bonus.value;
}, 1),
craftedCombatMultiplier: defaultRecipes.filter((r) => {
return craftedRecipeIds.includes(r.id) && r.bonus.type === "combat_power";
}).reduce((mult, r) => {
// eslint-disable-next-line capitalized-comments -- v8 ignore
/* v8 ignore next -- @preserve */
return mult * r.bonus.value;
}, 1),
craftedEssenceMultiplier: defaultRecipes.filter((r) => {
return (
craftedRecipeIds.includes(r.id) && r.bonus.type === "essence_income"
);
}).reduce((mult, r) => {
// eslint-disable-next-line capitalized-comments -- v8 ignore
/* v8 ignore next -- @preserve */
return mult * r.bonus.value;
}, 1),
craftedGoldMultiplier: defaultRecipes.filter((r) => {
return craftedRecipeIds.includes(r.id) && r.bonus.type === "gold_income";
}).reduce((mult, r) => {
return mult * r.bonus.value;
}, 1),
};
};
craftRouter.post("/", async(context) => {
const discordId = context.get("discordId");
const body = await context.req.json<CraftRecipeRequest>();
const { recipeId } = body;
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions -- Runtime body validation
if (!recipeId) {
return context.json({ error: "recipeId is required" }, 400);
}
const recipe = defaultRecipes.find((r) => {
return r.id === recipeId;
});
if (!recipe) {
return context.json({ error: "Unknown recipe" }, 404);
}
const record = await prisma.gameState.findUnique({ where: { discordId } });
if (!record) {
return context.json({ error: "No save found" }, 404);
}
const rawState: unknown = record.state;
/* eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- Prisma returns JsonValue; cast to GameState */
const state = rawState as GameState;
if (!state.exploration) {
return context.json({ error: "No exploration state found" }, 400);
}
if (state.exploration.craftedRecipeIds.includes(recipeId)) {
return context.json({ error: "Recipe already crafted" }, 400);
}
// Verify the player has all required materials
for (const requirement of recipe.requiredMaterials) {
const material = state.exploration.materials.find((m) => {
return m.materialId === requirement.materialId;
});
const quantity = material?.quantity ?? 0;
if (quantity < requirement.quantity) {
return context.json(
{
error: `Not enough ${requirement.materialId} (need ${String(requirement.quantity)}, have ${String(quantity)})`,
},
400,
);
}
}
// Deduct materials
for (const requirement of recipe.requiredMaterials) {
const material = state.exploration.materials.find((m) => {
return m.materialId === requirement.materialId;
});
if (material) {
material.quantity = material.quantity - requirement.quantity;
}
}
// Add recipe and recompute all multipliers from scratch
state.exploration.craftedRecipeIds.push(recipeId);
const updatedMultipliers = recomputeCraftedMultipliers(
state.exploration.craftedRecipeIds,
);
state.exploration.craftedGoldMultiplier
= updatedMultipliers.craftedGoldMultiplier;
state.exploration.craftedEssenceMultiplier
= updatedMultipliers.craftedEssenceMultiplier;
state.exploration.craftedClickMultiplier
= updatedMultipliers.craftedClickMultiplier;
state.exploration.craftedCombatMultiplier
= updatedMultipliers.craftedCombatMultiplier;
await prisma.gameState.update({
/* eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- Prisma requires object */
data: { state: state as object, updatedAt: Date.now() },
where: { discordId },
});
const bonusType = recipe.bonus.type;
const bonusValue = recipe.bonus.value;
const response: CraftRecipeResponse = {
bonusType,
bonusValue,
recipeId,
...updatedMultipliers,
};
return context.json(response);
});
export { craftRouter };
+355
View File
@@ -0,0 +1,355 @@
/**
* @file Exploration routes handling area exploration mechanics.
* @copyright nhcarrigan
* @license Naomi's Public License
* @author Naomi Carrigan
*/
/* eslint-disable max-lines-per-function -- Route handlers require many steps */
/* eslint-disable max-statements -- Route handlers require many statements */
/* eslint-disable complexity -- Route handlers have inherent complexity */
import { Hono } from "hono";
import { defaultExplorations } from "../data/explorations.js";
import { initialExploration } from "../data/initialState.js";
import { prisma } from "../db/client.js";
import { authMiddleware } from "../middleware/auth.js";
import type { HonoEnvironment } from "../types/hono.js";
import type {
ExploreCollectEventResult,
ExploreCollectRequest,
ExploreCollectResponse,
ExploreStartRequest,
ExploreStartResponse,
GameState,
} from "@elysium/types";
const exploreRouter = new Hono<HonoEnvironment>();
exploreRouter.use("*", authMiddleware);
const nothingProbability = 0.2;
const nothingMessages = [
"Your scouts searched thoroughly but found nothing of value.",
"The area yielded nothing remarkable this time.",
"Your scouts returned empty-handed.",
"A wasted journey — the area proved barren.",
"Nothing to show for the effort. Perhaps next time.",
];
/**
* Returns a random "nothing found" message.
* V8 ignore next 2 -- @preserve.
* @returns A random message string.
*/
const pickNothingMessage = (): string => {
const index = Math.floor(Math.random() * nothingMessages.length);
// eslint-disable-next-line capitalized-comments -- v8 ignore
/* v8 ignore next -- @preserve */
return nothingMessages[index] ?? nothingMessages[0] ?? "";
};
exploreRouter.post("/start", async(context) => {
const discordId = context.get("discordId");
const body = await context.req.json<ExploreStartRequest>();
const { areaId } = body;
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions -- Runtime body validation
if (!areaId) {
return context.json({ error: "areaId is required" }, 400);
}
const explorationArea = defaultExplorations.find((a) => {
return a.id === areaId;
});
if (!explorationArea) {
return context.json({ error: "Unknown exploration area" }, 404);
}
const record = await prisma.gameState.findUnique({ where: { discordId } });
if (!record) {
return context.json({ error: "No save found" }, 404);
}
const rawState: unknown = record.state;
/* eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- Prisma returns JsonValue; cast to GameState */
const state = rawState as GameState;
// Backfill exploration state for old saves that predate this feature
if (!state.exploration) {
state.exploration = structuredClone(initialExploration);
// Unlock areas for zones already unlocked in this save
for (const area of state.exploration.areas) {
const areaData = defaultExplorations.find((areaItem) => {
return areaItem.id === area.id;
});
// eslint-disable-next-line capitalized-comments -- v8 ignore
/* v8 ignore next 3 -- @preserve */
if (!areaData) {
continue;
}
const zone = state.zones.find((z) => {
return z.id === areaData.zoneId;
});
if (zone?.status === "unlocked") {
area.status = "available";
}
}
}
const zone = state.zones.find((z) => {
return z.id === explorationArea.zoneId;
});
if (!zone || zone.status !== "unlocked") {
return context.json({ error: "Zone is not unlocked" }, 400);
}
const area = state.exploration.areas.find((a) => {
return a.id === areaId;
});
if (!area) {
return context.json({ error: "Exploration area not found in state" }, 404);
}
const anyInProgress = state.exploration.areas.some((a) => {
return a.status === "in_progress";
});
if (anyInProgress) {
return context.json(
{ error: "An exploration is already in progress" },
400,
);
}
if (area.status === "locked") {
return context.json({ error: "Exploration area is locked" }, 400);
}
const now = Date.now();
area.status = "in_progress";
area.startedAt = now;
await prisma.gameState.update({
/* eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- Prisma requires object */
data: { state: state as object, updatedAt: now },
where: { discordId },
});
// eslint-disable-next-line stylistic/no-mixed-operators -- duration * 1000 is clear
const endsAt = now + explorationArea.durationSeconds * 1000;
const response: ExploreStartResponse = {
areaId,
endsAt,
};
return context.json(response);
});
exploreRouter.post("/collect", async(context) => {
const discordId = context.get("discordId");
const body = await context.req.json<ExploreCollectRequest>();
const { areaId } = body;
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions -- Runtime body validation
if (!areaId) {
return context.json({ error: "areaId is required" }, 400);
}
const explorationArea = defaultExplorations.find((a) => {
return a.id === areaId;
});
if (!explorationArea) {
return context.json({ error: "Unknown exploration area" }, 404);
}
const record = await prisma.gameState.findUnique({ where: { discordId } });
if (!record) {
return context.json({ error: "No save found" }, 404);
}
const rawState: unknown = record.state;
/* eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- Prisma returns JsonValue; cast to GameState */
const state = rawState as GameState;
if (!state.exploration) {
return context.json({ error: "No exploration state found" }, 400);
}
const area = state.exploration.areas.find((a) => {
return a.id === areaId;
});
if (!area) {
return context.json({ error: "Exploration area not found" }, 404);
}
if (area.status !== "in_progress") {
return context.json({ error: "Exploration is not in progress" }, 400);
}
const now = Date.now();
// eslint-disable-next-line capitalized-comments -- v8 ignore
/* v8 ignore next -- @preserve */
const startedAt = area.startedAt ?? 0;
const durationMs = explorationArea.durationSeconds * 1000;
const expiresAt = startedAt + durationMs;
if (now < expiresAt) {
return context.json({ error: "Exploration is not yet complete" }, 400);
}
area.status = "available";
area.completedOnce = true;
// 20% chance of finding nothing
if (Math.random() < nothingProbability) {
await prisma.gameState.update({
/* eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- Prisma requires object */
data: { state: state as object, updatedAt: now },
where: { discordId },
});
const response: ExploreCollectResponse = {
event: null,
foundNothing: true,
materialsFound: [],
nothingMessage: pickNothingMessage(),
};
return context.json(response);
}
// Pick a random event
const eventIndex = Math.floor(Math.random() * explorationArea.events.length);
const event = explorationArea.events[eventIndex];
// eslint-disable-next-line capitalized-comments -- v8 ignore
/* v8 ignore next 3 -- @preserve */
if (!event) {
return context.json({ error: "No events available" }, 500);
}
// Apply event effects and build the result summary
let goldChange = 0;
let essenceChange = 0;
let materialGained: { materialId: string; quantity: number } | null = null;
if (event.effect.type === "gold_gain") {
// Gold gain — amount may be undefined in edge cases
// eslint-disable-next-line capitalized-comments -- v8 ignore
/* v8 ignore next -- @preserve */
const amount = event.effect.amount ?? 0;
state.resources.gold = state.resources.gold + amount;
state.player.totalGoldEarned = state.player.totalGoldEarned + amount;
goldChange = amount;
} else if (event.effect.type === "gold_loss") {
// Gold loss — amount may be undefined in edge cases
// eslint-disable-next-line capitalized-comments -- v8 ignore
/* v8 ignore next -- @preserve */
const amount = Math.min(state.resources.gold, event.effect.amount ?? 0);
state.resources.gold = state.resources.gold - amount;
goldChange = -amount;
} else if (event.effect.type === "essence_gain") {
// Essence gain — amount may be undefined in edge cases
// eslint-disable-next-line capitalized-comments -- v8 ignore
/* v8 ignore next -- @preserve */
const amount = event.effect.amount ?? 0;
state.resources.essence = state.resources.essence + amount;
essenceChange = amount;
} else if (event.effect.type === "material_gain") {
const { materialId } = event.effect;
// eslint-disable-next-line capitalized-comments -- v8 ignore
/* v8 ignore next -- @preserve */
const quantity = event.effect.quantity ?? 1;
if (materialId !== undefined && materialId !== "") {
const existing = state.exploration.materials.find((m) => {
return m.materialId === materialId;
});
if (existing) {
existing.quantity = existing.quantity + quantity;
} else {
state.exploration.materials.push({ materialId, quantity });
}
materialGained = { materialId, quantity };
// eslint-disable-next-line capitalized-comments -- v8 ignore
/* v8 ignore next 13 -- @preserve */
}
} else if (event.effect.type === "adventurer_loss") { // eslint-disable-line @typescript-eslint/no-unnecessary-condition -- exhausted all other union members above
// Adventurer loss — fraction and loop are defensive
// eslint-disable-next-line capitalized-comments -- v8 ignore
/* v8 ignore next 8 -- @preserve */
const fraction = event.effect.fraction ?? 0.05;
for (const adventurer of state.adventurers) {
const lost = Math.floor(adventurer.count * fraction);
if (lost > 0) {
adventurer.count = Math.max(0, adventurer.count - lost);
}
}
}
// eslint-disable-next-line capitalized-comments -- v8 ignore
/* v8 ignore next 8 -- @preserve */
let adventurerLostCount = 0;
if (event.effect.type === "adventurer_loss") {
const fraction = event.effect.fraction ?? 0.05;
for (const adv of state.adventurers) {
const lost = Math.floor(adv.count * fraction);
adventurerLostCount = adventurerLostCount + lost;
}
}
const eventResult: ExploreCollectEventResult = {
adventurerLostCount: adventurerLostCount,
essenceChange: essenceChange,
goldChange: goldChange,
materialGained: materialGained,
text: event.text,
};
// Roll for material drops from possibleMaterials (weighted random selection)
const materialsFound: Array<{ materialId: string; quantity: number }> = [];
if (explorationArea.possibleMaterials.length > 0) {
let totalWeight = 0;
for (const materialDrop of explorationArea.possibleMaterials) {
totalWeight = totalWeight + materialDrop.weight;
}
let roll = Math.random() * totalWeight;
for (const possible of explorationArea.possibleMaterials) {
roll = roll - possible.weight;
if (roll <= 0) {
const maxMinDiff = possible.maxQuantity - possible.minQuantity;
const range = maxMinDiff + 1;
const randomOffset = Math.floor(Math.random() * range);
const quantity = randomOffset + possible.minQuantity;
const { materialId } = possible;
const existing = state.exploration.materials.find((m) => {
return m.materialId === materialId;
});
if (existing) {
existing.quantity = existing.quantity + quantity;
} else {
state.exploration.materials.push({ materialId, quantity });
}
materialsFound.push({ materialId, quantity });
break;
}
}
}
await prisma.gameState.update({
/* eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- Prisma requires object */
data: { state: state as object, updatedAt: now },
where: { discordId },
});
const response: ExploreCollectResponse = {
event: eventResult,
foundNothing: false,
materialsFound: materialsFound,
};
return context.json(response);
});
export { exploreRouter };
File diff suppressed because it is too large Load Diff
+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 };
+113 -43
View File
@@ -1,28 +1,31 @@
import type { BuyPrestigeUpgradeRequest, GameState, PrestigeRequest } from "@elysium/types"; /**
* @file Prestige routes handling prestige resets and upgrade purchases.
* @copyright nhcarrigan
* @license Naomi's Public License
* @author Naomi Carrigan
*/
/* eslint-disable max-lines-per-function -- Route handlers require many steps */
/* eslint-disable max-statements -- Route handlers require many statements */
import { Hono } from "hono"; import { Hono } from "hono";
import type { HonoEnv } from "../types/hono.js"; import { defaultPrestigeUpgrades } from "../data/prestigeUpgrades.js";
import { prisma } from "../db/client.js"; import { prisma } from "../db/client.js";
import { authMiddleware } from "../middleware/auth.js"; import { authMiddleware } from "../middleware/auth.js";
import { DEFAULT_PRESTIGE_UPGRADES } from "../data/prestigeUpgrades.js";
import { updateChallengeProgress } from "../services/dailyChallenges.js"; import { updateChallengeProgress } from "../services/dailyChallenges.js";
import { import {
buildPostPrestigeState, buildPostPrestigeState,
computeRunestoneMultipliers, computeRunestoneMultipliers,
isEligibleForPrestige, isEligibleForPrestige,
} from "../services/prestige.js"; } from "../services/prestige.js";
import { postMilestoneWebhook } from "../services/webhook.js";
import type { HonoEnvironment } from "../types/hono.js";
import type { BuyPrestigeUpgradeRequest, GameState } from "@elysium/types";
export const prestigeRouter = new Hono<HonoEnv>(); const prestigeRouter = new Hono<HonoEnvironment>();
prestigeRouter.use("*", authMiddleware); prestigeRouter.use("*", authMiddleware);
prestigeRouter.post("/", async (context) => { prestigeRouter.post("/", async(context) => {
const discordId = context.get("discordId") as string; const discordId = context.get("discordId");
const body = await context.req.json<PrestigeRequest>();
const characterName = body.characterName?.trim();
if (!characterName) {
return context.json({ error: "characterName is required" }, 400);
}
const record = await prisma.gameState.findUnique({ where: { discordId } }); const record = await prisma.gameState.findUnique({ where: { discordId } });
@@ -30,11 +33,14 @@ prestigeRouter.post("/", async (context) => {
return context.json({ error: "No save found" }, 404); return context.json({ error: "No save found" }, 404);
} }
/* eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- Prisma returns JsonValue */
const state = record.state as unknown as GameState; const state = record.state as unknown as GameState;
if (!isEligibleForPrestige(state)) { if (!isEligibleForPrestige(state)) {
return context.json( return context.json(
{ error: "Not eligible for prestige — collect 1,000,000 total gold first" }, {
error: "Not eligible for prestige — collect 1,000,000 total gold first",
},
400, 400,
); );
} }
@@ -43,59 +49,119 @@ prestigeRouter.post("/", async (context) => {
let updatedDailyChallenges = state.dailyChallenges; let updatedDailyChallenges = state.dailyChallenges;
let challengeCrystals = 0; let challengeCrystals = 0;
if (updatedDailyChallenges) { if (updatedDailyChallenges) {
const result = updateChallengeProgress(updatedDailyChallenges, "prestige", 1); const result = updateChallengeProgress(
updatedDailyChallenges,
"prestige",
1,
);
updatedDailyChallenges = result.updatedChallenges; updatedDailyChallenges = result.updatedChallenges;
challengeCrystals = result.crystalsAwarded; challengeCrystals = result.crystalsAwarded;
} }
const { newState, newPrestigeData, runestonesEarned, milestoneRunestones } = buildPostPrestigeState( const {
state, milestoneRunestones,
characterName, prestigeData,
); prestigeState,
runestonesEarned,
} = buildPostPrestigeState(state, state.player.characterName);
// Preserve daily challenges across the prestige reset and apply any crystal rewards // Preserve daily challenges across the prestige reset and apply any crystal rewards
const finalState: GameState = { const finalState: GameState = {
...newState, ...prestigeState,
...(updatedDailyChallenges !== undefined ? { dailyChallenges: updatedDailyChallenges } : {}), ...updatedDailyChallenges === undefined
? {}
: { dailyChallenges: updatedDailyChallenges },
resources: { resources: {
...newState.resources, ...prestigeState.resources,
crystals: newState.resources.crystals + challengeCrystals, crystals: prestigeState.resources.crystals + challengeCrystals,
}, },
}; };
// Capture current-run stats to accumulate into lifetime totals before resetting
// eslint-disable-next-line capitalized-comments -- v8 ignore
/* v8 ignore next 10 -- @preserve */
const runBossesDefeated = state.bosses.filter((boss) => {
return boss.status === "defeated";
}).length;
const runQuestsCompleted = state.quests.filter((quest) => {
return quest.status === "completed";
}).length;
let runAdventurersRecruited = 0;
for (const adventurer of state.adventurers) {
runAdventurersRecruited = runAdventurersRecruited + adventurer.count;
}
// eslint-disable-next-line capitalized-comments -- v8 ignore
/* v8 ignore next 3 -- @preserve */
const runAchievementsUnlocked = state.achievements.filter((achievement) => {
return achievement.unlockedAt !== null;
}).length;
const now = Date.now(); const now = Date.now();
await prisma.gameState.update({ await prisma.gameState.update({
/* eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- Prisma requires object */
data: { state: finalState as object, updatedAt: now },
where: { discordId }, where: { discordId },
data: { state: finalState as object, updatedAt: now },
}); });
await prisma.player.update({ await prisma.player.update({
where: { discordId },
data: { data: {
characterName, characterName: state.player.characterName,
totalGoldEarned: 0,
totalClicks: 0,
lastSavedAt: now, lastSavedAt: now,
lifetimeAchievementsUnlocked: { increment: runAchievementsUnlocked },
lifetimeAdventurersRecruited: { increment: runAdventurersRecruited },
lifetimeBossesDefeated: { increment: runBossesDefeated },
lifetimeClicks: { increment: state.player.totalClicks },
// Accumulate into lifetime totals — never reset
lifetimeGoldEarned: { increment: state.player.totalGoldEarned },
lifetimeQuestsCompleted: { increment: runQuestsCompleted },
totalClicks: 0,
// Reset current-run counters
totalGoldEarned: 0,
}, },
where: { discordId },
});
void postMilestoneWebhook(discordId, "prestige", {
// eslint-disable-next-line capitalized-comments -- v8 ignore
/* v8 ignore next -- @preserve */
apotheosis: prestigeState.apotheosis?.count ?? 0,
prestige: prestigeData.count,
// eslint-disable-next-line capitalized-comments -- v8 ignore
/* v8 ignore next 2 -- @preserve */
transcendence: prestigeState.transcendence?.count ?? 0,
}); });
return context.json({ return context.json({
runestones: runestonesEarned, milestoneRunestones: milestoneRunestones,
newPrestigeCount: newPrestigeData.count, newPrestigeCount: prestigeData.count, // eslint-disable-line unicorn/no-keyword-prefix -- API response field name required by client
milestoneRunestones, runestones: runestonesEarned,
}); });
}); });
prestigeRouter.post("/buy-upgrade", async (context) => { prestigeRouter.post("/buy-upgrade", async(context) => {
const discordId = context.get("discordId") as string; const discordId = context.get("discordId");
const body = await context.req.json<BuyPrestigeUpgradeRequest>(); const body = await context.req.json<BuyPrestigeUpgradeRequest>();
const { upgradeId } = body; const { upgradeId } = body;
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions -- Runtime body validation
if (!upgradeId) { if (!upgradeId) {
return context.json({ error: "upgradeId is required" }, 400); return context.json({ error: "upgradeId is required" }, 400);
} }
const upgrade = DEFAULT_PRESTIGE_UPGRADES.find((u) => u.id === upgradeId); const upgrade = defaultPrestigeUpgrades.find((prestigeUpgrade) => {
return prestigeUpgrade.id === upgradeId;
});
if (!upgrade) { if (!upgrade) {
return context.json({ error: "Unknown prestige upgrade" }, 404); return context.json({ error: "Unknown prestige upgrade" }, 404);
} }
@@ -105,6 +171,7 @@ prestigeRouter.post("/buy-upgrade", async (context) => {
return context.json({ error: "No save found" }, 404); return context.json({ error: "No save found" }, 404);
} }
/* eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- Prisma returns JsonValue */
const state = record.state as unknown as GameState; const state = record.state as unknown as GameState;
const { purchasedUpgradeIds, runestones } = state.prestige; const { purchasedUpgradeIds, runestones } = state.prestige;
@@ -116,29 +183,32 @@ prestigeRouter.post("/buy-upgrade", async (context) => {
return context.json({ error: "Not enough runestones" }, 400); return context.json({ error: "Not enough runestones" }, 400);
} }
const newRunestones = runestones - upgrade.runestonesCost; const updatedRunestones = runestones - upgrade.runestonesCost;
const newPurchasedUpgradeIds = [...purchasedUpgradeIds, upgradeId]; const updatedPurchasedUpgradeIds = [ ...purchasedUpgradeIds, upgradeId ];
const newState: GameState = { const updatedState: GameState = {
...state, ...state,
prestige: { prestige: {
...state.prestige, ...state.prestige,
runestones: newRunestones, purchasedUpgradeIds: updatedPurchasedUpgradeIds,
purchasedUpgradeIds: newPurchasedUpgradeIds, runestones: updatedRunestones,
...computeRunestoneMultipliers(newPurchasedUpgradeIds), ...computeRunestoneMultipliers(updatedPurchasedUpgradeIds),
}, },
}; };
await prisma.gameState.update({ await prisma.gameState.update({
/* eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- Prisma requires object */
data: { state: updatedState as object, updatedAt: Date.now() },
where: { discordId }, where: { discordId },
data: { state: newState as object, updatedAt: Date.now() },
}); });
const multipliers = computeRunestoneMultipliers(newPurchasedUpgradeIds); const multipliers = computeRunestoneMultipliers(updatedPurchasedUpgradeIds);
return context.json({ return context.json({
runestonesRemaining: newRunestones, purchasedUpgradeIds: updatedPurchasedUpgradeIds,
purchasedUpgradeIds: newPurchasedUpgradeIds, runestonesRemaining: updatedRunestones,
...multipliers, ...multipliers,
}); });
}); });
export { prestigeRouter };
+225 -67
View File
@@ -1,43 +1,89 @@
import type { /**
GameState, * @file Profile routes handling player profile retrieval and updates.
ProfileSettings, * @copyright nhcarrigan
UpdateProfileRequest, * @license Naomi's Public License
* @author Naomi Carrigan
*/
/* eslint-disable max-lines-per-function -- Route handlers require many steps */
/* eslint-disable max-statements -- Route handlers require many steps */
/* eslint-disable complexity -- Route handlers have inherent complexity */
/* eslint-disable stylistic/key-spacing -- ProfileSettings keys exceed max-len when aligned */
/* eslint-disable stylistic/max-len -- ProfileSettings key names exceed line length limit */
/* eslint-disable @typescript-eslint/no-unnecessary-condition -- Defensive checks for runtime nullable fields */
import {
DEFAULT_PROFILE_SETTINGS,
type GameState,
type ProfileSettings,
type UpdateProfileRequest,
} from "@elysium/types"; } from "@elysium/types";
import { DEFAULT_PROFILE_SETTINGS } from "@elysium/types";
import { Hono } from "hono"; import { Hono } from "hono";
import type { HonoEnv } from "../types/hono.js"; import { gameTitles } from "../data/titles.js";
import { prisma } from "../db/client.js"; import { prisma } from "../db/client.js";
import { authMiddleware } from "../middleware/auth.js"; import { authMiddleware } from "../middleware/auth.js";
import { parseUnlockedTitles } from "../services/titles.js";
import type { HonoEnvironment } from "../types/hono.js";
export const profileRouter = new Hono<HonoEnv>(); const profileRouter = new Hono<HonoEnvironment>();
const VALID_NUMBER_FORMATS = new Set(["suffix", "scientific", "engineering"]); const validNumberFormats = new Set([ "suffix", "scientific", "engineering" ]);
/**
* Parses a raw profile settings blob from the database into a typed ProfileSettings object.
* @param raw - The raw value from the database.
* @returns A valid ProfileSettings object with defaults for missing fields.
*/
const parseProfileSettings = (raw: unknown): ProfileSettings => { const parseProfileSettings = (raw: unknown): ProfileSettings => {
if (raw !== null && typeof raw === "object" && !Array.isArray(raw)) { if (raw === null || typeof raw !== "object" || Array.isArray(raw)) {
const obj = raw as Record<string, unknown>; return { ...DEFAULT_PROFILE_SETTINGS };
const numberFormat = VALID_NUMBER_FORMATS.has(obj.numberFormat as string)
? (obj.numberFormat as ProfileSettings["numberFormat"])
: "suffix";
return {
showTotalGold: obj.showTotalGold !== false,
showTotalClicks: obj.showTotalClicks !== false,
showPrestige: obj.showPrestige !== false,
showGuildFounded: obj.showGuildFounded !== false,
showBossesDefeated: obj.showBossesDefeated !== false,
showQuestsCompleted: obj.showQuestsCompleted !== false,
showAdventurersRecruited: obj.showAdventurersRecruited !== false,
showAchievementsUnlocked: obj.showAchievementsUnlocked !== false,
numberFormat,
};
} }
return { ...DEFAULT_PROFILE_SETTINGS }; /* eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- Runtime shape check */
const rawObject = raw as Record<string, unknown>;
/* eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- Runtime shape check */
const parsedNumberFormat = rawObject.numberFormat as string;
const numberFormat = validNumberFormats.has(parsedNumberFormat)
/* eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- Runtime shape check */
? (parsedNumberFormat as ProfileSettings["numberFormat"])
: "suffix";
return {
enableNotifications: rawObject.enableNotifications === true,
enableSounds: rawObject.enableSounds === true,
numberFormat: numberFormat,
showAchievementsUnlocked: rawObject.showAchievementsUnlocked !== false,
showAdventurersRecruited: rawObject.showAdventurersRecruited !== false,
showApotheosis: rawObject.showApotheosis !== false,
showBossesDefeated: rawObject.showBossesDefeated !== false,
showCurrentClicks: rawObject.showCurrentClicks !== false,
showCurrentGold: rawObject.showCurrentGold !== false,
showGuildFounded: rawObject.showGuildFounded !== false,
showLifetimeAchievementsUnlocked: rawObject.showLifetimeAchievementsUnlocked !== false,
showLifetimeAdventurersRecruited: rawObject.showLifetimeAdventurersRecruited !== false,
showLifetimeBossesDefeated: rawObject.showLifetimeBossesDefeated !== false,
showLifetimeQuestsCompleted: rawObject.showLifetimeQuestsCompleted !== false,
showOnLeaderboards: rawObject.showOnLeaderboards !== false,
showPrestige: rawObject.showPrestige !== false,
showQuestsCompleted: rawObject.showQuestsCompleted !== false,
showTotalClicks: rawObject.showTotalClicks !== false,
showTotalGold: rawObject.showTotalGold !== false,
showTranscendence: rawObject.showTranscendence !== false,
};
}; };
profileRouter.get("/:discordId", async (context) => { /**
* Resolves a title ID to its display name.
* @param id - The title ID to resolve.
* @returns An object with id and name fields.
*/
const resolveTitle = (id: string): { id: string; name: string } => {
const title = gameTitles.find((gameTitle) => {
return gameTitle.id === id;
});
return { id: id, name: title?.name ?? id };
};
profileRouter.get("/:discordId", async(context) => {
const { discordId } = context.req.param(); const { discordId } = context.req.param();
const [player, gameStateRecord] = await Promise.all([ const [ player, gameStateRecord ] = await Promise.all([
prisma.player.findUnique({ where: { discordId } }), prisma.player.findUnique({ where: { discordId } }),
prisma.gameState.findUnique({ where: { discordId } }), prisma.gameState.findUnique({ where: { discordId } }),
]); ]);
@@ -46,67 +92,179 @@ profileRouter.get("/:discordId", async (context) => {
return context.json({ error: "Player not found" }, 404); return context.json({ error: "Player not found" }, 404);
} }
/* eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- Prisma returns JsonValue */
const state = gameStateRecord?.state as unknown as GameState | undefined; const state = gameStateRecord?.state as unknown as GameState | undefined;
const prestigeCount = state?.prestige.count ?? 0; const prestigeCount = state?.prestige.count ?? 0;
const transcendenceCount = state?.transcendence?.count ?? 0;
const apotheosisCount = state?.apotheosis?.count ?? 0;
const profileSettings = parseProfileSettings(player.profileSettings); const profileSettings = parseProfileSettings(player.profileSettings);
const bossesDefeated = state?.bosses.filter((b) => b.status === "defeated").length ?? 0; const bossesDefeated
const questsCompleted = state?.quests.filter((q) => q.status === "completed").length ?? 0; = state?.bosses.filter((boss) => {
const adventurersRecruited = return boss.status === "defeated";
state?.adventurers.reduce((sum, a) => sum + a.count, 0) ?? 0; }).length ?? 0;
const achievementsUnlocked = const questsCompleted
(state?.achievements ?? []).filter((a) => a.unlockedAt !== null).length; = state?.quests.filter((quest) => {
return quest.status === "completed";
}).length ?? 0;
let adventurersRecruited = 0;
if (state) {
// eslint-disable-next-line capitalized-comments -- v8 ignore
/* v8 ignore next 3 -- @preserve */
for (const adventurer of state.adventurers) {
adventurersRecruited = adventurersRecruited + adventurer.count;
}
}
// eslint-disable-next-line capitalized-comments -- v8 ignore
/* v8 ignore next 3 -- @preserve */
const achievementsUnlocked = (state?.achievements ?? []).filter((achievement) => {
return achievement.unlockedAt !== null;
}).length;
const unlockedTitleIds = parseUnlockedTitles(player.unlockedTitles);
const unlockedTitles = unlockedTitleIds.map((id) => {
return resolveTitle(id);
});
// eslint-disable-next-line capitalized-comments -- v8 ignore
/* v8 ignore next 12 -- @preserve */
const equippedItems = (state?.equipment ?? []).
filter((item) => {
return item.owned && item.equipped;
}).
map((item) => {
return {
bonus: item.bonus,
name: item.name,
rarity: item.rarity,
type: item.type,
};
});
const completedChapters = state?.story?.completedChapters ?? [];
return context.json({ return context.json({
characterName: player.characterName, achievementsUnlocked: achievementsUnlocked,
username: player.username, activeTitle: player.activeTitle,
avatar: player.avatar ?? null, adventurersRecruited: adventurersRecruited,
apotheosisCount: apotheosisCount,
avatar: player.avatar,
bio: player.bio ?? "", bio: player.bio ?? "",
profileSettings, bossesDefeated: bossesDefeated,
prestigeCount, characterClass: player.characterClass,
totalGoldEarned: player.totalGoldEarned, characterName: player.characterName,
totalClicks: player.totalClicks, characterRace: player.characterRace ?? "",
bossesDefeated, completedChapters: completedChapters,
questsCompleted,
adventurersRecruited,
achievementsUnlocked,
createdAt: player.createdAt, createdAt: player.createdAt,
currentRunClicks: state?.player.totalClicks ?? 0,
currentRunGold: state?.player.totalGoldEarned ?? 0,
equippedItems: equippedItems,
guildDescription: player.guildDescription,
guildName: player.guildName,
lifetimeAchievementsUnlocked: player.lifetimeAchievementsUnlocked,
lifetimeAdventurersRecruited: player.lifetimeAdventurersRecruited,
lifetimeBossesDefeated: player.lifetimeBossesDefeated,
lifetimeQuestsCompleted: player.lifetimeQuestsCompleted,
prestigeCount: prestigeCount,
profileSettings: profileSettings,
pronouns: player.pronouns ?? "",
questsCompleted: questsCompleted,
totalClicks: player.lifetimeClicks,
totalGoldEarned: player.lifetimeGoldEarned,
transcendenceCount: transcendenceCount,
unlockedTitles: unlockedTitles,
username: player.username,
}); });
}); });
profileRouter.put("/", authMiddleware, async (context) => { profileRouter.put("/", authMiddleware, async(context) => {
const discordId = context.get("discordId") as string; const discordId = context.get("discordId");
const body = await context.req.json<UpdateProfileRequest>(); const body = await context.req.json<UpdateProfileRequest>();
const characterName = (body.characterName ?? "").trim().slice(0, 32); // eslint-disable-next-line @typescript-eslint/strict-boolean-expressions -- Runtime body validation
const bio = (body.bio ?? "").trim().slice(0, 200); if (!body.characterName) {
const numberFormat = VALID_NUMBER_FORMATS.has(body.profileSettings?.numberFormat as string)
? (body.profileSettings?.numberFormat as ProfileSettings["numberFormat"])
: "suffix";
const profileSettings: ProfileSettings = {
showTotalGold: body.profileSettings?.showTotalGold !== false,
showTotalClicks: body.profileSettings?.showTotalClicks !== false,
showPrestige: body.profileSettings?.showPrestige !== false,
showGuildFounded: body.profileSettings?.showGuildFounded !== false,
showBossesDefeated: body.profileSettings?.showBossesDefeated !== false,
showQuestsCompleted: body.profileSettings?.showQuestsCompleted !== false,
showAdventurersRecruited: body.profileSettings?.showAdventurersRecruited !== false,
showAchievementsUnlocked: body.profileSettings?.showAchievementsUnlocked !== false,
numberFormat,
};
if (!characterName) {
return context.json({ error: "Character name cannot be empty" }, 400); return context.json({ error: "Character name cannot be empty" }, 400);
} }
const characterName = body.characterName.trim().slice(0, 32);
if (characterName === "") {
return context.json({ error: "Character name cannot be empty" }, 400);
}
const pronouns = (body.pronouns ?? "").trim().slice(0, 20);
const characterRace = (body.characterRace ?? "").trim().slice(0, 32);
const characterClass = (body.characterClass ?? "").trim().slice(0, 32);
const bio = (body.bio ?? "").trim().slice(0, 200);
const guildName = (body.guildName ?? "").trim().slice(0, 64);
const guildDescription = (body.guildDescription ?? "").trim().slice(0, 500);
// eslint-disable-next-line capitalized-comments -- v8 ignore
/* v8 ignore next 2 -- @preserve */
/* eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- Runtime shape check */
const parsedNumberFormat = (body.profileSettings.numberFormat ?? "") as string;
const numberFormat = validNumberFormats.has(parsedNumberFormat)
/* eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- Runtime shape check */
? (parsedNumberFormat as ProfileSettings["numberFormat"])
: "suffix";
const profileSettings: ProfileSettings = {
enableNotifications: body.profileSettings.enableNotifications ?? false,
enableSounds: body.profileSettings.enableSounds ?? false,
numberFormat: numberFormat,
showAchievementsUnlocked: body.profileSettings.showAchievementsUnlocked ?? true,
showAdventurersRecruited: body.profileSettings.showAdventurersRecruited ?? true,
showApotheosis: body.profileSettings.showApotheosis ?? true,
showBossesDefeated: body.profileSettings.showBossesDefeated ?? true,
showCurrentClicks: body.profileSettings.showCurrentClicks ?? true,
showCurrentGold: body.profileSettings.showCurrentGold ?? true,
showGuildFounded: body.profileSettings.showGuildFounded ?? true,
showLifetimeAchievementsUnlocked: body.profileSettings.showLifetimeAchievementsUnlocked ?? true,
showLifetimeAdventurersRecruited: body.profileSettings.showLifetimeAdventurersRecruited ?? true,
showLifetimeBossesDefeated: body.profileSettings.showLifetimeBossesDefeated ?? true,
showLifetimeQuestsCompleted: body.profileSettings.showLifetimeQuestsCompleted ?? true,
showOnLeaderboards: body.profileSettings.showOnLeaderboards ?? true,
showPrestige: body.profileSettings.showPrestige ?? true,
showQuestsCompleted: body.profileSettings.showQuestsCompleted ?? true,
showTotalClicks: body.profileSettings.showTotalClicks ?? true,
showTotalGold: body.profileSettings.showTotalGold ?? true,
showTranscendence: body.profileSettings.showTranscendence ?? true,
};
const activeTitle
= typeof body.activeTitle === "string"
? body.activeTitle.slice(0, 64)
: undefined;
const updated = await prisma.player.update({ const updated = await prisma.player.update({
data: {
bio: bio,
characterClass: characterClass,
characterName: characterName,
characterRace: characterRace,
guildDescription: guildDescription,
guildName: guildName,
/* eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- Prisma requires object */
profileSettings: profileSettings as object,
pronouns: pronouns,
...activeTitle === undefined
? {}
: { activeTitle },
},
where: { discordId }, where: { discordId },
data: { characterName, bio, profileSettings: profileSettings as object },
}); });
return context.json({ return context.json({
characterName: updated.characterName, activeTitle: updated.activeTitle,
bio: updated.bio, bio: updated.bio,
profileSettings, characterClass: updated.characterClass,
characterName: updated.characterName,
characterRace: updated.characterRace,
guildDescription: updated.guildDescription,
guildName: updated.guildName,
profileSettings: profileSettings,
pronouns: updated.pronouns,
}); });
}); });
export { profileRouter };
+191
View File
@@ -0,0 +1,191 @@
/**
* @file Transcendence routes handling transcendence resets and echo upgrade purchases.
* @copyright nhcarrigan
* @license Naomi's Public License
* @author Naomi Carrigan
*/
/* eslint-disable max-lines-per-function -- Route handlers require many steps */
/* eslint-disable max-statements -- Route handlers require many statements */
import { Hono } from "hono";
import { defaultTranscendenceUpgrades } from "../data/transcendenceUpgrades.js";
import { prisma } from "../db/client.js";
import { authMiddleware } from "../middleware/auth.js";
import {
buildPostTranscendenceState,
computeTranscendenceMultipliers,
isEligibleForTranscendence,
} from "../services/transcendence.js";
import { postMilestoneWebhook } from "../services/webhook.js";
import type { HonoEnvironment } from "../types/hono.js";
import type { BuyEchoUpgradeRequest, GameState } from "@elysium/types";
const transcendenceRouter = new Hono<HonoEnvironment>();
transcendenceRouter.use("*", authMiddleware);
transcendenceRouter.post("/", async(context) => {
const discordId = context.get("discordId");
const record = await prisma.gameState.findUnique({ where: { discordId } });
if (!record) {
return context.json({ error: "No save found" }, 404);
}
/* eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- Prisma returns JsonValue */
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 {
echoesEarned,
transcendenceData,
transcendenceState,
} = buildPostTranscendenceState(state, state.player.characterName);
// Capture current-run stats before the nuclear reset
const runBossesDefeated = state.bosses.filter((boss) => {
return boss.status === "defeated";
}).length;
// eslint-disable-next-line capitalized-comments -- v8 ignore
/* v8 ignore next 7 -- @preserve */
const runQuestsCompleted = state.quests.filter((quest) => {
return quest.status === "completed";
}).length;
let runAdventurersRecruited = 0;
for (const adventurer of state.adventurers) {
runAdventurersRecruited = runAdventurersRecruited + adventurer.count;
}
// eslint-disable-next-line capitalized-comments -- v8 ignore
/* v8 ignore next 3 -- @preserve */
const runAchievementsUnlocked = state.achievements.filter((achievement) => {
return achievement.unlockedAt !== null;
}).length;
const now = Date.now();
await prisma.gameState.update({
/* eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- Prisma requires object */
data: { state: transcendenceState as object, updatedAt: now },
where: { discordId },
});
await prisma.player.update({
data: {
characterName: state.player.characterName,
lastSavedAt: now,
lifetimeAchievementsUnlocked: { increment: runAchievementsUnlocked },
lifetimeAdventurersRecruited: { increment: runAdventurersRecruited },
lifetimeBossesDefeated: { increment: runBossesDefeated },
lifetimeClicks: { increment: state.player.totalClicks },
// Accumulate into lifetime totals
lifetimeGoldEarned: { increment: state.player.totalGoldEarned },
lifetimeQuestsCompleted: { increment: runQuestsCompleted },
totalClicks: 0,
// Reset current-run counters (same as prestige)
totalGoldEarned: 0,
},
where: { discordId },
});
void postMilestoneWebhook(discordId, "transcendence", {
// eslint-disable-next-line capitalized-comments -- v8 ignore
/* v8 ignore next -- @preserve */
// eslint-disable-next-line capitalized-comments -- v8 ignore
/* v8 ignore next -- @preserve */
apotheosis: transcendenceState.apotheosis?.count ?? 0,
prestige: transcendenceState.prestige.count,
transcendence: transcendenceData.count,
});
return context.json({
echoes: echoesEarned,
// eslint-disable-next-line unicorn/no-keyword-prefix -- API response field name required by client
newTranscendenceCount: transcendenceData.count,
});
});
transcendenceRouter.post("/buy-upgrade", async(context) => {
const discordId = context.get("discordId");
const body = await context.req.json<BuyEchoUpgradeRequest>();
const { upgradeId } = body;
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions -- Runtime body validation
if (!upgradeId) {
return context.json({ error: "upgradeId is required" }, 400);
}
const upgrade = defaultTranscendenceUpgrades.find((transcendenceUpgrade) => {
return transcendenceUpgrade.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);
}
/* eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- Prisma returns JsonValue */
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 updatedEchoes = echoes - upgrade.cost;
const updatedPurchasedIds = [ ...purchasedUpgradeIds, upgradeId ];
const updatedMultipliers
= computeTranscendenceMultipliers(updatedPurchasedIds);
const updatedState: GameState = {
...state,
transcendence: {
...state.transcendence,
echoes: updatedEchoes,
purchasedUpgradeIds: updatedPurchasedIds,
...updatedMultipliers,
},
};
await prisma.gameState.update({
/* eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- Prisma requires object */
data: { state: updatedState as object, updatedAt: Date.now() },
where: { discordId },
});
return context.json({
echoesRemaining: updatedEchoes,
purchasedUpgradeIds: updatedPurchasedIds,
...updatedMultipliers,
});
});
export { transcendenceRouter };
+68
View File
@@ -0,0 +1,68 @@
/**
* @file Apotheosis service handling eligibility checks and state building.
* @copyright nhcarrigan
* @license Naomi's Public License
* @author Naomi Carrigan
*/
import { initialGameState } from "../data/initialState.js";
import {
defaultTranscendenceUpgrades,
} from "../data/transcendenceUpgrades.js";
import type { ApotheosisData, GameState } from "@elysium/types";
/**
* Total number of echo upgrades all must be purchased to unlock Apotheosis.
*/
const totalEchoUpgrades = defaultTranscendenceUpgrades.length;
/**
* Returns true when the player is eligible to achieve Apotheosis:
* all Transcendence echo upgrades must be purchased.
* @param state - The current game state.
* @returns Whether the player is eligible for Apotheosis.
*/
const isEligibleForApotheosis = (state: GameState): boolean => {
const purchasedIds = state.transcendence?.purchasedUpgradeIds ?? [];
return (
purchasedIds.length >= totalEchoUpgrades
&& defaultTranscendenceUpgrades.every((u) => {
return purchasedIds.includes(u.id);
})
);
};
/**
* Builds the updated 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.
* @param currentState - The current game state before apotheosis.
* @param characterName - The character name to carry over.
* @returns The updated game state and apotheosis data.
*/
const buildPostApotheosisState = (
currentState: GameState,
characterName: string,
): { updatedApotheosisData: ApotheosisData; updatedState: GameState } => {
const apotheosisCount = (currentState.apotheosis?.count ?? 0) + 1;
const updatedApotheosisData: ApotheosisData = { count: apotheosisCount };
const freshState = initialGameState(currentState.player, characterName);
const updatedState: 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: updatedApotheosisData,
// Story chapter progress is permanent — survives all resets
...currentState.story
? { story: currentState.story }
: {},
};
return { updatedApotheosisData, updatedState };
};
export { buildPostApotheosisState, isEligibleForApotheosis };
+114 -37
View File
@@ -1,36 +1,77 @@
/**
* @file Daily challenge generation and progress tracking utilities.
* @copyright nhcarrigan
* @license Naomi's Public License
* @author Naomi Carrigan
*/
import { dailyChallengeTemplates } from "../data/dailyChallenges.js";
import type { import type {
DailyChallenge, DailyChallenge,
DailyChallengeState, DailyChallengeState,
DailyChallengeType, DailyChallengeType,
GameState, GameState,
} from "@elysium/types"; } from "@elysium/types";
import { DAILY_CHALLENGE_TEMPLATES } from "../data/dailyChallenges.js";
// Use the server's PST/PDT timezone so challenges roll over at PST midnight /**
const getTodayString = (): string => * Returns today's date string in PST/PDT so challenges roll over at midnight Pacific.
new Intl.DateTimeFormat("en-CA", { timeZone: "America/Los_Angeles" }).format(new Date()); * @returns A date string in YYYY-MM-DD format.
*/
const getTodayString = (): string => {
return new Intl.DateTimeFormat("en-CA", {
timeZone: "America/Los_Angeles",
}).format(new Date());
};
/** Simple deterministic pseudo-random based on a numeric seed. */ /**
* Simple deterministic pseudo-random number based on a numeric seed.
* @param seed - The numeric seed value.
* @returns A pseudo-random float in [0, 1).
*/
const seededRandom = (seed: number): number => { const seededRandom = (seed: number): number => {
const x = Math.sin(seed + 1) * 10_000; const x = Math.sin(seed + 1) * 10_000;
return x - Math.floor(x); return x - Math.floor(x);
}; };
/** Converts a date string into a stable numeric seed. */ /**
const dateSeed = (dateStr: string): number => * Converts a date string into a stable numeric seed.
dateStr.split("").reduce((acc, char, i) => acc + char.charCodeAt(0) * (i + 1), 0); * @param dateString - A date string such as "2025-01-01".
* @returns A numeric seed derived from the date characters.
*/
const dateSeed = (dateString: string): number => {
let accumulator = 0;
let index = 0;
for (const char of dateString) {
// eslint-disable-next-line capitalized-comments -- v8 ignore
/* v8 ignore next -- @preserve */
const charValue = char.codePointAt(0) ?? 0;
const contribution = charValue * (index + 1);
accumulator = accumulator + contribution;
index = index + 1;
}
return accumulator;
};
/** Deterministically shuffles an array using a numeric seed. */ /**
const shuffleWithSeed = <T>(arr: T[], seed: number): T[] => { * Deterministically shuffles an array using a numeric seed (Fisher-Yates).
const result = [...arr]; * @param array - The array to shuffle.
for (let i = result.length - 1; i > 0; i--) { * @param seed - The seed controlling shuffle order.
const j = Math.floor(seededRandom(seed + i) * (i + 1)); * @returns A new shuffled array.
[result[i], result[j]] = [result[j]!, result[i]!]; */
const shuffleWithSeed = <T>(array: Array<T>, seed: number): Array<T> => {
const result = [ ...array ];
for (let index = result.length - 1; index > 0; index = index - 1) {
const swapIndex = Math.floor(seededRandom(seed + index) * (index + 1));
/* eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- index and swapIndex are always in bounds */
const fromSwap = result[swapIndex]!;
/* eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- index and swapIndex are always in bounds */
const fromIndex = result[index]!;
result[index] = fromSwap;
result[swapIndex] = fromIndex;
} }
return result; return result;
}; };
const CHALLENGE_TYPES: DailyChallengeType[] = [ const challengeTypes: Array<DailyChallengeType> = [
"clicks", "clicks",
"bossesDefeated", "bossesDefeated",
"questsCompleted", "questsCompleted",
@@ -40,45 +81,64 @@ const CHALLENGE_TYPES: DailyChallengeType[] = [
/** /**
* Generates 3 daily challenges for the given date string, deterministically. * Generates 3 daily challenges for the given date string, deterministically.
* Picks one challenge from 3 different randomly-selected types. * Picks one challenge from 3 different randomly-selected types.
* @param dateString - The date string (YYYY-MM-DD) to generate challenges for.
* @returns An array of 3 DailyChallenge objects.
*/ */
export const generateDailyChallenges = (dateStr: string): DailyChallenge[] => { const generateDailyChallenges = (
const seed = dateSeed(dateStr); dateString: string,
const selectedTypes = shuffleWithSeed([...CHALLENGE_TYPES], seed).slice(0, 3); ): Array<DailyChallenge> => {
const seed = dateSeed(dateString);
const selectedTypes = shuffleWithSeed([ ...challengeTypes ], seed).
slice(0, 3);
return selectedTypes.map((type, index) => { return selectedTypes.map((type, index) => {
const templates = DAILY_CHALLENGE_TEMPLATES.filter((t) => t.type === type); const templates = dailyChallengeTemplates.filter((template) => {
const templateIndex = Math.floor(seededRandom(seed + index * 100) * templates.length); return template.type === type;
});
const indexOffset = index * 100;
const templateIndex = Math.floor(
seededRandom(seed + indexOffset) * templates.length,
);
/* eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- templateIndex is always valid: seededRandom returns [0,1) so floor * length is always in bounds */
const template = templates[templateIndex]!; const template = templates[templateIndex]!;
return { return {
id: `${dateStr}_${type}`, completed: false,
type: template.type, id: `${dateString}_${type}`,
label: template.label, label: template.label,
target: template.target, progress: 0,
progress: 0,
completed: false,
rewardCrystals: template.rewardCrystals, rewardCrystals: template.rewardCrystals,
target: template.target,
type: template.type,
}; };
}); });
}; };
/** /**
* Returns the current daily challenge state, generating fresh challenges if * Returns the current daily challenge state, generating fresh challenges when
* the stored date doesn't match today (i.e. a new day has begun). * the stored date does not match today.
* @param state - The current game state.
* @returns The current or freshly-generated DailyChallengeState.
*/ */
export const getOrResetDailyChallenges = (state: GameState): DailyChallengeState => { const getOrResetDailyChallenges = (
state: GameState,
): DailyChallengeState => {
const today = getTodayString(); const today = getTodayString();
if (state.dailyChallenges?.date === today) { if (state.dailyChallenges?.date === today) {
return state.dailyChallenges; return state.dailyChallenges;
} }
return { date: today, challenges: generateDailyChallenges(today) }; return { challenges: generateDailyChallenges(today), date: today };
}; };
/** /**
* Increments progress for challenges matching the given type. * Increments progress for challenges matching the given type.
* Returns the updated challenge state and total crystals awarded for newly completed challenges. * Returns the updated challenge state and total crystals awarded for newly completed challenges.
* @param challengeState - The current daily challenge state.
* @param type - The challenge type to increment progress for.
* @param amount - The amount to increment progress by.
* @returns The updated challenge state and total crystals awarded.
*/ */
export const updateChallengeProgress = ( const updateChallengeProgress = (
challengeState: DailyChallengeState, challengeState: DailyChallengeState,
type: DailyChallengeType, type: DailyChallengeType,
amount: number, amount: number,
@@ -88,16 +148,33 @@ export const updateChallengeProgress = (
const updatedChallenges: DailyChallengeState = { const updatedChallenges: DailyChallengeState = {
...challengeState, ...challengeState,
challenges: challengeState.challenges.map((challenge) => { challenges: challengeState.challenges.map((challenge) => {
if (challenge.type !== type || challenge.completed) return challenge; if (challenge.type !== type || challenge.completed) {
return challenge;
}
const newProgress = Math.min(challenge.progress + amount, challenge.target); const updatedProgress = Math.min(
const nowCompleted = newProgress >= challenge.target; challenge.progress + amount,
challenge.target,
);
const nowCompleted = updatedProgress >= challenge.target;
if (nowCompleted) crystalsAwarded += challenge.rewardCrystals; if (nowCompleted) {
crystalsAwarded = crystalsAwarded + challenge.rewardCrystals;
}
return { ...challenge, progress: newProgress, completed: nowCompleted }; return {
...challenge,
completed: nowCompleted,
progress: updatedProgress,
};
}), }),
}; };
return { updatedChallenges, crystalsAwarded }; return { crystalsAwarded, updatedChallenges };
};
export {
generateDailyChallenges,
getOrResetDailyChallenges,
updateChallengeProgress,
}; };
+74 -33
View File
@@ -1,49 +1,78 @@
export interface DiscordTokenResponse { /**
access_token: string; * @file Discord OAuth helpers for token exchange, user fetching, and URL building.
token_type: string; * @copyright nhcarrigan
expires_in: number; * @license Naomi's Public License
* @author Naomi Carrigan
*/
/* eslint-disable @typescript-eslint/naming-convention -- Discord API requires snake_case fields and HTTP headers require Pascal-Case */
interface DiscordTokenResponse {
access_token: string;
token_type: string;
expires_in: number;
refresh_token: string; refresh_token: string;
scope: string; scope: string;
} }
export interface DiscordUser { interface DiscordUser {
id: string; id: string;
username: string; username: string;
discriminator: string; discriminator: string;
avatar: string | null; avatar: string | null;
} }
export const exchangeCode = async (code: string): Promise<DiscordTokenResponse> => { /**
const clientId = process.env["DISCORD_CLIENT_ID"]; * Exchanges a Discord OAuth authorisation code for an access token.
const clientSecret = process.env["DISCORD_CLIENT_SECRET"]; * @param code - The authorisation code received from Discord's OAuth callback.
const redirectUri = process.env["DISCORD_REDIRECT_URI"]; * @returns The Discord token response containing the access token.
* @throws {Error} If OAuth environment variables are missing or the exchange fails.
*/
const exchangeCode = async(
code: string,
): Promise<DiscordTokenResponse> => {
const clientId = process.env.DISCORD_CLIENT_ID;
const clientSecret = process.env.DISCORD_CLIENT_SECRET;
const redirectUri = process.env.DISCORD_REDIRECT_URI;
if (!clientId || !clientSecret || !redirectUri) { if (
clientId === undefined || clientId === ""
|| clientSecret === undefined || clientSecret === ""
|| redirectUri === undefined || redirectUri === ""
) {
throw new Error("Discord OAuth environment variables are required"); throw new Error("Discord OAuth environment variables are required");
} }
const params = new URLSearchParams({ const parameters = new URLSearchParams({
client_id: clientId, client_id: clientId,
client_secret: clientSecret, client_secret: clientSecret,
grant_type: "authorization_code", code: code,
code, grant_type: "authorization_code",
redirect_uri: redirectUri, redirect_uri: redirectUri,
}); });
const response = await fetch("https://discord.com/api/v10/oauth2/token", { const response = await fetch("https://discord.com/api/v10/oauth2/token", {
method: "POST", body: parameters.toString(),
headers: { "Content-Type": "application/x-www-form-urlencoded" }, headers: { "Content-Type": "application/x-www-form-urlencoded" },
body: params.toString(), method: "POST",
}); });
if (!response.ok) { if (!response.ok) {
throw new Error(`Discord token exchange failed: ${response.statusText}`); throw new Error(`Discord token exchange failed: ${response.statusText}`);
} }
return response.json() as Promise<DiscordTokenResponse>; /* eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- Response JSON matches DiscordTokenResponse shape */
return await (response.json() as Promise<DiscordTokenResponse>);
}; };
export const fetchDiscordUser = async (accessToken: string): Promise<DiscordUser> => { /**
* Fetches the Discord user profile for the given access token.
* @param accessToken - A valid Discord OAuth access token.
* @returns The Discord user object.
* @throws {Error} If the user fetch fails.
*/
const fetchDiscordUser = async(
accessToken: string,
): Promise<DiscordUser> => {
const response = await fetch("https://discord.com/api/v10/users/@me", { const response = await fetch("https://discord.com/api/v10/users/@me", {
headers: { Authorization: `Bearer ${accessToken}` }, headers: { Authorization: `Bearer ${accessToken}` },
}); });
@@ -52,23 +81,35 @@ export const fetchDiscordUser = async (accessToken: string): Promise<DiscordUser
throw new Error(`Discord user fetch failed: ${response.statusText}`); throw new Error(`Discord user fetch failed: ${response.statusText}`);
} }
return response.json() as Promise<DiscordUser>; /* eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- Response JSON matches DiscordUser shape */
return await (response.json() as Promise<DiscordUser>);
}; };
export const buildOAuthUrl = (): string => { /**
const clientId = process.env["DISCORD_CLIENT_ID"]; * Builds the Discord OAuth authorisation URL.
const redirectUri = process.env["DISCORD_REDIRECT_URI"]; * @returns The full OAuth URL to redirect the user to.
* @throws {Error} If OAuth environment variables are missing.
*/
const buildOAuthUrl = (): string => {
const clientId = process.env.DISCORD_CLIENT_ID;
const redirectUri = process.env.DISCORD_REDIRECT_URI;
if (!clientId || !redirectUri) { if (
clientId === undefined || clientId === ""
|| redirectUri === undefined || redirectUri === ""
) {
throw new Error("Discord OAuth environment variables are required"); throw new Error("Discord OAuth environment variables are required");
} }
const params = new URLSearchParams({ const parameters = new URLSearchParams({
client_id: clientId, client_id: clientId,
redirect_uri: redirectUri, redirect_uri: redirectUri,
response_type: "code", response_type: "code",
scope: "identify", scope: "identify",
}); });
return `https://discord.com/api/oauth2/authorize?${params.toString()}`; return `https://discord.com/api/oauth2/authorize?${parameters.toString()}`;
}; };
export type { DiscordTokenResponse, DiscordUser };
export { buildOAuthUrl, exchangeCode, fetchDiscordUser };
+50 -23
View File
@@ -1,42 +1,65 @@
import { createHmac } from "crypto"; /**
* @file JWT token signing and verification utilities.
* @copyright nhcarrigan
* @license Naomi's Public License
* @author Naomi Carrigan
*/
import { createHmac } from "node:crypto";
interface JwtPayload { interface JwtPayload {
discordId: string; discordId: string;
iat: number; iat: number;
exp: number; exp: number;
} }
const base64UrlEncode = (data: string): string => const base64UrlEncode = (data: string): string => {
Buffer.from(data).toString("base64url"); return Buffer.from(data).toString("base64url");
};
const base64UrlDecode = (data: string): string => const base64UrlDecode = (data: string): string => {
Buffer.from(data, "base64url").toString("utf8"); return Buffer.from(data, "base64url").toString("utf8");
};
export const signToken = (discordId: string): string => { /**
const secret = process.env["JWT_SECRET"]; * Signs a JWT token for the given Discord ID.
if (!secret) { * @param discordId - The Discord user ID to encode in the token.
* @returns A signed JWT string valid for 30 days.
* @throws {Error} If the JWT_SECRET environment variable is not set.
*/
const signToken = (discordId: string): string => {
const secret = process.env.JWT_SECRET;
if (secret === undefined || secret === "") {
throw new Error("JWT_SECRET environment variable is required"); throw new Error("JWT_SECRET environment variable is required");
} }
const header = base64UrlEncode(JSON.stringify({ alg: "HS256", typ: "JWT" })); const header = base64UrlEncode(JSON.stringify({ alg: "HS256", typ: "JWT" }));
// 30 days expiry
const thirtyDaysInSeconds = 60 * 60 * 24 * 30;
const payload = base64UrlEncode( const payload = base64UrlEncode(
JSON.stringify({ JSON.stringify({
discordId, discordId: discordId,
iat: Math.floor(Date.now() / 1000), exp: Math.floor(Date.now() / 1000) + thirtyDaysInSeconds,
exp: Math.floor(Date.now() / 1000) + 60 * 60 * 24 * 30, // 30 days iat: Math.floor(Date.now() / 1000),
}), }),
); );
const signature = createHmac("sha256", secret) const signature = createHmac("sha256", secret).
.update(`${header}.${payload}`) update(`${header}.${payload}`).
.digest("base64url"); digest("base64url");
return `${header}.${payload}.${signature}`; return `${header}.${payload}.${signature}`;
}; };
export const verifyToken = (token: string): JwtPayload => { /**
const secret = process.env["JWT_SECRET"]; * Verifies a JWT token and returns the decoded payload.
if (!secret) { * @param token - The JWT string to verify.
* @returns The decoded JWT payload containing discordId, iat, and exp.
* @throws {Error} If the JWT_SECRET is missing, the token is malformed, the
* signature is invalid, or the token has expired.
*/
const verifyToken = (token: string): JwtPayload => {
const secret = process.env.JWT_SECRET;
if (secret === undefined || secret === "") {
throw new Error("JWT_SECRET environment variable is required"); throw new Error("JWT_SECRET environment variable is required");
} }
@@ -45,16 +68,18 @@ export const verifyToken = (token: string): JwtPayload => {
throw new Error("Invalid token format"); throw new Error("Invalid token format");
} }
const [header, payload, signature] = parts as [string, string, string]; /* eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- Array destructure of known-length tuple */
const [ header, payload, signature ] = parts as [string, string, string];
const expectedSignature = createHmac("sha256", secret) const expectedSignature = createHmac("sha256", secret).
.update(`${header}.${payload}`) update(`${header}.${payload}`).
.digest("base64url"); digest("base64url");
if (signature !== expectedSignature) { if (signature !== expectedSignature) {
throw new Error("Invalid token signature"); throw new Error("Invalid token signature");
} }
/* eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- Parsed JSON from trusted base64url payload */
const decoded = JSON.parse(base64UrlDecode(payload)) as JwtPayload; const decoded = JSON.parse(base64UrlDecode(payload)) as JwtPayload;
if (decoded.exp < Math.floor(Date.now() / 1000)) { if (decoded.exp < Math.floor(Date.now() / 1000)) {
@@ -63,3 +88,5 @@ export const verifyToken = (token: string): JwtPayload => {
return decoded; return decoded;
}; };
export { signToken, verifyToken };
+54 -28
View File
@@ -1,24 +1,42 @@
/**
* @file Offline earnings calculator for gold and essence accrued while logged out.
* @copyright nhcarrigan
* @license Naomi's Public License
* @author Naomi Carrigan
*/
/* eslint-disable max-lines-per-function -- Offline earnings calculation requires iterating all adventurers with multi-step math */
import type { GameState } from "@elysium/types"; import type { GameState } from "@elysium/types";
const MAX_OFFLINE_SECONDS = 8 * 60 * 60; // 8 hours /**
* Maximum offline accrual cap: 8 hours.
*/
const maxOfflineSeconds = 8 * 60 * 60;
/** /**
* Calculates the gold and essence earned whilst the player was offline. * Calculates the gold and essence earned whilst the player was offline.
* Capped at 8 hours to prevent exploit via system clock manipulation. * Capped at 8 hours to prevent exploit via system clock manipulation.
* Applies the same multipliers as the client-side tick engine. * Applies the same multipliers as the client-side tick engine.
* @param state - The current game state to calculate offline earnings from.
* @param nowMs - The current timestamp in milliseconds.
* @returns The gold, essence, and elapsed seconds earned offline.
*/ */
export const calculateOfflineEarnings = ( const calculateOfflineEarnings = (
state: GameState, state: GameState,
nowMs: number, nowMs: number,
): { offlineGold: number; offlineEssence: number; offlineSeconds: number } => { ): { offlineGold: number; offlineEssence: number; offlineSeconds: number } => {
const elapsedSeconds = Math.min( const elapsedSeconds = Math.min(
(nowMs - state.lastTickAt) / 1000, (nowMs - state.lastTickAt) / 1000,
MAX_OFFLINE_SECONDS, maxOfflineSeconds,
); );
const equipmentGoldMultiplier = (state.equipment ?? []) // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- Defensive check for runtime nullable fields
.filter((e) => e.equipped) const equipmentGoldMultiplier = (state.equipment ?? []).
.reduce((mult, e) => mult * (e.bonus.goldMultiplier ?? 1), 1); filter((item) => {
return item.equipped;
}).
reduce((mult, item) => {
return mult * (item.bonus.goldMultiplier ?? 1);
}, 1);
const runestonesIncome = state.prestige.runestonesIncomeMultiplier ?? 1; const runestonesIncome = state.prestige.runestonesIncomeMultiplier ?? 1;
const runestonesEssence = state.prestige.runestonesEssenceMultiplier ?? 1; const runestonesEssence = state.prestige.runestonesEssenceMultiplier ?? 1;
@@ -31,36 +49,44 @@ export const calculateOfflineEarnings = (
continue; continue;
} }
const upgradeMultiplier = state.upgrades const upgradeMultiplier = state.upgrades.
.filter( filter((upgrade) => {
(u) => const isGlobal = upgrade.target === "global";
u.purchased && const isForAdventurer
(u.target === "global" || = upgrade.target === "adventurer"
(u.target === "adventurer" && u.adventurerId === adventurer.id)), && upgrade.adventurerId === adventurer.id;
) const affectsAdventurer = isGlobal || isForAdventurer;
.reduce((mult, u) => mult * u.multiplier, 1); return upgrade.purchased && affectsAdventurer;
}).
reduce((mult, upgrade) => {
return mult * upgrade.multiplier;
}, 1);
const prestige = state.prestige.productionMultiplier; const prestige = state.prestige.productionMultiplier;
goldPerSecond += const goldContribution
adventurer.goldPerSecond * = adventurer.goldPerSecond
adventurer.count * * adventurer.count
upgradeMultiplier * * upgradeMultiplier
prestige * * prestige
runestonesIncome * * runestonesIncome
equipmentGoldMultiplier; * equipmentGoldMultiplier;
goldPerSecond = goldPerSecond + goldContribution;
essencePerSecond += const essenceContribution
adventurer.essencePerSecond * = adventurer.essencePerSecond
adventurer.count * * adventurer.count
upgradeMultiplier * * upgradeMultiplier
prestige * * prestige
runestonesEssence; * runestonesEssence;
essencePerSecond = essencePerSecond + essenceContribution;
} }
return { return {
offlineGold: goldPerSecond * elapsedSeconds,
offlineEssence: essencePerSecond * elapsedSeconds, offlineEssence: essencePerSecond * elapsedSeconds,
offlineGold: goldPerSecond * elapsedSeconds,
offlineSeconds: elapsedSeconds, offlineSeconds: elapsedSeconds,
}; };
}; };
export { calculateOfflineEarnings };
+194 -65
View File
@@ -1,117 +1,246 @@
/**
* @file Prestige eligibility checks, runestone calculations, and post-prestige state builder.
* @copyright nhcarrigan
* @license Naomi's Public License
* @author Naomi Carrigan
*/
/* eslint-disable max-lines-per-function -- buildPostPrestigeState requires constructing a large composite state object */
import { initialGameState } from "../data/initialState.js";
import { defaultPrestigeUpgrades } from "../data/prestigeUpgrades.js";
import type { import type {
GameState, GameState,
PrestigeData, PrestigeData,
PrestigeUpgradeCategory, PrestigeUpgradeCategory,
} from "@elysium/types"; } from "@elysium/types";
import { INITIAL_GAME_STATE } from "../data/initialState.js";
import { DEFAULT_PRESTIGE_UPGRADES } from "../data/prestigeUpgrades.js";
const BASE_PRESTIGE_GOLD_THRESHOLD = 1_000_000; const basePrestigeGoldThreshold = 1_000_000;
const THRESHOLD_SCALE_FACTOR = 5; const thresholdScaleFactor = 5;
const RUNESTONES_PER_PRESTIGE_LEVEL = 10; const runestonesPerPrestigeLevel = 10;
const MILESTONE_INTERVAL = 5; const milestoneInterval = 5;
const MILESTONE_RUNESTONES_PER_INTERVAL = 25; const milestoneRunestonesPerInterval = 25;
/** /**
* Calculates the gold threshold required for the next prestige. * Calculates the gold threshold required for the next prestige.
* Formula: BASE * SCALE_FACTOR^prestigeCount each prestige makes the next threshold harder. * Formula: BASE * SCALE_FACTOR^prestigeCount each prestige makes the next threshold harder.
* @param prestigeCount - The current number of prestiges completed.
* @param thresholdMultiplier - An optional echo-upgrade multiplier applied to the threshold.
* @returns The gold amount required to prestige.
*/ */
export const calculatePrestigeThreshold = (prestigeCount: number): number => const calculatePrestigeThreshold = (
BASE_PRESTIGE_GOLD_THRESHOLD * Math.pow(THRESHOLD_SCALE_FACTOR, prestigeCount); prestigeCount: number,
thresholdMultiplier = 1,
): number => {
return (
basePrestigeGoldThreshold
* Math.pow(thresholdScaleFactor, prestigeCount)
* thresholdMultiplier
);
};
export const isEligibleForPrestige = (state: GameState): boolean => /**
state.player.totalGoldEarned >= calculatePrestigeThreshold(state.prestige.count); * Returns true if the player has earned enough gold to prestige.
* @param state - The current game state.
* @returns Whether the player is eligible for a prestige reset.
*/
const isEligibleForPrestige = (state: GameState): boolean => {
const thresholdMultiplier
= state.transcendence?.echoPrestigeThresholdMultiplier ?? 1;
return (
state.player.totalGoldEarned
>= calculatePrestigeThreshold(state.prestige.count, thresholdMultiplier)
);
};
const getCategoryMultiplier = ( const getCategoryMultiplier = (
purchasedUpgradeIds: string[], purchasedUpgradeIds: Array<string>,
category: PrestigeUpgradeCategory, category: PrestigeUpgradeCategory,
): number => ): number => {
DEFAULT_PRESTIGE_UPGRADES.filter( return defaultPrestigeUpgrades.filter((upgrade) => {
(u) => u.category === category && purchasedUpgradeIds.includes(u.id), const matchesCategory = upgrade.category === category;
).reduce((mult, u) => mult * u.multiplier, 1); const isPurchased = purchasedUpgradeIds.includes(upgrade.id);
return matchesCategory && isPurchased;
}).reduce((mult, upgrade) => {
return mult * upgrade.multiplier;
}, 1);
};
export const computeRunestoneMultipliers = ( /**
purchasedUpgradeIds: string[], * Computes all four runestone multipliers from the purchased upgrade IDs.
* @param purchasedUpgradeIds - The array of purchased prestige upgrade IDs.
* @returns An object containing all four runestone multiplier values.
*/
const computeRunestoneMultipliers = (
purchasedUpgradeIds: Array<string>,
): { ): {
runestonesIncomeMultiplier: number; runestonesIncomeMultiplier: number;
runestonesClickMultiplier: number; runestonesClickMultiplier: number;
runestonesEssenceMultiplier: number; runestonesEssenceMultiplier: number;
runestonesCrystalMultiplier: number; runestonesCrystalMultiplier: number;
} => ({ } => {
runestonesIncomeMultiplier: getCategoryMultiplier(purchasedUpgradeIds, "income"), return {
runestonesClickMultiplier: getCategoryMultiplier(purchasedUpgradeIds, "click"), runestonesClickMultiplier: getCategoryMultiplier(
runestonesEssenceMultiplier: getCategoryMultiplier(purchasedUpgradeIds, "essence"), purchasedUpgradeIds,
runestonesCrystalMultiplier: getCategoryMultiplier(purchasedUpgradeIds, "crystals"), "click",
}); ),
runestonesCrystalMultiplier: getCategoryMultiplier(
purchasedUpgradeIds,
"crystals",
),
runestonesEssenceMultiplier: getCategoryMultiplier(
purchasedUpgradeIds,
"essence",
),
runestonesIncomeMultiplier: getCategoryMultiplier(
purchasedUpgradeIds,
"income",
),
};
};
interface RunestoneParameters {
totalGoldEarned: number;
prestigeCount: number;
purchasedUpgradeIds: Array<string>;
echoRunestoneMultiplier?: number;
}
/** /**
* Calculates how many runestones the player earns from a prestige. * Calculates how many runestones the player earns from a prestige.
* Formula: floor(sqrt(totalGoldEarned / threshold)) * RUNESTONES_PER_PRESTIGE_LEVEL * runestoneMultiplier * Formula: floor(sqrt(totalGoldEarned / threshold)) * RUNESTONES_PER_PRESTIGE_LEVEL * runestoneMultiplier.
* @param parameters - The parameters for the runestone calculation.
* @param parameters.totalGoldEarned - The total gold earned in the current run.
* @param parameters.prestigeCount - The current prestige count.
* @param parameters.purchasedUpgradeIds - The purchased prestige upgrade IDs.
* @param parameters.echoRunestoneMultiplier - An optional echo-upgrade multiplier.
* @returns The number of runestones earned.
*/ */
export const calculateRunestones = ( const calculateRunestones = (parameters: RunestoneParameters): number => {
totalGoldEarned: number, const {
prestigeCount: number, totalGoldEarned,
purchasedUpgradeIds: string[], prestigeCount,
): number => { purchasedUpgradeIds,
echoRunestoneMultiplier = 1,
} = parameters;
const threshold = calculatePrestigeThreshold(prestigeCount); const threshold = calculatePrestigeThreshold(prestigeCount);
const base = const base
Math.floor(Math.sqrt(totalGoldEarned / threshold)) * RUNESTONES_PER_PRESTIGE_LEVEL; = Math.floor(Math.sqrt(totalGoldEarned / threshold))
const runestoneMult = getCategoryMultiplier(purchasedUpgradeIds, "runestones"); * runestonesPerPrestigeLevel;
return Math.floor(base * runestoneMult); const runestoneMult = getCategoryMultiplier(
purchasedUpgradeIds,
"runestones",
);
return Math.floor(base * runestoneMult * echoRunestoneMultiplier);
}; };
/** /**
* Calculates the new prestige production multiplier. * Calculates the new prestige production multiplier.
* Formula: 1.15^prestigeCount exponential scaling per prestige. * Formula: 1.15^prestigeCount exponential scaling per prestige.
* @param prestigeCount - The new prestige count.
* @returns The production multiplier for the new prestige level.
*/ */
export const calculateProductionMultiplier = (prestigeCount: number): number => const calculateProductionMultiplier = (
Math.pow(1.15, prestigeCount); prestigeCount: number,
): number => {
return Math.pow(1.15, prestigeCount);
};
/** /**
* Returns the milestone runestone bonus for the given prestige count. * Returns the milestone runestone bonus for the given prestige count.
* Every MILESTONE_INTERVAL prestiges awards milestone_number * MILESTONE_RUNESTONES_PER_INTERVAL stones. * Every MILESTONE_INTERVAL prestiges awards milestone_number * MILESTONE_RUNESTONES_PER_INTERVAL stones.
* @param prestigeCount - The prestige count after the current prestige.
* @returns The milestone runestone bonus, or 0 if not a milestone prestige.
*/ */
export const calculateMilestoneBonus = (newPrestigeCount: number): number => { const calculateMilestoneBonus = (prestigeCount: number): number => {
if (newPrestigeCount % MILESTONE_INTERVAL !== 0) return 0; if (prestigeCount % milestoneInterval !== 0) {
const milestoneNumber = newPrestigeCount / MILESTONE_INTERVAL; return 0;
return milestoneNumber * MILESTONE_RUNESTONES_PER_INTERVAL; }
const milestoneNumber = prestigeCount / milestoneInterval;
return milestoneNumber * milestoneRunestonesPerInterval;
}; };
/** /**
* Generates the reset game state after a prestige. * Generates the reset game state after a prestige.
* Carries over prestige data and runestones; resets everything else. * Carries over prestige data and runestones; resets everything else.
* @param currentState - The game state at the time of the prestige.
* @param characterName - The player's character name to carry forward.
* @returns The new game state, prestige data, and runestone counts.
*/ */
export const buildPostPrestigeState = ( const buildPostPrestigeState = (
currentState: GameState, currentState: GameState,
characterName: string, characterName: string,
): { newState: GameState; newPrestigeData: PrestigeData; runestonesEarned: number; milestoneRunestones: number } => { ): {
const runestonesEarned = calculateRunestones( prestigeState: GameState;
currentState.player.totalGoldEarned, prestigeData: PrestigeData;
currentState.prestige.count, runestonesEarned: number;
currentState.prestige.purchasedUpgradeIds, milestoneRunestones: number;
); } => {
const newPrestigeCount = currentState.prestige.count + 1; const {
const { purchasedUpgradeIds } = currentState.prestige; autoPrestigeEnabled,
const milestoneRunestones = calculateMilestoneBonus(newPrestigeCount); count: currentPrestigeCount,
const newPrestigeData: PrestigeData = {
count: newPrestigeCount,
runestones: currentState.prestige.runestones + runestonesEarned + milestoneRunestones,
productionMultiplier: calculateProductionMultiplier(newPrestigeCount),
purchasedUpgradeIds, purchasedUpgradeIds,
lastPrestigedAt: Date.now(), runestones: currentRunestones,
} = currentState.prestige;
const echoRunestoneMultiplier
= currentState.transcendence?.echoPrestigeRunestoneMultiplier ?? 1;
const runestonesEarned = calculateRunestones({
echoRunestoneMultiplier: echoRunestoneMultiplier,
prestigeCount: currentPrestigeCount,
purchasedUpgradeIds: purchasedUpgradeIds,
totalGoldEarned: currentState.player.totalGoldEarned,
});
const updatedPrestigeCount = currentPrestigeCount + 1;
const milestoneRunestones = calculateMilestoneBonus(updatedPrestigeCount);
const prestigeData: PrestigeData = {
count: updatedPrestigeCount,
lastPrestigedAt: Date.now(),
productionMultiplier: calculateProductionMultiplier(updatedPrestigeCount),
purchasedUpgradeIds: purchasedUpgradeIds,
runestones:
currentRunestones + runestonesEarned + milestoneRunestones,
...computeRunestoneMultipliers(purchasedUpgradeIds), ...computeRunestoneMultipliers(purchasedUpgradeIds),
...(currentState.prestige.autoPrestigeEnabled !== undefined ...autoPrestigeEnabled === undefined
? { autoPrestigeEnabled: currentState.prestige.autoPrestigeEnabled } ? {}
: {}), : { autoPrestigeEnabled },
}; };
const freshState = INITIAL_GAME_STATE(currentState.player, characterName); const freshState = initialGameState(currentState.player, characterName);
const newState: GameState = { const prestigeState: GameState = {
...freshState, ...freshState,
prestige: newPrestigeData,
lastTickAt: Date.now(), lastTickAt: Date.now(),
prestige: prestigeData,
// Codex lore persists across prestiges — players keep their discovered entries
...currentState.codex === undefined
? {}
: { codex: currentState.codex },
// Transcendence data is permanent — never wiped by prestige
...currentState.transcendence === undefined
? {}
: { transcendence: currentState.transcendence },
// Apotheosis data is eternal — never wiped by prestige
...currentState.apotheosis === undefined
? {}
: { apotheosis: currentState.apotheosis },
// Story chapter progress is permanent — survives all resets
...currentState.story === undefined
? {}
: { story: currentState.story },
}; };
return { newState, newPrestigeData, runestonesEarned, milestoneRunestones }; return {
milestoneRunestones,
prestigeData,
prestigeState,
runestonesEarned,
};
};
export {
buildPostPrestigeState,
calculateMilestoneBonus,
calculatePrestigeThreshold,
calculateProductionMultiplier,
calculateRunestones,
computeRunestoneMultipliers,
isEligibleForPrestige,
}; };
+91
View File
@@ -0,0 +1,91 @@
/**
* @file Title unlock logic for checking and awarding in-game titles.
* @copyright nhcarrigan
* @license Naomi's Public License
* @author Naomi Carrigan
*/
import { gameTitles } from "../data/titles.js";
import type { GameState } from "@elysium/types";
interface TitleCheckParameters {
currentUnlocked: Array<string>;
state: GameState;
guildName: string;
createdAt: number;
}
/**
* Checks which titles the player has newly earned and returns their IDs.
* @param parameters - The parameters for the title check.
* @param parameters.currentUnlocked - The array of already-unlocked title IDs.
* @param parameters.state - The current game state.
* @param parameters.guildName - The player's current guild name.
* @param parameters.createdAt - The timestamp (ms) when the player account was created.
* @returns An array of newly unlocked title IDs.
*/
const checkAndUnlockTitles = (
parameters: TitleCheckParameters,
): Array<string> => {
const { currentUnlocked, state, guildName, createdAt } = parameters;
const metrics: Record<string, number | boolean> = {
achievementsUnlocked: state.achievements.filter((achievement) => {
return achievement.unlockedAt !== null;
}).length,
adventurerTotal: state.adventurers.reduce((sum, adventurer) => {
return sum + adventurer.count;
}, 0),
apotheosisCount: state.apotheosis?.count ?? 0,
bossesDefeated: state.bosses.filter((boss) => {
return boss.status === "defeated";
}).length,
guildFounded: guildName.trim().length > 0,
playedDays: Math.floor((Date.now() - createdAt) / 86_400_000),
prestigeCount: state.prestige.count,
questsCompleted: state.quests.filter((quest) => {
return quest.status === "completed";
}).length,
totalClicks: state.player.totalClicks,
totalGoldEarned: state.player.totalGoldEarned,
transcendenceCount: state.transcendence?.count ?? 0,
};
const newlyUnlocked: Array<string> = [];
for (const title of gameTitles) {
if (currentUnlocked.includes(title.id)) {
continue;
}
const { type, amount } = title.condition;
let earned = false;
if (type === "guildFounded") {
earned = metrics.guildFounded === true;
} else if (amount !== undefined) {
/* eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- metrics[type] is number when type is not guildFounded */
earned = (metrics[type] as number) >= amount;
}
if (earned) {
newlyUnlocked.push(title.id);
}
}
return newlyUnlocked;
};
/**
* Parses the raw unlocked titles value from the database into a string array.
* @param raw - The raw value from the database (may be any type).
* @returns An array of title ID strings.
*/
const parseUnlockedTitles = (raw: unknown): Array<string> => {
if (Array.isArray(raw)) {
return raw.filter((item): item is string => {
return typeof item === "string";
});
}
return [];
};
export { checkAndUnlockTitles, parseUnlockedTitles };
+170
View File
@@ -0,0 +1,170 @@
/**
* @file Transcendence eligibility checks, echo calculations, and post-transcendence state builder.
* @copyright nhcarrigan
* @license Naomi's Public License
* @author Naomi Carrigan
*/
import { initialGameState } from "../data/initialState.js";
import { defaultTranscendenceUpgrades } from "../data/transcendenceUpgrades.js";
import type {
GameState,
TranscendenceData,
TranscendenceUpgradeCategory,
} from "@elysium/types";
/**
* ID of the boss that must be defeated to unlock transcendence.
*/
const finalBossId = "the_absolute_one";
/**
* Base constant used in the echo yield formula.
*/
const echoFormulaConstant = 853;
const getCategoryMultiplier = (
purchasedIds: Array<string>,
category: TranscendenceUpgradeCategory,
): number => {
return defaultTranscendenceUpgrades.filter((upgrade) => {
return upgrade.category === category && purchasedIds.includes(upgrade.id);
}).reduce((mult, upgrade) => {
return mult * upgrade.multiplier;
}, 1);
};
/**
* Computes all transcendence multipliers from the purchased upgrade IDs.
* @param purchasedUpgradeIds - The array of purchased transcendence upgrade IDs.
* @returns An object containing all transcendence multiplier values.
*/
const computeTranscendenceMultipliers = (
purchasedUpgradeIds: Array<string>,
): Omit<TranscendenceData, "count" | "echoes" | "purchasedUpgradeIds"> => {
return {
echoCombatMultiplier: getCategoryMultiplier(
purchasedUpgradeIds,
"combat",
),
echoIncomeMultiplier: getCategoryMultiplier(
purchasedUpgradeIds,
"income",
),
echoMetaMultiplier: getCategoryMultiplier(
purchasedUpgradeIds,
"echo_meta",
),
echoPrestigeRunestoneMultiplier: getCategoryMultiplier(
purchasedUpgradeIds,
"prestige_runestones",
),
echoPrestigeThresholdMultiplier: getCategoryMultiplier(
purchasedUpgradeIds,
"prestige_threshold",
),
};
};
/**
* Returns true when the player is eligible to transcend:
* they must have defeated the final boss at least once.
* @param state - The current game state.
* @returns Whether the player is eligible for transcendence.
*/
const isEligibleForTranscendence = (state: GameState): boolean => {
return state.bosses.some((boss) => {
return boss.id === finalBossId && boss.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.
* @param prestigeCount - The current prestige count.
* @param echoMetaMultiplier - The echo meta multiplier from transcendence upgrades.
* @returns The number of echoes earned.
*/
const calculateEchoes = (
prestigeCount: number,
echoMetaMultiplier: number,
): number => {
const safeCount = Math.max(prestigeCount, 1);
const baseEchoes = echoFormulaConstant / Math.sqrt(safeCount);
return Math.floor(baseEchoes * echoMetaMultiplier);
};
/**
* Builds the permanent-data spread objects that survive a transcendence reset.
* @param currentState - The game state at the time of transcendence.
* @param transcendenceData - The newly-computed transcendence data to carry forward.
* @returns A partial GameState object containing all data that persists through transcendence.
*/
const buildPermanentSpreads = (
currentState: GameState,
transcendenceData: TranscendenceData,
): Partial<GameState> => {
return {
transcendence: transcendenceData,
...currentState.codex === undefined
? {}
: { codex: currentState.codex },
...currentState.apotheosis === undefined
? {}
: { apotheosis: currentState.apotheosis },
...currentState.story === undefined
? {}
: { story: currentState.story },
};
};
/**
* Builds the new game state after a transcendence (nuclear reset).
* Wipes everything except codex, dailyChallenges, and transcendence data.
* @param currentState - The game state at the time of transcendence.
* @param characterName - The player's character name to carry forward.
* @returns The new game state, transcendence data, and echoes earned.
*/
const buildPostTranscendenceState = (
currentState: GameState,
characterName: string,
): {
transcendenceState: GameState;
transcendenceData: 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 updatedCount = (previousTranscendence?.count ?? 0) + 1;
const updatedPurchasedIds = previousTranscendence?.purchasedUpgradeIds ?? [];
const transcendenceData: TranscendenceData = {
count: updatedCount,
echoes: previousEchoes + echoesEarned,
purchasedUpgradeIds: updatedPurchasedIds,
...computeTranscendenceMultipliers(updatedPurchasedIds),
};
const freshState = initialGameState(currentState.player, characterName);
const transcendenceState: GameState = {
...freshState,
lastTickAt: Date.now(),
...buildPermanentSpreads(currentState, transcendenceData),
};
return { echoesEarned, transcendenceData, transcendenceState };
};
export {
buildPostTranscendenceState,
calculateEchoes,
computeTranscendenceMultipliers,
isEligibleForTranscendence,
};
+89
View File
@@ -0,0 +1,89 @@
/**
* @file Discord webhook and role-grant utilities for milestone events.
* @copyright nhcarrigan
* @license Naomi's Public License
* @author Naomi Carrigan
*/
/* eslint-disable @typescript-eslint/naming-convention -- Discord API requires snake_case and Pascal-case header names */
const discordApi = "https://discord.com/api/v10";
/**
* Grants the apotheosis Discord role to the given player if configured.
* Fails silently so role grant errors do not affect the game action.
* @param discordId - The Discord user ID to grant the role to.
* @returns A promise that resolves when the role grant attempt completes.
*/
const grantApotheosisRole = async(discordId: string): Promise<void> => {
const botToken = process.env.DISCORD_BOT_TOKEN;
const guildId = process.env.DISCORD_GUILD_ID;
const roleId = process.env.DISCORD_APOTHEOSIS_ROLE_ID;
if (
botToken === undefined || botToken === ""
|| guildId === undefined || guildId === ""
|| roleId === undefined || roleId === ""
) {
return;
}
try {
await fetch(
`${discordApi}/guilds/${guildId}/members/${discordId}/roles/${roleId}`,
{
headers: { Authorization: `Bot ${botToken}` },
method: "PUT",
},
);
} catch {
// Graceful degradation — role grant failure must not affect the apotheosis
}
};
type MilestoneType = "prestige" | "transcendence" | "apotheosis";
interface MilestoneCounts {
prestige: number;
transcendence: number;
apotheosis: number;
}
const milestoneVerbs: Record<MilestoneType, string> = {
apotheosis: "reached apotheosis",
prestige: "prestiged",
transcendence: "transcended",
};
/**
* Posts a milestone announcement to the configured Discord webhook.
* Fails silently so webhook errors do not affect the game action.
* @param discordId - The Discord user ID of the player.
* @param milestone - The type of milestone reached.
* @param counts - The current prestige, transcendence, and apotheosis counts.
* @returns A promise that resolves when the webhook post attempt completes.
*/
const postMilestoneWebhook = async(
discordId: string,
milestone: MilestoneType,
counts: MilestoneCounts,
): Promise<void> => {
const webhookUrl = process.env.DISCORD_MILESTONE_WEBHOOK;
if (webhookUrl === undefined || webhookUrl === "") {
return;
}
const verb = milestoneVerbs[milestone];
/* eslint-disable-next-line @typescript-eslint/restrict-template-expressions -- counts fields are numbers, intentionally stringified */
const content = `<@${discordId}> has ${verb}~! They are now on Prestige ${counts.prestige}, Transcendence ${counts.transcendence}, Apotheosis ${counts.apotheosis}!`;
try {
await fetch(webhookUrl, {
body: JSON.stringify({ content }),
headers: { "Content-Type": "application/json" },
method: "POST",
});
} catch {
// Graceful degradation — webhook failure must not affect the game action
}
};
export { grantApotheosisRole, postMilestoneWebhook };
+10 -1
View File
@@ -1 +1,10 @@
export type HonoEnv = { Variables: { discordId: string } }; /**
* @file Hono environment type definitions.
* @copyright nhcarrigan
* @license Naomi's Public License
* @author Naomi Carrigan
*/
/* eslint-disable @typescript-eslint/naming-convention -- Variables is required by Hono */
export interface HonoEnvironment {
Variables: { discordId: string };
}
+58
View File
@@ -0,0 +1,58 @@
/* eslint-disable max-lines-per-function -- Test suites naturally have many cases */
import { beforeEach, describe, expect, it, vi } from "vitest";
import { Hono } from "hono";
vi.mock("../../src/services/jwt.js", () => ({
verifyToken: vi.fn(),
}));
describe("authMiddleware", () => {
beforeEach(() => {
vi.resetModules();
});
const makeApp = async () => {
const { authMiddleware } = await import("../../src/middleware/auth.js");
const { verifyToken } = await import("../../src/services/jwt.js");
const app = new Hono<{ Variables: { discordId: string } }>();
app.use("*", authMiddleware);
app.get("/test", (c) => c.json({ discordId: c.get("discordId") }));
return { app, verifyToken };
};
it("returns 401 when Authorization header is missing", async () => {
const { app } = await makeApp();
const res = await app.fetch(new Request("http://localhost/test"));
expect(res.status).toBe(401);
});
it("returns 401 when Authorization header does not start with Bearer", async () => {
const { app } = await makeApp();
const res = await app.fetch(new Request("http://localhost/test", {
headers: { Authorization: "Basic abc123" },
}));
expect(res.status).toBe(401);
});
it("sets discordId in context when token is valid", async () => {
const { app, verifyToken } = await makeApp();
vi.mocked(verifyToken).mockReturnValueOnce({ discordId: "user_123", iat: 0, exp: 9999999999 });
const res = await app.fetch(new Request("http://localhost/test", {
headers: { Authorization: "Bearer valid_token" },
}));
expect(res.status).toBe(200);
const body = await res.json() as { discordId: string };
expect(body.discordId).toBe("user_123");
});
it("returns 401 when verifyToken throws", async () => {
const { app, verifyToken } = await makeApp();
vi.mocked(verifyToken).mockImplementationOnce(() => {
throw new Error("Invalid token");
});
const res = await app.fetch(new Request("http://localhost/test", {
headers: { Authorization: "Bearer bad_token" },
}));
expect(res.status).toBe(401);
});
});
+73
View File
@@ -0,0 +1,73 @@
/* eslint-disable max-lines-per-function -- Test suites naturally have many cases */
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import { Hono } from "hono";
describe("about route", () => {
const mockFetch = vi.fn();
beforeEach(() => {
vi.resetModules();
vi.stubGlobal("fetch", mockFetch);
});
afterEach(() => {
vi.unstubAllGlobals();
mockFetch.mockReset();
});
const makeApp = async () => {
const { aboutRouter } = await import("../../src/routes/about.js");
const app = new Hono();
app.route("/about", aboutRouter);
return app;
};
it("returns releases from a successful fetch", async () => {
const releases = [{ id: 1, name: "v1.0.0", body: "notes" }];
mockFetch.mockResolvedValueOnce({ ok: true, json: () => Promise.resolve(releases) });
const app = await makeApp();
const res = await app.fetch(new Request("http://localhost/about"));
expect(res.status).toBe(200);
const body = await res.json() as { releases: unknown[] };
expect(body.releases).toEqual(releases);
});
it("returns empty releases when fetch is not ok", async () => {
mockFetch.mockResolvedValueOnce({ ok: false });
const app = await makeApp();
const res = await app.fetch(new Request("http://localhost/about"));
expect(res.status).toBe(200);
const body = await res.json() as { releases: unknown[] };
expect(body.releases).toEqual([]);
});
it("returns empty releases when fetch throws", async () => {
mockFetch.mockRejectedValueOnce(new Error("Network error"));
const app = await makeApp();
const res = await app.fetch(new Request("http://localhost/about"));
expect(res.status).toBe(200);
const body = await res.json() as { releases: unknown[] };
expect(body.releases).toEqual([]);
});
it("returns cached releases on second call within TTL", async () => {
const releases = [{ id: 1, name: "v1.0.0", body: "notes" }];
mockFetch.mockResolvedValueOnce({ ok: true, json: () => Promise.resolve(releases) });
const app = await makeApp();
// First call populates cache
await app.fetch(new Request("http://localhost/about"));
// Second call should use cache, not call fetch again
const res = await app.fetch(new Request("http://localhost/about"));
expect(res.status).toBe(200);
expect(mockFetch).toHaveBeenCalledTimes(1);
});
it("includes apiVersion in response", async () => {
mockFetch.mockResolvedValueOnce({ ok: true, json: () => Promise.resolve([]) });
const app = await makeApp();
const res = await app.fetch(new Request("http://localhost/about"));
expect(res.status).toBe(200);
const body = await res.json() as { apiVersion: string };
expect(typeof body.apiVersion).toBe("string");
});
});
+107
View File
@@ -0,0 +1,107 @@
/* eslint-disable max-lines-per-function -- Test suites naturally have many cases */
/* eslint-disable @typescript-eslint/consistent-type-assertions -- Tests build minimal state objects */
import { beforeEach, describe, expect, it, vi } from "vitest";
import { Hono } from "hono";
import type { GameState } from "@elysium/types";
vi.mock("../../src/db/client.js", () => ({
prisma: {
player: { update: vi.fn() },
gameState: { findUnique: vi.fn(), update: vi.fn() },
},
}));
vi.mock("../../src/middleware/auth.js", () => ({
authMiddleware: vi.fn(async (c: { set: (key: string, value: string) => void }, next: () => Promise<void>) => {
c.set("discordId", "test_discord_id");
await next();
}),
}));
vi.mock("../../src/services/webhook.js", () => ({
grantApotheosisRole: vi.fn().mockResolvedValue(undefined),
postMilestoneWebhook: vi.fn().mockResolvedValue(undefined),
}));
const DISCORD_ID = "test_discord_id";
const makeState = (overrides: Partial<GameState> = {}): GameState => ({
player: { discordId: DISCORD_ID, username: "u", discriminator: "0", avatar: null, totalGoldEarned: 0, totalClicks: 0, characterName: "T" },
resources: { gold: 0, essence: 0, crystals: 0, runestones: 0 },
adventurers: [],
upgrades: [],
quests: [],
bosses: [],
equipment: [],
achievements: [],
zones: [],
exploration: { areas: [], materials: [], craftedRecipeIds: [], craftedGoldMultiplier: 1, craftedEssenceMultiplier: 1, craftedClickMultiplier: 1, craftedCombatMultiplier: 1 },
companions: { unlockedCompanionIds: [], activeCompanionId: null },
prestige: { count: 0, runestones: 0, productionMultiplier: 1, purchasedUpgradeIds: [] },
baseClickPower: 1,
lastTickAt: 0,
schemaVersion: 1,
...overrides,
} as GameState);
describe("apotheosis route", () => {
let app: Hono;
let prisma: { player: { update: ReturnType<typeof vi.fn> }; gameState: { findUnique: ReturnType<typeof vi.fn>; update: ReturnType<typeof vi.fn> } };
beforeEach(async () => {
vi.clearAllMocks();
const { apotheosisRouter } = await import("../../src/routes/apotheosis.js");
const { prisma: p } = await import("../../src/db/client.js");
prisma = p as typeof prisma;
app = new Hono();
app.route("/apotheosis", apotheosisRouter);
});
const post = (path = "/apotheosis") =>
app.fetch(new Request(`http://localhost${path}`, { method: "POST" }));
it("returns 404 when no save is found", async () => {
vi.mocked(prisma.gameState.findUnique).mockResolvedValueOnce(null);
const res = await post();
expect(res.status).toBe(404);
});
it("returns 400 when not eligible for apotheosis", async () => {
// State without all transcendence upgrades purchased
const state = makeState({
transcendence: {
count: 1, echoes: 0, purchasedUpgradeIds: [],
echoIncomeMultiplier: 1, echoCombatMultiplier: 1,
echoPrestigeThresholdMultiplier: 1, echoPrestigeRunestoneMultiplier: 1, echoMetaMultiplier: 1,
},
});
vi.mocked(prisma.gameState.findUnique).mockResolvedValueOnce({ state } as never);
const res = await post();
expect(res.status).toBe(400);
});
it("returns apotheosis count on success", async () => {
// Need all 15 transcendence upgrades purchased for eligibility
const allUpgradeIds = [
"echo_income_1", "echo_income_2", "echo_income_3", "echo_income_4", "echo_income_5",
"echo_combat_1", "echo_combat_2", "echo_combat_3",
"echo_prestige_threshold_1", "echo_prestige_threshold_2",
"echo_prestige_runestones_1", "echo_prestige_runestones_2",
"echo_meta_1", "echo_meta_2", "echo_meta_3",
];
const state = makeState({
transcendence: {
count: 1, echoes: 0, purchasedUpgradeIds: allUpgradeIds,
echoIncomeMultiplier: 1, echoCombatMultiplier: 1,
echoPrestigeThresholdMultiplier: 1, echoPrestigeRunestoneMultiplier: 1, echoMetaMultiplier: 1,
},
});
vi.mocked(prisma.gameState.findUnique).mockResolvedValueOnce({ state } as never);
vi.mocked(prisma.gameState.update).mockResolvedValueOnce({} as never);
vi.mocked(prisma.player.update).mockResolvedValueOnce({} as never);
const res = await post();
expect(res.status).toBe(200);
const body = await res.json() as { apotheosisCount: number };
expect(body.apotheosisCount).toBe(1);
});
});
+117
View File
@@ -0,0 +1,117 @@
/* eslint-disable max-lines-per-function -- Test suites naturally have many cases */
/* eslint-disable @typescript-eslint/consistent-type-assertions -- Tests build minimal state objects */
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import { Hono } from "hono";
vi.mock("../../src/db/client.js", () => ({
prisma: {
player: {
findUnique: vi.fn(),
create: vi.fn(),
update: vi.fn(),
},
gameState: {
create: vi.fn(),
},
},
}));
vi.mock("../../src/services/discord.js", () => ({
buildOAuthUrl: vi.fn(),
exchangeCode: vi.fn(),
fetchDiscordUser: vi.fn(),
}));
vi.mock("../../src/services/jwt.js", () => ({
signToken: vi.fn().mockReturnValue("test_jwt"),
}));
describe("auth route", () => {
beforeEach(() => {
vi.clearAllMocks();
process.env["CORS_ORIGIN"] = "http://localhost:5173";
});
afterEach(() => {
delete process.env["CORS_ORIGIN"];
});
const makeApp = async () => {
const { authRouter } = await import("../../src/routes/auth.js");
const { buildOAuthUrl, exchangeCode, fetchDiscordUser } = await import("../../src/services/discord.js");
const { prisma } = await import("../../src/db/client.js");
const app = new Hono();
app.route("/auth", authRouter);
return { app, buildOAuthUrl: vi.mocked(buildOAuthUrl), exchangeCode: vi.mocked(exchangeCode), fetchDiscordUser: vi.mocked(fetchDiscordUser), prisma };
};
describe("GET /url", () => {
it("returns the OAuth URL when buildOAuthUrl succeeds", async () => {
const { app, buildOAuthUrl } = await makeApp();
buildOAuthUrl.mockReturnValueOnce("https://discord.com/oauth2/authorize?...");
const res = await app.fetch(new Request("http://localhost/auth/url"));
expect(res.status).toBe(200);
const body = await res.json() as { url: string };
expect(body.url).toContain("discord.com");
});
it("returns 500 when buildOAuthUrl throws", async () => {
const { app, buildOAuthUrl } = await makeApp();
buildOAuthUrl.mockImplementationOnce(() => { throw new Error("Missing env"); });
const res = await app.fetch(new Request("http://localhost/auth/url"));
expect(res.status).toBe(500);
});
});
describe("GET /callback", () => {
it("returns 400 when code parameter is missing", async () => {
const { app } = await makeApp();
const res = await app.fetch(new Request("http://localhost/auth/callback"));
expect(res.status).toBe(400);
});
it("redirects with isNew=true for a new user", async () => {
const { app, exchangeCode, fetchDiscordUser, prisma } = await makeApp();
exchangeCode.mockResolvedValueOnce({ access_token: "token" });
fetchDiscordUser.mockResolvedValueOnce({ id: "new_user", username: "Newbie", discriminator: "0", avatar: null });
vi.mocked(prisma.player.findUnique).mockResolvedValueOnce(null);
const createdPlayer = {
discordId: "new_user", username: "Newbie", discriminator: "0", avatar: null,
characterName: "Newbie", createdAt: 0, lastSavedAt: 0,
totalGoldEarned: 0, totalClicks: 0, lifetimeGoldEarned: 0, lifetimeClicks: 0,
lifetimeBossesDefeated: 0, lifetimeQuestsCompleted: 0,
lifetimeAdventurersRecruited: 0, lifetimeAchievementsUnlocked: 0,
};
vi.mocked(prisma.player.create).mockResolvedValueOnce(createdPlayer as never);
vi.mocked(prisma.gameState.create).mockResolvedValueOnce({} as never);
const res = await app.fetch(new Request("http://localhost/auth/callback?code=auth_code"));
expect(res.status).toBe(302);
const location = res.headers.get("Location") ?? "";
expect(location).toContain("isNew=true");
expect(location).toContain("token=test_jwt");
});
it("redirects with isNew=false for an existing user", async () => {
const { app, exchangeCode, fetchDiscordUser, prisma } = await makeApp();
exchangeCode.mockResolvedValueOnce({ access_token: "token" });
fetchDiscordUser.mockResolvedValueOnce({ id: "existing_user", username: "OldTimer", discriminator: "0", avatar: null });
const existingPlayer = { discordId: "existing_user", username: "OldTimer", discriminator: "0", avatar: null, characterName: "OldTimer" };
vi.mocked(prisma.player.findUnique).mockResolvedValueOnce(existingPlayer as never);
const updatedPlayer = { ...existingPlayer, discordId: "existing_user" };
vi.mocked(prisma.player.update).mockResolvedValueOnce(updatedPlayer as never);
const res = await app.fetch(new Request("http://localhost/auth/callback?code=auth_code"));
expect(res.status).toBe(302);
const location = res.headers.get("Location") ?? "";
expect(location).toContain("isNew=false");
});
it("redirects with error when callback throws", async () => {
const { app, exchangeCode } = await makeApp();
exchangeCode.mockRejectedValueOnce(new Error("OAuth failed"));
const res = await app.fetch(new Request("http://localhost/auth/callback?code=bad_code"));
expect(res.status).toBe(302);
const location = res.headers.get("Location") ?? "";
expect(location).toContain("error=auth_failed");
});
});
});
+296
View File
@@ -0,0 +1,296 @@
/* eslint-disable max-lines-per-function -- Test suites naturally have many cases */
/* eslint-disable max-lines -- Test suites naturally have many cases */
/* eslint-disable @typescript-eslint/consistent-type-assertions -- Tests build minimal state objects */
import { beforeEach, describe, expect, it, vi } from "vitest";
import { Hono } from "hono";
import type { GameState } from "@elysium/types";
vi.mock("../../src/db/client.js", () => ({
prisma: {
gameState: { findUnique: vi.fn(), update: vi.fn() },
},
}));
vi.mock("../../src/middleware/auth.js", () => ({
authMiddleware: vi.fn(async (c: { set: (key: string, value: string) => void }, next: () => Promise<void>) => {
c.set("discordId", "test_discord_id");
await next();
}),
}));
const DISCORD_ID = "test_discord_id";
const makeBoss = (overrides: Record<string, unknown> = {}) => ({
id: "test_boss",
zoneId: "test_zone",
status: "available",
prestigeRequirement: 0,
currentHp: 100,
maxHp: 100,
damagePerSecond: 1,
goldReward: 50,
essenceReward: 10,
crystalReward: 0,
upgradeRewards: [] as string[],
equipmentRewards: [] as string[],
...overrides,
});
const makeAdventurer = (overrides: Record<string, unknown> = {}) => ({
id: "test_adventurer",
count: 1,
combatPower: 10000, // Very high DPS to guarantee win
level: 10,
unlocked: true,
goldPerSecond: 1,
essencePerSecond: 0,
...overrides,
});
const makeState = (overrides: Partial<GameState> = {}): GameState => ({
player: { discordId: DISCORD_ID, username: "u", discriminator: "0", avatar: null, totalGoldEarned: 0, totalClicks: 0, characterName: "T" },
resources: { gold: 0, essence: 0, crystals: 0, runestones: 0 },
adventurers: [],
upgrades: [],
quests: [],
bosses: [],
equipment: [],
achievements: [],
zones: [],
exploration: { areas: [], materials: [], craftedRecipeIds: [], craftedGoldMultiplier: 1, craftedEssenceMultiplier: 1, craftedClickMultiplier: 1, craftedCombatMultiplier: 1 },
companions: { unlockedCompanionIds: [], activeCompanionId: null },
prestige: { count: 0, runestones: 0, productionMultiplier: 1, purchasedUpgradeIds: [] },
baseClickPower: 1,
lastTickAt: 0,
schemaVersion: 1,
...overrides,
} as GameState);
describe("boss route", () => {
let app: Hono;
let prisma: { gameState: { findUnique: ReturnType<typeof vi.fn>; update: ReturnType<typeof vi.fn> } };
beforeEach(async () => {
vi.clearAllMocks();
const { bossRouter } = await import("../../src/routes/boss.js");
const { prisma: p } = await import("../../src/db/client.js");
prisma = p as typeof prisma;
app = new Hono();
app.route("/boss", bossRouter);
});
const challenge = (body: Record<string, unknown>) =>
app.fetch(new Request("http://localhost/boss/challenge", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(body),
}));
it("returns 400 when bossId is missing", async () => {
const res = await challenge({});
expect(res.status).toBe(400);
});
it("returns 404 when no save is found", async () => {
vi.mocked(prisma.gameState.findUnique).mockResolvedValueOnce(null);
const res = await challenge({ bossId: "test_boss" });
expect(res.status).toBe(404);
});
it("returns 404 when boss is not in state", async () => {
const state = makeState({ bosses: [] });
vi.mocked(prisma.gameState.findUnique).mockResolvedValueOnce({ state } as never);
const res = await challenge({ bossId: "test_boss" });
expect(res.status).toBe(404);
});
it("returns 400 when boss is already defeated", async () => {
const state = makeState({ bosses: [makeBoss({ status: "defeated" })] as GameState["bosses"] });
vi.mocked(prisma.gameState.findUnique).mockResolvedValueOnce({ state } as never);
const res = await challenge({ bossId: "test_boss" });
expect(res.status).toBe(400);
});
it("returns 403 when prestige requirement is not met", async () => {
const state = makeState({
bosses: [makeBoss({ prestigeRequirement: 5 })] as GameState["bosses"],
prestige: { count: 0, runestones: 0, productionMultiplier: 1, purchasedUpgradeIds: [] },
});
vi.mocked(prisma.gameState.findUnique).mockResolvedValueOnce({ state } as never);
const res = await challenge({ bossId: "test_boss" });
expect(res.status).toBe(403);
});
it("returns 400 when party has no adventurers", async () => {
const state = makeState({ bosses: [makeBoss()] as GameState["bosses"], adventurers: [] });
vi.mocked(prisma.gameState.findUnique).mockResolvedValueOnce({ state } as never);
const res = await challenge({ bossId: "test_boss" });
expect(res.status).toBe(400);
});
it("returns won=true when party defeats boss", async () => {
const state = makeState({
bosses: [makeBoss({ currentHp: 100, maxHp: 100, damagePerSecond: 1 })] as GameState["bosses"],
adventurers: [makeAdventurer({ combatPower: 10000, count: 1, level: 10 })] as GameState["adventurers"],
zones: [{ id: "test_zone", status: "locked" }] as GameState["zones"],
});
vi.mocked(prisma.gameState.findUnique).mockResolvedValueOnce({ state } as never);
vi.mocked(prisma.gameState.update).mockResolvedValueOnce({} as never);
const res = await challenge({ bossId: "test_boss" });
expect(res.status).toBe(200);
const body = await res.json() as { won: boolean; rewards: { gold: number } };
expect(body.won).toBe(true);
expect(body.rewards.gold).toBe(50);
});
it("returns won=false when party is defeated", async () => {
const state = makeState({
bosses: [makeBoss({ currentHp: 1_000_000, maxHp: 1_000_000, damagePerSecond: 1_000_000 })] as GameState["bosses"],
// Include an adventurer with count=0 to cover the casualty-loop skip branch
adventurers: [
makeAdventurer({ combatPower: 1, count: 10, level: 1 }),
makeAdventurer({ id: "zero_count_adventurer", combatPower: 0, count: 0, level: 1 }),
] as GameState["adventurers"],
});
vi.mocked(prisma.gameState.findUnique).mockResolvedValueOnce({ state } as never);
vi.mocked(prisma.gameState.update).mockResolvedValueOnce({} as never);
const res = await challenge({ bossId: "test_boss" });
expect(res.status).toBe(200);
const body = await res.json() as { won: boolean; casualties: Array<{ adventurerId: string }> };
expect(body.won).toBe(false);
expect(Array.isArray(body.casualties)).toBe(true);
});
it("skips zone unlock when zone is already unlocked and bossId matches", async () => {
const state = makeState({
bosses: [makeBoss({ currentHp: 100, maxHp: 100, damagePerSecond: 1 })] as GameState["bosses"],
adventurers: [makeAdventurer()] as GameState["adventurers"],
// Zone is already unlocked — the loop should skip it via the status==="unlocked" continue
zones: [{ id: "test_zone", status: "unlocked", unlockBossId: "test_boss", unlockQuestId: null }] as GameState["zones"],
quests: [],
});
vi.mocked(prisma.gameState.findUnique).mockResolvedValueOnce({ state } as never);
vi.mocked(prisma.gameState.update).mockResolvedValueOnce({} as never);
const res = await challenge({ bossId: "test_boss" });
expect(res.status).toBe(200);
const body = await res.json() as { won: boolean };
expect(body.won).toBe(true);
});
it("skips zone unlock when quest condition is not satisfied", async () => {
const state = makeState({
bosses: [makeBoss({ currentHp: 100, maxHp: 100, damagePerSecond: 1 })] as GameState["bosses"],
adventurers: [makeAdventurer()] as GameState["adventurers"],
// Zone has unlockBossId matching but the required quest is not completed
zones: [{ id: "test_zone", status: "locked", unlockBossId: "test_boss", unlockQuestId: "required_quest" }] as GameState["zones"],
quests: [{ id: "required_quest", status: "active" }] as GameState["quests"],
});
vi.mocked(prisma.gameState.findUnique).mockResolvedValueOnce({ state } as never);
vi.mocked(prisma.gameState.update).mockResolvedValueOnce({} as never);
const res = await challenge({ bossId: "test_boss" });
expect(res.status).toBe(200);
const body = await res.json() as { won: boolean };
expect(body.won).toBe(true);
});
it("unlocks next zone boss when boss is defeated and zone condition is met", async () => {
const nextBoss = makeBoss({ id: "next_boss", status: "locked", prestigeRequirement: 0 });
const state = makeState({
bosses: [
makeBoss({ currentHp: 100, maxHp: 100, damagePerSecond: 1 }),
nextBoss,
] as GameState["bosses"],
adventurers: [makeAdventurer()] as GameState["adventurers"],
zones: [{ id: "test_zone", status: "locked", unlockBossId: "test_boss", unlockQuestId: null }] as GameState["zones"],
quests: [],
});
vi.mocked(prisma.gameState.findUnique).mockResolvedValueOnce({ state } as never);
vi.mocked(prisma.gameState.update).mockResolvedValueOnce({} as never);
const res = await challenge({ bossId: "test_boss" });
expect(res.status).toBe(200);
const body = await res.json() as { won: boolean };
expect(body.won).toBe(true);
});
it("handles boss with upgrade and equipment rewards on win", async () => {
const state = makeState({
bosses: [makeBoss({
upgradeRewards: ["some_upgrade"],
equipmentRewards: ["some_equipment"],
})] as GameState["bosses"],
adventurers: [makeAdventurer()] as GameState["adventurers"],
upgrades: [{ id: "some_upgrade", purchased: false, unlocked: false, target: "global", multiplier: 1 }] as GameState["upgrades"],
equipment: [{ id: "some_equipment", owned: false, equipped: false, type: "weapon", bonus: {} }] as GameState["equipment"],
zones: [],
});
vi.mocked(prisma.gameState.findUnique).mockResolvedValueOnce({ state } as never);
vi.mocked(prisma.gameState.update).mockResolvedValueOnce({} as never);
const res = await challenge({ bossId: "test_boss" });
expect(res.status).toBe(200);
const body = await res.json() as { won: boolean; rewards: { upgradeIds: string[]; equipmentIds: string[] } };
expect(body.won).toBe(true);
expect(body.rewards.upgradeIds).toContain("some_upgrade");
expect(body.rewards.equipmentIds).toContain("some_equipment");
});
it("updates daily challenge progress on boss defeat", async () => {
const state = makeState({
bosses: [makeBoss()] as GameState["bosses"],
adventurers: [makeAdventurer()] as GameState["adventurers"],
zones: [],
dailyChallenges: {
date: "2024-01-01",
challenges: [{ id: "boss_challenge", type: "bossesDefeated", target: 3, progress: 0, completed: false, crystalReward: 5 }],
} as GameState["dailyChallenges"],
});
vi.mocked(prisma.gameState.findUnique).mockResolvedValueOnce({ state } as never);
vi.mocked(prisma.gameState.update).mockResolvedValueOnce({} as never);
const res = await challenge({ bossId: "test_boss" });
expect(res.status).toBe(200);
});
it("applies adventurer-specific upgrade to party DPS", async () => {
const state = makeState({
bosses: [makeBoss({ currentHp: 100, maxHp: 100, damagePerSecond: 1 })] as GameState["bosses"],
adventurers: [makeAdventurer({ id: "test_adventurer" })] as GameState["adventurers"],
upgrades: [{ id: "adv_upgrade", purchased: true, unlocked: true, target: "adventurer", adventurerId: "test_adventurer", multiplier: 2 }] as GameState["upgrades"],
zones: [],
});
vi.mocked(prisma.gameState.findUnique).mockResolvedValueOnce({ state } as never);
vi.mocked(prisma.gameState.update).mockResolvedValueOnce({} as never);
const res = await challenge({ bossId: "test_boss" });
expect(res.status).toBe(200);
const body = await res.json() as { won: boolean };
expect(body.won).toBe(true);
});
it("applies global upgrade multiplier to party DPS when global upgrade is purchased", async () => {
const state = makeState({
bosses: [makeBoss({ currentHp: 100, maxHp: 100, damagePerSecond: 1 })] as GameState["bosses"],
adventurers: [makeAdventurer({ combatPower: 10000, count: 1 })] as GameState["adventurers"],
upgrades: [{ id: "global_1", purchased: true, unlocked: true, target: "global", multiplier: 2 }] as GameState["upgrades"],
zones: [],
});
vi.mocked(prisma.gameState.findUnique).mockResolvedValueOnce({ state } as never);
vi.mocked(prisma.gameState.update).mockResolvedValueOnce({} as never);
const res = await challenge({ bossId: "test_boss" });
expect(res.status).toBe(200);
const body = await res.json() as { won: boolean };
expect(body.won).toBe(true);
});
it("unlocks zone when boss defeated and quest condition is also satisfied", async () => {
const state = makeState({
bosses: [makeBoss({ currentHp: 100, maxHp: 100, damagePerSecond: 1 })] as GameState["bosses"],
adventurers: [makeAdventurer()] as GameState["adventurers"],
zones: [{ id: "test_zone", status: "locked", unlockBossId: "test_boss", unlockQuestId: "test_quest" }] as GameState["zones"],
quests: [{ id: "test_quest", status: "completed" }] as GameState["quests"],
});
vi.mocked(prisma.gameState.findUnique).mockResolvedValueOnce({ state } as never);
vi.mocked(prisma.gameState.update).mockResolvedValueOnce({} as never);
const res = await challenge({ bossId: "test_boss" });
expect(res.status).toBe(200);
const body = await res.json() as { won: boolean };
expect(body.won).toBe(true);
});
});
+146
View File
@@ -0,0 +1,146 @@
/* eslint-disable max-lines-per-function -- Test suites naturally have many cases */
/* eslint-disable @typescript-eslint/consistent-type-assertions -- Tests build minimal state objects */
import { beforeEach, describe, expect, it, vi } from "vitest";
import { Hono } from "hono";
import type { GameState } from "@elysium/types";
vi.mock("../../src/db/client.js", () => ({
prisma: {
gameState: { findUnique: vi.fn(), update: vi.fn() },
},
}));
vi.mock("../../src/middleware/auth.js", () => ({
authMiddleware: vi.fn(async (c: { set: (key: string, value: string) => void }, next: () => Promise<void>) => {
c.set("discordId", "test_discord_id");
await next();
}),
}));
const DISCORD_ID = "test_discord_id";
// heartwood_tincture requires 5 verdant_sap + 3 forest_crystal
const TEST_RECIPE_ID = "heartwood_tincture";
const makeState = (overrides: Partial<GameState> = {}): GameState => ({
player: { discordId: DISCORD_ID, username: "u", discriminator: "0", avatar: null, totalGoldEarned: 0, totalClicks: 0, characterName: "T" },
resources: { gold: 0, essence: 0, crystals: 0, runestones: 0 },
adventurers: [],
upgrades: [],
quests: [],
bosses: [],
equipment: [],
achievements: [],
zones: [],
exploration: {
areas: [],
materials: [{ materialId: "verdant_sap", quantity: 10 }, { materialId: "forest_crystal", quantity: 5 }],
craftedRecipeIds: [],
craftedGoldMultiplier: 1,
craftedEssenceMultiplier: 1,
craftedClickMultiplier: 1,
craftedCombatMultiplier: 1,
},
companions: { unlockedCompanionIds: [], activeCompanionId: null },
prestige: { count: 0, runestones: 0, productionMultiplier: 1, purchasedUpgradeIds: [] },
baseClickPower: 1,
lastTickAt: 0,
schemaVersion: 1,
...overrides,
} as GameState);
describe("craft route", () => {
let app: Hono;
let prisma: { gameState: { findUnique: ReturnType<typeof vi.fn>; update: ReturnType<typeof vi.fn> } };
beforeEach(async () => {
vi.clearAllMocks();
const { craftRouter } = await import("../../src/routes/craft.js");
const { prisma: p } = await import("../../src/db/client.js");
prisma = p as typeof prisma;
app = new Hono();
app.route("/craft", craftRouter);
});
const post = (body: Record<string, unknown>) =>
app.fetch(new Request("http://localhost/craft", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(body),
}));
it("returns 400 when recipeId is missing", async () => {
const res = await post({});
expect(res.status).toBe(400);
});
it("returns 404 for unknown recipe", async () => {
const res = await post({ recipeId: "nonexistent_recipe" });
expect(res.status).toBe(404);
});
it("returns 404 when no save is found", async () => {
vi.mocked(prisma.gameState.findUnique).mockResolvedValueOnce(null);
const res = await post({ recipeId: TEST_RECIPE_ID });
expect(res.status).toBe(404);
});
it("returns 400 when no exploration state exists", async () => {
const state = makeState({ exploration: undefined });
vi.mocked(prisma.gameState.findUnique).mockResolvedValueOnce({ state } as never);
const res = await post({ recipeId: TEST_RECIPE_ID });
expect(res.status).toBe(400);
});
it("returns 400 when recipe is already crafted", async () => {
const state = makeState({ exploration: { areas: [], materials: [], craftedRecipeIds: [TEST_RECIPE_ID], craftedGoldMultiplier: 1, craftedEssenceMultiplier: 1, craftedClickMultiplier: 1, craftedCombatMultiplier: 1 } });
vi.mocked(prisma.gameState.findUnique).mockResolvedValueOnce({ state } as never);
const res = await post({ recipeId: TEST_RECIPE_ID });
expect(res.status).toBe(400);
});
it("returns 400 when not enough materials", async () => {
const state = makeState({
exploration: {
areas: [],
materials: [{ materialId: "verdant_sap", quantity: 1 }], // needs 5
craftedRecipeIds: [],
craftedGoldMultiplier: 1,
craftedEssenceMultiplier: 1,
craftedClickMultiplier: 1,
craftedCombatMultiplier: 1,
},
});
vi.mocked(prisma.gameState.findUnique).mockResolvedValueOnce({ state } as never);
const res = await post({ recipeId: TEST_RECIPE_ID });
expect(res.status).toBe(400);
});
it("returns 400 when second material is completely absent from list", async () => {
// verdant_sap present (enough), but forest_crystal absent entirely — quantity ?? 0 = 0
const state = makeState({
exploration: {
areas: [],
materials: [{ materialId: "verdant_sap", quantity: 10 }],
craftedRecipeIds: [],
craftedGoldMultiplier: 1,
craftedEssenceMultiplier: 1,
craftedClickMultiplier: 1,
craftedCombatMultiplier: 1,
},
});
vi.mocked(prisma.gameState.findUnique).mockResolvedValueOnce({ state } as never);
const res = await post({ recipeId: TEST_RECIPE_ID });
expect(res.status).toBe(400);
});
it("returns craft result on success", async () => {
const state = makeState();
vi.mocked(prisma.gameState.findUnique).mockResolvedValueOnce({ state } as never);
vi.mocked(prisma.gameState.update).mockResolvedValueOnce({} as never);
const res = await post({ recipeId: TEST_RECIPE_ID });
expect(res.status).toBe(200);
const body = await res.json() as { recipeId: string; bonusType: string };
expect(body.recipeId).toBe(TEST_RECIPE_ID);
expect(body.bonusType).toBe("gold_income");
});
});
+410
View File
@@ -0,0 +1,410 @@
/* eslint-disable max-lines-per-function -- Test suites naturally have many cases */
/* eslint-disable max-lines -- Test suites naturally have many cases */
/* eslint-disable @typescript-eslint/consistent-type-assertions -- Tests build minimal state objects */
import { beforeEach, describe, expect, it, vi } from "vitest";
import { Hono } from "hono";
import type { GameState } from "@elysium/types";
vi.mock("../../src/db/client.js", () => ({
prisma: {
gameState: { findUnique: vi.fn(), update: vi.fn() },
},
}));
vi.mock("../../src/middleware/auth.js", () => ({
authMiddleware: vi.fn(async (c: { set: (key: string, value: string) => void }, next: () => Promise<void>) => {
c.set("discordId", "test_discord_id");
await next();
}),
}));
const DISCORD_ID = "test_discord_id";
// verdant_meadow is the first area in verdant_vale zone
const TEST_AREA_ID = "verdant_meadow";
const TEST_ZONE_ID = "verdant_vale";
const makeState = (overrides: Partial<GameState> = {}): GameState => ({
player: { discordId: DISCORD_ID, username: "u", discriminator: "0", avatar: null, totalGoldEarned: 0, totalClicks: 0, characterName: "T" },
resources: { gold: 0, essence: 0, crystals: 0, runestones: 0 },
adventurers: [],
upgrades: [],
quests: [],
bosses: [],
equipment: [],
achievements: [],
zones: [{ id: TEST_ZONE_ID, status: "unlocked" }] as GameState["zones"],
exploration: {
areas: [{ id: TEST_AREA_ID, status: "available", completedOnce: false }] as GameState["exploration"]["areas"],
materials: [],
craftedRecipeIds: [],
craftedGoldMultiplier: 1,
craftedEssenceMultiplier: 1,
craftedClickMultiplier: 1,
craftedCombatMultiplier: 1,
},
companions: { unlockedCompanionIds: [], activeCompanionId: null },
prestige: { count: 0, runestones: 0, productionMultiplier: 1, purchasedUpgradeIds: [] },
baseClickPower: 1,
lastTickAt: 0,
schemaVersion: 1,
...overrides,
} as GameState);
describe("explore route", () => {
let app: Hono;
let prisma: { gameState: { findUnique: ReturnType<typeof vi.fn>; update: ReturnType<typeof vi.fn> } };
beforeEach(async () => {
vi.clearAllMocks();
const { exploreRouter } = await import("../../src/routes/explore.js");
const { prisma: p } = await import("../../src/db/client.js");
prisma = p as typeof prisma;
app = new Hono();
app.route("/explore", exploreRouter);
});
const postStart = (body: Record<string, unknown>) =>
app.fetch(new Request("http://localhost/explore/start", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(body),
}));
const postCollect = (body: Record<string, unknown>) =>
app.fetch(new Request("http://localhost/explore/collect", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(body),
}));
describe("POST /start", () => {
it("returns 400 when areaId is missing", async () => {
const res = await postStart({});
expect(res.status).toBe(400);
});
it("returns 404 for unknown area", async () => {
const res = await postStart({ areaId: "nonexistent_area" });
expect(res.status).toBe(404);
});
it("returns 404 when no save is found", async () => {
vi.mocked(prisma.gameState.findUnique).mockResolvedValueOnce(null);
const res = await postStart({ areaId: TEST_AREA_ID });
expect(res.status).toBe(404);
});
it("returns 400 when zone is not unlocked", async () => {
const state = makeState({ zones: [{ id: TEST_ZONE_ID, status: "locked" }] as GameState["zones"] });
vi.mocked(prisma.gameState.findUnique).mockResolvedValueOnce({ state } as never);
const res = await postStart({ areaId: TEST_AREA_ID });
expect(res.status).toBe(400);
});
it("returns 404 when area is not found in state", async () => {
const state = makeState({ exploration: { areas: [], materials: [], craftedRecipeIds: [], craftedGoldMultiplier: 1, craftedEssenceMultiplier: 1, craftedClickMultiplier: 1, craftedCombatMultiplier: 1 } });
vi.mocked(prisma.gameState.findUnique).mockResolvedValueOnce({ state } as never);
const res = await postStart({ areaId: TEST_AREA_ID });
expect(res.status).toBe(404);
});
it("returns 400 when another exploration is already in progress", async () => {
const state = makeState({
exploration: {
areas: [{ id: TEST_AREA_ID, status: "available" }, { id: "other_area", status: "in_progress" }] as GameState["exploration"]["areas"],
materials: [],
craftedRecipeIds: [],
craftedGoldMultiplier: 1,
craftedEssenceMultiplier: 1,
craftedClickMultiplier: 1,
craftedCombatMultiplier: 1,
},
});
vi.mocked(prisma.gameState.findUnique).mockResolvedValueOnce({ state } as never);
const res = await postStart({ areaId: TEST_AREA_ID });
expect(res.status).toBe(400);
});
it("returns 400 when area is locked", async () => {
const state = makeState({
exploration: {
areas: [{ id: TEST_AREA_ID, status: "locked" }] as GameState["exploration"]["areas"],
materials: [],
craftedRecipeIds: [],
craftedGoldMultiplier: 1,
craftedEssenceMultiplier: 1,
craftedClickMultiplier: 1,
craftedCombatMultiplier: 1,
},
});
vi.mocked(prisma.gameState.findUnique).mockResolvedValueOnce({ state } as never);
const res = await postStart({ areaId: TEST_AREA_ID });
expect(res.status).toBe(400);
});
it("starts exploration and returns endsAt on success", async () => {
const state = makeState();
vi.mocked(prisma.gameState.findUnique).mockResolvedValueOnce({ state } as never);
vi.mocked(prisma.gameState.update).mockResolvedValueOnce({} as never);
const res = await postStart({ areaId: TEST_AREA_ID });
expect(res.status).toBe(200);
const body = await res.json() as { areaId: string; endsAt: number };
expect(body.areaId).toBe(TEST_AREA_ID);
expect(body.endsAt).toBeGreaterThan(Date.now());
});
it("backfills exploration state for old saves without exploration", async () => {
const state = makeState({ exploration: undefined });
vi.mocked(prisma.gameState.findUnique).mockResolvedValueOnce({ state } as never);
vi.mocked(prisma.gameState.update).mockResolvedValueOnce({} as never);
// Even with backfilled state, verdant_meadow may not be available initially — just check the route runs
const res = await postStart({ areaId: TEST_AREA_ID });
// Should not be a 500; either 200 or a game-logic error
expect(res.status).not.toBe(500);
});
});
describe("POST /collect", () => {
it("returns 400 when areaId is missing", async () => {
const res = await postCollect({});
expect(res.status).toBe(400);
});
it("returns 404 for unknown area", async () => {
const res = await postCollect({ areaId: "nonexistent_area" });
expect(res.status).toBe(404);
});
it("returns 404 when no save is found", async () => {
vi.mocked(prisma.gameState.findUnique).mockResolvedValueOnce(null);
const res = await postCollect({ areaId: TEST_AREA_ID });
expect(res.status).toBe(404);
});
it("returns 400 when no exploration state exists", async () => {
const state = makeState({ exploration: undefined });
vi.mocked(prisma.gameState.findUnique).mockResolvedValueOnce({ state } as never);
const res = await postCollect({ areaId: TEST_AREA_ID });
expect(res.status).toBe(400);
});
it("returns 404 when area is not found in state", async () => {
const state = makeState({ exploration: { areas: [], materials: [], craftedRecipeIds: [], craftedGoldMultiplier: 1, craftedEssenceMultiplier: 1, craftedClickMultiplier: 1, craftedCombatMultiplier: 1 } });
vi.mocked(prisma.gameState.findUnique).mockResolvedValueOnce({ state } as never);
const res = await postCollect({ areaId: TEST_AREA_ID });
expect(res.status).toBe(404);
});
it("returns 400 when area is not in progress", async () => {
const state = makeState();
vi.mocked(prisma.gameState.findUnique).mockResolvedValueOnce({ state } as never);
const res = await postCollect({ areaId: TEST_AREA_ID });
expect(res.status).toBe(400);
});
it("returns 400 when exploration is not yet complete", async () => {
const now = Date.now();
const state = makeState({
exploration: {
areas: [{ id: TEST_AREA_ID, status: "in_progress", startedAt: now, completedOnce: false }] as GameState["exploration"]["areas"],
materials: [],
craftedRecipeIds: [],
craftedGoldMultiplier: 1,
craftedEssenceMultiplier: 1,
craftedClickMultiplier: 1,
craftedCombatMultiplier: 1,
},
});
vi.mocked(prisma.gameState.findUnique).mockResolvedValueOnce({ state } as never);
const res = await postCollect({ areaId: TEST_AREA_ID });
expect(res.status).toBe(400);
});
it("collects exploration results when complete", async () => {
// Set startedAt far in the past so it's definitely complete
const state = makeState({
exploration: {
areas: [{ id: TEST_AREA_ID, status: "in_progress", startedAt: 0, completedOnce: false }] as GameState["exploration"]["areas"],
materials: [],
craftedRecipeIds: [],
craftedGoldMultiplier: 1,
craftedEssenceMultiplier: 1,
craftedClickMultiplier: 1,
craftedCombatMultiplier: 1,
},
});
vi.mocked(prisma.gameState.findUnique).mockResolvedValueOnce({ state } as never);
vi.mocked(prisma.gameState.update).mockResolvedValueOnce({} as never);
const res = await postCollect({ areaId: TEST_AREA_ID });
expect(res.status).toBe(200);
const body = await res.json() as { foundNothing: boolean; materialsFound: unknown[] };
expect(typeof body.foundNothing).toBe("boolean");
expect(Array.isArray(body.materialsFound)).toBe(true);
});
it("returns foundNothing=true when random triggers the nothing path", async () => {
const mockRandom = vi.spyOn(Math, "random");
// First call: the nothing probability check (< 0.2 triggers nothing)
mockRandom.mockReturnValueOnce(0.1);
const state = makeState({
exploration: {
areas: [{ id: TEST_AREA_ID, status: "in_progress", startedAt: 0, completedOnce: false }] as GameState["exploration"]["areas"],
materials: [],
craftedRecipeIds: [],
craftedGoldMultiplier: 1,
craftedEssenceMultiplier: 1,
craftedClickMultiplier: 1,
craftedCombatMultiplier: 1,
},
});
vi.mocked(prisma.gameState.findUnique).mockResolvedValueOnce({ state } as never);
vi.mocked(prisma.gameState.update).mockResolvedValueOnce({} as never);
const res = await postCollect({ areaId: TEST_AREA_ID });
expect(res.status).toBe(200);
const body = await res.json() as { foundNothing: boolean; nothingMessage: string };
expect(body.foundNothing).toBe(true);
expect(typeof body.nothingMessage).toBe("string");
mockRandom.mockRestore();
});
it("applies gold_loss event and pushes new material from possibleMaterials", async () => {
const mockRandom = vi.spyOn(Math, "random");
// verdant_meadow events: [gold_gain(0), gold_loss(1), material_gain(2), essence_gain(3)]
mockRandom
.mockReturnValueOnce(0.5) // nothing check: 0.5 >= 0.2 → proceed
.mockReturnValueOnce(0.26) // event: Math.floor(0.26 * 4) = 1 → gold_loss
.mockReturnValueOnce(0) // possibleMaterials roll: 0 * 3 = 0, 0 - 3 = -3 ≤ 0 → verdant_sap
.mockReturnValueOnce(0); // quantity: Math.floor(0 * 3) + 1 = 1
const state = makeState({
resources: { gold: 100, essence: 0, crystals: 0, runestones: 0 },
exploration: {
areas: [{ id: TEST_AREA_ID, status: "in_progress", startedAt: 0, completedOnce: false }] as GameState["exploration"]["areas"],
materials: [],
craftedRecipeIds: [],
craftedGoldMultiplier: 1,
craftedEssenceMultiplier: 1,
craftedClickMultiplier: 1,
craftedCombatMultiplier: 1,
},
});
vi.mocked(prisma.gameState.findUnique).mockResolvedValueOnce({ state } as never);
vi.mocked(prisma.gameState.update).mockResolvedValueOnce({} as never);
const res = await postCollect({ areaId: TEST_AREA_ID });
expect(res.status).toBe(200);
const body = await res.json() as { foundNothing: boolean; event: { goldChange: number }; materialsFound: Array<{ materialId: string }> };
expect(body.foundNothing).toBe(false);
expect(body.event.goldChange).toBeLessThan(0);
expect(body.materialsFound.some((m) => m.materialId === "verdant_sap")).toBe(true);
mockRandom.mockRestore();
});
it("applies essence_gain event during exploration collect", async () => {
const mockRandom = vi.spyOn(Math, "random");
mockRandom
.mockReturnValueOnce(0.5) // nothing check: proceed
.mockReturnValueOnce(0.76) // event: Math.floor(0.76 * 4) = 3 → essence_gain
.mockReturnValueOnce(0) // possibleMaterials roll → verdant_sap
.mockReturnValueOnce(0); // quantity → 1
const state = makeState({
exploration: {
areas: [{ id: TEST_AREA_ID, status: "in_progress", startedAt: 0, completedOnce: false }] as GameState["exploration"]["areas"],
materials: [],
craftedRecipeIds: [],
craftedGoldMultiplier: 1,
craftedEssenceMultiplier: 1,
craftedClickMultiplier: 1,
craftedCombatMultiplier: 1,
},
});
vi.mocked(prisma.gameState.findUnique).mockResolvedValueOnce({ state } as never);
vi.mocked(prisma.gameState.update).mockResolvedValueOnce({} as never);
const res = await postCollect({ areaId: TEST_AREA_ID });
expect(res.status).toBe(200);
const body = await res.json() as { event: { essenceChange: number } };
expect(body.event.essenceChange).toBeGreaterThan(0);
mockRandom.mockRestore();
});
it("pushes new material via material_gain event when material not already in list", async () => {
const mockRandom = vi.spyOn(Math, "random");
mockRandom
.mockReturnValueOnce(0.5) // nothing check: proceed
.mockReturnValueOnce(0.51) // event: Math.floor(0.51 * 4) = 2 → material_gain (verdant_sap qty=2)
.mockReturnValueOnce(0) // possibleMaterials roll → verdant_sap
.mockReturnValueOnce(0); // quantity → 1
const state = makeState({
exploration: {
areas: [{ id: TEST_AREA_ID, status: "in_progress", startedAt: 0, completedOnce: false }] as GameState["exploration"]["areas"],
materials: [],
craftedRecipeIds: [],
craftedGoldMultiplier: 1,
craftedEssenceMultiplier: 1,
craftedClickMultiplier: 1,
craftedCombatMultiplier: 1,
},
});
vi.mocked(prisma.gameState.findUnique).mockResolvedValueOnce({ state } as never);
vi.mocked(prisma.gameState.update).mockResolvedValueOnce({} as never);
const res = await postCollect({ areaId: TEST_AREA_ID });
expect(res.status).toBe(200);
const body = await res.json() as { event: { materialGained: { materialId: string; quantity: number } } };
expect(body.event.materialGained?.materialId).toBe("verdant_sap");
mockRandom.mockRestore();
});
it("increments existing material quantity via material_gain event", async () => {
const mockRandom = vi.spyOn(Math, "random");
mockRandom
.mockReturnValueOnce(0.5) // nothing check: proceed
.mockReturnValueOnce(0.51) // event: Math.floor(0.51 * 4) = 2 → material_gain (verdant_sap qty=2)
.mockReturnValueOnce(0) // possibleMaterials roll → verdant_sap
.mockReturnValueOnce(0); // quantity → 1
const state = makeState({
exploration: {
areas: [{ id: TEST_AREA_ID, status: "in_progress", startedAt: 0, completedOnce: false }] as GameState["exploration"]["areas"],
materials: [{ materialId: "verdant_sap", quantity: 5 }],
craftedRecipeIds: [],
craftedGoldMultiplier: 1,
craftedEssenceMultiplier: 1,
craftedClickMultiplier: 1,
craftedCombatMultiplier: 1,
},
});
vi.mocked(prisma.gameState.findUnique).mockResolvedValueOnce({ state } as never);
vi.mocked(prisma.gameState.update).mockResolvedValueOnce({} as never);
const res = await postCollect({ areaId: TEST_AREA_ID });
expect(res.status).toBe(200);
const body = await res.json() as { event: { materialGained: { materialId: string; quantity: number } } };
expect(body.event.materialGained?.materialId).toBe("verdant_sap");
mockRandom.mockRestore();
});
it("increments existing material quantity when material already in list", async () => {
const mockRandom = vi.spyOn(Math, "random");
// verdant_meadow has 4 events (indices 0-3), 1 possibleMaterial (verdant_sap, weight=3)
mockRandom
.mockReturnValueOnce(0.5) // nothing check: 0.5 >= 0.2 → proceed
.mockReturnValueOnce(0) // event selection: Math.floor(0 * 4) = 0 → gold_gain (index 0)
.mockReturnValueOnce(0) // material roll: 0 * 3 = 0, then 0 - 3 = -3 <= 0 → verdant_sap selected
.mockReturnValueOnce(0); // quantity roll: Math.floor(0 * 3) + 1 = 1
const state = makeState({
exploration: {
areas: [{ id: TEST_AREA_ID, status: "in_progress", startedAt: 0, completedOnce: false }] as GameState["exploration"]["areas"],
materials: [{ materialId: "verdant_sap", quantity: 5 }],
craftedRecipeIds: [],
craftedGoldMultiplier: 1,
craftedEssenceMultiplier: 1,
craftedClickMultiplier: 1,
craftedCombatMultiplier: 1,
},
});
vi.mocked(prisma.gameState.findUnique).mockResolvedValueOnce({ state } as never);
vi.mocked(prisma.gameState.update).mockResolvedValueOnce({} as never);
const res = await postCollect({ areaId: TEST_AREA_ID });
expect(res.status).toBe(200);
const body = await res.json() as { materialsFound: Array<{ materialId: string }> };
expect(body.materialsFound.some((m) => m.materialId === "verdant_sap")).toBe(true);
mockRandom.mockRestore();
});
});
});
+454
View File
@@ -0,0 +1,454 @@
/* eslint-disable max-lines-per-function -- Test suites naturally have many cases */
/* eslint-disable max-lines -- Test suites naturally have many cases */
/* eslint-disable @typescript-eslint/consistent-type-assertions -- Tests build minimal state objects */
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import { Hono } from "hono";
import type { GameState } from "@elysium/types";
vi.mock("../../src/db/client.js", () => ({
prisma: {
player: { findUnique: vi.fn(), update: vi.fn() },
gameState: { findUnique: vi.fn(), create: vi.fn(), update: vi.fn(), upsert: vi.fn() },
},
}));
vi.mock("../../src/middleware/auth.js", () => ({
authMiddleware: vi.fn(async (c: { set: (key: string, value: string) => void }, next: () => Promise<void>) => {
c.set("discordId", "test_discord_id");
await next();
}),
}));
const DISCORD_ID = "test_discord_id";
const CURRENT_SCHEMA_VERSION = 1;
const makeState = (overrides: Partial<GameState> = {}): GameState => ({
player: { discordId: DISCORD_ID, username: "u", discriminator: "0", avatar: null, totalGoldEarned: 0, totalClicks: 0, characterName: "T" },
resources: { gold: 0, essence: 0, crystals: 0, runestones: 0 },
adventurers: [],
upgrades: [],
quests: [],
bosses: [],
equipment: [],
achievements: [],
zones: [],
exploration: { areas: [], materials: [], craftedRecipeIds: [], craftedGoldMultiplier: 1, craftedEssenceMultiplier: 1, craftedClickMultiplier: 1, craftedCombatMultiplier: 1 },
companions: { unlockedCompanionIds: [], activeCompanionId: null },
prestige: { count: 0, runestones: 0, productionMultiplier: 1, purchasedUpgradeIds: [] },
baseClickPower: 1,
lastTickAt: Date.now() - 60_000, // 60 seconds ago
schemaVersion: CURRENT_SCHEMA_VERSION,
...overrides,
} as GameState);
const makePlayer = (overrides: Record<string, unknown> = {}) => ({
discordId: DISCORD_ID,
characterName: "T",
username: "u",
discriminator: "0",
avatar: null,
createdAt: Date.now(),
lastSavedAt: 0,
totalGoldEarned: 0,
totalClicks: 0,
lifetimeGoldEarned: 0,
lifetimeClicks: 0,
lifetimeBossesDefeated: 0,
lifetimeQuestsCompleted: 0,
lifetimeAdventurersRecruited: 0,
lifetimeAchievementsUnlocked: 0,
loginStreak: 1,
lastLoginDate: null,
unlockedTitles: null,
guildName: null,
...overrides,
});
describe("game route", () => {
let app: Hono;
let prisma: {
player: { findUnique: ReturnType<typeof vi.fn>; update: ReturnType<typeof vi.fn> };
gameState: { findUnique: ReturnType<typeof vi.fn>; create: ReturnType<typeof vi.fn>; update: ReturnType<typeof vi.fn>; upsert: ReturnType<typeof vi.fn> };
};
beforeEach(async () => {
vi.clearAllMocks();
delete process.env["ANTI_CHEAT_SECRET"];
const { gameRouter } = await import("../../src/routes/game.js");
const { prisma: p } = await import("../../src/db/client.js");
prisma = p as typeof prisma;
app = new Hono();
app.route("/game", gameRouter);
});
afterEach(() => {
delete process.env["ANTI_CHEAT_SECRET"];
});
describe("GET /load", () => {
it("returns 404 when neither game state nor player exists", async () => {
vi.mocked(prisma.gameState.findUnique).mockResolvedValueOnce(null);
vi.mocked(prisma.player.findUnique).mockResolvedValueOnce(null);
const res = await app.fetch(new Request("http://localhost/game/load"));
expect(res.status).toBe(404);
});
it("creates fresh state when game state is missing but player exists", async () => {
vi.mocked(prisma.gameState.findUnique).mockResolvedValueOnce(null);
vi.mocked(prisma.player.findUnique).mockResolvedValueOnce(makePlayer() as never);
vi.mocked(prisma.gameState.create).mockResolvedValueOnce({} as never);
const res = await app.fetch(new Request("http://localhost/game/load"));
expect(res.status).toBe(200);
const body = await res.json() as { offlineGold: number; schemaOutdated: boolean };
expect(body.offlineGold).toBe(0);
expect(body.schemaOutdated).toBe(false);
});
it("returns state with offline earnings when game state exists", async () => {
const state = makeState({ lastTickAt: Date.now() - 10_000 }); // 10 seconds ago
vi.mocked(prisma.gameState.findUnique).mockResolvedValueOnce({ state } as never);
vi.mocked(prisma.player.findUnique).mockResolvedValueOnce(makePlayer() as never);
vi.mocked(prisma.gameState.update).mockResolvedValueOnce({} as never).mockRejectedValueOnce(Object.assign(new Error("conflict"), { code: "P2034" }));
vi.mocked(prisma.player.update).mockResolvedValueOnce({} as never);
const res = await app.fetch(new Request("http://localhost/game/load"));
expect(res.status).toBe(200);
const body = await res.json() as { state: GameState; offlineSeconds: number; currentSchemaVersion: number };
expect(body.currentSchemaVersion).toBe(CURRENT_SCHEMA_VERSION);
expect(typeof body.offlineSeconds).toBe("number");
});
it("awards login bonus when player logs in on a new day", async () => {
const yesterday = new Date(Date.now() - 86_400_000).toISOString().slice(0, 10);
const state = makeState();
vi.mocked(prisma.gameState.findUnique).mockResolvedValueOnce({ state } as never);
vi.mocked(prisma.player.findUnique).mockResolvedValueOnce(makePlayer({ lastLoginDate: yesterday, loginStreak: 3 }) as never);
vi.mocked(prisma.player.update).mockResolvedValueOnce({} as never);
vi.mocked(prisma.gameState.update).mockResolvedValueOnce({} as never);
const res = await app.fetch(new Request("http://localhost/game/load"));
expect(res.status).toBe(200);
const body = await res.json() as { loginBonus: { streak: number; goldEarned: number } | null };
expect(body.loginBonus).not.toBeNull();
expect(body.loginBonus?.streak).toBe(4);
});
it("resets streak when login gap is more than one day", async () => {
const longAgo = "2020-01-01";
const state = makeState();
vi.mocked(prisma.gameState.findUnique).mockResolvedValueOnce({ state } as never);
vi.mocked(prisma.player.findUnique).mockResolvedValueOnce(makePlayer({ lastLoginDate: longAgo, loginStreak: 10 }) as never);
vi.mocked(prisma.player.update).mockResolvedValueOnce({} as never);
vi.mocked(prisma.gameState.update).mockResolvedValueOnce({} as never);
const res = await app.fetch(new Request("http://localhost/game/load"));
expect(res.status).toBe(200);
const body = await res.json() as { loginBonus: { streak: number } | null };
expect(body.loginBonus?.streak).toBe(1);
});
it("does not award login bonus when already logged in today", async () => {
const todayUTC = new Date().toISOString().slice(0, 10);
const state = makeState();
vi.mocked(prisma.gameState.findUnique).mockResolvedValueOnce({ state } as never);
vi.mocked(prisma.player.findUnique).mockResolvedValueOnce(makePlayer({ lastLoginDate: todayUTC }) as never);
vi.mocked(prisma.gameState.update).mockResolvedValueOnce({} as never);
const res = await app.fetch(new Request("http://localhost/game/load"));
expect(res.status).toBe(200);
const body = await res.json() as { loginBonus: null };
expect(body.loginBonus).toBeNull();
});
it("includes HMAC signature when ANTI_CHEAT_SECRET is set", async () => {
process.env["ANTI_CHEAT_SECRET"] = "my_secret";
const state = makeState();
vi.mocked(prisma.gameState.findUnique).mockResolvedValueOnce({ state } as never);
vi.mocked(prisma.player.findUnique).mockResolvedValueOnce(makePlayer() as never);
vi.mocked(prisma.gameState.update).mockResolvedValueOnce({} as never);
vi.mocked(prisma.player.update).mockResolvedValueOnce({} as never);
const res = await app.fetch(new Request("http://localhost/game/load"));
expect(res.status).toBe(200);
const body = await res.json() as { signature: string | undefined };
expect(typeof body.signature).toBe("string");
});
it("marks schema as outdated when save has older schema version", async () => {
const state = makeState({ schemaVersion: 0 });
vi.mocked(prisma.gameState.findUnique).mockResolvedValueOnce({ state } as never);
vi.mocked(prisma.player.findUnique).mockResolvedValueOnce(makePlayer() as never);
vi.mocked(prisma.gameState.update).mockResolvedValueOnce({} as never);
vi.mocked(prisma.player.update).mockResolvedValueOnce({} as never);
const res = await app.fetch(new Request("http://localhost/game/load"));
expect(res.status).toBe(200);
const body = await res.json() as { schemaOutdated: boolean };
expect(body.schemaOutdated).toBe(true);
});
it("returns non-zero offline earnings when adventurers have production stats", async () => {
const todayUTC = new Date().toISOString().slice(0, 10);
const state = makeState({
adventurers: [{
id: "worker", count: 1, unlocked: true, level: 1,
goldPerSecond: 1, essencePerSecond: 1, combatPower: 0,
}] as GameState["adventurers"],
});
vi.mocked(prisma.gameState.findUnique).mockResolvedValueOnce({ state } as never);
vi.mocked(prisma.player.findUnique).mockResolvedValueOnce(
makePlayer({ lastLoginDate: todayUTC }) as never,
);
vi.mocked(prisma.gameState.update).mockResolvedValueOnce({} as never);
const res = await app.fetch(new Request("http://localhost/game/load"));
expect(res.status).toBe(200);
const body = await res.json() as { offlineGold: number; offlineEssence: number };
expect(body.offlineGold).toBeGreaterThan(0);
expect(body.offlineEssence).toBeGreaterThan(0);
});
});
describe("POST /save", () => {
const save = (body: Record<string, unknown>) =>
app.fetch(new Request("http://localhost/game/save", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(body),
}));
it("returns 400 when state is missing from body", async () => {
const res = await save({});
expect(res.status).toBe(400);
});
it("returns 409 when save schema version is outdated", async () => {
const state = makeState({ schemaVersion: 0 });
const res = await save({ state });
expect(res.status).toBe(409);
});
it("saves state when no previous record exists", async () => {
vi.mocked(prisma.gameState.findUnique).mockResolvedValueOnce(null);
vi.mocked(prisma.player.findUnique).mockResolvedValueOnce(makePlayer() as never);
vi.mocked(prisma.player.update).mockResolvedValueOnce({} as never);
vi.mocked(prisma.gameState.upsert).mockResolvedValueOnce({} as never);
const state = makeState();
const res = await save({ state });
expect(res.status).toBe(200);
const body = await res.json() as { savedAt: number };
expect(body.savedAt).toBeGreaterThan(0);
});
it("falls back to state characterName when playerRecord is null", async () => {
vi.mocked(prisma.gameState.findUnique).mockResolvedValueOnce(null);
vi.mocked(prisma.player.findUnique).mockResolvedValueOnce(null);
vi.mocked(prisma.player.update).mockResolvedValueOnce({} as never);
vi.mocked(prisma.gameState.upsert).mockResolvedValueOnce({} as never);
const state = makeState();
const res = await save({ state });
expect(res.status).toBe(200);
});
it("validates and sanitizes state when previous record exists", async () => {
const prevState = makeState({ resources: { gold: 0, essence: 0, crystals: 0, runestones: 0 } });
const incomingState = makeState({ resources: { gold: 1e400, essence: 0, crystals: 0, runestones: 9999 } });
vi.mocked(prisma.gameState.findUnique).mockResolvedValueOnce({ state: prevState } as never);
vi.mocked(prisma.player.findUnique).mockResolvedValueOnce(makePlayer() as never);
vi.mocked(prisma.player.update).mockResolvedValueOnce({} as never);
vi.mocked(prisma.gameState.upsert).mockResolvedValueOnce({} as never);
const res = await save({ state: incomingState });
expect(res.status).toBe(200);
});
it("rejects save with wrong HMAC signature when secret is configured", async () => {
process.env["ANTI_CHEAT_SECRET"] = "my_secret";
const prevState = makeState();
vi.mocked(prisma.gameState.findUnique).mockResolvedValueOnce({ state: prevState } as never);
vi.mocked(prisma.player.findUnique).mockResolvedValueOnce(makePlayer() as never);
const res = await save({ state: makeState(), signature: "wrong_signature" });
expect(res.status).toBe(400);
});
it("accepts save with correct HMAC signature", async () => {
process.env["ANTI_CHEAT_SECRET"] = "my_secret";
const { createHmac } = await import("node:crypto");
const prevState = makeState();
const correctSig = createHmac("sha256", "my_secret").update(JSON.stringify(prevState)).digest("hex");
vi.mocked(prisma.gameState.findUnique).mockResolvedValueOnce({ state: prevState } as never);
vi.mocked(prisma.player.findUnique).mockResolvedValueOnce(makePlayer() as never);
vi.mocked(prisma.player.update).mockResolvedValueOnce({} as never);
vi.mocked(prisma.gameState.upsert).mockResolvedValueOnce({} as never);
const res = await save({ state: makeState(), signature: correctSig });
expect(res.status).toBe(200);
});
it("unlocks new titles and persists them", async () => {
const prevState = makeState();
vi.mocked(prisma.gameState.findUnique).mockResolvedValueOnce({ state: prevState } as never);
vi.mocked(prisma.player.findUnique).mockResolvedValueOnce(makePlayer({ guildName: "My Guild" }) as never);
vi.mocked(prisma.player.update).mockResolvedValueOnce({} as never);
vi.mocked(prisma.gameState.upsert).mockResolvedValueOnce({} as never);
const res = await save({ state: makeState() });
expect(res.status).toBe(200);
// Just verifies the route completes without error when title checking runs
});
it("exercises all validateAndSanitize branches with rich state", async () => {
const now = Date.now();
const prevState = makeState({
resources: { gold: 1000, essence: 50, crystals: 5, runestones: 5 },
adventurers: [
{ id: "militia", count: 5, unlocked: true, level: 2, goldPerSecond: 0.5, essencePerSecond: 0, combatPower: 3 },
] as GameState["adventurers"],
upgrades: [
{ id: "global_1", purchased: true, unlocked: true, target: "global", multiplier: 2 },
{ id: "click_1", purchased: true, unlocked: true, target: "click", multiplier: 1.5 },
] as GameState["upgrades"],
quests: [
// main path: active → completed (startedAt far in past → expired)
{ id: "first_steps", status: "active", startedAt: 1000 },
// defensive: prevQuest.status === "completed" → skip in computeQuestRewards
{ id: "goblin_camp", status: "completed", startedAt: 1000 },
// defensive: prevQuest.status !== "active" → skip
{ id: "haunted_mine", status: "locked", startedAt: null },
// defensive: startedAt == null → skip
{ id: "ancient_ruins", status: "active", startedAt: null },
// defensive: !questData → skip (not in DEFAULT_QUESTS)
{ id: "not_a_real_quest", status: "active", startedAt: 1000 },
// anti-rollback: completed in prev, active in incoming → quests.map restores completed
{ id: "rollback_quest", status: "completed", startedAt: 1000 },
] as GameState["quests"],
bosses: [
// main path in computeBossRewards: available → defeated
{ id: "troll_king", status: "available", currentHp: 1000, maxHp: 1000, damagePerSecond: 5, goldReward: 10000, essenceReward: 25, crystalReward: 0, upgradeRewards: [], equipmentRewards: [], prestigeRequirement: 0 },
// defensive: prevBoss.status === "defeated" → skip
{ id: "lich_queen", status: "defeated", currentHp: 0, maxHp: 10000, damagePerSecond: 20, goldReward: 100000, essenceReward: 200, crystalReward: 10, upgradeRewards: [], equipmentRewards: [], prestigeRequirement: 0 },
// defensive: prevBoss.status === "locked" → skip
{ id: "forest_giant", status: "locked", currentHp: 35000, maxHp: 35000, damagePerSecond: 40, goldReward: 350000, essenceReward: 400, crystalReward: 20, upgradeRewards: [], equipmentRewards: [], prestigeRequirement: 0 },
// defensive: !bossData → skip (not in DEFAULT_BOSSES)
{ id: "not_a_real_boss", status: "available", currentHp: 100, maxHp: 100, damagePerSecond: 1, goldReward: 0, essenceReward: 0, crystalReward: 0, upgradeRewards: [], equipmentRewards: [], prestigeRequirement: 0 },
// anti-rollback: defeated in prev, available in incoming → bosses.map restores defeated
{ id: "anti_rollback_boss", status: "defeated", currentHp: 0, maxHp: 100, damagePerSecond: 1, goldReward: 0, essenceReward: 0, crystalReward: 0, upgradeRewards: [], equipmentRewards: [], prestigeRequirement: 0 },
] as GameState["bosses"],
achievements: [
{ id: "ach1", unlockedAt: 1000 }, // prev has unlockedAt → anti-rollback when incoming=null
{ id: "ach2", unlockedAt: null }, // prev null → future timestamp check → caught
{ id: "ach3", unlockedAt: null }, // prev null → legitimate past unlock → return a
] as GameState["achievements"],
exploration: {
areas: [],
materials: [{ materialId: "verdant_sap", quantity: 10 }],
craftedRecipeIds: ["haunted_mine_recipe"],
craftedGoldMultiplier: 2,
craftedEssenceMultiplier: 1,
craftedClickMultiplier: 1,
craftedCombatMultiplier: 1,
},
transcendence: { count: 1, echoes: 10, purchasedUpgradeIds: [], echoIncomeMultiplier: 1, echoCombatMultiplier: 1, echoPrestigeThresholdMultiplier: 1, echoPrestigeRunestoneMultiplier: 1, echoMetaMultiplier: 1 },
apotheosis: { count: 2 },
story: { unlockedChapterIds: ["ch1"], completedChapters: [{ chapterId: "ch1", completedAt: 1000 }] },
});
const incomingState = makeState({
resources: { gold: 1e18, essence: 1e18, crystals: 5, runestones: 0 },
adventurers: [
{ id: "militia", count: 5, unlocked: true, level: 2, goldPerSecond: 0.5, essencePerSecond: 0, combatPower: 3 },
] as GameState["adventurers"],
upgrades: [
{ id: "global_1", purchased: true, unlocked: true, target: "global", multiplier: 2 },
{ id: "click_1", purchased: true, unlocked: true, target: "click", multiplier: 1.5 },
] as GameState["upgrades"],
quests: [
{ id: "first_steps", status: "completed", startedAt: 1000 }, // was active → now completed
{ id: "goblin_camp", status: "completed", startedAt: 1000 }, // both completed → skip
{ id: "haunted_mine", status: "completed", startedAt: null }, // prevStatus=locked → skip
{ id: "ancient_ruins", status: "completed", startedAt: null }, // startedAt=null → skip
{ id: "not_a_real_quest", status: "completed", startedAt: 1000 }, // !questData → skip
{ id: "rollback_quest", status: "active", startedAt: 1000 }, // anti-rollback → restored
{ id: "orphan_quest", status: "completed", startedAt: 1000 }, // !prevQuest → skip
{ id: "still_active_quest", status: "active", startedAt: 1000 }, // status !== completed → skip
] as GameState["quests"],
bosses: [
{ id: "troll_king", status: "defeated", currentHp: 0, maxHp: 1000, damagePerSecond: 5, goldReward: 10000, essenceReward: 25, crystalReward: 0, upgradeRewards: [], equipmentRewards: [], prestigeRequirement: 0 },
{ id: "lich_queen", status: "defeated", currentHp: 0, maxHp: 10000, damagePerSecond: 20, goldReward: 100000, essenceReward: 200, crystalReward: 10, upgradeRewards: [], equipmentRewards: [], prestigeRequirement: 0 },
{ id: "forest_giant", status: "defeated", currentHp: 0, maxHp: 35000, damagePerSecond: 40, goldReward: 350000, essenceReward: 400, crystalReward: 20, upgradeRewards: [], equipmentRewards: [], prestigeRequirement: 0 },
{ id: "not_a_real_boss", status: "defeated", currentHp: 0, maxHp: 100, damagePerSecond: 1, goldReward: 0, essenceReward: 0, crystalReward: 0, upgradeRewards: [], equipmentRewards: [], prestigeRequirement: 0 },
{ id: "anti_rollback_boss", status: "available", currentHp: 100, maxHp: 100, damagePerSecond: 1, goldReward: 0, essenceReward: 0, crystalReward: 0, upgradeRewards: [], equipmentRewards: [], prestigeRequirement: 0 },
{ id: "orphan_boss", status: "defeated", currentHp: 0, maxHp: 100, damagePerSecond: 1, goldReward: 0, essenceReward: 0, crystalReward: 0, upgradeRewards: [], equipmentRewards: [], prestigeRequirement: 0 },
{ id: "still_available_boss", status: "available", currentHp: 100, maxHp: 100, damagePerSecond: 1, goldReward: 0, essenceReward: 0, crystalReward: 0, upgradeRewards: [], equipmentRewards: [], prestigeRequirement: 0 },
] as GameState["bosses"],
achievements: [
{ id: "ach1", unlockedAt: null }, // prev had unlockedAt → anti-rollback restores it
{ id: "ach2", unlockedAt: now + 99999 }, // future timestamp → cheat caught
{ id: "ach3", unlockedAt: 1000 }, // past timestamp → legitimate unlock
{ id: "ach4", unlockedAt: null }, // not in prev → !prev → return a
] as GameState["achievements"],
exploration: {
areas: [],
materials: [{ materialId: "verdant_sap", quantity: 1000 }], // inflated → capped at 10
craftedRecipeIds: ["haunted_mine_recipe", "fake_recipe"], // fake_recipe filtered out
craftedGoldMultiplier: 1,
craftedEssenceMultiplier: 1,
craftedClickMultiplier: 1,
craftedCombatMultiplier: 1,
},
transcendence: { count: 1, echoes: 100, purchasedUpgradeIds: [], echoIncomeMultiplier: 1, echoCombatMultiplier: 1, echoPrestigeThresholdMultiplier: 1, echoPrestigeRunestoneMultiplier: 1, echoMetaMultiplier: 1 },
apotheosis: { count: 5 },
story: {
unlockedChapterIds: ["ch1", "ch2"],
completedChapters: [{ chapterId: "ch1", completedAt: 1000 }, { chapterId: "ch2", completedAt: now }],
},
});
vi.mocked(prisma.gameState.findUnique).mockResolvedValueOnce({ state: prevState } as never);
vi.mocked(prisma.player.findUnique).mockResolvedValueOnce(makePlayer({ createdAt: Date.now() }) as never);
vi.mocked(prisma.player.update).mockResolvedValueOnce({} as never);
vi.mocked(prisma.gameState.upsert).mockResolvedValueOnce({} as never);
const res = await save({ state: incomingState });
expect(res.status).toBe(200);
const body = await res.json() as { savedAt: number };
expect(body.savedAt).toBeGreaterThan(0);
});
it("validates companion when active companion is legitimately unlocked", async () => {
const prevState = makeState();
const stateWithCompanion = makeState({
companions: { unlockedCompanionIds: [], activeCompanionId: "lyra" },
});
vi.mocked(prisma.gameState.findUnique).mockResolvedValueOnce({ state: prevState } as never);
vi.mocked(prisma.player.findUnique).mockResolvedValueOnce(
makePlayer({ lifetimeBossesDefeated: 100 }) as never,
);
vi.mocked(prisma.player.update).mockResolvedValueOnce({} as never);
vi.mocked(prisma.gameState.upsert).mockResolvedValueOnce({} as never);
const res = await save({ state: stateWithCompanion });
expect(res.status).toBe(200);
});
});
describe("POST /reset", () => {
const reset = () =>
app.fetch(new Request("http://localhost/game/reset", { method: "POST" }));
it("returns 404 when player is not found", async () => {
vi.mocked(prisma.player.findUnique).mockResolvedValueOnce(null);
const res = await reset();
expect(res.status).toBe(404);
});
it("creates fresh state and returns it on success", async () => {
vi.mocked(prisma.player.findUnique).mockResolvedValueOnce(makePlayer() as never);
vi.mocked(prisma.gameState.upsert).mockResolvedValueOnce({} as never);
const res = await reset();
expect(res.status).toBe(200);
const body = await res.json() as { offlineGold: number; schemaOutdated: boolean; loginBonus: null };
expect(body.offlineGold).toBe(0);
expect(body.schemaOutdated).toBe(false);
expect(body.loginBonus).toBeNull();
});
it("includes HMAC signature in reset response when secret is configured", async () => {
process.env["ANTI_CHEAT_SECRET"] = "reset_secret";
vi.mocked(prisma.player.findUnique).mockResolvedValueOnce(makePlayer() as never);
vi.mocked(prisma.gameState.upsert).mockResolvedValueOnce({} as never);
const res = await reset();
expect(res.status).toBe(200);
const body = await res.json() as { signature: string | undefined };
expect(typeof body.signature).toBe("string");
});
});
});
+198
View File
@@ -0,0 +1,198 @@
/* eslint-disable max-lines-per-function -- Test suites naturally have many cases */
/* eslint-disable @typescript-eslint/consistent-type-assertions -- Tests build minimal state objects */
import { beforeEach, describe, expect, it, vi } from "vitest";
import { Hono } from "hono";
vi.mock("../../src/db/client.js", () => ({
prisma: {
player: { findMany: vi.fn() },
gameState: { findMany: vi.fn() },
},
}));
const makePlayer = (overrides: Record<string, unknown> = {}) => ({
discordId: "player_1",
characterName: "Hero",
username: "hero",
avatar: null,
profileSettings: null,
activeTitle: null,
lifetimeGoldEarned: 0,
lifetimeBossesDefeated: 0,
lifetimeQuestsCompleted: 0,
lifetimeAchievementsUnlocked: 0,
...overrides,
});
describe("leaderboards route", () => {
let app: Hono;
let prisma: { player: { findMany: ReturnType<typeof vi.fn> }; gameState: { findMany: ReturnType<typeof vi.fn> } };
beforeEach(async () => {
vi.clearAllMocks();
const { leaderboardRouter } = await import("../../src/routes/leaderboards.js");
const { prisma: p } = await import("../../src/db/client.js");
prisma = p as typeof prisma;
app = new Hono();
app.route("/leaderboards", leaderboardRouter);
});
const get = (query = "") =>
app.fetch(new Request(`http://localhost/leaderboards${query ? `?${query}` : ""}`));
it("returns 400 for an invalid category", async () => {
const res = await get("category=invalid");
expect(res.status).toBe(400);
});
it("returns totalGold leaderboard by default", async () => {
const players = [
makePlayer({ discordId: "p1", lifetimeGoldEarned: 1000 }),
makePlayer({ discordId: "p2", lifetimeGoldEarned: 500 }),
];
vi.mocked(prisma.player.findMany).mockResolvedValueOnce(players as never);
const res = await get();
expect(res.status).toBe(200);
const body = await res.json() as { category: string; entries: Array<{ rank: number; value: number }> };
expect(body.category).toBe("totalGold");
expect(body.entries[0]?.value).toBe(1000);
expect(body.entries[0]?.rank).toBe(1);
});
it("returns bossesDefeated leaderboard", async () => {
vi.mocked(prisma.player.findMany).mockResolvedValueOnce([makePlayer({ lifetimeBossesDefeated: 42 })] as never);
const res = await get("category=bossesDefeated");
expect(res.status).toBe(200);
const body = await res.json() as { entries: Array<{ value: number }> };
expect(body.entries[0]?.value).toBe(42);
});
it("returns questsCompleted leaderboard", async () => {
vi.mocked(prisma.player.findMany).mockResolvedValueOnce([makePlayer({ lifetimeQuestsCompleted: 7 })] as never);
const res = await get("category=questsCompleted");
expect(res.status).toBe(200);
const body = await res.json() as { entries: Array<{ value: number }> };
expect(body.entries[0]?.value).toBe(7);
});
it("returns achievementsUnlocked leaderboard", async () => {
vi.mocked(prisma.player.findMany).mockResolvedValueOnce([makePlayer({ lifetimeAchievementsUnlocked: 3 })] as never);
const res = await get("category=achievementsUnlocked");
expect(res.status).toBe(200);
const body = await res.json() as { entries: Array<{ value: number }> };
expect(body.entries[0]?.value).toBe(3);
});
it("returns prestigeCount from game state", async () => {
vi.mocked(prisma.player.findMany).mockResolvedValueOnce([makePlayer({ discordId: "p1" })] as never);
vi.mocked(prisma.gameState.findMany).mockResolvedValueOnce([{
discordId: "p1",
state: { prestige: { count: 5 }, transcendence: null, apotheosis: null },
}] as never);
const res = await get("category=prestigeCount");
expect(res.status).toBe(200);
const body = await res.json() as { entries: Array<{ value: number }> };
expect(body.entries[0]?.value).toBe(5);
});
it("returns transcendenceCount from game state", async () => {
vi.mocked(prisma.player.findMany).mockResolvedValueOnce([makePlayer({ discordId: "p1" })] as never);
vi.mocked(prisma.gameState.findMany).mockResolvedValueOnce([{
discordId: "p1",
state: { prestige: { count: 0 }, transcendence: { count: 2 }, apotheosis: null },
}] as never);
const res = await get("category=transcendenceCount");
expect(res.status).toBe(200);
const body = await res.json() as { entries: Array<{ value: number }> };
expect(body.entries[0]?.value).toBe(2);
});
it("returns apotheosisCount from game state", async () => {
vi.mocked(prisma.player.findMany).mockResolvedValueOnce([makePlayer({ discordId: "p1" })] as never);
vi.mocked(prisma.gameState.findMany).mockResolvedValueOnce([{
discordId: "p1",
state: { prestige: { count: 0 }, transcendence: null, apotheosis: { count: 1 } },
}] as never);
const res = await get("category=apotheosisCount");
expect(res.status).toBe(200);
const body = await res.json() as { entries: Array<{ value: number }> };
expect(body.entries[0]?.value).toBe(1);
});
it("filters out players with showOnLeaderboards=false", async () => {
const players = [
makePlayer({ discordId: "visible", lifetimeGoldEarned: 100 }),
makePlayer({ discordId: "hidden", lifetimeGoldEarned: 200, profileSettings: { showOnLeaderboards: false } }),
];
vi.mocked(prisma.player.findMany).mockResolvedValueOnce(players as never);
const res = await get();
expect(res.status).toBe(200);
const body = await res.json() as { entries: Array<{ discordId: string }> };
expect(body.entries).toHaveLength(1);
expect(body.entries[0]?.discordId).toBe("visible");
});
it("respects the limit parameter", async () => {
const players = Array.from({ length: 5 }, (_, i) => makePlayer({ discordId: `p${String(i)}`, lifetimeGoldEarned: i }));
vi.mocked(prisma.player.findMany).mockResolvedValueOnce(players as never);
const res = await get("limit=2");
expect(res.status).toBe(200);
const body = await res.json() as { entries: unknown[] };
expect(body.entries).toHaveLength(2);
});
it("uses active title name in entries", async () => {
vi.mocked(prisma.player.findMany).mockResolvedValueOnce([
makePlayer({ discordId: "p1", activeTitle: "the_first" }),
] as never);
const res = await get();
expect(res.status).toBe(200);
const body = await res.json() as { entries: Array<{ activeTitle: string }> };
// title may or may not be found — just verify the field exists
expect(typeof body.entries[0]?.activeTitle).toBe("string");
});
it("defaults to 0 for game-state categories when state is missing", async () => {
vi.mocked(prisma.player.findMany).mockResolvedValueOnce([makePlayer({ discordId: "p1" })] as never);
vi.mocked(prisma.gameState.findMany).mockResolvedValueOnce([] as never);
const res = await get("category=prestigeCount");
expect(res.status).toBe(200);
const body = await res.json() as { entries: Array<{ value: number }> };
expect(body.entries[0]?.value).toBe(0);
});
it("resolves title name when active title ID is found in TITLES", async () => {
vi.mocked(prisma.player.findMany).mockResolvedValueOnce([
makePlayer({ discordId: "p1", activeTitle: "the_adventurous" }),
] as never);
const res = await get();
expect(res.status).toBe(200);
const body = await res.json() as { entries: Array<{ activeTitle: string }> };
// "the_adventurous" has name "The Adventurous" in TITLES — should differ from raw ID
expect(body.entries[0]?.activeTitle).toBe("The Adventurous");
});
it("defaults to 0 for transcendenceCount when transcendence is null in state", async () => {
vi.mocked(prisma.player.findMany).mockResolvedValueOnce([makePlayer({ discordId: "p1" })] as never);
vi.mocked(prisma.gameState.findMany).mockResolvedValueOnce([{
discordId: "p1",
state: { prestige: { count: 0 }, transcendence: null, apotheosis: null },
}] as never);
const res = await get("category=transcendenceCount");
expect(res.status).toBe(200);
const body = await res.json() as { entries: Array<{ value: number }> };
expect(body.entries[0]?.value).toBe(0);
});
it("defaults to 0 for apotheosisCount when apotheosis is null in state", async () => {
vi.mocked(prisma.player.findMany).mockResolvedValueOnce([makePlayer({ discordId: "p1" })] as never);
vi.mocked(prisma.gameState.findMany).mockResolvedValueOnce([{
discordId: "p1",
state: { prestige: { count: 0 }, transcendence: null, apotheosis: null },
}] as never);
const res = await get("category=apotheosisCount");
expect(res.status).toBe(200);
const body = await res.json() as { entries: Array<{ value: number }> };
expect(body.entries[0]?.value).toBe(0);
});
});
+156
View File
@@ -0,0 +1,156 @@
/* eslint-disable max-lines-per-function -- Test suites naturally have many cases */
/* eslint-disable max-lines -- Test suites naturally have many cases */
/* eslint-disable @typescript-eslint/consistent-type-assertions -- Tests build minimal state objects */
import { beforeEach, describe, expect, it, vi } from "vitest";
import { Hono } from "hono";
import type { GameState } from "@elysium/types";
vi.mock("../../src/db/client.js", () => ({
prisma: {
player: { update: vi.fn() },
gameState: { findUnique: vi.fn(), update: vi.fn() },
},
}));
vi.mock("../../src/middleware/auth.js", () => ({
authMiddleware: vi.fn(async (c: { set: (key: string, value: string) => void }, next: () => Promise<void>) => {
c.set("discordId", "test_discord_id");
await next();
}),
}));
vi.mock("../../src/services/webhook.js", () => ({
postMilestoneWebhook: vi.fn().mockResolvedValue(undefined),
}));
const DISCORD_ID = "test_discord_id";
const makeState = (overrides: Partial<GameState> = {}): GameState => ({
player: { discordId: DISCORD_ID, username: "u", discriminator: "0", avatar: null, totalGoldEarned: 1_000_000, totalClicks: 0, characterName: "T" },
resources: { gold: 0, essence: 0, crystals: 0, runestones: 0 },
adventurers: [],
upgrades: [],
quests: [],
bosses: [],
equipment: [],
achievements: [],
zones: [],
exploration: { areas: [], materials: [], craftedRecipeIds: [], craftedGoldMultiplier: 1, craftedEssenceMultiplier: 1, craftedClickMultiplier: 1, craftedCombatMultiplier: 1 },
companions: { unlockedCompanionIds: [], activeCompanionId: null },
prestige: { count: 0, runestones: 100, productionMultiplier: 1, purchasedUpgradeIds: [] },
baseClickPower: 1,
lastTickAt: 0,
schemaVersion: 1,
...overrides,
} as GameState);
describe("prestige route", () => {
let app: Hono;
let prisma: {
player: { update: ReturnType<typeof vi.fn> };
gameState: { findUnique: ReturnType<typeof vi.fn>; update: ReturnType<typeof vi.fn> };
};
beforeEach(async () => {
vi.clearAllMocks();
const { prestigeRouter } = await import("../../src/routes/prestige.js");
const { prisma: p } = await import("../../src/db/client.js");
prisma = p as typeof prisma;
app = new Hono();
app.route("/prestige", prestigeRouter);
});
const post = (path: string, body?: Record<string, unknown>) =>
app.fetch(new Request(`http://localhost/prestige${path}`, {
method: "POST",
headers: body ? { "Content-Type": "application/json" } : undefined,
body: body ? JSON.stringify(body) : undefined,
}));
describe("POST /", () => {
it("returns 404 when no save is found", async () => {
vi.mocked(prisma.gameState.findUnique).mockResolvedValueOnce(null);
const res = await post("");
expect(res.status).toBe(404);
});
it("returns 400 when not eligible (not enough gold)", async () => {
const state = makeState({ player: { discordId: DISCORD_ID, username: "u", discriminator: "0", avatar: null, totalGoldEarned: 0, totalClicks: 0, characterName: "T" } });
vi.mocked(prisma.gameState.findUnique).mockResolvedValueOnce({ state } as never);
const res = await post("");
expect(res.status).toBe(400);
});
it("returns runestones on successful prestige", async () => {
const state = makeState();
vi.mocked(prisma.gameState.findUnique).mockResolvedValueOnce({ state } as never);
vi.mocked(prisma.gameState.update).mockResolvedValueOnce({} as never);
vi.mocked(prisma.player.update).mockResolvedValueOnce({} as never);
const res = await post("");
expect(res.status).toBe(200);
const body = await res.json() as { runestones: number; newPrestigeCount: number };
expect(body.newPrestigeCount).toBe(1);
expect(body.runestones).toBeGreaterThanOrEqual(0);
});
it("updates daily challenge progress when dailyChallenges are set", async () => {
const state = makeState({
dailyChallenges: {
date: "2024-01-01",
challenges: [{ id: "prestige_challenge", type: "prestige", target: 2, progress: 0, completed: false, crystalReward: 5 }],
} as GameState["dailyChallenges"],
});
vi.mocked(prisma.gameState.findUnique).mockResolvedValueOnce({ state } as never);
vi.mocked(prisma.gameState.update).mockResolvedValueOnce({} as never);
vi.mocked(prisma.player.update).mockResolvedValueOnce({} as never);
const res = await post("");
expect(res.status).toBe(200);
const body = await res.json() as { runestones: number; newPrestigeCount: number };
expect(body.newPrestigeCount).toBe(1);
});
});
describe("POST /buy-upgrade", () => {
it("returns 400 when upgradeId is missing", async () => {
const res = await post("/buy-upgrade", {});
expect(res.status).toBe(400);
});
it("returns 404 for unknown upgrade", async () => {
const res = await post("/buy-upgrade", { upgradeId: "nonexistent_upgrade" });
expect(res.status).toBe(404);
});
it("returns 404 when no save is found", async () => {
vi.mocked(prisma.gameState.findUnique).mockResolvedValueOnce(null);
const res = await post("/buy-upgrade", { upgradeId: "income_1" });
expect(res.status).toBe(404);
});
it("returns 400 when upgrade is already purchased", async () => {
const state = makeState({ prestige: { count: 0, runestones: 100, productionMultiplier: 1, purchasedUpgradeIds: ["income_1"] } });
vi.mocked(prisma.gameState.findUnique).mockResolvedValueOnce({ state } as never);
const res = await post("/buy-upgrade", { upgradeId: "income_1" });
expect(res.status).toBe(400);
});
it("returns 400 when not enough runestones", async () => {
const state = makeState({ prestige: { count: 0, runestones: 0, productionMultiplier: 1, purchasedUpgradeIds: [] } });
vi.mocked(prisma.gameState.findUnique).mockResolvedValueOnce({ state } as never);
// income_1 costs 10 runestones but state has 0
const res = await post("/buy-upgrade", { upgradeId: "income_1" });
expect(res.status).toBe(400);
});
it("returns updated multipliers on successful purchase", async () => {
const state = makeState({ prestige: { count: 0, runestones: 100, productionMultiplier: 1, purchasedUpgradeIds: [] } });
vi.mocked(prisma.gameState.findUnique).mockResolvedValueOnce({ state } as never);
vi.mocked(prisma.gameState.update).mockResolvedValueOnce({} as never);
const res = await post("/buy-upgrade", { upgradeId: "income_1" });
expect(res.status).toBe(200);
const body = await res.json() as { runestonesRemaining: number; purchasedUpgradeIds: string[] };
expect(body.runestonesRemaining).toBe(90); // 100 - 10
expect(body.purchasedUpgradeIds).toContain("income_1");
});
});
});
+260
View File
@@ -0,0 +1,260 @@
/* eslint-disable max-lines-per-function -- Test suites naturally have many cases */
/* eslint-disable max-lines -- Test suites naturally have many cases */
/* eslint-disable @typescript-eslint/consistent-type-assertions -- Tests build minimal state objects */
import { beforeEach, describe, expect, it, vi } from "vitest";
import { Hono } from "hono";
import type { GameState } from "@elysium/types";
vi.mock("../../src/db/client.js", () => ({
prisma: {
player: { findUnique: vi.fn(), update: vi.fn() },
gameState: { findUnique: vi.fn() },
},
}));
vi.mock("../../src/middleware/auth.js", () => ({
authMiddleware: vi.fn(async (c: { set: (key: string, value: string) => void }, next: () => Promise<void>) => {
c.set("discordId", "test_discord_id");
await next();
}),
}));
const DISCORD_ID = "test_discord_id";
const makePlayer = (overrides: Record<string, unknown> = {}) => ({
discordId: DISCORD_ID,
characterName: "Hero",
username: "hero",
discriminator: "0",
avatar: null,
pronouns: "she/her",
characterRace: "Elf",
characterClass: "Mage",
bio: "A brave hero",
guildName: "Brave Guild",
guildDescription: "We are brave",
profileSettings: null,
createdAt: 1000,
lastSavedAt: 2000,
lifetimeGoldEarned: 500,
lifetimeClicks: 100,
lifetimeBossesDefeated: 5,
lifetimeQuestsCompleted: 10,
lifetimeAdventurersRecruited: 20,
lifetimeAchievementsUnlocked: 3,
unlockedTitles: null,
activeTitle: null,
loginStreak: 1,
lastLoginDate: null,
...overrides,
});
const makeState = (overrides: Partial<GameState> = {}): GameState => ({
player: { discordId: DISCORD_ID, username: "hero", discriminator: "0", avatar: null, totalGoldEarned: 0, totalClicks: 0, characterName: "Hero" },
resources: { gold: 0, essence: 0, crystals: 0, runestones: 0 },
adventurers: [],
upgrades: [],
quests: [],
bosses: [],
equipment: [],
achievements: [],
zones: [],
exploration: { areas: [], materials: [], craftedRecipeIds: [], craftedGoldMultiplier: 1, craftedEssenceMultiplier: 1, craftedClickMultiplier: 1, craftedCombatMultiplier: 1 },
companions: { unlockedCompanionIds: [], activeCompanionId: null },
prestige: { count: 0, runestones: 0, productionMultiplier: 1, purchasedUpgradeIds: [] },
baseClickPower: 1,
lastTickAt: 0,
schemaVersion: 1,
...overrides,
} as GameState);
describe("profile route", () => {
let app: Hono;
let prisma: {
player: { findUnique: ReturnType<typeof vi.fn>; update: ReturnType<typeof vi.fn> };
gameState: { findUnique: ReturnType<typeof vi.fn> };
};
beforeEach(async () => {
vi.clearAllMocks();
const { profileRouter } = await import("../../src/routes/profile.js");
const { prisma: p } = await import("../../src/db/client.js");
prisma = p as typeof prisma;
app = new Hono();
app.route("/profile", profileRouter);
});
describe("GET /:discordId", () => {
it("returns 404 when player is not found", async () => {
vi.mocked(prisma.player.findUnique).mockResolvedValueOnce(null);
vi.mocked(prisma.gameState.findUnique).mockResolvedValueOnce(null);
const res = await app.fetch(new Request("http://localhost/profile/unknown_id"));
expect(res.status).toBe(404);
});
it("returns player profile with game state data", async () => {
const state = makeState({
prestige: { count: 3, runestones: 10, productionMultiplier: 1.45, purchasedUpgradeIds: [] },
bosses: [{ id: "b1", status: "defeated" }] as GameState["bosses"],
quests: [{ id: "q1", status: "completed" }] as GameState["quests"],
achievements: [{ id: "a1", unlockedAt: 1000 }] as GameState["achievements"],
transcendence: { count: 1, echoes: 10, purchasedUpgradeIds: [], echoIncomeMultiplier: 1, echoCombatMultiplier: 1, echoPrestigeThresholdMultiplier: 1, echoPrestigeRunestoneMultiplier: 1, echoMetaMultiplier: 1 },
apotheosis: { count: 1 },
});
vi.mocked(prisma.player.findUnique).mockResolvedValueOnce(makePlayer() as never);
vi.mocked(prisma.gameState.findUnique).mockResolvedValueOnce({ state } as never);
const res = await app.fetch(new Request(`http://localhost/profile/${DISCORD_ID}`));
expect(res.status).toBe(200);
const body = await res.json() as {
characterName: string;
prestigeCount: number;
bossesDefeated: number;
questsCompleted: number;
achievementsUnlocked: number;
transcendenceCount: number;
apotheosisCount: number;
};
expect(body.characterName).toBe("Hero");
expect(body.prestigeCount).toBe(3);
expect(body.bossesDefeated).toBe(1);
expect(body.questsCompleted).toBe(1);
expect(body.achievementsUnlocked).toBe(1);
expect(body.transcendenceCount).toBe(1);
expect(body.apotheosisCount).toBe(1);
});
it("returns empty strings for null nullable player fields", async () => {
vi.mocked(prisma.player.findUnique).mockResolvedValueOnce(
makePlayer({ pronouns: null, characterRace: null, characterClass: null, bio: null, guildName: null, guildDescription: null }) as never,
);
vi.mocked(prisma.gameState.findUnique).mockResolvedValueOnce(null);
const res = await app.fetch(new Request(`http://localhost/profile/${DISCORD_ID}`));
expect(res.status).toBe(200);
const body = await res.json() as { pronouns: string; characterRace: string; bio: string };
expect(body.pronouns).toBe("");
expect(body.characterRace).toBe("");
expect(body.bio).toBe("");
});
it("returns defaults when no game state exists", async () => {
vi.mocked(prisma.player.findUnique).mockResolvedValueOnce(makePlayer() as never);
vi.mocked(prisma.gameState.findUnique).mockResolvedValueOnce(null);
const res = await app.fetch(new Request(`http://localhost/profile/${DISCORD_ID}`));
expect(res.status).toBe(200);
const body = await res.json() as { prestigeCount: number; bossesDefeated: number };
expect(body.prestigeCount).toBe(0);
expect(body.bossesDefeated).toBe(0);
});
it("parses profileSettings when it is a valid object", async () => {
const settings = { showTotalGold: false, showOnLeaderboards: false, numberFormat: "scientific" };
vi.mocked(prisma.player.findUnique).mockResolvedValueOnce(makePlayer({ profileSettings: settings }) as never);
vi.mocked(prisma.gameState.findUnique).mockResolvedValueOnce(null);
const res = await app.fetch(new Request(`http://localhost/profile/${DISCORD_ID}`));
expect(res.status).toBe(200);
const body = await res.json() as { profileSettings: { numberFormat: string; showTotalGold: boolean } };
expect(body.profileSettings.numberFormat).toBe("scientific");
expect(body.profileSettings.showTotalGold).toBe(false);
});
it("falls back to suffix numberFormat in GET when stored profileSettings has invalid format", async () => {
vi.mocked(prisma.player.findUnique).mockResolvedValueOnce(
makePlayer({ profileSettings: { numberFormat: "invalid_format" } }) as never,
);
vi.mocked(prisma.gameState.findUnique).mockResolvedValueOnce(null);
const res = await app.fetch(new Request(`http://localhost/profile/${DISCORD_ID}`));
expect(res.status).toBe(200);
const body = await res.json() as { profileSettings: { numberFormat: string } };
expect(body.profileSettings.numberFormat).toBe("suffix");
});
it("maps known and unknown unlocked title IDs to name and fallback id", async () => {
vi.mocked(prisma.player.findUnique).mockResolvedValueOnce(
makePlayer({ unlockedTitles: ["the_adventurous", "unknown_title_id"] }) as never,
);
vi.mocked(prisma.gameState.findUnique).mockResolvedValueOnce(null);
const res = await app.fetch(new Request(`http://localhost/profile/${DISCORD_ID}`));
expect(res.status).toBe(200);
const body = await res.json() as { unlockedTitles: Array<{ id: string; name: string }> };
const known = body.unlockedTitles.find((t) => t.id === "the_adventurous");
expect(known?.name).toBe("The Adventurous");
const unknown = body.unlockedTitles.find((t) => t.id === "unknown_title_id");
expect(unknown?.name).toBe("unknown_title_id");
});
it("includes completed story chapters in profile response", async () => {
const state = makeState({
story: {
unlockedChapterIds: [ "boss_troll_king" ],
completedChapters: [ { chapterId: "boss_troll_king", choiceId: "fight" } ],
},
});
vi.mocked(prisma.player.findUnique).mockResolvedValueOnce(makePlayer() as never);
vi.mocked(prisma.gameState.findUnique).mockResolvedValueOnce({ state } as never);
const res = await app.fetch(new Request(`http://localhost/profile/${DISCORD_ID}`));
expect(res.status).toBe(200);
const body = await res.json() as {
completedChapters: Array<{ chapterId: string; choiceId: string }>;
};
expect(body.completedChapters).toHaveLength(1);
expect(body.completedChapters[0]).toMatchObject({ chapterId: "boss_troll_king", choiceId: "fight" });
});
});
describe("PUT /", () => {
const put = (body: Record<string, unknown>) =>
app.fetch(new Request("http://localhost/profile", {
method: "PUT",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(body),
}));
it("returns 400 when character name is empty after trim", async () => {
const res = await put({ characterName: " " });
expect(res.status).toBe(400);
});
it("returns 400 when characterName is absent from request body", async () => {
const res = await put({});
expect(res.status).toBe(400);
});
it("updates profile and returns updated data", async () => {
const updatedPlayer = {
characterName: "NewName", pronouns: "they/them", characterRace: "Human", characterClass: "Rogue",
bio: "Updated bio", guildName: "New Guild", guildDescription: "Desc",
profileSettings: null, activeTitle: "the_first",
};
vi.mocked(prisma.player.update).mockResolvedValueOnce(updatedPlayer as never);
const res = await put({
characterName: "NewName",
pronouns: "they/them",
characterRace: "Human",
characterClass: "Rogue",
bio: "Updated bio",
guildName: "New Guild",
guildDescription: "Desc",
profileSettings: { numberFormat: "engineering", showTotalGold: true, showOnLeaderboards: true },
activeTitle: "the_first",
});
expect(res.status).toBe(200);
const body = await res.json() as { characterName: string; activeTitle: string };
expect(body.characterName).toBe("NewName");
expect(body.activeTitle).toBe("the_first");
});
it("uses suffix numberFormat when invalid value is provided", async () => {
vi.mocked(prisma.player.update).mockResolvedValueOnce({
characterName: "Hero", pronouns: null, characterRace: null, characterClass: null,
bio: null, guildName: null, guildDescription: null, profileSettings: null, activeTitle: null,
} as never);
const res = await put({
characterName: "Hero",
profileSettings: { numberFormat: "invalid_format" },
});
expect(res.status).toBe(200);
const body = await res.json() as { profileSettings: { numberFormat: string } };
expect(body.profileSettings.numberFormat).toBe("suffix");
});
});
});
+153
View File
@@ -0,0 +1,153 @@
/* eslint-disable max-lines-per-function -- Test suites naturally have many cases */
/* eslint-disable max-lines -- Test suites naturally have many cases */
/* eslint-disable @typescript-eslint/consistent-type-assertions -- Tests build minimal state objects */
import { beforeEach, describe, expect, it, vi } from "vitest";
import { Hono } from "hono";
import type { GameState } from "@elysium/types";
vi.mock("../../src/db/client.js", () => ({
prisma: {
player: { update: vi.fn() },
gameState: { findUnique: vi.fn(), update: vi.fn() },
},
}));
vi.mock("../../src/middleware/auth.js", () => ({
authMiddleware: vi.fn(async (c: { set: (key: string, value: string) => void }, next: () => Promise<void>) => {
c.set("discordId", "test_discord_id");
await next();
}),
}));
vi.mock("../../src/services/webhook.js", () => ({
postMilestoneWebhook: vi.fn().mockResolvedValue(undefined),
}));
const DISCORD_ID = "test_discord_id";
const makeState = (overrides: Partial<GameState> = {}): GameState => ({
player: { discordId: DISCORD_ID, username: "u", discriminator: "0", avatar: null, totalGoldEarned: 0, totalClicks: 0, characterName: "T" },
resources: { gold: 0, essence: 0, crystals: 0, runestones: 0 },
adventurers: [],
upgrades: [],
quests: [],
bosses: [{ id: "the_absolute_one", status: "defeated" }] as GameState["bosses"],
equipment: [],
achievements: [],
zones: [],
exploration: { areas: [], materials: [], craftedRecipeIds: [], craftedGoldMultiplier: 1, craftedEssenceMultiplier: 1, craftedClickMultiplier: 1, craftedCombatMultiplier: 1 },
companions: { unlockedCompanionIds: [], activeCompanionId: null },
prestige: { count: 0, runestones: 0, productionMultiplier: 1, purchasedUpgradeIds: [] },
baseClickPower: 1,
lastTickAt: 0,
schemaVersion: 1,
...overrides,
} as GameState);
describe("transcendence route", () => {
let app: Hono;
let prisma: {
player: { update: ReturnType<typeof vi.fn> };
gameState: { findUnique: ReturnType<typeof vi.fn>; update: ReturnType<typeof vi.fn> };
};
beforeEach(async () => {
vi.clearAllMocks();
const { transcendenceRouter } = await import("../../src/routes/transcendence.js");
const { prisma: p } = await import("../../src/db/client.js");
prisma = p as typeof prisma;
app = new Hono();
app.route("/transcendence", transcendenceRouter);
});
const post = (path: string, body?: Record<string, unknown>) =>
app.fetch(new Request(`http://localhost/transcendence${path}`, {
method: "POST",
headers: body ? { "Content-Type": "application/json" } : undefined,
body: body ? JSON.stringify(body) : undefined,
}));
describe("POST /", () => {
it("returns 404 when no save is found", async () => {
vi.mocked(prisma.gameState.findUnique).mockResolvedValueOnce(null);
const res = await post("");
expect(res.status).toBe(404);
});
it("returns 400 when the absolute one is not defeated", async () => {
const state = makeState({ bosses: [] });
vi.mocked(prisma.gameState.findUnique).mockResolvedValueOnce({ state } as never);
const res = await post("");
expect(res.status).toBe(400);
});
it("returns echoes and count on successful transcendence", async () => {
const state = makeState();
vi.mocked(prisma.gameState.findUnique).mockResolvedValueOnce({ state } as never);
vi.mocked(prisma.gameState.update).mockResolvedValueOnce({} as never);
vi.mocked(prisma.player.update).mockResolvedValueOnce({} as never);
const res = await post("");
expect(res.status).toBe(200);
const body = await res.json() as { echoes: number; newTranscendenceCount: number };
expect(body.newTranscendenceCount).toBe(1);
expect(body.echoes).toBeGreaterThanOrEqual(0);
});
});
describe("POST /buy-upgrade", () => {
it("returns 400 when upgradeId is missing", async () => {
const res = await post("/buy-upgrade", {});
expect(res.status).toBe(400);
});
it("returns 404 for unknown upgrade", async () => {
const res = await post("/buy-upgrade", { upgradeId: "nonexistent_echo" });
expect(res.status).toBe(404);
});
it("returns 404 when no save is found", async () => {
vi.mocked(prisma.gameState.findUnique).mockResolvedValueOnce(null);
const res = await post("/buy-upgrade", { upgradeId: "echo_income_1" });
expect(res.status).toBe(404);
});
it("returns 400 when transcendence data is missing from state", async () => {
const state = makeState({ transcendence: undefined });
vi.mocked(prisma.gameState.findUnique).mockResolvedValueOnce({ state } as never);
const res = await post("/buy-upgrade", { upgradeId: "echo_income_1" });
expect(res.status).toBe(400);
});
it("returns 400 when upgrade is already purchased", async () => {
const state = makeState({
transcendence: { count: 1, echoes: 100, purchasedUpgradeIds: ["echo_income_1"], echoIncomeMultiplier: 1, echoCombatMultiplier: 1, echoPrestigeThresholdMultiplier: 1, echoPrestigeRunestoneMultiplier: 1, echoMetaMultiplier: 1 },
});
vi.mocked(prisma.gameState.findUnique).mockResolvedValueOnce({ state } as never);
const res = await post("/buy-upgrade", { upgradeId: "echo_income_1" });
expect(res.status).toBe(400);
});
it("returns 400 when not enough echoes", async () => {
const state = makeState({
transcendence: { count: 1, echoes: 0, purchasedUpgradeIds: [], echoIncomeMultiplier: 1, echoCombatMultiplier: 1, echoPrestigeThresholdMultiplier: 1, echoPrestigeRunestoneMultiplier: 1, echoMetaMultiplier: 1 },
});
vi.mocked(prisma.gameState.findUnique).mockResolvedValueOnce({ state } as never);
// echo_income_1 costs 5 echoes but state has 0
const res = await post("/buy-upgrade", { upgradeId: "echo_income_1" });
expect(res.status).toBe(400);
});
it("returns updated data on successful echo upgrade purchase", async () => {
const state = makeState({
transcendence: { count: 1, echoes: 100, purchasedUpgradeIds: [], echoIncomeMultiplier: 1, echoCombatMultiplier: 1, echoPrestigeThresholdMultiplier: 1, echoPrestigeRunestoneMultiplier: 1, echoMetaMultiplier: 1 },
});
vi.mocked(prisma.gameState.findUnique).mockResolvedValueOnce({ state } as never);
vi.mocked(prisma.gameState.update).mockResolvedValueOnce({} as never);
const res = await post("/buy-upgrade", { upgradeId: "echo_income_1" });
expect(res.status).toBe(200);
const body = await res.json() as { echoesRemaining: number; purchasedUpgradeIds: string[] };
expect(body.echoesRemaining).toBe(95); // 100 - 5
expect(body.purchasedUpgradeIds).toContain("echo_income_1");
});
});
});
+115
View File
@@ -0,0 +1,115 @@
/* eslint-disable max-lines-per-function -- Test suites naturally have many cases */
/* eslint-disable @typescript-eslint/consistent-type-assertions -- Tests build minimal state objects */
import { describe, expect, it } from "vitest";
import {
buildPostApotheosisState,
isEligibleForApotheosis,
} from "../../src/services/apotheosis.js";
import { defaultTranscendenceUpgrades } from "../../src/data/transcendenceUpgrades.js";
import type { GameState } from "@elysium/types";
const ALL_UPGRADE_IDS = defaultTranscendenceUpgrades.map((u) => u.id);
const makeMinimalState = (overrides: Partial<GameState> = {}): GameState =>
({
player: { discordId: "t", username: "u", discriminator: "0", avatar: null, totalGoldEarned: 0, totalClicks: 0, characterName: "T" },
resources: { gold: 0, essence: 0, crystals: 0, runestones: 0 },
adventurers: [],
upgrades: [],
quests: [],
bosses: [],
equipment: [],
achievements: [],
zones: [],
exploration: { areas: [], materials: [], craftedRecipeIds: [], craftedGoldMultiplier: 1, craftedEssenceMultiplier: 1, craftedClickMultiplier: 1, craftedCombatMultiplier: 1 },
companions: { unlockedCompanionIds: [], activeCompanionId: null },
prestige: { count: 0, runestones: 0, productionMultiplier: 1, purchasedUpgradeIds: [] },
baseClickPower: 1,
lastTickAt: 0,
schemaVersion: 1,
...overrides,
} as GameState);
describe("isEligibleForApotheosis", () => {
it("returns true when all transcendence upgrades are purchased", () => {
const state = makeMinimalState({
transcendence: {
count: 1, echoes: 0, purchasedUpgradeIds: ALL_UPGRADE_IDS,
echoIncomeMultiplier: 1, echoCombatMultiplier: 1,
echoPrestigeThresholdMultiplier: 1, echoPrestigeRunestoneMultiplier: 1, echoMetaMultiplier: 1,
},
});
expect(isEligibleForApotheosis(state)).toBe(true);
});
it("returns false when one upgrade is missing", () => {
const partialIds = ALL_UPGRADE_IDS.slice(0, -1);
const state = makeMinimalState({
transcendence: {
count: 1, echoes: 0, purchasedUpgradeIds: partialIds,
echoIncomeMultiplier: 1, echoCombatMultiplier: 1,
echoPrestigeThresholdMultiplier: 1, echoPrestigeRunestoneMultiplier: 1, echoMetaMultiplier: 1,
},
});
expect(isEligibleForApotheosis(state)).toBe(false);
});
it("returns false when transcendence is undefined", () => {
const state = makeMinimalState({ transcendence: undefined });
expect(isEligibleForApotheosis(state)).toBe(false);
});
it("returns false when purchasedUpgradeIds is empty", () => {
const state = makeMinimalState({
transcendence: {
count: 1, echoes: 0, purchasedUpgradeIds: [],
echoIncomeMultiplier: 1, echoCombatMultiplier: 1,
echoPrestigeThresholdMultiplier: 1, echoPrestigeRunestoneMultiplier: 1, echoMetaMultiplier: 1,
},
});
expect(isEligibleForApotheosis(state)).toBe(false);
});
});
describe("buildPostApotheosisState", () => {
it("increments apotheosis count from 0", () => {
const state = makeMinimalState();
const { updatedApotheosisData } = buildPostApotheosisState(state, "T");
expect(updatedApotheosisData.count).toBe(1);
});
it("increments apotheosis count from existing value", () => {
const state = makeMinimalState({ apotheosis: { count: 2 } });
const { updatedApotheosisData } = buildPostApotheosisState(state, "T");
expect(updatedApotheosisData.count).toBe(3);
});
it("persists codex", () => {
const codex = { entries: [{ id: "e1", unlockedAt: 1000, sourceType: "exploration" as const }] };
const state = makeMinimalState({ codex });
const { updatedState } = buildPostApotheosisState(state, "T");
expect(updatedState.codex).toEqual(codex);
});
it("persists story", () => {
const story = { unlockedChapterIds: ["ch1"], completedChapters: [] };
const state = makeMinimalState({ story });
const { updatedState } = buildPostApotheosisState(state, "T");
expect(updatedState.story).toEqual(story);
});
it("wipes prestige data", () => {
const state = makeMinimalState({
prestige: { count: 10, runestones: 1000, productionMultiplier: 3, purchasedUpgradeIds: [] },
});
const { updatedState } = buildPostApotheosisState(state, "T");
expect(updatedState.prestige.count).toBe(0);
expect(updatedState.prestige.runestones).toBe(0);
});
it("sets apotheosis count on new state", () => {
const state = makeMinimalState({ apotheosis: { count: 0 } });
const { updatedState } = buildPostApotheosisState(state, "T");
expect(updatedState.apotheosis?.count).toBe(1);
});
});
@@ -0,0 +1,162 @@
/* eslint-disable max-lines-per-function -- Test suites naturally have many cases */
/* eslint-disable max-lines -- Test suites naturally have many cases */
/* eslint-disable @typescript-eslint/consistent-type-assertions -- Tests build minimal state objects */
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import type { DailyChallengeState, GameState } from "@elysium/types";
// We reset modules so the module picks up fake timers when re-imported
beforeEach(() => {
vi.resetModules();
vi.useFakeTimers();
});
afterEach(() => {
vi.useRealTimers();
});
const makeState = (dailyChallenges?: DailyChallengeState): GameState =>
({ dailyChallenges } as unknown as GameState);
const LA_MIDNIGHT_2024_01_15 = new Date("2024-01-15T08:00:00.000Z"); // LA midnight = UTC+8
const LA_MIDNIGHT_2024_01_16 = new Date("2024-01-16T08:00:00.000Z");
describe("generateDailyChallenges", () => {
it("returns exactly 3 challenges", async () => {
vi.setSystemTime(LA_MIDNIGHT_2024_01_15);
const { generateDailyChallenges } = await import("../../src/services/dailyChallenges.js");
const result = generateDailyChallenges("2024-01-15");
expect(result).toHaveLength(3);
});
it("all challenges start with progress 0 and completed false", async () => {
vi.setSystemTime(LA_MIDNIGHT_2024_01_15);
const { generateDailyChallenges } = await import("../../src/services/dailyChallenges.js");
const result = generateDailyChallenges("2024-01-15");
for (const challenge of result) {
expect(challenge.progress).toBe(0);
expect(challenge.completed).toBe(false);
}
});
it("is deterministic for the same date", async () => {
vi.setSystemTime(LA_MIDNIGHT_2024_01_15);
const { generateDailyChallenges } = await import("../../src/services/dailyChallenges.js");
const a = generateDailyChallenges("2024-01-15");
const b = generateDailyChallenges("2024-01-15");
expect(a.map((c) => c.id)).toEqual(b.map((c) => c.id));
});
it("generates different challenges for different dates", async () => {
vi.setSystemTime(LA_MIDNIGHT_2024_01_15);
const { generateDailyChallenges } = await import("../../src/services/dailyChallenges.js");
const day1 = generateDailyChallenges("2024-01-15");
const day2 = generateDailyChallenges("2024-01-16");
// They should differ in at least one challenge ID (types vary by seed)
expect(day1.map((c) => c.type)).not.toEqual(day2.map((c) => c.type));
});
});
describe("getOrResetDailyChallenges", () => {
it("returns existing challenges when date matches today", async () => {
vi.setSystemTime(LA_MIDNIGHT_2024_01_15);
const { getOrResetDailyChallenges } = await import("../../src/services/dailyChallenges.js");
const existing: DailyChallengeState = {
date: "2024-01-15",
challenges: [{ id: "old_challenge", type: "clicks", label: "l", target: 100, progress: 50, completed: false, rewardCrystals: 1 }],
};
const state = makeState(existing);
const result = getOrResetDailyChallenges(state);
expect(result).toBe(existing);
});
it("generates fresh challenges when date is yesterday", async () => {
vi.setSystemTime(LA_MIDNIGHT_2024_01_16);
const { getOrResetDailyChallenges } = await import("../../src/services/dailyChallenges.js");
const stale: DailyChallengeState = {
date: "2024-01-15",
challenges: [],
};
const state = makeState(stale);
const result = getOrResetDailyChallenges(state);
expect(result.date).toBe("2024-01-16");
expect(result.challenges).toHaveLength(3);
});
it("generates fresh challenges when dailyChallenges is undefined", async () => {
vi.setSystemTime(LA_MIDNIGHT_2024_01_15);
const { getOrResetDailyChallenges } = await import("../../src/services/dailyChallenges.js");
const state = makeState(undefined);
const result = getOrResetDailyChallenges(state);
expect(result.challenges).toHaveLength(3);
expect(result.date).toBe("2024-01-15");
});
});
describe("updateChallengeProgress", () => {
const makeChallenge = (
type: DailyChallengeState["challenges"][0]["type"],
progress: number,
completed: boolean,
) => ({
id: `${type}_test`,
type,
label: "Test",
target: 100,
progress,
completed,
rewardCrystals: 10,
});
const makeState2 = (challenges: DailyChallengeState["challenges"]): DailyChallengeState => ({
date: "2024-01-15",
challenges,
});
it("increments progress for matching non-completed challenges", async () => {
vi.setSystemTime(LA_MIDNIGHT_2024_01_15);
const { updateChallengeProgress } = await import("../../src/services/dailyChallenges.js");
const state = makeState2([makeChallenge("clicks", 0, false)]);
const { updatedChallenges } = updateChallengeProgress(state, "clicks", 10);
expect(updatedChallenges.challenges[0]!.progress).toBe(10);
});
it("does not modify already-completed challenges", async () => {
vi.setSystemTime(LA_MIDNIGHT_2024_01_15);
const { updateChallengeProgress } = await import("../../src/services/dailyChallenges.js");
const state = makeState2([makeChallenge("clicks", 100, true)]);
const { updatedChallenges } = updateChallengeProgress(state, "clicks", 50);
expect(updatedChallenges.challenges[0]!.progress).toBe(100);
});
it("does not modify challenges of a different type", async () => {
vi.setSystemTime(LA_MIDNIGHT_2024_01_15);
const { updateChallengeProgress } = await import("../../src/services/dailyChallenges.js");
const state = makeState2([makeChallenge("bossesDefeated", 0, false)]);
const { updatedChallenges } = updateChallengeProgress(state, "clicks", 10);
expect(updatedChallenges.challenges[0]!.progress).toBe(0);
});
it("awards crystals when challenge completes", async () => {
vi.setSystemTime(LA_MIDNIGHT_2024_01_15);
const { updateChallengeProgress } = await import("../../src/services/dailyChallenges.js");
const state = makeState2([makeChallenge("clicks", 90, false)]);
const { crystalsAwarded } = updateChallengeProgress(state, "clicks", 20);
expect(crystalsAwarded).toBe(10);
});
it("caps progress at target value", async () => {
vi.setSystemTime(LA_MIDNIGHT_2024_01_15);
const { updateChallengeProgress } = await import("../../src/services/dailyChallenges.js");
const state = makeState2([makeChallenge("clicks", 95, false)]);
const { updatedChallenges } = updateChallengeProgress(state, "clicks", 100);
expect(updatedChallenges.challenges[0]!.progress).toBe(100);
});
it("returns zero crystals when no challenge completes", async () => {
vi.setSystemTime(LA_MIDNIGHT_2024_01_15);
const { updateChallengeProgress } = await import("../../src/services/dailyChallenges.js");
const state = makeState2([makeChallenge("clicks", 0, false)]);
const { crystalsAwarded } = updateChallengeProgress(state, "clicks", 10);
expect(crystalsAwarded).toBe(0);
});
});
+90
View File
@@ -0,0 +1,90 @@
/* eslint-disable max-lines-per-function -- Test suites naturally have many cases */
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
describe("discord service", () => {
const ORIGINAL_ENV = process.env;
const mockFetch = vi.fn();
beforeEach(() => {
process.env = { ...ORIGINAL_ENV };
vi.resetModules();
vi.stubGlobal("fetch", mockFetch);
});
afterEach(() => {
process.env = ORIGINAL_ENV;
vi.unstubAllGlobals();
mockFetch.mockReset();
});
describe("buildOAuthUrl", () => {
it("throws when DISCORD_CLIENT_ID is missing", async () => {
delete process.env["DISCORD_CLIENT_ID"];
process.env["DISCORD_REDIRECT_URI"] = "http://localhost/callback";
const { buildOAuthUrl } = await import("../../src/services/discord.js");
expect(() => buildOAuthUrl()).toThrow("Discord OAuth environment variables are required");
});
it("throws when DISCORD_REDIRECT_URI is missing", async () => {
process.env["DISCORD_CLIENT_ID"] = "client123";
delete process.env["DISCORD_REDIRECT_URI"];
const { buildOAuthUrl } = await import("../../src/services/discord.js");
expect(() => buildOAuthUrl()).toThrow("Discord OAuth environment variables are required");
});
it("returns a URL with correct query params", async () => {
process.env["DISCORD_CLIENT_ID"] = "client123";
process.env["DISCORD_REDIRECT_URI"] = "http://localhost/callback";
const { buildOAuthUrl } = await import("../../src/services/discord.js");
const url = buildOAuthUrl();
expect(url).toContain("client_id=client123");
expect(url).toContain("response_type=code");
expect(url).toContain("scope=identify");
});
});
describe("exchangeCode", () => {
it("throws when env vars are missing", async () => {
delete process.env["DISCORD_CLIENT_ID"];
const { exchangeCode } = await import("../../src/services/discord.js");
await expect(exchangeCode("mycode")).rejects.toThrow("Discord OAuth environment variables are required");
});
it("throws when response is not ok", async () => {
process.env["DISCORD_CLIENT_ID"] = "cid";
process.env["DISCORD_CLIENT_SECRET"] = "secret";
process.env["DISCORD_REDIRECT_URI"] = "http://localhost/cb";
mockFetch.mockResolvedValueOnce({ ok: false, statusText: "Unauthorized" });
const { exchangeCode } = await import("../../src/services/discord.js");
await expect(exchangeCode("bad_code")).rejects.toThrow("Discord token exchange failed");
});
it("returns parsed body on success", async () => {
process.env["DISCORD_CLIENT_ID"] = "cid";
process.env["DISCORD_CLIENT_SECRET"] = "secret";
process.env["DISCORD_REDIRECT_URI"] = "http://localhost/cb";
const tokenData = { access_token: "tok", token_type: "Bearer", expires_in: 3600, refresh_token: "ref", scope: "identify" };
mockFetch.mockResolvedValueOnce({ ok: true, json: () => Promise.resolve(tokenData) });
const { exchangeCode } = await import("../../src/services/discord.js");
const result = await exchangeCode("good_code");
expect(result.access_token).toBe("tok");
});
});
describe("fetchDiscordUser", () => {
it("throws when response is not ok", async () => {
mockFetch.mockResolvedValueOnce({ ok: false, statusText: "Forbidden" });
const { fetchDiscordUser } = await import("../../src/services/discord.js");
await expect(fetchDiscordUser("bad_token")).rejects.toThrow("Discord user fetch failed");
});
it("returns parsed user on success", async () => {
const user = { id: "123", username: "testuser", discriminator: "0", avatar: null };
mockFetch.mockResolvedValueOnce({ ok: true, json: () => Promise.resolve(user) });
const { fetchDiscordUser } = await import("../../src/services/discord.js");
const result = await fetchDiscordUser("valid_token");
expect(result.id).toBe("123");
expect(result.username).toBe("testuser");
});
});
});
+76
View File
@@ -0,0 +1,76 @@
/* eslint-disable max-lines-per-function -- Test suites naturally have many cases */
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
describe("jwt service", () => {
const ORIGINAL_ENV = process.env;
beforeEach(() => {
process.env = { ...ORIGINAL_ENV };
vi.resetModules();
});
afterEach(() => {
process.env = ORIGINAL_ENV;
});
describe("signToken", () => {
it("throws when JWT_SECRET is not set", async () => {
delete process.env["JWT_SECRET"];
const { signToken } = await import("../../src/services/jwt.js");
expect(() => signToken("test_id")).toThrow("JWT_SECRET environment variable is required");
});
it("returns a three-part dot-separated token", async () => {
process.env["JWT_SECRET"] = "test_secret";
const { signToken } = await import("../../src/services/jwt.js");
const token = signToken("test_id");
expect(token.split(".")).toHaveLength(3);
});
});
describe("verifyToken", () => {
it("throws when JWT_SECRET is not set", async () => {
delete process.env["JWT_SECRET"];
const { verifyToken } = await import("../../src/services/jwt.js");
expect(() => verifyToken("a.b.c")).toThrow("JWT_SECRET environment variable is required");
});
it("round-trips a token correctly", async () => {
process.env["JWT_SECRET"] = "test_secret";
const { signToken, verifyToken } = await import("../../src/services/jwt.js");
const token = signToken("user_123");
const payload = verifyToken(token);
expect(payload.discordId).toBe("user_123");
});
it("throws on wrong token format (not 3 parts)", async () => {
process.env["JWT_SECRET"] = "test_secret";
const { verifyToken } = await import("../../src/services/jwt.js");
expect(() => verifyToken("only.two")).toThrow("Invalid token format");
});
it("throws on tampered signature", async () => {
process.env["JWT_SECRET"] = "test_secret";
const { signToken, verifyToken } = await import("../../src/services/jwt.js");
const token = signToken("user_123");
const parts = token.split(".");
const tampered = `${parts[0]}.${parts[1]}.BAD_SIGNATURE`;
expect(() => verifyToken(tampered)).toThrow("Invalid token signature");
});
it("throws on expired token", async () => {
process.env["JWT_SECRET"] = "test_secret";
const { verifyToken } = await import("../../src/services/jwt.js");
// Build a token with exp in the past
const header = Buffer.from(JSON.stringify({ alg: "HS256", typ: "JWT" })).toString("base64url");
const payload = Buffer.from(
JSON.stringify({ discordId: "x", iat: 1000, exp: 1001 }),
).toString("base64url");
const { createHmac } = await import("crypto");
const signature = createHmac("sha256", "test_secret")
.update(`${header}.${payload}`)
.digest("base64url");
expect(() => verifyToken(`${header}.${payload}.${signature}`)).toThrow("Token has expired");
});
});
});
@@ -0,0 +1,189 @@
/* eslint-disable max-lines-per-function -- Test suites naturally have many cases */
/* eslint-disable @typescript-eslint/consistent-type-assertions -- Tests build minimal state objects */
import { describe, expect, it } from "vitest";
import { calculateOfflineEarnings } from "../../src/services/offlineProgress.js";
import type { GameState } from "@elysium/types";
const makeState = (overrides: Partial<GameState> = {}): GameState =>
({
lastTickAt: 0,
adventurers: [],
upgrades: [],
equipment: [],
prestige: {
count: 0,
runestones: 0,
productionMultiplier: 1,
purchasedUpgradeIds: [],
runestonesIncomeMultiplier: 1,
runestonesEssenceMultiplier: 1,
},
...overrides,
} as GameState);
describe("calculateOfflineEarnings", () => {
it("returns zero earnings when no adventurers", () => {
const state = makeState({ lastTickAt: 0 });
const result = calculateOfflineEarnings(state, 60_000);
expect(result.offlineGold).toBe(0);
expect(result.offlineEssence).toBe(0);
expect(result.offlineSeconds).toBe(60);
});
it("returns zero when all adventurers have count 0", () => {
const state = makeState({
lastTickAt: 0,
adventurers: [{ id: "a", unlocked: true, count: 0, goldPerSecond: 10, essencePerSecond: 0 }] as GameState["adventurers"],
});
const result = calculateOfflineEarnings(state, 60_000);
expect(result.offlineGold).toBe(0);
});
it("returns zero when adventurer is not unlocked", () => {
const state = makeState({
lastTickAt: 0,
adventurers: [{ id: "a", unlocked: false, count: 5, goldPerSecond: 10, essencePerSecond: 0 }] as GameState["adventurers"],
});
const result = calculateOfflineEarnings(state, 60_000);
expect(result.offlineGold).toBe(0);
});
it("calculates basic gold earnings correctly", () => {
const state = makeState({
lastTickAt: 0,
adventurers: [{ id: "a", unlocked: true, count: 2, goldPerSecond: 5, essencePerSecond: 0 }] as GameState["adventurers"],
});
const result = calculateOfflineEarnings(state, 10_000);
// 2 adventurers × 5 gps × 10 seconds = 100 gold
expect(result.offlineGold).toBe(100);
expect(result.offlineSeconds).toBe(10);
});
it("calculates basic essence earnings correctly", () => {
const state = makeState({
lastTickAt: 0,
adventurers: [{ id: "a", unlocked: true, count: 1, goldPerSecond: 0, essencePerSecond: 3 }] as GameState["adventurers"],
});
const result = calculateOfflineEarnings(state, 10_000);
expect(result.offlineEssence).toBe(30);
});
it("caps earnings at 8 hours regardless of elapsed time", () => {
const state = makeState({
lastTickAt: 0,
adventurers: [{ id: "a", unlocked: true, count: 1, goldPerSecond: 1, essencePerSecond: 0 }] as GameState["adventurers"],
});
const twelveHoursMs = 12 * 60 * 60 * 1000;
const result = calculateOfflineEarnings(state, twelveHoursMs);
const maxSeconds = 8 * 60 * 60;
expect(result.offlineGold).toBe(maxSeconds);
expect(result.offlineSeconds).toBe(maxSeconds);
});
it("applies global upgrade multiplier", () => {
const state = makeState({
lastTickAt: 0,
adventurers: [{ id: "a", unlocked: true, count: 1, goldPerSecond: 10, essencePerSecond: 0 }] as GameState["adventurers"],
upgrades: [{ id: "u1", purchased: true, target: "global", multiplier: 2 }] as GameState["upgrades"],
});
const result = calculateOfflineEarnings(state, 1_000);
expect(result.offlineGold).toBe(20);
});
it("applies adventurer-specific upgrade multiplier", () => {
const state = makeState({
lastTickAt: 0,
adventurers: [{ id: "peasant", unlocked: true, count: 1, goldPerSecond: 10, essencePerSecond: 0 }] as GameState["adventurers"],
upgrades: [{ id: "u1", purchased: true, target: "adventurer", adventurerId: "peasant", multiplier: 3 }] as GameState["upgrades"],
});
const result = calculateOfflineEarnings(state, 1_000);
expect(result.offlineGold).toBe(30);
});
it("does not apply upgrade for different adventurer", () => {
const state = makeState({
lastTickAt: 0,
adventurers: [{ id: "peasant", unlocked: true, count: 1, goldPerSecond: 10, essencePerSecond: 0 }] as GameState["adventurers"],
upgrades: [{ id: "u1", purchased: true, target: "adventurer", adventurerId: "knight", multiplier: 3 }] as GameState["upgrades"],
});
const result = calculateOfflineEarnings(state, 1_000);
expect(result.offlineGold).toBe(10);
});
it("applies equipment gold multiplier for equipped items only", () => {
const state = makeState({
lastTickAt: 0,
adventurers: [{ id: "a", unlocked: true, count: 1, goldPerSecond: 10, essencePerSecond: 0 }] as GameState["adventurers"],
equipment: [
{ id: "e1", equipped: true, bonus: { goldMultiplier: 2 } },
{ id: "e2", equipped: false, bonus: { goldMultiplier: 5 } },
] as GameState["equipment"],
});
const result = calculateOfflineEarnings(state, 1_000);
// Only e1 applies: 10 × 2 × 1s = 20
expect(result.offlineGold).toBe(20);
});
it("applies runestone income multiplier to gold", () => {
const state = makeState({
lastTickAt: 0,
adventurers: [{ id: "a", unlocked: true, count: 1, goldPerSecond: 10, essencePerSecond: 0 }] as GameState["adventurers"],
prestige: {
count: 0, runestones: 0, productionMultiplier: 1, purchasedUpgradeIds: [],
runestonesIncomeMultiplier: 2,
runestonesEssenceMultiplier: 1,
} as GameState["prestige"],
});
const result = calculateOfflineEarnings(state, 1_000);
expect(result.offlineGold).toBe(20);
});
it("applies runestone essence multiplier to essence", () => {
const state = makeState({
lastTickAt: 0,
adventurers: [{ id: "a", unlocked: true, count: 1, goldPerSecond: 0, essencePerSecond: 5 }] as GameState["adventurers"],
prestige: {
count: 0, runestones: 0, productionMultiplier: 1, purchasedUpgradeIds: [],
runestonesIncomeMultiplier: 1,
runestonesEssenceMultiplier: 3,
} as GameState["prestige"],
});
const result = calculateOfflineEarnings(state, 1_000);
expect(result.offlineEssence).toBe(15);
});
it("defaults to 1 when runestonesIncomeMultiplier is undefined", () => {
const state = makeState({
lastTickAt: 0,
adventurers: [{ id: "a", unlocked: true, count: 1, goldPerSecond: 10, essencePerSecond: 2 }] as GameState["adventurers"],
// Prestige without runestone multiplier fields — hits the ?? 1 fallback
prestige: { count: 0, runestones: 0, productionMultiplier: 1, purchasedUpgradeIds: [] } as GameState["prestige"],
});
const result = calculateOfflineEarnings(state, 1_000);
expect(result.offlineGold).toBe(10);
expect(result.offlineEssence).toBe(2);
});
it("defaults to 1 when equipment is undefined", () => {
const state = makeState({
lastTickAt: 0,
adventurers: [{ id: "a", unlocked: true, count: 1, goldPerSecond: 10, essencePerSecond: 0 }] as GameState["adventurers"],
equipment: undefined,
});
const result = calculateOfflineEarnings(state, 1_000);
expect(result.offlineGold).toBe(10);
});
it("defaults goldMultiplier to 1 when equipment item has no goldMultiplier", () => {
const state = makeState({
lastTickAt: 0,
adventurers: [{ id: "a", unlocked: true, count: 1, goldPerSecond: 10, essencePerSecond: 0 }] as GameState["adventurers"],
equipment: [
{ id: "e1", equipped: true, bonus: {} }, // no goldMultiplier — hits ?? 1
] as GameState["equipment"],
});
const result = calculateOfflineEarnings(state, 1_000);
// goldMultiplier defaults to 1, so no boost
expect(result.offlineGold).toBe(10);
});
});
+245
View File
@@ -0,0 +1,245 @@
/* eslint-disable max-lines-per-function -- Test suites naturally have many cases */
/* eslint-disable max-lines -- Test suites naturally have many cases */
/* eslint-disable @typescript-eslint/consistent-type-assertions -- Tests build minimal state objects */
import { describe, expect, it } from "vitest";
import {
buildPostPrestigeState,
calculateMilestoneBonus,
calculatePrestigeThreshold,
calculateProductionMultiplier,
calculateRunestones,
computeRunestoneMultipliers,
isEligibleForPrestige,
} from "../../src/services/prestige.js";
import type { GameState } from "@elysium/types";
const makePlayer = (totalGoldEarned: number) => ({
discordId: "test_id",
username: "testuser",
discriminator: "0",
avatar: null,
totalGoldEarned,
totalClicks: 0,
characterName: "Tester",
});
const makeMinimalState = (overrides: Partial<GameState> = {}): GameState =>
({
player: makePlayer(0),
resources: { gold: 0, essence: 0, crystals: 0, runestones: 0 },
adventurers: [],
upgrades: [],
quests: [],
bosses: [],
equipment: [],
achievements: [],
zones: [],
exploration: { areas: [], materials: [], craftedRecipeIds: [], craftedGoldMultiplier: 1, craftedEssenceMultiplier: 1, craftedClickMultiplier: 1, craftedCombatMultiplier: 1 },
companions: { unlockedCompanionIds: [], activeCompanionId: null },
prestige: { count: 0, runestones: 0, productionMultiplier: 1, purchasedUpgradeIds: [] },
baseClickPower: 1,
lastTickAt: 0,
schemaVersion: 1,
...overrides,
} as GameState);
describe("calculatePrestigeThreshold", () => {
it("returns base threshold at count 0", () => {
expect(calculatePrestigeThreshold(0)).toBe(1_000_000);
});
it("returns 5× at count 1", () => {
expect(calculatePrestigeThreshold(1)).toBe(5_000_000);
});
it("returns 25× at count 2", () => {
expect(calculatePrestigeThreshold(2)).toBe(25_000_000);
});
it("applies threshold multiplier correctly", () => {
expect(calculatePrestigeThreshold(0, 2)).toBe(2_000_000);
});
});
describe("isEligibleForPrestige", () => {
it("returns true when totalGoldEarned meets threshold", () => {
const state = makeMinimalState({ player: makePlayer(1_000_000) });
expect(isEligibleForPrestige(state)).toBe(true);
});
it("returns false when totalGoldEarned is below threshold", () => {
const state = makeMinimalState({ player: makePlayer(999_999) });
expect(isEligibleForPrestige(state)).toBe(false);
});
it("uses echoPrestigeThresholdMultiplier from transcendence when present", () => {
const state = makeMinimalState({
player: makePlayer(2_000_000),
transcendence: {
count: 1, echoes: 0, purchasedUpgradeIds: [],
echoIncomeMultiplier: 1, echoCombatMultiplier: 1,
echoPrestigeThresholdMultiplier: 2,
echoPrestigeRunestoneMultiplier: 1, echoMetaMultiplier: 1,
},
});
// threshold = 1_000_000 × 2 = 2_000_000 — exactly meets
expect(isEligibleForPrestige(state)).toBe(true);
});
});
describe("calculateRunestones", () => {
it("calculates basic runestones formula", () => {
// floor(sqrt(4_000_000 / 1_000_000)) × 10 = floor(2) × 10 = 20
const result = calculateRunestones({ totalGoldEarned: 4_000_000, prestigeCount: 0, purchasedUpgradeIds: [] });
expect(result).toBe(20);
});
it("applies echo runestone multiplier", () => {
// floor(sqrt(4) × 10) = 20; × 2 = 40
const result = calculateRunestones({ totalGoldEarned: 4_000_000, prestigeCount: 0, purchasedUpgradeIds: [], echoRunestoneMultiplier: 2 });
expect(result).toBe(40);
});
it("applies purchased runestone upgrade multiplier", () => {
// With "runestones_1" purchased (multiplier 1.25): floor(20 × 1.25) = 25
const result = calculateRunestones({ totalGoldEarned: 4_000_000, prestigeCount: 0, purchasedUpgradeIds: ["runestone_gain_1"] });
expect(result).toBeGreaterThan(20);
});
});
describe("calculateProductionMultiplier", () => {
it("returns 1 at count 0", () => {
expect(calculateProductionMultiplier(0)).toBe(1);
});
it("returns 1.15 at count 1", () => {
expect(calculateProductionMultiplier(1)).toBeCloseTo(1.15);
});
it("scales exponentially", () => {
expect(calculateProductionMultiplier(10)).toBeCloseTo(Math.pow(1.15, 10));
});
});
describe("calculateMilestoneBonus", () => {
it("returns 0 for non-milestone prestiges", () => {
expect(calculateMilestoneBonus(1)).toBe(0);
expect(calculateMilestoneBonus(3)).toBe(0);
expect(calculateMilestoneBonus(4)).toBe(0);
});
it("returns 25 at prestige 5", () => {
expect(calculateMilestoneBonus(5)).toBe(25);
});
it("returns 50 at prestige 10", () => {
expect(calculateMilestoneBonus(10)).toBe(50);
});
it("returns 75 at prestige 15", () => {
expect(calculateMilestoneBonus(15)).toBe(75);
});
});
describe("computeRunestoneMultipliers", () => {
it("returns all 1s with empty ids", () => {
const result = computeRunestoneMultipliers([]);
expect(result.runestonesIncomeMultiplier).toBe(1);
expect(result.runestonesClickMultiplier).toBe(1);
expect(result.runestonesEssenceMultiplier).toBe(1);
expect(result.runestonesCrystalMultiplier).toBe(1);
});
it("applies income upgrade when purchased", () => {
const result = computeRunestoneMultipliers(["income_1"]);
expect(result.runestonesIncomeMultiplier).toBeGreaterThan(1);
expect(result.runestonesClickMultiplier).toBe(1);
});
it("applies click upgrade when purchased", () => {
const result = computeRunestoneMultipliers(["click_power_1"]);
expect(result.runestonesClickMultiplier).toBeGreaterThan(1);
expect(result.runestonesIncomeMultiplier).toBe(1);
});
it("applies essence upgrade when purchased", () => {
const result = computeRunestoneMultipliers(["essence_1"]);
expect(result.runestonesEssenceMultiplier).toBeGreaterThan(1);
});
it("applies crystals upgrade when purchased", () => {
const result = computeRunestoneMultipliers(["crystal_1"]);
expect(result.runestonesCrystalMultiplier).toBeGreaterThan(1);
});
});
describe("buildPostPrestigeState", () => {
it("increments prestige count", () => {
const state = makeMinimalState({ player: makePlayer(4_000_000) });
const { prestigeData } = buildPostPrestigeState(state, "Tester");
expect(prestigeData.count).toBe(1);
});
it("sums runestones earned", () => {
const state = makeMinimalState({ player: makePlayer(4_000_000) });
const { prestigeData, runestonesEarned } = buildPostPrestigeState(state, "Tester");
expect(runestonesEarned).toBeGreaterThan(0);
expect(prestigeData.runestones).toBe(runestonesEarned);
});
it("adds milestone runestones at prestige 5", () => {
const state = makeMinimalState({
player: makePlayer(100_000_000),
prestige: { count: 4, runestones: 0, productionMultiplier: 1, purchasedUpgradeIds: [] },
});
const { milestoneRunestones } = buildPostPrestigeState(state, "Tester");
expect(milestoneRunestones).toBe(25);
});
it("persists codex from current state", () => {
const codex = { entries: [{ id: "e1", unlockedAt: 1000, sourceType: "exploration" as const }] };
const state = makeMinimalState({ codex });
const { prestigeState } = buildPostPrestigeState(state, "Tester");
expect(prestigeState.codex).toEqual(codex);
});
it("persists story from current state", () => {
const story = { unlockedChapterIds: ["ch1"], completedChapters: [] };
const state = makeMinimalState({ story });
const { prestigeState } = buildPostPrestigeState(state, "Tester");
expect(prestigeState.story).toEqual(story);
});
it("persists transcendence from current state", () => {
const transcendence = {
count: 1, echoes: 10, purchasedUpgradeIds: [],
echoIncomeMultiplier: 1, echoCombatMultiplier: 1,
echoPrestigeThresholdMultiplier: 1,
echoPrestigeRunestoneMultiplier: 1, echoMetaMultiplier: 1,
};
const state = makeMinimalState({ transcendence });
const { prestigeState } = buildPostPrestigeState(state, "Tester");
expect(prestigeState.transcendence).toEqual(transcendence);
});
it("preserves autoPrestigeEnabled when set", () => {
const state = makeMinimalState({
prestige: { count: 0, runestones: 0, productionMultiplier: 1, purchasedUpgradeIds: [], autoPrestigeEnabled: true },
});
const { prestigeData } = buildPostPrestigeState(state, "Tester");
expect(prestigeData.autoPrestigeEnabled).toBe(true);
});
it("omits autoPrestigeEnabled when not set", () => {
const state = makeMinimalState();
const { prestigeData } = buildPostPrestigeState(state, "Tester");
expect(prestigeData.autoPrestigeEnabled).toBeUndefined();
});
it("preserves apotheosis data across prestige", () => {
const apotheosis = { count: 2 };
const state = makeMinimalState({ apotheosis });
const { prestigeState } = buildPostPrestigeState(state, "Tester");
expect(prestigeState.apotheosis).toEqual(apotheosis);
});
});
+151
View File
@@ -0,0 +1,151 @@
/* eslint-disable max-lines-per-function -- Test suites naturally have many cases */
/* eslint-disable @typescript-eslint/consistent-type-assertions -- Tests build minimal state objects */
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import {
checkAndUnlockTitles,
parseUnlockedTitles,
} from "../../src/services/titles.js";
import type { GameState } from "@elysium/types";
const makeMinimalState = (overrides: Partial<GameState> = {}): GameState =>
({
player: { discordId: "t", username: "u", discriminator: "0", avatar: null, totalGoldEarned: 0, totalClicks: 0, characterName: "T" },
bosses: [],
quests: [],
prestige: { count: 0, runestones: 0, productionMultiplier: 1, purchasedUpgradeIds: [] },
adventurers: [],
achievements: [],
...overrides,
} as GameState);
describe("parseUnlockedTitles", () => {
it("returns the array as-is when input is a string array", () => {
expect(parseUnlockedTitles(["boss_slayer", "the_adventurous"])).toEqual(["boss_slayer", "the_adventurous"]);
});
it("returns empty array for null input", () => {
expect(parseUnlockedTitles(null)).toEqual([]);
});
it("returns empty array for undefined input", () => {
expect(parseUnlockedTitles(undefined)).toEqual([]);
});
it("returns empty array for object input", () => {
expect(parseUnlockedTitles({ key: "value" })).toEqual([]);
});
it("returns empty array for number input", () => {
expect(parseUnlockedTitles(42)).toEqual([]);
});
it("filters non-string values from mixed array", () => {
expect(parseUnlockedTitles(["valid", 42, null, "also_valid"])).toEqual(["valid", "also_valid"]);
});
it("returns empty array for an empty array", () => {
expect(parseUnlockedTitles([])).toEqual([]);
});
});
describe("checkAndUnlockTitles", () => {
const NOW = 1_700_000_000_000;
const THIRTY_DAYS_MS = 30 * 86_400_000;
beforeEach(() => {
vi.spyOn(Date, "now").mockReturnValue(NOW);
});
afterEach(() => {
vi.restoreAllMocks();
});
it("returns empty array when no new titles are earned", () => {
const state = makeMinimalState();
const result = checkAndUnlockTitles({ currentUnlocked: [], state, guildName: "", createdAt: NOW });
expect(result).toEqual([]);
});
it("skips titles already unlocked", () => {
const state = makeMinimalState({
player: { discordId: "t", username: "u", discriminator: "0", avatar: null, totalGoldEarned: 0, totalClicks: 10_000, characterName: "T" },
});
const result = checkAndUnlockTitles({ currentUnlocked: ["click_maniac"], state, guildName: "", createdAt: NOW });
expect(result).not.toContain("click_maniac");
});
it("unlocks guild_founder when guild name is non-empty", () => {
const state = makeMinimalState();
const result = checkAndUnlockTitles({ currentUnlocked: [], state, guildName: "My Guild", createdAt: NOW });
expect(result).toContain("guild_founder");
});
it("does not unlock guild_founder for whitespace-only guild name", () => {
const state = makeMinimalState();
const result = checkAndUnlockTitles({ currentUnlocked: [], state, guildName: " ", createdAt: NOW });
expect(result).not.toContain("guild_founder");
});
it("unlocks the_adventurous when 1 quest is completed", () => {
const state = makeMinimalState({
quests: [{ status: "completed" }] as GameState["quests"],
});
const result = checkAndUnlockTitles({ currentUnlocked: [], state, guildName: "", createdAt: NOW });
expect(result).toContain("the_adventurous");
});
it("unlocks boss_slayer when 1 boss is defeated", () => {
const state = makeMinimalState({
bosses: [{ status: "defeated" }] as GameState["bosses"],
});
const result = checkAndUnlockTitles({ currentUnlocked: [], state, guildName: "", createdAt: NOW });
expect(result).toContain("boss_slayer");
});
it("unlocks the_undying at prestige 1", () => {
const state = makeMinimalState({
prestige: { count: 1, runestones: 0, productionMultiplier: 1, purchasedUpgradeIds: [] },
});
const result = checkAndUnlockTitles({ currentUnlocked: [], state, guildName: "", createdAt: NOW });
expect(result).toContain("the_undying");
});
it("unlocks veteran after 30 days of play", () => {
const createdAt = NOW - THIRTY_DAYS_MS;
const state = makeMinimalState();
const result = checkAndUnlockTitles({ currentUnlocked: [], state, guildName: "", createdAt });
expect(result).toContain("veteran");
});
it("does not unlock veteran before 30 days", () => {
const createdAt = NOW - (29 * 86_400_000);
const state = makeMinimalState();
const result = checkAndUnlockTitles({ currentUnlocked: [], state, guildName: "", createdAt });
expect(result).not.toContain("veteran");
});
it("returns multiple newly unlocked titles at once", () => {
const state = makeMinimalState({
bosses: [{ status: "defeated" }] as GameState["bosses"],
quests: [{ status: "completed" }] as GameState["quests"],
});
const result = checkAndUnlockTitles({ currentUnlocked: [], state, guildName: "Guild", createdAt: NOW });
expect(result).toContain("boss_slayer");
expect(result).toContain("the_adventurous");
expect(result).toContain("guild_founder");
});
it("reads transcendenceCount and apotheosisCount from state when present", () => {
const state = makeMinimalState({
transcendence: {
count: 1, echoes: 0, purchasedUpgradeIds: [],
echoIncomeMultiplier: 1, echoCombatMultiplier: 1,
echoPrestigeThresholdMultiplier: 1, echoPrestigeRunestoneMultiplier: 1, echoMetaMultiplier: 1,
},
apotheosis: { count: 1 },
});
// Just verify this runs without error — the counts are read via ?. chains
const result = checkAndUnlockTitles({ currentUnlocked: [], state, guildName: "", createdAt: NOW });
expect(Array.isArray(result)).toBe(true);
});
});
@@ -0,0 +1,171 @@
/* eslint-disable max-lines-per-function -- Test suites naturally have many cases */
/* eslint-disable @typescript-eslint/consistent-type-assertions -- Tests build minimal state objects */
import { describe, expect, it } from "vitest";
import {
buildPostTranscendenceState,
calculateEchoes,
computeTranscendenceMultipliers,
isEligibleForTranscendence,
} from "../../src/services/transcendence.js";
import type { GameState } from "@elysium/types";
const makeMinimalState = (overrides: Partial<GameState> = {}): GameState =>
({
player: { discordId: "t", username: "u", discriminator: "0", avatar: null, totalGoldEarned: 0, totalClicks: 0, characterName: "T" },
resources: { gold: 0, essence: 0, crystals: 0, runestones: 0 },
adventurers: [],
upgrades: [],
quests: [],
bosses: [],
equipment: [],
achievements: [],
zones: [],
exploration: { areas: [], materials: [], craftedRecipeIds: [], craftedGoldMultiplier: 1, craftedEssenceMultiplier: 1, craftedClickMultiplier: 1, craftedCombatMultiplier: 1 },
companions: { unlockedCompanionIds: [], activeCompanionId: null },
prestige: { count: 0, runestones: 0, productionMultiplier: 1, purchasedUpgradeIds: [] },
baseClickPower: 1,
lastTickAt: 0,
schemaVersion: 1,
...overrides,
} as GameState);
describe("computeTranscendenceMultipliers", () => {
it("returns all 1s with empty ids", () => {
const result = computeTranscendenceMultipliers([]);
expect(result.echoIncomeMultiplier).toBe(1);
expect(result.echoCombatMultiplier).toBe(1);
expect(result.echoPrestigeThresholdMultiplier).toBe(1);
expect(result.echoPrestigeRunestoneMultiplier).toBe(1);
expect(result.echoMetaMultiplier).toBe(1);
});
it("applies income upgrade when purchased", () => {
const result = computeTranscendenceMultipliers(["echo_income_1"]);
expect(result.echoIncomeMultiplier).toBeGreaterThan(1);
expect(result.echoCombatMultiplier).toBe(1);
});
it("applies combat upgrade when purchased", () => {
const result = computeTranscendenceMultipliers(["echo_combat_1"]);
expect(result.echoCombatMultiplier).toBeGreaterThan(1);
expect(result.echoIncomeMultiplier).toBe(1);
});
it("applies prestige_threshold upgrade when purchased", () => {
const result = computeTranscendenceMultipliers(["echo_prestige_threshold_1"]);
expect(result.echoPrestigeThresholdMultiplier).not.toBe(1);
});
it("applies prestige_runestones upgrade when purchased", () => {
const result = computeTranscendenceMultipliers(["echo_prestige_runestones_1"]);
expect(result.echoPrestigeRunestoneMultiplier).toBeGreaterThan(1);
});
it("applies echo_meta upgrade when purchased", () => {
const result = computeTranscendenceMultipliers(["echo_meta_1"]);
expect(result.echoMetaMultiplier).toBeGreaterThan(1);
});
});
describe("isEligibleForTranscendence", () => {
it("returns true when final boss is defeated", () => {
const state = makeMinimalState({
bosses: [{ id: "the_absolute_one", status: "defeated" }] as GameState["bosses"],
});
expect(isEligibleForTranscendence(state)).toBe(true);
});
it("returns false when final boss is available but not defeated", () => {
const state = makeMinimalState({
bosses: [{ id: "the_absolute_one", status: "available" }] as GameState["bosses"],
});
expect(isEligibleForTranscendence(state)).toBe(false);
});
it("returns false when final boss is not in the list", () => {
const state = makeMinimalState({ bosses: [] });
expect(isEligibleForTranscendence(state)).toBe(false);
});
it("returns false when a different boss is defeated", () => {
const state = makeMinimalState({
bosses: [{ id: "some_other_boss", status: "defeated" }] as GameState["bosses"],
});
expect(isEligibleForTranscendence(state)).toBe(false);
});
});
describe("calculateEchoes", () => {
it("handles prestige count of 0 by treating it as 1", () => {
// safeCount = max(0, 1) = 1; floor(853 / sqrt(1)) = 853
expect(calculateEchoes(0, 1)).toBe(853);
});
it("calculates echoes at count 1", () => {
expect(calculateEchoes(1, 1)).toBe(853);
});
it("decreases echoes with higher prestige count", () => {
const echoesAt1 = calculateEchoes(1, 1);
const echoesAt4 = calculateEchoes(4, 1);
expect(echoesAt4).toBeLessThan(echoesAt1);
// floor(853 / sqrt(4)) = floor(853 / 2) = 426
expect(echoesAt4).toBe(426);
});
it("applies echoMetaMultiplier", () => {
const base = calculateEchoes(1, 1);
const withMult = calculateEchoes(1, 2);
expect(withMult).toBe(base * 2);
});
});
describe("buildPostTranscendenceState", () => {
it("increments transcendence count from 0", () => {
const state = makeMinimalState();
const { transcendenceData } = buildPostTranscendenceState(state, "T");
expect(transcendenceData.count).toBe(1);
});
it("accumulates echoes", () => {
const state = makeMinimalState({
transcendence: {
count: 1, echoes: 100, purchasedUpgradeIds: [],
echoIncomeMultiplier: 1, echoCombatMultiplier: 1,
echoPrestigeThresholdMultiplier: 1, echoPrestigeRunestoneMultiplier: 1, echoMetaMultiplier: 1,
},
});
const { transcendenceData, echoesEarned } = buildPostTranscendenceState(state, "T");
expect(transcendenceData.echoes).toBe(100 + echoesEarned);
});
it("persists codex from current state", () => {
const codex = { entries: [{ id: "e1", unlockedAt: 1000, sourceType: "exploration" as const }] };
const state = makeMinimalState({ codex });
const { transcendenceState } = buildPostTranscendenceState(state, "T");
expect(transcendenceState.codex).toEqual(codex);
});
it("persists story from current state", () => {
const story = { unlockedChapterIds: ["ch1"], completedChapters: [] };
const state = makeMinimalState({ story });
const { transcendenceState } = buildPostTranscendenceState(state, "T");
expect(transcendenceState.story).toEqual(story);
});
it("persists apotheosis from current state", () => {
const apotheosis = { count: 2 };
const state = makeMinimalState({ apotheosis });
const { transcendenceState } = buildPostTranscendenceState(state, "T");
expect(transcendenceState.apotheosis).toEqual(apotheosis);
});
it("resets prestige to fresh state", () => {
const state = makeMinimalState({
prestige: { count: 5, runestones: 500, productionMultiplier: 2, purchasedUpgradeIds: [] },
});
const { transcendenceState } = buildPostTranscendenceState(state, "T");
expect(transcendenceState.prestige.count).toBe(0);
expect(transcendenceState.prestige.runestones).toBe(0);
});
});
+123
View File
@@ -0,0 +1,123 @@
/* eslint-disable max-lines-per-function -- Test suites naturally have many cases */
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
describe("webhook service", () => {
const ORIGINAL_ENV = process.env;
const mockFetch = vi.fn();
beforeEach(() => {
process.env = { ...ORIGINAL_ENV };
vi.resetModules();
vi.stubGlobal("fetch", mockFetch);
});
afterEach(() => {
process.env = ORIGINAL_ENV;
vi.unstubAllGlobals();
mockFetch.mockReset();
});
describe("grantApotheosisRole", () => {
it("does nothing when bot token is missing", async () => {
delete process.env["DISCORD_BOT_TOKEN"];
process.env["DISCORD_GUILD_ID"] = "guild123";
process.env["DISCORD_APOTHEOSIS_ROLE_ID"] = "role123";
const { grantApotheosisRole } = await import("../../src/services/webhook.js");
await grantApotheosisRole("user123");
expect(mockFetch).not.toHaveBeenCalled();
});
it("does nothing when guild id is missing", async () => {
process.env["DISCORD_BOT_TOKEN"] = "token";
delete process.env["DISCORD_GUILD_ID"];
process.env["DISCORD_APOTHEOSIS_ROLE_ID"] = "role123";
const { grantApotheosisRole } = await import("../../src/services/webhook.js");
await grantApotheosisRole("user123");
expect(mockFetch).not.toHaveBeenCalled();
});
it("does nothing when role id is missing", async () => {
process.env["DISCORD_BOT_TOKEN"] = "token";
process.env["DISCORD_GUILD_ID"] = "guild123";
delete process.env["DISCORD_APOTHEOSIS_ROLE_ID"];
const { grantApotheosisRole } = await import("../../src/services/webhook.js");
await grantApotheosisRole("user123");
expect(mockFetch).not.toHaveBeenCalled();
});
it("calls Discord API with correct URL and auth when env vars are set", async () => {
process.env["DISCORD_BOT_TOKEN"] = "bot_token";
process.env["DISCORD_GUILD_ID"] = "guild123";
process.env["DISCORD_APOTHEOSIS_ROLE_ID"] = "role456";
mockFetch.mockResolvedValueOnce({ ok: true });
const { grantApotheosisRole } = await import("../../src/services/webhook.js");
await grantApotheosisRole("user789");
expect(mockFetch).toHaveBeenCalledWith(
"https://discord.com/api/v10/guilds/guild123/members/user789/roles/role456",
expect.objectContaining({
method: "PUT",
headers: expect.objectContaining({ Authorization: "Bot bot_token" }),
}),
);
});
it("swallows fetch errors gracefully", async () => {
process.env["DISCORD_BOT_TOKEN"] = "tok";
process.env["DISCORD_GUILD_ID"] = "g";
process.env["DISCORD_APOTHEOSIS_ROLE_ID"] = "r";
mockFetch.mockRejectedValueOnce(new Error("Network error"));
const { grantApotheosisRole } = await import("../../src/services/webhook.js");
await expect(grantApotheosisRole("user")).resolves.toBeUndefined();
});
});
describe("postMilestoneWebhook", () => {
const counts = { prestige: 1, transcendence: 0, apotheosis: 0 };
it("does nothing when webhook URL is missing", async () => {
delete process.env["DISCORD_MILESTONE_WEBHOOK"];
const { postMilestoneWebhook } = await import("../../src/services/webhook.js");
await postMilestoneWebhook("user123", "prestige", counts);
expect(mockFetch).not.toHaveBeenCalled();
});
it("posts prestige message with correct body", async () => {
process.env["DISCORD_MILESTONE_WEBHOOK"] = "https://discord.com/webhook/abc";
mockFetch.mockResolvedValueOnce({ ok: true });
const { postMilestoneWebhook } = await import("../../src/services/webhook.js");
await postMilestoneWebhook("user123", "prestige", counts);
const [url, options] = mockFetch.mock.calls[0] as [string, RequestInit];
expect(url).toBe("https://discord.com/webhook/abc");
const body = JSON.parse(options.body as string) as { content: string };
expect(body.content).toContain("<@user123>");
expect(body.content).toContain("prestiged");
});
it("posts transcendence message correctly", async () => {
process.env["DISCORD_MILESTONE_WEBHOOK"] = "https://discord.com/webhook/abc";
mockFetch.mockResolvedValueOnce({ ok: true });
const { postMilestoneWebhook } = await import("../../src/services/webhook.js");
await postMilestoneWebhook("user123", "transcendence", { prestige: 0, transcendence: 1, apotheosis: 0 });
const [, options] = mockFetch.mock.calls[0] as [string, RequestInit];
const body = JSON.parse(options.body as string) as { content: string };
expect(body.content).toContain("transcended");
});
it("posts apotheosis message correctly", async () => {
process.env["DISCORD_MILESTONE_WEBHOOK"] = "https://discord.com/webhook/abc";
mockFetch.mockResolvedValueOnce({ ok: true });
const { postMilestoneWebhook } = await import("../../src/services/webhook.js");
await postMilestoneWebhook("user123", "apotheosis", { prestige: 0, transcendence: 0, apotheosis: 1 });
const [, options] = mockFetch.mock.calls[0] as [string, RequestInit];
const body = JSON.parse(options.body as string) as { content: string };
expect(body.content).toContain("reached apotheosis");
});
it("swallows fetch errors gracefully", async () => {
process.env["DISCORD_MILESTONE_WEBHOOK"] = "https://discord.com/webhook/abc";
mockFetch.mockRejectedValueOnce(new Error("Network timeout"));
const { postMilestoneWebhook } = await import("../../src/services/webhook.js");
await expect(postMilestoneWebhook("user", "prestige", counts)).resolves.toBeUndefined();
});
});
});
+6 -1
View File
@@ -5,7 +5,12 @@ export default defineConfig({
coverage: { coverage: {
provider: "v8", provider: "v8",
include: ["src/**/*.ts"], include: ["src/**/*.ts"],
exclude: ["src/types/**/*.ts"], exclude: [
"src/types/**/*.ts",
"src/db/client.ts",
"src/index.ts",
"src/data/materials.ts",
],
thresholds: { thresholds: {
statements: 100, statements: 100,
branches: 100, branches: 100,
+42 -2
View File
@@ -1,3 +1,43 @@
import { NaomisConfig } from "@nhcarrigan/eslint-config"; import config from "@nhcarrigan/eslint-config";
export default [...NaomisConfig]; export default [
...config,
{
files: [ "src/**/*.tsx" ],
rules: {
"@typescript-eslint/naming-convention": [
"warn",
{
format: [ "camelCase", "PascalCase" ],
leadingUnderscore: "allow",
selector: "variable",
trailingUnderscore: "forbid",
},
{
format: [ "camelCase" ],
leadingUnderscore: "allow",
selector: "function",
trailingUnderscore: "forbid",
},
{
format: [ "PascalCase" ],
leadingUnderscore: "forbid",
selector: "typeLike",
trailingUnderscore: "forbid",
},
{
format: [ "PascalCase" ],
leadingUnderscore: "forbid",
selector: "class",
trailingUnderscore: "forbid",
},
],
"react/jsx-no-bind": [
"error",
{
allowFunctions: true,
},
],
},
},
];
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "@elysium/web", "name": "@elysium/web",
"version": "0.0.0", "version": "0.1.1",
"private": true, "private": true,
"type": "module", "type": "module",
"scripts": { "scripts": {
-50
View File
@@ -1,50 +0,0 @@
import { useState } from "react";
import { GameProvider } from "./context/GameContext.js";
import { GameLayout } from "./components/game/GameLayout.js";
import { LoginPage } from "./components/game/LoginPage.js";
import { ProfilePage } from "./components/game/ProfilePage.js";
const getProfileDiscordId = (): string | null => {
const match = /^\/profile\/(\d+)$/.exec(window.location.pathname);
return match?.[1] ?? null;
};
const handleAuthCallback = (): boolean => {
if (window.location.pathname !== "/auth/callback") {
return false;
}
const params = new URLSearchParams(window.location.search);
const token = params.get("token");
if (token) {
localStorage.setItem("elysium_token", token);
}
window.history.replaceState(null, "", "/");
return Boolean(token);
};
const isAuthenticated = (): boolean => {
const fromCallback = handleAuthCallback();
return fromCallback || Boolean(localStorage.getItem("elysium_token"));
};
export const App = (): React.JSX.Element => {
const [loggedIn, setLoggedIn] = useState(isAuthenticated);
const profileDiscordId = getProfileDiscordId();
if (profileDiscordId) {
return <ProfilePage discordId={profileDiscordId} />;
}
if (!loggedIn) {
return <LoginPage onLogin={() => { setLoggedIn(true); }} />;
}
return (
<GameProvider>
<GameLayout />
</GameProvider>
);
};
+239 -42
View File
@@ -1,105 +1,302 @@
/**
* @file API client for communicating with the Elysium backend.
* @copyright nhcarrigan
* @license Naomi's Public License
* @author Naomi Carrigan
*/
import type { import type {
AboutResponse, AboutResponse,
ApotheosisRequest,
ApotheosisResponse,
AuthResponse, AuthResponse,
BossChallengeRequest, BossChallengeRequest,
BossChallengeResponse, BossChallengeResponse,
BuyEchoUpgradeRequest,
BuyEchoUpgradeResponse,
BuyPrestigeUpgradeRequest, BuyPrestigeUpgradeRequest,
BuyPrestigeUpgradeResponse, BuyPrestigeUpgradeResponse,
CraftRecipeRequest,
CraftRecipeResponse,
ExploreCollectRequest,
ExploreCollectResponse,
ExploreStartRequest,
ExploreStartResponse,
LoadResponse, LoadResponse,
PrestigeRequest, PrestigeRequest,
PrestigeResponse, PrestigeResponse,
PublicProfileResponse, PublicProfileResponse,
SaveRequest, SaveRequest,
SaveResponse, SaveResponse,
TranscendenceRequest,
TranscendenceResponse,
UpdateProfileRequest, UpdateProfileRequest,
UpdateProfileResponse, UpdateProfileResponse,
} from "@elysium/types"; } from "@elysium/types";
const BASE_URL = "/api"; const baseUrl = "/api";
const getToken = (): string | null => localStorage.getItem("elysium_token"); const getToken = (): string | null => {
return globalThis.localStorage.getItem("elysium_token");
};
const headers = (): Record<string, string> => { /* eslint-disable @typescript-eslint/naming-convention -- HTTP header names require specific casing */
const buildHeaders = (): Record<string, string> => {
const token = getToken(); const token = getToken();
return { return {
"Content-Type": "application/json", "Content-Type": "application/json",
...(token ? { Authorization: `Bearer ${token}` } : {}), ...token !== null && token.length > 0
? { Authorization: `Bearer ${token}` }
: {},
}; };
}; };
/* eslint-enable @typescript-eslint/naming-convention -- HTTP header names require specific casing */
const request = async <T>( const fetchJson = async <T>(
path: string, path: string,
options?: RequestInit, options?: RequestInit,
): Promise<T> => { ): Promise<T> => {
const response = await fetch(`${BASE_URL}${path}`, { const response = await fetch(`${baseUrl}${path}`, {
...options, ...options,
headers: { ...headers(), ...options?.headers }, headers: { ...buildHeaders(), ...options?.headers },
}); });
if (!response.ok) { if (!response.ok) {
const error = (await response.json().catch(() => ({ error: "Unknown error" }))) as { /* eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- JSON error response requires type assertion */
error: string; const errorBody = (await response.json().catch(() => {
}; return { error: "Unknown error" };
throw new Error(error.error); })) as Record<string, unknown>;
const message
= typeof errorBody.error === "string"
? errorBody.error
: "Unknown error";
throw new Error(message);
} }
return response.json() as Promise<T>; /* eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- JSON response requires type assertion */
return await (response.json() as Promise<T>);
}; };
export const getAbout = async (): Promise<AboutResponse> => /**
request<AboutResponse>("/about"); * Fetches the about information from the API.
* @returns The about response data.
*/
const getAbout = async(): Promise<AboutResponse> => {
return await fetchJson<AboutResponse>("/about");
};
export const getAuthUrl = async (): Promise<string> => { /**
const data = await request<{ url: string }>("/auth/url"); * Fetches the Discord OAuth URL from the API.
* @returns The authentication URL string.
*/
const getAuthUrl = async(): Promise<string> => {
const data = await fetchJson<{ url: string }>("/auth/url");
return data.url; return data.url;
}; };
export const handleAuthCallback = async (code: string): Promise<AuthResponse> => { /**
const data = await request<AuthResponse>(`/auth/callback?code=${code}`); * Handles the Discord OAuth callback and stores the auth token.
localStorage.setItem("elysium_token", data.token); * @param code - The OAuth authorization code from Discord.
* @returns The authentication response data.
*/
const handleAuthCallback = async(code: string): Promise<AuthResponse> => {
const data = await fetchJson<AuthResponse>(`/auth/callback?code=${code}`);
globalThis.localStorage.setItem("elysium_token", data.token);
return data; return data;
}; };
export const loadGame = async (): Promise<LoadResponse> => /**
request<LoadResponse>("/game/load"); * Loads the current game state from the server.
* @returns The load response containing the game state.
*/
const loadGame = async(): Promise<LoadResponse> => {
return await fetchJson<LoadResponse>("/game/load");
};
export const saveGame = async (body: SaveRequest): Promise<SaveResponse> => /**
request<SaveResponse>("/game/save", { * Resets all game progress on the server.
* @returns The load response after reset.
*/
const resetProgress = async(): Promise<LoadResponse> => {
return await fetchJson<LoadResponse>("/game/reset", { method: "POST" });
};
/**
* Saves the current game state to the server.
* @param body - The save request payload containing the game state.
* @returns The save response data.
*/
const saveGame = async(body: SaveRequest): Promise<SaveResponse> => {
return await fetchJson<SaveResponse>("/game/save", {
body: JSON.stringify(body),
method: "POST", method: "POST",
body: JSON.stringify(body),
}); });
};
export const challengeBoss = async ( /**
* Challenges a boss with the current game state.
* @param body - The boss challenge request payload.
* @returns The boss challenge response data.
*/
const challengeBoss = async(
body: BossChallengeRequest, body: BossChallengeRequest,
): Promise<BossChallengeResponse> => ): Promise<BossChallengeResponse> => {
request<BossChallengeResponse>("/boss/challenge", { return await fetchJson<BossChallengeResponse>("/boss/challenge", {
body: JSON.stringify(body),
method: "POST", method: "POST",
body: JSON.stringify(body),
}); });
};
export const prestige = async (body: PrestigeRequest): Promise<PrestigeResponse> => /**
request<PrestigeResponse>("/prestige", { * Triggers a prestige reset on the server.
* @param body - The prestige request payload.
* @returns The prestige response data.
*/
const prestige = async(body: PrestigeRequest): Promise<PrestigeResponse> => {
return await fetchJson<PrestigeResponse>("/prestige", {
body: JSON.stringify(body),
method: "POST", method: "POST",
body: JSON.stringify(body),
}); });
};
export const buyPrestigeUpgrade = async ( /**
* Purchases a prestige upgrade on the server.
* @param body - The buy prestige upgrade request payload.
* @returns The buy prestige upgrade response data.
*/
const buyPrestigeUpgrade = async(
body: BuyPrestigeUpgradeRequest, body: BuyPrestigeUpgradeRequest,
): Promise<BuyPrestigeUpgradeResponse> => ): Promise<BuyPrestigeUpgradeResponse> => {
request<BuyPrestigeUpgradeResponse>("/prestige/buy-upgrade", { return await fetchJson<BuyPrestigeUpgradeResponse>("/prestige/buy-upgrade", {
body: JSON.stringify(body),
method: "POST", method: "POST",
body: JSON.stringify(body),
}); });
};
export const getPublicProfile = async ( /**
* Triggers a transcendence reset on the server.
* @param body - The transcendence request payload.
* @returns The transcendence response data.
*/
const transcend = async(
body: TranscendenceRequest,
): Promise<TranscendenceResponse> => {
return await fetchJson<TranscendenceResponse>("/transcendence", {
body: JSON.stringify(body),
method: "POST",
});
};
/**
* Purchases an echo upgrade on the server.
* @param body - The buy echo upgrade request payload.
* @returns The buy echo upgrade response data.
*/
const buyEchoUpgrade = async(
body: BuyEchoUpgradeRequest,
): Promise<BuyEchoUpgradeResponse> => {
return await fetchJson<BuyEchoUpgradeResponse>("/transcendence/buy-upgrade", {
body: JSON.stringify(body),
method: "POST",
});
};
/**
* Triggers an apotheosis reset on the server.
* @param body - The apotheosis request payload.
* @returns The apotheosis response data.
*/
const achieveApotheosis = async(
body: ApotheosisRequest,
): Promise<ApotheosisResponse> => {
return await fetchJson<ApotheosisResponse>("/apotheosis", {
body: JSON.stringify(body),
method: "POST",
});
};
/**
* Starts an exploration in a given area.
* @param body - The exploration start request payload.
* @returns The exploration start response data.
*/
const startExploration = async(
body: ExploreStartRequest,
): Promise<ExploreStartResponse> => {
return await fetchJson<ExploreStartResponse>("/explore/start", {
body: JSON.stringify(body),
method: "POST",
});
};
/**
* Collects the rewards from a completed exploration.
* @param body - The exploration collect request payload.
* @returns The exploration collect response data.
*/
const collectExploration = async(
body: ExploreCollectRequest,
): Promise<ExploreCollectResponse> => {
return await fetchJson<ExploreCollectResponse>("/explore/collect", {
body: JSON.stringify(body),
method: "POST",
});
};
/**
* Crafts a recipe on the server.
* @param body - The craft recipe request payload.
* @returns The craft recipe response data.
*/
const craftRecipe = async(
body: CraftRecipeRequest,
): Promise<CraftRecipeResponse> => {
return await fetchJson<CraftRecipeResponse>("/craft", {
body: JSON.stringify(body),
method: "POST",
});
};
/**
* Fetches a public player profile by Discord ID.
* @param discordId - The Discord ID of the player to look up.
* @returns The public profile response data.
*/
const getPublicProfile = async(
discordId: string, discordId: string,
): Promise<PublicProfileResponse> => ): Promise<PublicProfileResponse> => {
request<PublicProfileResponse>(`/profile/${discordId}`); return await fetchJson<PublicProfileResponse>(`/profile/${discordId}`);
};
export const updateProfile = async ( /**
* Updates the current player's profile.
* @param body - The update profile request payload.
* @returns The update profile response data.
*/
const updateProfile = async(
body: UpdateProfileRequest, body: UpdateProfileRequest,
): Promise<UpdateProfileResponse> => ): Promise<UpdateProfileResponse> => {
request<UpdateProfileResponse>("/profile", { return await fetchJson<UpdateProfileResponse>("/profile", {
body: JSON.stringify(body),
method: "PUT", method: "PUT",
body: JSON.stringify(body),
}); });
};
export {
achieveApotheosis,
buyEchoUpgrade,
buyPrestigeUpgrade,
challengeBoss,
collectExploration,
craftRecipe,
getAbout,
getAuthUrl,
getPublicProfile,
handleAuthCallback,
loadGame,
prestige,
resetProgress,
saveGame,
startExploration,
transcend,
updateProfile,
};
+86
View File
@@ -0,0 +1,86 @@
/**
* @file Root application component that handles routing and authentication.
* @copyright nhcarrigan
* @license Naomi's Public License
* @author Naomi Carrigan
*/
import { type JSX, useState } from "react";
import { CharacterPage } from "./components/game/characterPage.js";
import { GameLayout } from "./components/game/gameLayout.js";
import { LeaderboardPage } from "./components/game/leaderboardPage.js";
import { LoginPage } from "./components/game/loginPage.js";
import { ProfilePage } from "./components/game/profilePage.js";
import { GameProvider } from "./context/gameContext.js";
const getProfileDiscordId = (): string | null => {
const match = /^\/profile\/(?<id>\d+)$/.exec(window.location.pathname);
return match?.groups?.id ?? null;
};
const getCharacterDiscordId = (): string | null => {
const match = /^\/character\/(?<id>\d+)$/.exec(window.location.pathname);
return match?.groups?.id ?? null;
};
const handleAuthCallback = (): boolean => {
if (window.location.pathname !== "/auth/callback") {
return false;
}
const parameters = new URLSearchParams(window.location.search);
const token = parameters.get("token");
if (token !== null && token.length > 0) {
localStorage.setItem("elysium_token", token);
}
window.history.replaceState(null, "", "/");
return token !== null && token.length > 0;
};
const isAuthenticated = (): boolean => {
const fromCallback = handleAuthCallback();
if (fromCallback) {
return true;
}
const storedToken = localStorage.getItem("elysium_token");
return storedToken !== null && storedToken.length > 0;
};
/**
* Renders the root application component, handling routing and authentication.
* @returns The JSX element.
*/
const app = (): JSX.Element => {
const [ loggedIn, setLoggedIn ] = useState(isAuthenticated);
const profileDiscordId = getProfileDiscordId();
if (profileDiscordId !== null) {
return <ProfilePage discordId={profileDiscordId} />;
}
const characterDiscordId = getCharacterDiscordId();
if (characterDiscordId !== null) {
return <CharacterPage discordId={characterDiscordId} />;
}
if (window.location.pathname === "/leaderboards") {
return <LeaderboardPage />;
}
function handleLogin(): void {
setLoggedIn(true);
}
if (!loggedIn) {
return <LoginPage onLogin={handleLogin} />;
}
return (
<GameProvider>
<GameLayout />
</GameProvider>
);
};
export { app as App };
-139
View File
@@ -1,139 +0,0 @@
import { useEffect, useState } from "react";
import { getAbout } from "../../api/client.js";
import type { AboutResponse } from "@elysium/types";
const HOW_TO_PLAY = [
{
title: "⚔️ Adventurers",
body: "Hire adventurers to earn gold and essence automatically. Each tier is more powerful than the last. Adventurers also contribute combat power for boss fights — the more you recruit, the stronger your party becomes.",
},
{
title: "👆 Clicking",
body: "Click the guild hall to earn gold manually. Upgrades and equipment can dramatically increase your gold per click. Clicking is especially powerful in the early game and when saving up for big purchases.",
},
{
title: "🔧 Upgrades",
body: "Purchase upgrades to multiply the gold and essence output of specific adventurer tiers, or boost your whole guild. Upgrades are permanent for the current run and compound with each other.",
},
{
title: "📜 Quests",
body: "Send your guild on quests that complete over time and reward gold, essence, crystals, equipment, and upgrades. Multiple quests can run simultaneously. Completing quests also unlocks new zones.",
},
{
title: "👹 Boss Fights",
body: "Challenge zone bosses to earn large one-time rewards and unlock new zones. Your party's combat power is based on the number and tier of adventurers you've recruited. Defeated bosses cannot be re-fought, but undefeated bosses regenerate HP over time.",
},
{
title: "🗺️ Zones",
body: "New zones unlock when you defeat the final boss AND complete the final quest of the previous zone. Each zone contains new bosses and quests with progressively greater rewards.",
},
{
title: "🗡️ Equipment & Sets",
body: "Earn equipment from boss drops and quest rewards. Each piece provides bonuses to gold income, click power, or combat. Rarer equipment provides stronger bonuses. Equip matching set pieces (2 or 3 of a named set) to unlock escalating set bonuses shown at the top of the Equipment panel.",
},
{
title: "⭐ Prestige",
body: "When you've progressed far enough, you can prestige to earn runestones — a permanent currency that persists across all runs. Prestige resets your current run but grants a production multiplier that stacks with every prestige. Name your prestige character to commemorate the run!",
},
{
title: "🔮 Runestones & Prestige Upgrades",
body: "Spend runestones in the Prestige Shop on permanent upgrades that carry over across all future runs. These upgrades multiply income, click power, essence, and crystal gain — making each new run more powerful than the last.",
},
{
title: "⚙️ Auto-Prestige",
body: "Purchase the Autonomous Ascension upgrade in the Prestige Shop (100 runestones) to unlock the Auto-Prestige toggle. When enabled, you will automatically ascend the moment you reach the prestige threshold, using your current character name. Toggle it on and off freely from the Prestige Shop.",
},
{
title: "🏆 Achievements",
body: "Earn achievements by hitting milestones — total gold earned, bosses defeated, quests completed, and more. Achievements are purely cosmetic and track your long-term progress across all prestige runs.",
},
{
title: "📅 Daily Challenges",
body: "Complete daily challenges for bonus rewards including gold, essence, crystals, and runestones. Challenges reset each day and vary in difficulty. Completing all daily challenges gives an extra bonus reward.",
},
{
title: "☁️ Cloud Saves",
body: "Your progress is automatically saved to the cloud every 30 seconds whilst you play. You can also force a manual save at any time using the sync button in the resource bar. Your save is protected by HMAC validation to ensure data integrity.",
},
];
const formatDate = (dateStr: string): string =>
new Date(dateStr).toLocaleDateString("en-GB", {
day: "numeric",
month: "short",
year: "numeric",
});
export const AboutPanel = (): React.JSX.Element => {
const [about, setAbout] = useState<AboutResponse | null>(null);
const [error, setError] = useState<string | null>(null);
const [expandedRelease, setExpandedRelease] = useState<string | null>(null);
useEffect(() => {
getAbout()
.then(setAbout)
.catch((err: unknown) => {
setError(err instanceof Error ? err.message : "Failed to load about data.");
});
}, []);
return (
<section className="panel about-panel">
<h2> About</h2>
<div className="about-versions">
<div className="about-version-card">
<span className="about-version-label">🌐 Client Version</span>
<span className="about-version-value">{__WEB_VERSION__}</span>
</div>
<div className="about-version-card">
<span className="about-version-label"> API Version</span>
<span className="about-version-value">{about?.apiVersion ?? "Loading..."}</span>
</div>
</div>
<h3 className="stats-section-header">📋 Changelog</h3>
{error !== null && <p className="about-error">{error}</p>}
{about === null && error === null && <p className="about-loading">Loading changelog...</p>}
{about !== null && about.releases.length === 0 && (
<p className="about-empty">No releases yet.</p>
)}
{about !== null && about.releases.length > 0 && (
<ul className="about-releases">
{about.releases.map((release) => (
<li key={release.tag_name} className="about-release">
<button
className="about-release-header"
type="button"
onClick={() => {
setExpandedRelease(
expandedRelease === release.tag_name ? null : release.tag_name,
);
}}
>
<span className="about-release-tag">{release.name || release.tag_name}</span>
<span className="about-release-date">{formatDate(release.published_at)}</span>
<span className="about-release-chevron">
{expandedRelease === release.tag_name ? "▲" : "▼"}
</span>
</button>
{expandedRelease === release.tag_name && (
<pre className="about-release-body">{release.body}</pre>
)}
</li>
))}
</ul>
)}
<h3 className="stats-section-header">📖 How to Play</h3>
<ul className="about-how-to-play">
{HOW_TO_PLAY.map((section) => (
<li key={section.title} className="about-htp-section">
<h4 className="about-htp-title">{section.title}</h4>
<p className="about-htp-body">{section.body}</p>
</li>
))}
</ul>
</section>
);
};
@@ -1,87 +0,0 @@
import type { Achievement } from "@elysium/types";
import { useState } from "react";
import { useGame } from "../../context/GameContext.js";
import { LockToggle } from "../ui/LockToggle.js";
const conditionDescription = (achievement: Achievement, formatNumber: (n: number) => string): string => {
const { condition } = achievement;
switch (condition.type) {
case "totalGoldEarned":
return `Earn ${formatNumber(condition.amount)} total gold`;
case "totalClicks":
return `Click ${formatNumber(condition.amount)} times`;
case "bossesDefeated":
return `Defeat ${condition.amount} boss${condition.amount > 1 ? "es" : ""}`;
case "questsCompleted":
return `Complete ${condition.amount} quest${condition.amount > 1 ? "s" : ""}`;
case "adventurerTotal":
return `Recruit ${formatNumber(condition.amount)} total adventurers`;
case "prestigeCount":
return `Prestige ${condition.amount} time${condition.amount > 1 ? "s" : ""}`;
case "equipmentOwned":
return `Own ${condition.amount} equipment item${condition.amount > 1 ? "s" : ""}`;
}
};
interface AchievementCardProps {
achievement: Achievement;
formatNumber: (n: number) => string;
}
const AchievementCard = ({ achievement, formatNumber }: AchievementCardProps): React.JSX.Element => {
const isUnlocked = achievement.unlockedAt !== null;
return (
<div className={`achievement-card ${isUnlocked ? "unlocked" : "locked"}`}>
<div className="achievement-icon">{achievement.icon}</div>
<div className="achievement-info">
<h3>{achievement.name}</h3>
<p>{achievement.description}</p>
<p className="achievement-condition">{conditionDescription(achievement, formatNumber)}</p>
{achievement.reward?.crystals != null && (
<p className="achievement-reward">💎 +{achievement.reward.crystals} Crystals</p>
)}
</div>
<div className="achievement-status">
{isUnlocked ? (
<span className="achievement-unlocked-badge"> Unlocked</span>
) : (
<span className="achievement-locked-badge">🔒</span>
)}
</div>
</div>
);
};
export const AchievementPanel = (): React.JSX.Element => {
const { state, formatNumber } = useGame();
const [showLocked, setShowLocked] = useState(true);
if (!state) return <section className="panel"><p>Loading...</p></section>;
const achievements = state.achievements ?? [];
const unlocked = achievements.filter((a) => a.unlockedAt !== null);
const locked = achievements.filter((a) => a.unlockedAt === null);
const visible = showLocked ? achievements : unlocked;
return (
<section className="panel achievement-panel">
<div className="panel-header">
<h2>Achievements</h2>
<LockToggle
lockedCount={locked.length}
showLocked={showLocked}
onToggle={() => { setShowLocked((v) => !v); }}
/>
</div>
<p className="achievement-progress">
{unlocked.length} / {achievements.length} unlocked
</p>
<div className="achievement-list">
{visible.map((achievement) => (
<AchievementCard key={achievement.id} achievement={achievement} formatNumber={formatNumber} />
))}
</div>
</section>
);
};
@@ -1,48 +0,0 @@
import { useEffect } from "react";
import type { Achievement } from "@elysium/types";
import { useGame } from "../../context/GameContext.js";
interface ToastItemProps {
achievement: Achievement;
onDismiss: (id: string) => void;
}
const ToastItem = ({ achievement, onDismiss }: ToastItemProps): React.JSX.Element => {
useEffect(() => {
const timer = setTimeout(() => {
onDismiss(achievement.id);
}, 4000);
return () => { clearTimeout(timer); };
}, [achievement.id, onDismiss]);
return (
<div className="achievement-toast" onClick={() => { onDismiss(achievement.id); }}>
<span className="toast-icon">{achievement.icon}</span>
<div className="toast-content">
<span className="toast-label">Achievement Unlocked!</span>
<span className="toast-name">{achievement.name}</span>
{achievement.reward?.crystals != null && (
<span className="toast-reward">💎 +{achievement.reward.crystals}</span>
)}
</div>
</div>
);
};
export const AchievementToast = (): React.JSX.Element | null => {
const { newAchievements, dismissAchievement } = useGame();
if (newAchievements.length === 0) return null;
return (
<div className="achievement-toast-container">
{newAchievements.map((achievement) => (
<ToastItem
key={achievement.id}
achievement={achievement}
onDismiss={dismissAchievement}
/>
))}
</div>
);
};
@@ -1,97 +0,0 @@
import type { Adventurer } from "@elysium/types";
import { useState } from "react";
import { useGame } from "../../context/GameContext.js";
import { LockToggle } from "../ui/LockToggle.js";
const CLASS_ICONS: Record<string, string> = {
warrior: "🗡️",
mage: "🔮",
rogue: "🗝️",
cleric: "✝️",
ranger: "🏹",
paladin: "🛡️",
};
const adventurerCost = (adventurer: Adventurer): number =>
Math.ceil(10 * Math.pow(1.15, adventurer.count));
interface AdventurerCardProps {
adventurer: Adventurer;
currentGold: number;
unlockHint?: string | undefined;
formatNumber: (n: number) => string;
}
const AdventurerCard = ({ adventurer, currentGold, unlockHint, formatNumber }: AdventurerCardProps): React.JSX.Element => {
const { buyAdventurer } = useGame();
const cost = adventurerCost(adventurer);
const canAfford = currentGold >= cost;
return (
<div className={`adventurer-card ${!adventurer.unlocked ? "locked" : ""}`}>
<div className="adventurer-icon">{CLASS_ICONS[adventurer.class] ?? "⚔️"}</div>
<div className="adventurer-info">
<h3>{adventurer.name}</h3>
<p>{formatNumber(adventurer.goldPerSecond)} gold/s each</p>
{adventurer.essencePerSecond > 0 && (
<p>{formatNumber(adventurer.essencePerSecond)} essence/s each</p>
)}
</div>
<div className="adventurer-count">×{adventurer.count}</div>
<button
className="buy-button"
disabled={!canAfford || !adventurer.unlocked}
onClick={() => { buyAdventurer(adventurer.id); }}
type="button"
>
{adventurer.unlocked ? `🪙 ${formatNumber(cost)}` : "🔒 Locked"}
</button>
{!adventurer.unlocked && unlockHint && (
<p className="unlock-hint">📜 Complete: {unlockHint}</p>
)}
</div>
);
};
export const AdventurerPanel = (): React.JSX.Element => {
const { state, formatNumber } = useGame();
const [showLocked, setShowLocked] = useState(true);
if (!state) return <section className="panel"><p>Loading...</p></section>;
const locked = state.adventurers.filter((a) => !a.unlocked);
const visible = showLocked ? state.adventurers : state.adventurers.filter((a) => a.unlocked);
const adventurerUnlockHints = new Map<string, string>();
for (const quest of state.quests) {
for (const reward of quest.rewards) {
if (reward.type === "adventurer" && reward.targetId) {
adventurerUnlockHints.set(reward.targetId, quest.name);
}
}
}
return (
<section className="panel adventurer-panel">
<div className="panel-header">
<h2>Adventurers</h2>
<LockToggle
lockedCount={locked.length}
showLocked={showLocked}
onToggle={() => { setShowLocked((v) => !v); }}
/>
</div>
<div className="adventurer-list">
{visible.map((adventurer) => (
<AdventurerCard
key={adventurer.id}
adventurer={adventurer}
currentGold={state.resources.gold}
unlockHint={adventurerUnlockHints.get(adventurer.id)}
formatNumber={formatNumber}
/>
))}
</div>
</section>
);
};
@@ -1,170 +0,0 @@
import type { BattleResult } from "../../context/GameContext.js";
import { useGame } from "../../context/GameContext.js";
import { useEffect, useState } from "react";
interface BattleModalProps {
battle: BattleResult;
onDismiss: () => void;
}
export const BattleModal = ({
battle,
onDismiss,
}: BattleModalProps): React.JSX.Element => {
const { result, bossName } = battle;
const { formatNumber } = useGame();
const [phase, setPhase] = useState<"animating" | "result">("animating");
// Starting HP percentages
const bossStartPercent = (result.bossHpBefore / result.bossMaxHp) * 100;
const partyStartPercent = 100;
// Target HP percentages (after battle)
const bossEndPercent = (result.bossHpAtBattleEnd / result.bossMaxHp) * 100;
const partyEndPercent = result.partyMaxHp > 0
? (result.partyHpRemaining / result.partyMaxHp) * 100
: 0;
const [bossHpPercent, setBossHpPercent] = useState(bossStartPercent);
const [partyHpPercent, setPartyHpPercent] = useState(partyStartPercent);
useEffect(() => {
// Brief delay so CSS transition has a starting point to animate from
const startAnimation = setTimeout(() => {
setBossHpPercent(bossEndPercent);
setPartyHpPercent(partyEndPercent);
}, 200);
// Reveal result after animation completes
const revealResult = setTimeout(() => {
setPhase("result");
}, 5_200);
return () => {
clearTimeout(startAnimation);
clearTimeout(revealResult);
};
}, [bossEndPercent, partyEndPercent]);
const bossHpBarColour = bossHpPercent > 50
? "#e74c3c"
: bossHpPercent > 25
? "#e67e22"
: "#c0392b";
const partyHpBarColour = partyHpPercent > 50
? "#27ae60"
: partyHpPercent > 25
? "#f39c12"
: "#e74c3c";
return (
<div className="modal-overlay">
<div className="modal battle-modal">
<h2> Battle: {bossName}</h2>
<div className="battle-stats">
<div className="battle-stat">
<span className="stat-label">Your Party DPS</span>
<span className="stat-value">{formatNumber(result.partyDPS)}</span>
</div>
<div className="battle-stat-divider">vs</div>
<div className="battle-stat">
<span className="stat-label">Boss DPS</span>
<span className="stat-value">{formatNumber(result.bossDPS)}</span>
</div>
</div>
<div className="battle-bars">
<div className="battle-bar-row">
<span className="bar-label">👹 {bossName}</span>
<div className="hp-bar-container">
<div
className="hp-bar-fill"
style={{
width: `${bossHpPercent.toFixed(1)}%`,
backgroundColor: bossHpBarColour,
transition: "width 5s ease-in-out",
}}
/>
</div>
<span className="bar-hp">
{formatNumber(result.bossHpAtBattleEnd)} / {formatNumber(result.bossMaxHp)}
</span>
</div>
<div className="vs-divider"> VS </div>
<div className="battle-bar-row">
<span className="bar-label">🛡 Your Party</span>
<div className="hp-bar-container">
<div
className="hp-bar-fill party-hp"
style={{
width: `${partyHpPercent.toFixed(1)}%`,
backgroundColor: partyHpBarColour,
transition: "width 5s ease-in-out",
}}
/>
</div>
<span className="bar-hp">
{formatNumber(result.partyHpRemaining)} / {formatNumber(result.partyMaxHp)}
</span>
</div>
</div>
{phase === "animating" && (
<p className="battle-in-progress">Battling</p>
)}
{phase === "result" && (
<div className={`battle-outcome ${result.won ? "victory" : "defeat"}`}>
{result.won ? (
<>
<h3>🏆 Victory!</h3>
{result.rewards && (
<div className="battle-rewards">
<p>Rewards:</p>
<span>🪙 {formatNumber(result.rewards.gold)} gold</span>
{result.rewards.essence > 0 && (
<span> {formatNumber(result.rewards.essence)} essence</span>
)}
{result.rewards.crystals > 0 && (
<span>💎 {formatNumber(result.rewards.crystals)} crystals</span>
)}
{result.rewards.bountyRunestones > 0 && (
<span className="battle-bounty">🔮 {formatNumber(result.rewards.bountyRunestones)} runestones (first kill!)</span>
)}
</div>
)}
</>
) : (
<>
<h3>💀 Defeat</h3>
<p>Your party was defeated. The boss has reset.</p>
{result.casualties && result.casualties.length > 0 && (
<div className="battle-casualties">
<p>Casualties:</p>
{result.casualties.map((c) => (
<span key={c.adventurerId}>
{c.killed} {c.adventurerId} lost
</span>
))}
</div>
)}
</>
)}
<button
className="dismiss-button"
onClick={onDismiss}
type="button"
>
Continue
</button>
</div>
)}
</div>
</div>
);
};
-234
View File
@@ -1,234 +0,0 @@
import type { Boss } from "@elysium/types";
import { useState } from "react";
import { useGame } from "../../context/GameContext.js";
import { LockToggle } from "../ui/LockToggle.js";
import { ZoneSelector } from "./ZoneSelector.js";
interface BossCardProps {
boss: Boss;
prestigeCount: number;
onChallenge: (bossId: string) => void;
isChallenging: boolean;
unlockHint?: string | undefined;
formatNumber: (n: number) => string;
}
const BossCard = ({
boss,
prestigeCount,
onChallenge,
isChallenging,
unlockHint,
formatNumber,
}: BossCardProps): React.JSX.Element => {
const hpPercent = (boss.currentHp / boss.maxHp) * 100;
const isPrestigeLocked = boss.prestigeRequirement > prestigeCount;
const canChallenge =
(boss.status === "available" || boss.status === "in_progress") && !isChallenging;
return (
<div className={`boss-card boss-${boss.status}`}>
<div className="boss-info">
<h3>{boss.name}</h3>
<p>{boss.description}</p>
{isPrestigeLocked && boss.status === "locked" && (
<p className="prestige-lock">
🔒 Requires Prestige {boss.prestigeRequirement}
</p>
)}
{!isPrestigeLocked && boss.status === "locked" && unlockHint && (
<p className="unlock-hint">{unlockHint}</p>
)}
</div>
{boss.status !== "locked" && boss.status !== "defeated" && (
<div className="boss-hp">
<div className="hp-bar">
<div
className="hp-fill"
style={{ width: `${hpPercent.toFixed(1)}%` }}
/>
</div>
<span className="hp-text">
{formatNumber(boss.currentHp)} / {formatNumber(boss.maxHp)} HP
</span>
</div>
)}
<div className="boss-meta">
<span className="boss-dps">💢 Boss DPS: {formatNumber(boss.damagePerSecond)}</span>
</div>
<div className="boss-rewards">
<span>🪙 {formatNumber(boss.goldReward)}</span>
{boss.essenceReward > 0 && (
<span> {formatNumber(boss.essenceReward)}</span>
)}
{boss.crystalReward > 0 && (
<span>💎 {formatNumber(boss.crystalReward)}</span>
)}
{(boss.equipmentRewards ?? []).length > 0 && (
<span>🗡 {boss.equipmentRewards.length} Equipment</span>
)}
{boss.status !== "defeated" && boss.bountyRunestones > 0 && (
<span className="boss-bounty">🔮 {boss.bountyRunestones} (first kill)</span>
)}
</div>
{(boss.status === "available" || boss.status === "in_progress") && (
<button
className="attack-button"
disabled={!canChallenge}
onClick={() => {
onChallenge(boss.id);
}}
type="button"
>
{isChallenging ? "⚔️ Battling…" : "⚔️ Challenge"}
</button>
)}
{boss.status === "defeated" && (
<span className="boss-badge defeated"> Defeated</span>
)}
</div>
);
};
export const BossPanel = (): React.JSX.Element => {
const { state, challengeBoss, formatNumber } = useGame();
const [challengingBossId, setChallengingBossId] = useState<string | null>(null);
const [activeZoneId, setActiveZoneId] = useState("verdant_vale");
const [showLocked, setShowLocked] = useState(true);
if (!state) return <section className="panel"><p>Loading...</p></section>;
// Calculate party combat stats including equipment multiplier
let globalMultiplier = 1;
for (const upgrade of state.upgrades) {
if (upgrade.purchased && upgrade.target === "global") {
globalMultiplier *= upgrade.multiplier;
}
}
const prestigeMultiplier = 1 + state.prestige.count * 0.1;
const equipmentCombatMultiplier = (state.equipment ?? [])
.filter((e) => e.equipped && e.bonus.combatMultiplier != null)
.reduce((mult, e) => mult * (e.bonus.combatMultiplier ?? 1), 1);
let partyDPS = 0;
let partyHP = 0;
for (const adventurer of state.adventurers) {
if (adventurer.count === 0) continue;
let adventurerMultiplier = 1;
for (const upgrade of state.upgrades) {
if (
upgrade.purchased &&
upgrade.target === "adventurer" &&
upgrade.adventurerId === adventurer.id
) {
adventurerMultiplier *= upgrade.multiplier;
}
}
partyDPS +=
adventurer.combatPower *
adventurer.count *
adventurerMultiplier *
globalMultiplier *
prestigeMultiplier;
partyHP += adventurer.level * 50 * adventurer.count;
}
partyDPS *= equipmentCombatMultiplier;
const handleChallenge = async (bossId: string): Promise<void> => {
setChallengingBossId(bossId);
try {
await challengeBoss(bossId);
} finally {
setChallengingBossId(null);
}
};
const zones = state.zones ?? [];
const zoneBosses = state.bosses.filter((b) => b.zoneId === activeZoneId);
const lockedCount = zoneBosses.filter((b) => b.status === "locked").length;
const visibleBosses = showLocked
? zoneBosses
: zoneBosses.filter((b) => b.status !== "locked");
const bossUnlockHints = new Map<string, string>();
for (const zone of zones) {
const allZoneBosses = state.bosses.filter((b) => b.zoneId === zone.id);
for (let i = 0; i < allZoneBosses.length; i++) {
const boss = allZoneBosses[i];
if (!boss || boss.status !== "locked") continue;
if (i === 0) {
const parts: string[] = [];
if (zone.unlockBossId) {
const gateBoss = state.bosses.find((b) => b.id === zone.unlockBossId);
if (gateBoss) parts.push(`⚔️ Defeat: ${gateBoss.name}`);
}
if (zone.unlockQuestId) {
const gateQuest = state.quests.find((q) => q.id === zone.unlockQuestId);
if (gateQuest) parts.push(`📜 Complete: ${gateQuest.name}`);
}
if (parts.length > 0) {
bossUnlockHints.set(boss.id, parts.join(" & "));
}
} else {
const prevBoss = allZoneBosses[i - 1];
if (prevBoss) {
bossUnlockHints.set(boss.id, `⚔️ Defeat: ${prevBoss.name} first`);
}
}
}
}
return (
<section className="panel boss-panel">
<div className="panel-header">
<h2>Boss Encounters</h2>
<LockToggle
lockedCount={lockedCount}
showLocked={showLocked}
onToggle={() => { setShowLocked((v) => !v); }}
/>
</div>
<ZoneSelector
activeZoneId={activeZoneId}
zones={zones}
onSelectZone={setActiveZoneId}
/>
<div className="party-combat-stats">
<div className="combat-stat">
<span className="stat-label"> Party DPS</span>
<span className="stat-value">{formatNumber(partyDPS)}</span>
</div>
<div className="combat-stat">
<span className="stat-label"> Party HP</span>
<span className="stat-value">{formatNumber(partyHP)}</span>
</div>
</div>
<div className="boss-list">
{visibleBosses.map((boss) => (
<BossCard
key={boss.id}
boss={boss}
formatNumber={formatNumber}
isChallenging={challengingBossId === boss.id}
prestigeCount={state.prestige.count}
unlockHint={bossUnlockHints.get(boss.id)}
onChallenge={(id) => {
void handleChallenge(id);
}}
/>
))}
{visibleBosses.length === 0 && (
<p className="empty-zone">No bosses to show in this zone.</p>
)}
</div>
</section>
);
};
@@ -1,65 +0,0 @@
import { useCallback, useRef, useState } from "react";
import { useGame } from "../../context/GameContext.js";
import { calculateClickPower } from "../../engine/tick.js";
interface FloatText {
id: number;
x: number;
y: number;
text: string;
}
export const ClickArea = (): React.JSX.Element => {
const { state, handleClick, formatNumber } = useGame();
const [floats, setFloats] = useState<FloatText[]>([]);
const nextIdRef = useRef(0);
const handleClickWithFloat = useCallback(
(e: React.MouseEvent<HTMLButtonElement>) => {
if (!state) return;
const rect = e.currentTarget.getBoundingClientRect();
const x = e.clientX - rect.left;
const y = e.clientY - rect.top;
const id = nextIdRef.current++;
const clickPower = calculateClickPower(state);
setFloats((prev) => [...prev, { id, x, y, text: `+${formatNumber(clickPower)}` }]);
handleClick();
setTimeout(() => {
setFloats((prev) => prev.filter((f) => f.id !== id));
}, 900);
},
[state, handleClick],
);
if (!state) return <div className="click-area-placeholder" />;
const clickPower = calculateClickPower(state);
return (
<section className="click-area">
<h2>Guild Hall</h2>
<div className="click-button-wrapper">
<button
className="click-button"
onClick={handleClickWithFloat}
type="button"
aria-label={`Click to earn ${formatNumber(clickPower)} gold`}
>
</button>
{floats.map((float) => (
<span
key={float.id}
className="click-float"
style={{ left: float.x, top: float.y }}
>
{float.text}
</span>
))}
</div>
<p className="click-power">+{formatNumber(clickPower)} gold/click</p>
</section>
);
};
@@ -1,91 +0,0 @@
import { useGame } from "../../context/GameContext.js";
const formatTimeUntilReset = (): string => {
const now = new Date();
// Mirror the server's PST/PDT-based rollover: challenges reset at PST midnight
const nowAsPST = new Date(now.toLocaleString("en-US", { timeZone: "America/Los_Angeles" }));
const tomorrowMidnightPST = new Date(nowAsPST);
tomorrowMidnightPST.setDate(tomorrowMidnightPST.getDate() + 1);
tomorrowMidnightPST.setHours(0, 0, 0, 0);
const pstOffset = nowAsPST.getTime() - now.getTime();
const resetAt = new Date(tomorrowMidnightPST.getTime() - pstOffset);
const msRemaining = resetAt.getTime() - now.getTime();
const hoursRemaining = Math.floor(msRemaining / (1000 * 60 * 60));
const minutesRemaining = Math.floor((msRemaining % (1000 * 60 * 60)) / (1000 * 60));
return `${String(hoursRemaining)}h ${String(minutesRemaining)}m`;
};
export const DailyChallengePanel = (): React.JSX.Element => {
const { state, formatNumber } = useGame();
if (!state) return <section className="panel"><p>Loading...</p></section>;
const { dailyChallenges } = state;
if (!dailyChallenges) {
return (
<section className="panel daily-challenge-panel">
<h2>📅 Daily Challenges</h2>
<p className="daily-challenge-subtitle">Load the game to generate today's challenges!</p>
</section>
);
}
const completedCount = dailyChallenges.challenges.filter((c) => c.completed).length;
return (
<section className="panel daily-challenge-panel">
<h2>📅 Daily Challenges</h2>
<div className="daily-challenge-header">
<p className="daily-challenge-subtitle">
Complete challenges for bonus 💎 crystals! Resets in{" "}
<strong>{formatTimeUntilReset()}</strong> (PST midnight).
</p>
<p className="daily-challenge-progress">
{completedCount} / {dailyChallenges.challenges.length} completed
</p>
</div>
<div className="daily-challenge-list">
{dailyChallenges.challenges.map((challenge) => {
const progressPercent = Math.min(
100,
Math.floor((challenge.progress / challenge.target) * 100),
);
return (
<div
key={challenge.id}
className={`daily-challenge-card ${challenge.completed ? "completed" : ""}`}
>
<div className="daily-challenge-info">
<h3 className="daily-challenge-label">{challenge.label}</h3>
<p className="daily-challenge-reward">
Reward: <strong>💎 {formatNumber(challenge.rewardCrystals)} crystals</strong>
</p>
</div>
<div className="daily-challenge-right">
{challenge.completed ? (
<span className="daily-challenge-done"> Complete!</span>
) : (
<>
<p className="daily-challenge-count">
{formatNumber(challenge.progress)} / {formatNumber(challenge.target)}
</p>
<div className="daily-challenge-bar-track">
<div
className="daily-challenge-bar-fill"
style={{ width: `${String(progressPercent)}%` }}
/>
</div>
</>
)}
</div>
</div>
);
})}
</div>
</section>
);
};
@@ -1,194 +0,0 @@
import type { NumberFormat, ProfileSettings } from "@elysium/types";
import { DEFAULT_PROFILE_SETTINGS } from "@elysium/types";
import { useEffect, useState } from "react";
import { updateProfile } from "../../api/client.js";
import { useGame } from "../../context/GameContext.js";
interface EditProfileModalProps {
onClose: () => void;
}
const STAT_TOGGLES: { key: keyof ProfileSettings; label: string; icon: string }[] = [
{ key: "showTotalGold", label: "Total Gold Earned", icon: "🪙" },
{ key: "showTotalClicks", label: "Total Clicks", icon: "👆" },
{ key: "showPrestige", label: "Prestige Level", icon: "⭐" },
{ key: "showBossesDefeated", label: "Bosses Defeated", icon: "💀" },
{ key: "showQuestsCompleted", label: "Quests Completed", icon: "📜" },
{ key: "showAdventurersRecruited", label: "Adventurers Recruited", icon: "⚔️" },
{ key: "showAchievementsUnlocked", label: "Achievements Unlocked", icon: "🏆" },
{ key: "showGuildFounded", label: "Guild Founded Date", icon: "📅" },
];
export const EditProfileModal = ({ onClose }: EditProfileModalProps): React.JSX.Element => {
const { state, numberFormat: currentNumberFormat, setNumberFormat } = useGame();
const player = state?.player;
const [characterName, setCharacterName] = useState(player?.characterName ?? "");
const [bio, setBio] = useState("");
const [settings, setSettings] = useState<ProfileSettings>({
...DEFAULT_PROFILE_SETTINGS,
numberFormat: currentNumberFormat,
});
const [loadingProfile, setLoadingProfile] = useState(true);
const [saving, setSaving] = useState(false);
const [error, setError] = useState<string | null>(null);
const [saved, setSaved] = useState(false);
// Fetch current profile to auto-populate bio and settings
useEffect(() => {
if (!player?.discordId) return;
fetch(`/api/profile/${player.discordId}`)
.then(async (res) => {
if (!res.ok) return;
const data = (await res.json()) as {
bio: string;
profileSettings: ProfileSettings;
characterName: string;
};
setBio(data.bio ?? "");
setSettings({ ...DEFAULT_PROFILE_SETTINGS, ...data.profileSettings });
setCharacterName(data.characterName ?? player.characterName ?? "");
})
.catch(() => {
// Fall back to local state if fetch fails — not a blocking error
})
.finally(() => {
setLoadingProfile(false);
});
}, [player?.discordId, player?.characterName]);
const handleSave = async (): Promise<void> => {
setSaving(true);
setError(null);
try {
await updateProfile({ characterName, bio, profileSettings: settings });
setNumberFormat(settings.numberFormat);
setSaved(true);
setTimeout(onClose, 900);
} catch (err: unknown) {
setError(err instanceof Error ? err.message : "Failed to save");
} finally {
setSaving(false);
}
};
const toggleSetting = (key: keyof ProfileSettings): void => {
setSettings((prev) => ({ ...prev, [key]: !prev[key] }));
};
return (
<div className="modal-overlay" role="dialog" aria-modal="true">
<div className="modal edit-profile-modal">
<div className="modal-header">
<h2>Edit Profile</h2>
<button
aria-label="Close"
className="modal-close"
onClick={onClose}
type="button"
>
</button>
</div>
{loadingProfile ? (
<p className="edit-profile-loading">Loading your profile</p>
) : (
<div className="edit-profile-form">
<label className="edit-profile-label" htmlFor="edit-char-name">
Display Name
</label>
<input
className="edit-profile-input"
id="edit-char-name"
maxLength={32}
placeholder="Your character's name"
type="text"
value={characterName}
onChange={(e) => { setCharacterName(e.target.value); }}
/>
<span className="edit-profile-hint">{characterName.length} / 32</span>
<label className="edit-profile-label" htmlFor="edit-bio">
Bio
</label>
<textarea
className="edit-profile-textarea"
id="edit-bio"
maxLength={200}
placeholder="Tell the world about your guild… (optional)"
rows={3}
value={bio}
onChange={(e) => { setBio(e.target.value); }}
/>
<span className="edit-profile-hint">{bio.length} / 200</span>
<div className="edit-profile-section">
<p className="edit-profile-label">Visible Stats</p>
<p className="edit-profile-sublabel">Choose which stats appear on your public profile.</p>
<div className="stat-toggles">
{STAT_TOGGLES.map(({ key, label, icon }) => (
<button
key={key}
className={`stat-toggle-btn ${settings[key] ? "stat-toggle-on" : "stat-toggle-off"}`}
onClick={() => { toggleSetting(key); }}
type="button"
>
<span>{icon} {label}</span>
<span className="stat-toggle-indicator">
{settings[key] ? "✓ Shown" : "Hidden"}
</span>
</button>
))}
</div>
</div>
<div className="edit-profile-section">
<p className="edit-profile-label">Number Format</p>
<p className="edit-profile-sublabel">How large numbers appear across the game.</p>
<div className="number-format-picker">
{(
[
{ value: "suffix", label: "Suffix", example: "1.23Qa" },
{ value: "scientific", label: "Scientific", example: "1.23e15" },
{ value: "engineering", label: "Engineering", example: "1.23E15" },
] as { value: NumberFormat; label: string; example: string }[]
).map(({ value, label, example }) => (
<button
key={value}
className={`number-format-btn ${settings.numberFormat === value ? "number-format-active" : ""}`}
onClick={() => { setSettings((prev) => ({ ...prev, numberFormat: value })); }}
type="button"
>
<span className="number-format-label">{label}</span>
<span className="number-format-example">{example}</span>
</button>
))}
</div>
</div>
{error && <p className="edit-profile-error">{error}</p>}
<div className="edit-profile-actions">
<button
className="edit-profile-cancel"
onClick={onClose}
type="button"
>
Cancel
</button>
<button
className="edit-profile-save"
disabled={saving || !characterName.trim()}
onClick={() => { void handleSave(); }}
type="button"
>
{saved ? "✓ Saved!" : saving ? "Saving…" : "Save Profile"}
</button>
</div>
</div>
)}
</div>
</div>
);
};
@@ -1,206 +0,0 @@
import type { Equipment, EquipmentType } from "@elysium/types";
import { useState } from "react";
import { useGame } from "../../context/GameContext.js";
import { EQUIPMENT_SETS } from "../../data/equipmentSets.js";
import { LockToggle } from "../ui/LockToggle.js";
const RARITY_LABEL: Record<string, string> = {
common: "Common",
rare: "Rare",
epic: "Epic",
legendary: "Legendary",
};
const TYPE_ICON: Record<EquipmentType, string> = {
weapon: "⚔️",
armour: "🛡️",
trinket: "💍",
};
const bonusDescription = (item: Equipment): string => {
const parts: string[] = [];
if (item.bonus.combatMultiplier != null) {
parts.push(`+${Math.round((item.bonus.combatMultiplier - 1) * 100)}% Combat`);
}
if (item.bonus.goldMultiplier != null) {
parts.push(`+${Math.round((item.bonus.goldMultiplier - 1) * 100)}% Gold/s`);
}
if (item.bonus.clickMultiplier != null) {
parts.push(`+${Math.round((item.bonus.clickMultiplier - 1) * 100)}% Click`);
}
return parts.join(", ");
};
interface EquipmentCardProps {
item: Equipment;
gold: number;
essence: number;
crystals: number;
dropBossName?: string | undefined;
setName?: string | undefined;
}
const costLabel = (cost: { gold: number; essence: number; crystals: number }): string => {
const parts: string[] = [];
if (cost.gold > 0) parts.push(`🪙 ${cost.gold.toLocaleString()}`);
if (cost.essence > 0) parts.push(`${cost.essence.toLocaleString()}`);
if (cost.crystals > 0) parts.push(`💎 ${cost.crystals.toLocaleString()}`);
return parts.join(" ");
};
const EquipmentCard = ({ item, gold, essence, crystals, dropBossName, setName }: EquipmentCardProps): React.JSX.Element => {
const { equipItem, buyEquipment } = useGame();
const canAfford = item.cost
? gold >= item.cost.gold && essence >= item.cost.essence && crystals >= item.cost.crystals
: false;
return (
<div className={`equipment-card rarity-${item.rarity} ${item.equipped ? "equipped" : ""} ${!item.owned ? "not-owned" : ""}`}>
<div className="equipment-icon">{TYPE_ICON[item.type]}</div>
<div className="equipment-info">
<div className="equipment-name-row">
<h3>{item.name}</h3>
<span className={`rarity-badge rarity-${item.rarity}`}>{RARITY_LABEL[item.rarity]}</span>
</div>
<p className="equipment-description">{item.description}</p>
<p className="equipment-bonus">{bonusDescription(item)}</p>
{setName && <span className="equipment-set-badge">🔗 {setName}</span>}
{!item.owned && item.cost && (
<p className="equipment-cost">{costLabel(item.cost)}</p>
)}
</div>
<div className="equipment-action">
{!item.owned && !item.cost && (
<span className="equipment-locked">
{dropBossName ? `⚔️ Drop: ${dropBossName}` : "🔒 Boss drop"}
</span>
)}
{!item.owned && item.cost && (
<button
className="equip-button"
disabled={!canAfford}
onClick={() => { buyEquipment(item.id); }}
type="button"
>
{canAfford ? "Purchase" : "Can't afford"}
</button>
)}
{item.owned && item.equipped && <span className="equipment-equipped-badge"> Equipped</span>}
{item.owned && !item.equipped && (
<button
className="equip-button"
onClick={() => { equipItem(item.id); }}
type="button"
>
Equip
</button>
)}
</div>
</div>
);
};
const SLOT_ORDER: EquipmentType[] = ["weapon", "armour", "trinket"];
const SLOT_LABEL: Record<EquipmentType, string> = {
weapon: "⚔️ Weapons",
armour: "🛡️ Armour",
trinket: "💍 Trinkets",
};
export const EquipmentPanel = (): React.JSX.Element => {
const { state } = useGame();
const [showLocked, setShowLocked] = useState(true);
if (!state) return <section className="panel"><p>Loading...</p></section>;
const equipment = state.equipment ?? [];
const unownedCount = equipment.filter((e) => !e.owned).length;
const equipmentDropSources = new Map<string, string>();
for (const boss of state.bosses) {
for (const equipmentId of (boss.equipmentRewards ?? [])) {
equipmentDropSources.set(equipmentId, boss.name);
}
}
// Build set name lookup for card badges
const setNameById = new Map<string, string>(
EQUIPMENT_SETS.map((s) => [s.id, s.name]),
);
// Compute active set bonuses for the summary strip
const equippedItemIds = equipment.filter((e) => e.equipped).map((e) => e.id);
const activeSets = EQUIPMENT_SETS.map((set) => {
const count = set.pieces.filter((id) => equippedItemIds.includes(id)).length;
return { set, count };
}).filter(({ count }) => count >= 2);
const setBonusDescription = (set: typeof EQUIPMENT_SETS[number], count: number): string => {
const parts: string[] = [];
for (const threshold of [2, 3] as const) {
if (count >= threshold) {
const bonus = set.bonuses[threshold];
if (bonus.goldMultiplier) parts.push(`+${Math.round((bonus.goldMultiplier - 1) * 100)}% Gold/s (${threshold}pc)`);
if (bonus.combatMultiplier) parts.push(`+${Math.round((bonus.combatMultiplier - 1) * 100)}% Combat (${threshold}pc)`);
if (bonus.clickMultiplier) parts.push(`+${Math.round((bonus.clickMultiplier - 1) * 100)}% Click (${threshold}pc)`);
}
}
return parts.join(", ");
};
return (
<section className="panel equipment-panel">
<div className="panel-header">
<h2>Equipment</h2>
<LockToggle
lockedCount={unownedCount}
showLocked={showLocked}
onToggle={() => { setShowLocked((v) => !v); }}
/>
</div>
<p className="equipment-intro">
Equipment drops from bosses and grants passive bonuses. Only one item per slot can be equipped at a time. Equip matching set pieces for bonus effects!
</p>
{activeSets.length > 0 && (
<div className="active-sets">
<h3 className="active-sets-heading"> Active Set Bonuses</h3>
{activeSets.map(({ set, count }) => (
<div key={set.id} className="active-set-row">
<span className="active-set-name">{set.name} ({count}/{set.pieces.length})</span>
<span className="active-set-bonus">{setBonusDescription(set, count)}</span>
</div>
))}
</div>
)}
{SLOT_ORDER.map((slotType) => {
const items = equipment.filter(
(e) => e.type === slotType && (showLocked || e.owned),
);
return (
<div key={slotType} className="equipment-slot-section">
<h3 className="slot-heading">{SLOT_LABEL[slotType]}</h3>
<div className="equipment-list">
{items.map((item) => (
<EquipmentCard
key={item.id}
item={item}
gold={state.resources.gold}
essence={state.resources.essence}
crystals={state.resources.crystals}
dropBossName={equipmentDropSources.get(item.id)}
setName={item.setId ? setNameById.get(item.setId) : undefined}
/>
))}
{items.length === 0 && (
<p className="empty-zone">No items to show in this slot.</p>
)}
</div>
</div>
);
})}
</section>
);
};
-116
View File
@@ -1,116 +0,0 @@
import { useState } from "react";
import { useGame } from "../../context/GameContext.js";
import { ResourceBar } from "../ui/ResourceBar.js";
import { AboutPanel } from "./AboutPanel.js";
import { AchievementPanel } from "./AchievementPanel.js";
import { AchievementToast } from "./AchievementToast.js";
import { AdventurerPanel } from "./AdventurerPanel.js";
import { BattleModal } from "./BattleModal.js";
import { BossPanel } from "./BossPanel.js";
import { ClickArea } from "./ClickArea.js";
import { EditProfileModal } from "./EditProfileModal.js";
import { EquipmentPanel } from "./EquipmentPanel.js";
import { OfflineModal } from "./OfflineModal.js";
import { PrestigePanel } from "./PrestigePanel.js";
import { QuestPanel } from "./QuestPanel.js";
import { StatisticsPanel } from "./StatisticsPanel.js";
import { UpgradePanel } from "./UpgradePanel.js";
import { DailyChallengePanel } from "./DailyChallengePanel.js";
type Tab = "adventurers" | "upgrades" | "quests" | "bosses" | "equipment" | "achievements" | "prestige" | "statistics" | "daily" | "about";
const TABS: { id: Tab; label: string }[] = [
{ id: "adventurers", label: "⚔️ Adventurers" },
{ id: "upgrades", label: "🔧 Upgrades" },
{ id: "quests", label: "📜 Quests" },
{ id: "bosses", label: "👹 Bosses" },
{ id: "equipment", label: "🗡️ Equipment" },
{ id: "achievements", label: "🏆 Achievements" },
{ id: "prestige", label: "⭐ Prestige" },
{ id: "statistics", label: "📊 Statistics" },
{ id: "daily", label: "📅 Daily" },
{ id: "about", label: "️ About" },
];
export const GameLayout = (): React.JSX.Element => {
const { state, isLoading, error, battleResult, dismissBattle, lastSavedAt, isSyncing, forceSync } = useGame();
const [activeTab, setActiveTab] = useState<Tab>("adventurers");
const [editingProfile, setEditingProfile] = useState(false);
if (isLoading) {
return (
<div className="loading-screen">
<p>Loading your adventure...</p>
</div>
);
}
if (error) {
return (
<div className="error-screen">
<p>Error: {error}</p>
</div>
);
}
if (!state) return <div className="loading-screen"><p>Loading...</p></div>;
const profileUrl = `/profile/${state.player.discordId}`;
return (
<div className="game-layout">
<ResourceBar
resources={state.resources}
runestones={state.prestige.runestones}
prestigeCount={state.prestige.count}
profileUrl={profileUrl}
onEditProfile={() => { setEditingProfile(true); }}
lastSavedAt={lastSavedAt}
isSyncing={isSyncing}
onForceSync={forceSync}
/>
<OfflineModal />
<AchievementToast />
{battleResult && (
<BattleModal battle={battleResult} onDismiss={dismissBattle} />
)}
{editingProfile && (
<EditProfileModal onClose={() => { setEditingProfile(false); }} />
)}
<div className="game-main">
<aside className="game-sidebar">
<ClickArea />
</aside>
<main className="game-content">
<nav className="tab-bar">
{TABS.map((tab) => (
<button
key={tab.id}
className={`tab-button ${activeTab === tab.id ? "active" : ""}`}
onClick={() => { setActiveTab(tab.id); }}
type="button"
>
{tab.label}
</button>
))}
</nav>
<div className="tab-content">
{activeTab === "adventurers" && <AdventurerPanel />}
{activeTab === "upgrades" && <UpgradePanel />}
{activeTab === "quests" && <QuestPanel />}
{activeTab === "bosses" && <BossPanel />}
{activeTab === "equipment" && <EquipmentPanel />}
{activeTab === "achievements" && <AchievementPanel />}
{activeTab === "prestige" && <PrestigePanel />}
{activeTab === "statistics" && <StatisticsPanel />}
{activeTab === "daily" && <DailyChallengePanel />}
{activeTab === "about" && <AboutPanel />}
</div>
</main>
</div>
</div>
);
};
@@ -1,87 +0,0 @@
import { useEffect, useState } from "react";
import { getAuthUrl, handleAuthCallback } from "../../api/client.js";
interface LoginPageProps {
onLogin: () => void;
}
export const LoginPage = ({ onLogin }: LoginPageProps): React.JSX.Element => {
const [authUrl, setAuthUrl] = useState<string | null>(null);
const [isLoading, setIsLoading] = useState(true);
const [error, setError] = useState<string | null>(null);
useEffect(() => {
// Handle OAuth callback
const params = new URLSearchParams(window.location.search);
const code = params.get("code");
if (code) {
setIsLoading(true);
handleAuthCallback(code)
.then(() => {
window.history.replaceState({}, "", "/");
onLogin();
})
.catch((err: unknown) => {
setError(err instanceof Error ? err.message : "Authentication failed");
setIsLoading(false);
});
return;
}
// Fetch the Discord OAuth URL
getAuthUrl()
.then((url) => {
setAuthUrl(url);
setIsLoading(false);
})
.catch(() => {
setError("Failed to load authentication URL");
setIsLoading(false);
});
}, [onLogin]);
if (isLoading) {
return (
<div className="login-page">
<div className="login-card">
<p>Loading...</p>
</div>
</div>
);
}
if (error) {
return (
<div className="login-page">
<div className="login-card">
<p className="error">{error}</p>
<button
type="button"
onClick={() => { window.location.reload(); }}
>
Try Again
</button>
</div>
</div>
);
}
return (
<div className="login-page">
<div className="login-card">
<h1> Elysium</h1>
<p>An idle fantasy RPG. Hire adventurers, defeat bosses, and ascend to glory.</p>
<a
className="discord-login-button"
href={authUrl ?? "#"}
>
Login with Discord
</a>
<p className="login-note">
Your progress is saved to your Discord account and shareable with others!
</p>
</div>
</div>
);
};
@@ -1,34 +0,0 @@
import { useGame } from "../../context/GameContext.js";
export const OfflineModal = (): React.JSX.Element | null => {
const { offlineGold, offlineEssence, dismissOfflineGold, formatNumber } = useGame();
if (offlineGold <= 0 && offlineEssence <= 0) return null;
return (
<div className="modal-overlay">
<div className="modal">
<h2>Welcome back!</h2>
<p>Your adventurers kept working whilst you were away and earned:</p>
{offlineGold > 0 && (
<p>
<strong>🪙 {formatNumber(offlineGold)} gold</strong>
</p>
)}
{offlineEssence > 0 && (
<p>
<strong> {formatNumber(offlineEssence)} essence</strong>
</p>
)}
<p className="modal-note">Offline progress is calculated up to 8 hours.</p>
<button
className="modal-close-button"
onClick={dismissOfflineGold}
type="button"
>
Collect!
</button>
</div>
</div>
);
};
@@ -1,253 +0,0 @@
import type { PrestigeUpgradeCategory } from "@elysium/types";
import { useState } from "react";
import { prestige } from "../../api/client.js";
import { useGame } from "../../context/GameContext.js";
import {
PRESTIGE_UPGRADES,
PRESTIGE_UPGRADE_CATEGORY_LABELS,
} from "../../data/prestigeUpgrades.js";
const BASE_THRESHOLD = 1_000_000;
const THRESHOLD_SCALE = 5;
const RUNESTONES_PER_LEVEL = 10;
const calculateThreshold = (prestigeCount: number): number =>
BASE_THRESHOLD * Math.pow(THRESHOLD_SCALE, prestigeCount);
const calculateProductionMultiplier = (prestigeCount: number): number =>
Math.pow(1.15, prestigeCount);
const calculateRunestonePreview = (
totalGoldEarned: number,
prestigeCount: number,
purchasedUpgradeIds: string[],
): number => {
const threshold = calculateThreshold(prestigeCount);
const base = Math.floor(Math.sqrt(totalGoldEarned / threshold)) * RUNESTONES_PER_LEVEL;
const runestoneMult = PRESTIGE_UPGRADES
.filter((u) => u.category === "runestones" && purchasedUpgradeIds.includes(u.id))
.reduce((mult, u) => mult * u.multiplier, 1);
return Math.floor(base * runestoneMult);
};
const CATEGORY_ORDER: PrestigeUpgradeCategory[] = [
"income",
"click",
"essence",
"crystals",
"runestones",
"utility",
];
export const PrestigePanel = (): React.JSX.Element => {
const { state, reload, formatNumber, buyPrestigeUpgrade, toggleAutoPrestige } = useGame();
const [characterName, setCharacterName] = useState("");
const [isPending, setIsPending] = useState(false);
const [result, setResult] = useState<{ runestones: number; count: number; milestoneRunestones: number } | null>(null);
const [prestigeError, setPrestigeError] = useState<string | null>(null);
const [buyingId, setBuyingId] = useState<string | null>(null);
const [activeTab, setActiveTab] = useState<"prestige" | "shop">("prestige");
if (!state) return <section className="panel"><p>Loading...</p></section>;
const { prestige: prestigeData, player } = state;
const threshold = calculateThreshold(prestigeData.count);
const isEligible = player.totalGoldEarned >= threshold;
const runestonePreview = calculateRunestonePreview(
player.totalGoldEarned,
prestigeData.count,
prestigeData.purchasedUpgradeIds,
);
const nextMultiplier = calculateProductionMultiplier(prestigeData.count + 1);
const handlePrestige = async (): Promise<void> => {
if (!characterName.trim()) return;
setIsPending(true);
setPrestigeError(null);
try {
const data = await prestige({ characterName: characterName.trim() });
setResult({ runestones: data.runestones, count: data.newPrestigeCount, milestoneRunestones: data.milestoneRunestones });
await reload();
} catch (err) {
setPrestigeError(err instanceof Error ? err.message : "Prestige failed");
} finally {
setIsPending(false);
}
};
const handleBuyUpgrade = async (upgradeId: string): Promise<void> => {
setBuyingId(upgradeId);
try {
await buyPrestigeUpgrade(upgradeId);
} finally {
setBuyingId(null);
}
};
const upgradesByCategory = CATEGORY_ORDER.map((category) => ({
category,
label: PRESTIGE_UPGRADE_CATEGORY_LABELS[category] ?? category,
upgrades: PRESTIGE_UPGRADES.filter((u) => u.category === category),
}));
return (
<section className="panel prestige-panel">
<h2> Prestige</h2>
<div className="prestige-tabs">
<button
className={`prestige-tab ${activeTab === "prestige" ? "active" : ""}`}
onClick={() => { setActiveTab("prestige"); }}
type="button"
>
Ascend
</button>
<button
className={`prestige-tab ${activeTab === "shop" ? "active" : ""}`}
onClick={() => { setActiveTab("shop"); }}
type="button"
>
🔮 Runestone Shop ({formatNumber(prestigeData.runestones)} stones)
</button>
</div>
{activeTab === "prestige" && (
<>
<p>
Prestige resets your progress but grants <strong>Runestones</strong> permanent
currency used for powerful upgrades. Each prestige multiplies your global production
by ×1.15 (compounding each run).
</p>
<div className="prestige-status">
<p>
Total gold this run:{" "}
<strong>{formatNumber(player.totalGoldEarned)}</strong>
</p>
<p>
Required to prestige: <strong>{formatNumber(threshold)}</strong>
</p>
<p>
Prestige count: <strong>{prestigeData.count}</strong>
</p>
<p>
Current production multiplier:{" "}
<strong>×{prestigeData.productionMultiplier.toFixed(2)}</strong>
</p>
<p>
After next prestige:{" "}
<strong>×{nextMultiplier.toFixed(2)}</strong>
</p>
<p>
Runestones: <strong>{formatNumber(prestigeData.runestones)}</strong>
</p>
{isEligible && (
<p className="runestone-preview">
Runestones on prestige: <strong>+{formatNumber(runestonePreview)}</strong>
</p>
)}
{!isEligible && (
<p className="prestige-progress">
Progress: {formatNumber(player.totalGoldEarned)} / {formatNumber(threshold)}{" "}
({((player.totalGoldEarned / threshold) * 100).toFixed(1)}%)
</p>
)}
</div>
{isEligible ? (
<div className="prestige-form">
<p>You are ready to prestige! Choose your new character name:</p>
<input
disabled={isPending}
maxLength={32}
onChange={(e) => { setCharacterName(e.target.value); }}
placeholder="Character name..."
type="text"
value={characterName}
/>
<button
className="prestige-button"
disabled={isPending || !characterName.trim()}
onClick={() => { void handlePrestige(); }}
type="button"
>
{isPending ? "Ascending..." : `✨ Ascend (+${formatNumber(runestonePreview)} Runestones)`}
</button>
{prestigeError && <p className="error">{prestigeError}</p>}
{result && (
<p className="success">
Ascended to Prestige {result.count}! Earned {formatNumber(result.runestones)} Runestones.
{result.milestoneRunestones > 0 && (
<> 🎉 Milestone bonus: +{formatNumber(result.milestoneRunestones)} Runestones!</>
)}
</p>
)}
</div>
) : (
<p className="prestige-locked">
Earn {formatNumber(threshold - player.totalGoldEarned)} more gold to unlock prestige.
</p>
)}
</>
)}
{activeTab === "shop" && (
<div className="runestone-shop">
<p className="shop-balance">
Balance: <strong>{formatNumber(prestigeData.runestones)} Runestones</strong>
</p>
{upgradesByCategory.map(({ category, label, upgrades }) => (
<div key={category} className="shop-category">
<h3>{label}</h3>
<div className="shop-upgrades">
{upgrades.map((upgrade) => {
const purchased = prestigeData.purchasedUpgradeIds.includes(upgrade.id);
const canAfford = prestigeData.runestones >= upgrade.runestonesCost;
const isLoading = buyingId === upgrade.id;
const isAutoPrestigeToggle = upgrade.id === "auto_prestige" && purchased;
const autoPrestigeEnabled = prestigeData.autoPrestigeEnabled ?? false;
return (
<div
key={upgrade.id}
className={`shop-upgrade-card ${purchased ? "purchased" : ""} ${!canAfford && !purchased ? "unaffordable" : ""}`}
>
<div className="shop-upgrade-info">
<h4>{upgrade.name}</h4>
<p>{upgrade.description}</p>
<p className="upgrade-cost">
{purchased ? "✅ Purchased" : `🔮 ${formatNumber(upgrade.runestonesCost)} Runestones`}
</p>
</div>
{isAutoPrestigeToggle && (
<button
className={`auto-prestige-toggle ${autoPrestigeEnabled ? "enabled" : "disabled"}`}
onClick={() => { toggleAutoPrestige(); }}
type="button"
>
{autoPrestigeEnabled ? "⚡ Auto ON" : "⏸ Auto OFF"}
</button>
)}
{!purchased && (
<button
className="buy-upgrade-button"
disabled={!canAfford || isLoading || buyingId !== null}
onClick={() => { void handleBuyUpgrade(upgrade.id); }}
type="button"
>
{isLoading ? "Buying..." : "Buy"}
</button>
)}
</div>
);
})}
</div>
</div>
))}
</div>
)}
</section>
);
};
@@ -1,163 +0,0 @@
import type { PublicProfileResponse } from "@elysium/types";
import { useEffect, useState } from "react";
import { useGame } from "../../context/GameContext.js";
interface ProfilePageProps {
discordId: string;
}
export const ProfilePage = ({ discordId }: ProfilePageProps): React.JSX.Element => {
const { formatNumber } = useGame();
const [profile, setProfile] = useState<PublicProfileResponse | null>(null);
const [error, setError] = useState<string | null>(null);
const [copied, setCopied] = useState(false);
useEffect(() => {
fetch(`/api/profile/${discordId}`)
.then(async (res) => {
if (!res.ok) throw new Error("Player not found");
return res.json() as Promise<PublicProfileResponse>;
})
.then(setProfile)
.catch((err: unknown) => {
setError(err instanceof Error ? err.message : "Failed to load profile");
});
}, [discordId]);
const handleCopy = (): void => {
void navigator.clipboard.writeText(window.location.href).then(() => {
setCopied(true);
setTimeout(() => { setCopied(false); }, 2000);
});
};
if (error) {
return (
<div className="profile-page">
<div className="profile-error">
<p> {error}</p>
<a className="profile-play-link" href="/"> Play Elysium</a>
</div>
</div>
);
}
if (!profile) {
return (
<div className="profile-page">
<div className="profile-loading">Loading profile</div>
</div>
);
}
const s = profile.profileSettings;
const avatarUrl = profile.avatar
? `https://cdn.discordapp.com/avatars/${discordId}/${profile.avatar}.png?size=128`
: `https://cdn.discordapp.com/embed/avatars/${parseInt(discordId, 10) % 5}.png`;
const memberSince = new Date(profile.createdAt).toLocaleDateString("en-GB", {
year: "numeric",
month: "long",
day: "numeric",
});
const visibleStats = [
s.showTotalGold && {
icon: "🪙",
value: formatNumber(profile.totalGoldEarned),
label: "Total Gold Earned",
date: false,
},
s.showTotalClicks && {
icon: "👆",
value: formatNumber(profile.totalClicks),
label: "Total Clicks",
date: false,
},
s.showBossesDefeated && {
icon: "💀",
value: String(profile.bossesDefeated),
label: "Bosses Defeated",
date: false,
},
s.showQuestsCompleted && {
icon: "📜",
value: String(profile.questsCompleted),
label: "Quests Completed",
date: false,
},
s.showAdventurersRecruited && {
icon: "⚔️",
value: formatNumber(profile.adventurersRecruited),
label: "Adventurers Recruited",
date: false,
},
s.showAchievementsUnlocked && {
icon: "🏆",
value: String(profile.achievementsUnlocked),
label: "Achievements Unlocked",
date: false,
},
s.showGuildFounded && {
icon: "📅",
value: memberSince,
label: "Guild Founded",
date: true,
},
].filter(Boolean) as Array<{ icon: string; value: string; label: string; date: boolean }>;
return (
<div className="profile-page">
<div className="profile-card">
<div className="profile-header">
<img
alt={`${profile.username}'s avatar`}
className="profile-avatar"
src={avatarUrl}
/>
<div className="profile-identity">
<h1 className="profile-character-name">{profile.characterName}</h1>
<p className="profile-username">@{profile.username}</p>
{s.showPrestige && profile.prestigeCount > 0 && (
<span className="profile-prestige-badge">
Prestige {profile.prestigeCount}
</span>
)}
</div>
</div>
{profile.bio && (
<p className="profile-bio">{profile.bio}</p>
)}
{visibleStats.length > 0 && (
<div className="profile-stats">
{visibleStats.map((stat) => (
<div key={stat.label} className="profile-stat">
<span className="profile-stat-icon">{stat.icon}</span>
<span className={`profile-stat-value ${stat.date ? "profile-stat-date" : ""}`}>
{stat.value}
</span>
<span className="profile-stat-label">{stat.label}</span>
</div>
))}
</div>
)}
<div className="profile-actions">
<button
className="profile-share-button"
onClick={handleCopy}
type="button"
>
{copied ? "✓ Copied!" : "🔗 Copy Profile Link"}
</button>
<a className="profile-play-link" href="/">
Play Elysium
</a>
</div>
</div>
</div>
);
};
-157
View File
@@ -1,157 +0,0 @@
import type { Quest } from "@elysium/types";
import { useState } from "react";
import { useGame } from "../../context/GameContext.js";
import { LockToggle } from "../ui/LockToggle.js";
import { ZoneSelector } from "./ZoneSelector.js";
const formatDuration = (seconds: number): string => {
if (seconds >= 3600) return `${Math.floor(seconds / 3600)}h ${Math.floor((seconds % 3600) / 60)}m`;
if (seconds >= 60) return `${Math.floor(seconds / 60)}m ${seconds % 60}s`;
return `${seconds}s`;
};
const questTimeRemaining = (quest: Quest): number => {
if (quest.status !== "active" || quest.startedAt == null) return 0;
const elapsed = (Date.now() - quest.startedAt) / 1000;
return Math.max(0, quest.durationSeconds - elapsed);
};
interface QuestCardProps {
quest: Quest;
partyCombatPower: number;
unlockHint?: string | undefined;
zoneHint?: string | undefined;
}
const QuestCard = ({ quest, partyCombatPower, unlockHint, zoneHint }: QuestCardProps): React.JSX.Element => {
const { startQuest, formatNumber } = useGame();
const cpRequired = quest.combatPowerRequired ?? 0;
const meetsCP = partyCombatPower >= cpRequired;
return (
<div className={`quest-card quest-${quest.status}`}>
<div className="quest-info">
<h3>{quest.name}</h3>
<p>{quest.description}</p>
{cpRequired > 0 && (
<p className={`quest-cp-requirement ${meetsCP ? "cp-met" : "cp-unmet"}`}>
Requires {formatNumber(cpRequired)} Combat Power
{quest.status === "available" && (meetsCP ? " ✓" : ` (you have ${formatNumber(partyCombatPower)})`)}
</p>
)}
<div className="quest-rewards">
{quest.rewards.map((reward, index) => (
// eslint-disable-next-line react/no-array-index-key -- rewards have no unique id
<span key={index} className="reward-tag">
{reward.type === "gold" && `🪙 ${formatNumber(reward.amount ?? 0)}`}
{reward.type === "essence" && `${formatNumber(reward.amount ?? 0)}`}
{reward.type === "crystals" && `💎 ${formatNumber(reward.amount ?? 0)}`}
{reward.type === "upgrade" && "🔓 Upgrade"}
{reward.type === "adventurer" && "👥 New Adventurer"}
</span>
))}
</div>
</div>
<div className="quest-action">
{quest.status === "locked" && (
<>
<span className="quest-badge locked">🔒 Locked</span>
{zoneHint && <p className="unlock-hint">🗺 Unlock zone: {zoneHint}</p>}
{!zoneHint && unlockHint && <p className="unlock-hint">📜 Complete: {unlockHint}</p>}
</>
)}
{quest.status === "available" && (
<button
className="start-quest-button"
disabled={!meetsCP}
onClick={() => { startQuest(quest.id); }}
title={meetsCP ? undefined : `Need ${formatNumber(cpRequired)} combat power`}
type="button"
>
Send Party ({formatDuration(quest.durationSeconds)})
</button>
)}
{quest.status === "active" && (
<span className="quest-badge active">
{formatDuration(Math.ceil(questTimeRemaining(quest)))} remaining
</span>
)}
{quest.status === "completed" && <span className="quest-badge completed"> Complete</span>}
</div>
</div>
);
};
export const QuestPanel = (): React.JSX.Element => {
const { state } = useGame();
const [activeZoneId, setActiveZoneId] = useState("verdant_vale");
const [showLocked, setShowLocked] = useState(true);
if (!state) return <section className="panel"><p>Loading...</p></section>;
const partyCombatPower = state.adventurers.reduce(
(total, a) => total + a.combatPower * a.count,
0,
);
const zones = state.zones ?? [];
const zoneQuests = state.quests.filter((q) => q.zoneId === activeZoneId);
const lockedCount = zoneQuests.filter((q) => q.status === "locked").length;
const visibleQuests = showLocked
? zoneQuests
: zoneQuests.filter((q) => q.status !== "locked");
const questNameById = new Map(state.quests.map((q) => [q.id, q.name]));
const zoneById = new Map(zones.map((z) => [z.id, z]));
const questUnlockHints = new Map<string, string>();
const questZoneHints = new Map<string, string>();
for (const quest of state.quests) {
if (quest.status !== "locked") continue;
const zone = zoneById.get(quest.zoneId);
if (zone?.status === "locked") {
questZoneHints.set(quest.id, zone.name);
} else if (quest.prerequisiteIds.length > 0) {
const prereqId = quest.prerequisiteIds[0];
if (prereqId) {
const prereqName = questNameById.get(prereqId);
if (prereqName) {
questUnlockHints.set(quest.id, prereqName);
}
}
}
}
return (
<section className="panel quest-panel">
<div className="panel-header">
<h2>Quests</h2>
<LockToggle
lockedCount={lockedCount}
showLocked={showLocked}
onToggle={() => { setShowLocked((v) => !v); }}
/>
</div>
<ZoneSelector
activeZoneId={activeZoneId}
zones={zones}
onSelectZone={setActiveZoneId}
/>
<div className="quest-list">
{visibleQuests.map((quest) => (
<QuestCard
key={quest.id}
partyCombatPower={partyCombatPower}
quest={quest}
unlockHint={questUnlockHints.get(quest.id)}
zoneHint={questZoneHints.get(quest.id)}
/>
))}
{visibleQuests.length === 0 && (
<p className="empty-zone">No quests to show in this zone.</p>
)}
</div>
</section>
);
};
@@ -1,153 +0,0 @@
import { useGame } from "../../context/GameContext.js";
import { PRESTIGE_UPGRADES } from "../../data/prestigeUpgrades.js";
const formatDate = (timestamp: number): string =>
new Date(timestamp).toLocaleDateString("en-GB", {
day: "numeric",
month: "short",
year: "numeric",
});
interface StatCardProps {
icon: string;
label: string;
value: string;
sub?: string;
}
const StatCard = ({ icon, label, value, sub }: StatCardProps): React.JSX.Element => (
<div className="profile-stat">
<span className="profile-stat-icon">{icon}</span>
<span className="profile-stat-value">{value}</span>
<span className="profile-stat-label">{label}</span>
{sub !== undefined && <span className="profile-stat-date">{sub}</span>}
</div>
);
export const StatisticsPanel = (): React.JSX.Element => {
const { state, formatNumber } = useGame();
if (!state) return <section className="panel"><p>Loading...</p></section>;
const { player, resources, prestige, bosses, quests, zones, adventurers, upgrades, equipment, achievements } = state;
const bossesDefeated = bosses.filter((b) => b.status === "defeated").length;
const questsCompleted = quests.filter((q) => q.status === "completed").length;
const zonesUnlocked = zones.filter((z) => z.status === "unlocked").length;
const adventurersRecruited = adventurers.reduce((sum, a) => sum + a.count, 0);
const equipmentOwned = (equipment ?? []).filter((e) => e.owned).length;
const upgradesPurchased = upgrades.filter((u) => u.purchased).length;
const achievementsUnlocked = (achievements ?? []).filter((a) => a.unlockedAt !== null).length;
const prestigeUpgradesPurchased = prestige.purchasedUpgradeIds.length;
return (
<section className="panel statistics-panel">
<h2>📊 Statistics</h2>
<h3 className="stats-section-header">All-Time</h3>
<div className="profile-stats">
<StatCard
icon="🪙"
label="Total Gold Earned"
value={formatNumber(player.totalGoldEarned)}
sub="across all runs"
/>
<StatCard
icon="👆"
label="Total Clicks"
value={formatNumber(player.totalClicks)}
/>
<StatCard
icon="⭐"
label="Prestiges"
value={String(prestige.count)}
/>
<StatCard
icon="📅"
label="Guild Founded"
value={formatDate(player.createdAt)}
/>
<StatCard
icon="☁️"
label="Last Cloud Save"
value={formatDate(player.lastSavedAt)}
/>
<StatCard
icon="✖️"
label="Production Multiplier"
value={`×${prestige.productionMultiplier.toFixed(2)}`}
sub="from prestige"
/>
</div>
<h3 className="stats-section-header">Current Run</h3>
<div className="profile-stats">
<StatCard
icon="🪙"
label="Gold"
value={formatNumber(resources.gold)}
/>
<StatCard
icon="✨"
label="Essence"
value={formatNumber(resources.essence)}
/>
<StatCard
icon="💎"
label="Crystals"
value={formatNumber(resources.crystals)}
/>
<StatCard
icon="🔮"
label="Runestones"
value={formatNumber(prestige.runestones)}
sub="permanent currency"
/>
</div>
<h3 className="stats-section-header">Progress</h3>
<div className="profile-stats">
<StatCard
icon="👹"
label="Bosses Defeated"
value={`${String(bossesDefeated)} / ${String(bosses.length)}`}
/>
<StatCard
icon="📜"
label="Quests Completed"
value={`${String(questsCompleted)} / ${String(quests.length)}`}
/>
<StatCard
icon="🗺️"
label="Zones Unlocked"
value={`${String(zonesUnlocked)} / ${String(zones.length)}`}
/>
<StatCard
icon="⚔️"
label="Adventurers Recruited"
value={formatNumber(adventurersRecruited)}
/>
<StatCard
icon="🗡️"
label="Equipment Owned"
value={`${String(equipmentOwned)} / ${String((equipment ?? []).length)}`}
/>
<StatCard
icon="🔧"
label="Upgrades Purchased"
value={`${String(upgradesPurchased)} / ${String(upgrades.length)}`}
/>
<StatCard
icon="🏆"
label="Achievements"
value={`${String(achievementsUnlocked)} / ${String((achievements ?? []).length)}`}
/>
<StatCard
icon="🔮"
label="Prestige Upgrades"
value={`${String(prestigeUpgradesPurchased)} / ${String(PRESTIGE_UPGRADES.length)}`}
/>
</div>
</section>
);
};
@@ -1,148 +0,0 @@
import type { Upgrade } from "@elysium/types";
import { useState } from "react";
import { useGame } from "../../context/GameContext.js";
import { LockToggle } from "../ui/LockToggle.js";
interface UpgradeCardProps {
upgrade: Upgrade;
currentGold: number;
currentEssence: number;
currentCrystals: number;
unlockHint?: string | undefined;
formatNumber: (n: number) => string;
}
const UpgradeCard = ({ upgrade, currentGold, currentEssence, currentCrystals, unlockHint, formatNumber }: UpgradeCardProps): React.JSX.Element => {
const { buyUpgrade } = useGame();
const canAfford =
currentGold >= upgrade.costGold &&
currentEssence >= upgrade.costEssence &&
currentCrystals >= (upgrade.costCrystals ?? 0);
if (!upgrade.unlocked) {
return (
<div className="upgrade-card locked">
<div className="upgrade-info">
<h3>🔒 {upgrade.name}</h3>
<p>{upgrade.description}</p>
<p className="upgrade-multiplier">×{upgrade.multiplier} multiplier</p>
</div>
<div className="upgrade-cost">
{upgrade.costGold > 0 && <span>🪙 {formatNumber(upgrade.costGold)}</span>}
{upgrade.costEssence > 0 && <span> {formatNumber(upgrade.costEssence)}</span>}
{(upgrade.costCrystals ?? 0) > 0 && <span>💎 {formatNumber(upgrade.costCrystals ?? 0)}</span>}
</div>
<span className="upgrade-locked-label">Locked</span>
{unlockHint && <p className="unlock-hint">{unlockHint}</p>}
</div>
);
}
if (upgrade.purchased) {
return (
<div className="upgrade-card purchased">
<span className="upgrade-name"> {upgrade.name}</span>
<span className="upgrade-desc">{upgrade.description}</span>
</div>
);
}
return (
<div className="upgrade-card">
<div className="upgrade-info">
<h3>{upgrade.name}</h3>
<p>{upgrade.description}</p>
<p className="upgrade-multiplier">×{upgrade.multiplier} multiplier</p>
</div>
<div className="upgrade-cost">
{upgrade.costGold > 0 && <span>🪙 {formatNumber(upgrade.costGold)}</span>}
{upgrade.costEssence > 0 && <span> {formatNumber(upgrade.costEssence)}</span>}
{(upgrade.costCrystals ?? 0) > 0 && <span>💎 {formatNumber(upgrade.costCrystals ?? 0)}</span>}
</div>
<button
className="buy-button"
disabled={!canAfford}
onClick={() => { buyUpgrade(upgrade.id); }}
type="button"
>
Buy
</button>
</div>
);
};
export const UpgradePanel = (): React.JSX.Element => {
const { state, formatNumber } = useGame();
const [showLocked, setShowLocked] = useState(true);
if (!state) return <section className="panel"><p>Loading...</p></section>;
const purchased = state.upgrades.filter((u) => u.purchased);
const available = state.upgrades.filter((u) => u.unlocked && !u.purchased);
const locked = state.upgrades.filter((u) => !u.unlocked);
const upgradeUnlockHints = new Map<string, string>();
for (const boss of state.bosses) {
for (const upgradeId of (boss.upgradeRewards ?? [])) {
upgradeUnlockHints.set(upgradeId, `⚔️ Defeat: ${boss.name}`);
}
}
for (const quest of state.quests) {
for (const reward of quest.rewards) {
if (reward.type === "upgrade" && reward.targetId && !upgradeUnlockHints.has(reward.targetId)) {
upgradeUnlockHints.set(reward.targetId, `📜 Complete: ${quest.name}`);
}
}
}
return (
<section className="panel upgrade-panel">
<div className="panel-header">
<h2>Upgrades</h2>
<LockToggle
lockedCount={locked.length}
showLocked={showLocked}
onToggle={() => { setShowLocked((v) => !v); }}
/>
</div>
<p className="upgrade-progress">{purchased.length} / {state.upgrades.length} purchased</p>
{state.upgrades.length === 0 ? (
<p className="empty-state">No upgrades available yet keep adventuring!</p>
) : (
<div className="upgrade-list">
{available.map((upgrade) => (
<UpgradeCard
key={upgrade.id}
upgrade={upgrade}
currentGold={state.resources.gold}
currentEssence={state.resources.essence}
currentCrystals={state.resources.crystals}
formatNumber={formatNumber}
/>
))}
{purchased.map((upgrade) => (
<UpgradeCard
key={upgrade.id}
upgrade={upgrade}
currentGold={state.resources.gold}
currentEssence={state.resources.essence}
currentCrystals={state.resources.crystals}
formatNumber={formatNumber}
/>
))}
{showLocked && locked.map((upgrade) => (
<UpgradeCard
key={upgrade.id}
upgrade={upgrade}
currentGold={state.resources.gold}
currentEssence={state.resources.essence}
currentCrystals={state.resources.crystals}
formatNumber={formatNumber}
unlockHint={upgradeUnlockHints.get(upgrade.id)}
/>
))}
</div>
)}
</section>
);
};
@@ -1,30 +0,0 @@
import type { Zone } from "@elysium/types";
interface ZoneSelectorProps {
zones: Zone[];
activeZoneId: string;
onSelectZone: (zoneId: string) => void;
}
export const ZoneSelector = ({
zones,
activeZoneId,
onSelectZone,
}: ZoneSelectorProps): React.JSX.Element => (
<div className="zone-selector">
{zones.map((zone) => (
<button
key={zone.id}
className={`zone-tab ${zone.id === activeZoneId ? "zone-tab-active" : ""}`}
onClick={() => {
onSelectZone(zone.id);
}}
title={zone.description}
type="button"
>
<span className="zone-emoji">{zone.emoji}</span>
<span className="zone-name">{zone.name}</span>
</button>
))}
</div>
);
+357
View File
@@ -0,0 +1,357 @@
/**
* @file About panel component displaying changelog and how-to-play guide.
* @copyright nhcarrigan
* @license Naomi's Public License
* @author Naomi Carrigan
*/
/* eslint-disable max-lines-per-function -- HOW_TO_PLAY data and render logic */
/* eslint-disable max-lines -- HOW_TO_PLAY data makes this file long */
import { type JSX, useEffect, useState } from "react";
import { getAbout } from "../../api/client.js";
import type { AboutResponse } from "@elysium/types";
const howToPlay = [
{
body:
"Hire adventurers to earn gold and essence automatically. Each tier is"
+ " more powerful than the last. Adventurers also contribute combat"
+ " power for boss fights — the more you recruit, the stronger your"
+ " party becomes.",
title: "⚔️ Adventurers",
},
{
body:
"Click the guild hall to earn gold manually. Upgrades and equipment can"
+ " dramatically increase your gold per click. Clicking is especially"
+ " powerful in the early game and when saving up for big purchases.",
title: "👆 Clicking",
},
{
body:
"Purchase upgrades to multiply the gold and essence output of specific"
+ " adventurer tiers, or boost your whole guild. Upgrades are permanent"
+ " for the current run and compound with each other.",
title: "🔧 Upgrades",
},
{
body:
"Send your guild on quests that complete over time and reward gold,"
+ " essence, crystals, equipment, and upgrades. Multiple quests can run"
+ " simultaneously. Completing quests also unlocks new zones.",
title: "📜 Quests",
},
{
body:
"Challenge zone bosses to earn large one-time rewards and unlock new"
+ " zones. Your party's combat power is based on the number and tier of"
+ " adventurers you've recruited. Defeated bosses cannot be re-fought,"
+ " but undefeated bosses regenerate HP over time.",
title: "👹 Boss Fights",
},
{
body:
"New zones unlock when you defeat the final boss AND complete the final"
+ " quest of the previous zone. Each zone contains new bosses and"
+ " quests with progressively greater rewards.",
title: "🗺️ Zones",
},
{
body:
"Earn equipment from boss drops and quest rewards. Each piece provides"
+ " bonuses to gold income, click power, or combat. Rarer equipment"
+ " provides stronger bonuses. Equip matching set pieces (2 or 3 of a"
+ " named set) to unlock escalating set bonuses shown at the top of the"
+ " Equipment panel.",
title: "🗡️ Equipment & Sets",
},
{
body:
"When you've progressed far enough, you can prestige to earn runestones"
+ " — a permanent currency that persists across all runs. Prestige"
+ " resets your current run but grants a production multiplier that"
+ " stacks with every prestige.",
title: "⭐ Prestige",
},
{
body:
"Spend runestones in the Prestige Shop on permanent upgrades that carry"
+ " over across all future runs. These upgrades multiply income, click"
+ " power, essence, and crystal gain — making each new run more powerful"
+ " than the last.",
title: "🔮 Runestones & Prestige Upgrades",
},
{
body:
"Purchase the Autonomous Ascension upgrade in the Prestige Shop"
+ " (100 runestones) to unlock the Auto-Prestige toggle. When enabled,"
+ " you will automatically ascend the moment you reach the prestige"
+ " threshold, using your current character name. Toggle it on and off"
+ " freely from the Prestige Shop.",
title: "⚙️ Auto-Prestige",
},
{
body:
"Earn achievements by hitting milestones — total gold earned, bosses"
+ " defeated, quests completed, and more. Achievements are purely"
+ " cosmetic and track your long-term progress across all prestige runs.",
title: "🏆 Achievements",
},
{
body:
"Complete daily challenges for bonus rewards including gold, essence,"
+ " crystals, and runestones. Challenges reset each day and vary in"
+ " difficulty. Completing all daily challenges gives an extra bonus"
+ " reward.",
title: "📅 Daily Challenges",
},
{
body:
"Send scouts to explore areas within each zone. Explorations run in"
+ " real-time and reward gold, essence, and crafting materials when"
+ " collected. Each area has a set duration — short explorations are"
+ " faster but longer ones offer rarer finds. A 📖 icon marks areas"
+ " you've collected from at least once, unlocking a Codex entry.",
title: "🗺️ Exploration",
},
{
body:
"Use materials gathered from exploration to craft permanent bonuses."
+ " Each recipe provides a multiplier to gold income, essence income,"
+ " click power, or combat power — all of which stack and persist across"
+ " prestige runs. Check the Crafting tab to see your material inventory"
+ " and available recipes per zone.",
title: "⚗️ Crafting",
},
{
body:
"Defeating bosses, completing quests, acquiring equipment, hiring"
+ " adventurers, purchasing upgrades, unlocking prestige upgrades,"
+ " discovering new zones, collecting from exploration areas, and"
+ " crafting recipes all permanently unlock lore entries in the Codex."
+ " A badge appears on the Codex tab and a toast notification pops up"
+ " each time new lore is discovered. Collect all 472 entries to build"
+ " a complete picture of the world of Elysium.",
title: "📖 Codex",
},
{
body:
"Visit the Character tab to write about your character and guild. Fill"
+ " in your character's name, pronouns, race, class, and backstory,"
+ " then create a guild with its own name and lore. Your character sheet"
+ " is visible on your public profile page.",
title: "📋 Character Sheet",
},
{
body:
"Earn Titles by reaching milestones — defeating bosses, completing"
+ " quests, prestiging, and more. Once unlocked, titles are yours"
+ " forever and are never lost on prestige or transcendence resets. Set"
+ " your active title from the Character tab to display it on your"
+ " character sheet and public profile.",
title: "🏅 Titles",
},
{
body:
"Defeat bosses to earn equipment drops: weapons, armour, and trinkets."
+ " Each item provides bonuses to gold income, combat power, or click"
+ " power. Only one item per slot can be equipped at a time — visit the"
+ " Equipment panel to manage your loadout. Your currently equipped"
+ " items are displayed on your character sheet and public profile.",
title: "🗡️ Equipment",
},
{
body:
"Compete with other adventurers on the public Leaderboards page!"
+ " Categories include Lifetime Gold, Bosses Defeated, Quests"
+ " Completed, Achievements, Prestige Count, Transcendence Count, and"
+ " Apotheosis Count. Click any player's row to view their character"
+ " sheet. You can opt out of appearing on leaderboards via the Privacy"
+ " section in your profile settings.",
title: "🏆 Leaderboards",
},
{
body:
"Log in every day to earn escalating rewards! Each consecutive day"
+ " awards more gold, and the 7th day of your streak grants bonus"
+ " crystals. Your streak resets if you miss a day. A week multiplier"
+ " increases all rewards the longer your overall streak runs. Your"
+ " current streak is displayed on your character sheet.",
title: "🔥 Daily Login Bonus",
},
{
body:
"Toggle automation in the Quests and Boss Encounters panels! Auto-Quest"
+ " automatically sends your party on the highest-zone available quest"
+ " as soon as one completes, skipping quests whose combat power"
+ " requirement isn't met. Auto-Boss automatically challenges the"
+ " highest available boss as soon as one is ready. Both can be toggled"
+ " on or off at any time using the 🤖 Auto button in each panel"
+ " header.",
title: "🤖 Auto-Quest & Auto-Boss",
},
{
body:
"Unlock companions by reaching certain milestones across all your runs."
+ " Each companion provides a powerful permanent bonus: increased"
+ " passive gold, click gold, boss damage, essence income, or reduced"
+ " quest time. You can only have one companion active at a time —"
+ " choose wisely based on your current strategy! Companions are"
+ " unlocked permanently once their condition is met and will never be"
+ " lost.",
title: "👥 Companions",
},
{
body:
"Your progress is automatically saved to the cloud every 30 seconds"
+ " whilst you play. You can also force a manual save at any time using"
+ " the sync button in the resource bar. Your save is protected by HMAC"
+ " validation to ensure data integrity.",
title: "☁️ Cloud Saves",
},
{
body:
"Transcendence is the ultimate prestige layer, unlocked by defeating"
+ " The Absolute One (requires Prestige 90). Transcending performs a"
+ " nuclear reset — wiping resources, prestige, runestones, upgrades,"
+ " and equipment — but grants Echoes based on your prestige count"
+ " (fewer prestiges = more Echoes). Echoes are permanent and survive"
+ " all future resets. Spend them in the Echo Shop on lasting"
+ " multipliers: passive income, combat power, prestige"
+ " quality-of-life, and Echo meta upgrades that amplify future Echo"
+ " yields.",
title: "🌌 Transcendence",
},
{
body:
"Apotheosis is the final act — a complete dissolution of everything you"
+ " have built, including your prestige and transcendence progress. It"
+ " is unlocked once you have purchased every Transcendence upgrade. In"
+ " exchange for this total reset, you receive the Apotheosis badge:"
+ " pure bragging rights, a mark of reaching the absolute pinnacle of"
+ " the game. Apotheosis can be achieved multiple times; each cycle"
+ " requires purchasing all Transcendence upgrades again. Your Codex"
+ " entries and lifetime profile statistics are always preserved.",
title: "✨ Apotheosis",
},
{
body:
"The Story tab contains 22 chapters that unlock as you progress. The"
+ " first 18 unlock when you defeat the final boss of each zone."
+ " Chapters 19 and 20 unlock after your first and fifth prestige"
+ " respectively. Chapter 21 unlocks on your first transcendence, and"
+ " Chapter 22 on your first apotheosis. Each chapter presents a"
+ " narrative moment and three choices — the choice you make is recorded"
+ " on your Character Sheet and shapes your guild's story. Story"
+ " progress is permanent and survives all resets.",
title: "📖 Story",
},
{
body:
"Enable sound effects and browser notifications in your profile settings"
+ " (click your character name in the top bar). Sound effects play when"
+ " you defeat a boss, complete or fail a quest, unlock an achievement,"
+ " prestige, transcend, or achieve apotheosis. Browser notifications"
+ " alert you to the same events even when the game tab is in the"
+ " background. You will be prompted to grant notification permission"
+ " when you first enable them.",
title: "🔔 Sounds & Notifications",
},
];
const formatDate = (dateString: string): string => {
return new Date(dateString).toLocaleDateString("en-GB", {
day: "numeric",
month: "short",
year: "numeric",
});
};
/**
* Renders the about panel with changelog and how-to-play sections.
* @returns The JSX element.
*/
const aboutPanel = (): JSX.Element => {
const [ about, setAbout ] = useState<AboutResponse | null>(null);
const [ error, setError ] = useState<string | null>(null);
const [ expandedRelease, setExpandedRelease ] = useState<string | null>(null);
useEffect(() => {
getAbout().
then(setAbout).
catch((caughtError: unknown) => {
setError(
caughtError instanceof Error
? caughtError.message
: "Failed to load about data.",
);
});
}, []);
return (
<section className="panel about-panel">
<h2>{"️ About"}</h2>
<h3 className="stats-section-header">{"📋 Changelog"}</h3>
{error !== null && <p className="about-error">{error}</p>}
{about === null && error === null
&& <p className="about-loading">{"Loading changelog..."}</p>
}
{about !== null && about.releases.length === 0
&& <p className="about-empty">{"No releases yet."}</p>
}
{about !== null && about.releases.length > 0
&& <ul className="about-releases">
{about.releases.map((release) => {
function handleToggle(): void {
setExpandedRelease(
expandedRelease === release.tag_name
? null
: release.tag_name,
);
}
return (
<li className="about-release" key={release.tag_name}>
<button
className="about-release-header"
onClick={handleToggle}
type="button"
>
<span className="about-release-tag">
{release.name.length > 0
? release.name
: release.tag_name}
</span>
<span className="about-release-date">
{formatDate(release.published_at)}
</span>
<span className="about-release-chevron">
{expandedRelease === release.tag_name
? "▲"
: "▼"}
</span>
</button>
{expandedRelease === release.tag_name
&& <pre className="about-release-body">{release.body}</pre>
}
</li>
);
})}
</ul>
}
<h3 className="stats-section-header">{"📖 How to Play"}</h3>
<ul className="about-how-to-play">
{howToPlay.map((section) => {
return (
<li className="about-htp-section" key={section.title}>
<h4 className="about-htp-title">{section.title}</h4>
<p className="about-htp-body">{section.body}</p>
</li>
);
})}
</ul>
</section>
);
};
export { aboutPanel as AboutPanel };
@@ -0,0 +1,169 @@
/**
* @file Achievement panel component displaying all game achievements.
* @copyright nhcarrigan
* @license Naomi's Public License
* @author Naomi Carrigan
*/
/* eslint-disable react/no-multi-comp -- Sub-component is tightly coupled to this panel */
import { type JSX, useState } from "react";
import { useGame } from "../../context/gameContext.js";
import { LockToggle } from "../ui/lockToggle.js";
import type { Achievement } from "@elysium/types";
/**
* Returns the plural form of a word based on a count.
* @param count - The count to check.
* @param word - The base word to pluralise.
* @returns The pluralised word string.
*/
const pluralise = (count: number, word: string): string => {
return count > 1
? `${word}s`
: word;
};
/**
* Generates a human-readable condition description for an achievement.
* @param achievement - The achievement to describe.
* @param formatNumber - The number formatting utility function.
* @returns A string describing the achievement condition.
*/
const conditionDescription = (
achievement: Achievement,
formatNumber: (n: number)=> string,
): string => {
const { condition } = achievement;
switch (condition.type) {
case "totalGoldEarned":
return `Earn ${formatNumber(condition.amount)} total gold`;
case "totalClicks":
return `Click ${formatNumber(condition.amount)} times`;
case "bossesDefeated":
return `Defeat ${String(condition.amount)} ${pluralise(condition.amount, "boss")}`;
case "questsCompleted":
return `Complete ${String(condition.amount)} ${pluralise(condition.amount, "quest")}`;
case "adventurerTotal":
return `Recruit ${formatNumber(condition.amount)} total adventurers`;
case "prestigeCount":
return `Prestige ${String(condition.amount)} ${pluralise(condition.amount, "time")}`;
case "equipmentOwned":
return `Own ${String(condition.amount)} equipment ${pluralise(condition.amount, "item")}`;
default:
return "Unknown condition";
}
};
interface AchievementCardProperties {
readonly achievement: Achievement;
readonly formatNumber: (n: number)=> string;
}
/**
* Renders a single achievement card.
* @param props - The achievement card properties.
* @param props.achievement - The achievement to display.
* @param props.formatNumber - The number formatting utility function.
* @returns The JSX element.
*/
const AchievementCard = ({
achievement,
formatNumber,
}: AchievementCardProperties): JSX.Element => {
const isUnlocked = achievement.unlockedAt !== null;
const crystals = achievement.reward?.crystals;
return (
<div className={`achievement-card ${isUnlocked
? "unlocked"
: "locked"}`}>
<div className="achievement-icon">{achievement.icon}</div>
<div className="achievement-info">
<h3>{achievement.name}</h3>
<p>{achievement.description}</p>
<p className="achievement-condition">
{conditionDescription(achievement, formatNumber)}
</p>
{crystals !== undefined
&& <p className="achievement-reward">
{"💎 +"}
{crystals}
{" Crystals"}
</p>
}
</div>
<div className="achievement-status">
{isUnlocked
? <span className="achievement-unlocked-badge">{"✓ Unlocked"}</span>
: <span className="achievement-locked-badge">{"🔒"}</span>
}
</div>
</div>
);
};
/**
* Renders the achievement panel with all achievements.
* @returns The JSX element.
*/
// eslint-disable-next-line max-lines-per-function -- Achievement panel renders many achievement states
const AchievementPanel = (): JSX.Element => {
const { state, formatNumber } = useGame();
const [ showLocked, setShowLocked ] = useState(true);
if (state === null) {
return (
<section className="panel">
<p>{"Loading..."}</p>
</section>
);
}
const achievementList = state.achievements;
const unlocked = achievementList.filter((a) => {
return a.unlockedAt !== null;
});
const locked = achievementList.filter((a) => {
return a.unlockedAt === null;
});
const visible = showLocked
? achievementList
: unlocked;
function handleToggle(): void {
setShowLocked((current) => {
return !current;
});
}
return (
<section className="panel achievement-panel">
<div className="panel-header">
<h2>{"Achievements"}</h2>
<LockToggle
lockedCount={locked.length}
onToggle={handleToggle}
showLocked={showLocked}
/>
</div>
<p className="achievement-progress">
{unlocked.length}
{" / "}
{achievementList.length}
{" unlocked"}
</p>
<div className="achievement-list">
{visible.map((achievement) => {
return (
<AchievementCard
achievement={achievement}
formatNumber={formatNumber}
key={achievement.id}
/>
);
})}
</div>
</section>
);
};
export { AchievementPanel };
@@ -0,0 +1,87 @@
/**
* @file Achievement toast notification component.
* @copyright nhcarrigan
* @license Naomi's Public License
* @author Naomi Carrigan
*/
/* eslint-disable react/no-multi-comp -- Sub-component is tightly coupled to the toast container */
import { type JSX, useEffect } from "react";
import { useGame } from "../../context/gameContext.js";
import type { Achievement } from "@elysium/types";
interface ToastItemProperties {
readonly achievement: Achievement;
readonly onDismiss: (id: string)=> void;
}
/**
* Renders a single achievement toast item.
* @param props - The toast item properties.
* @param props.achievement - The achievement to display.
* @param props.onDismiss - Callback to dismiss the toast.
* @returns The JSX element.
*/
const ToastItem = ({
achievement,
onDismiss,
}: ToastItemProperties): JSX.Element => {
useEffect(() => {
const timer = setTimeout(() => {
onDismiss(achievement.id);
}, 4000);
return (): void => {
clearTimeout(timer);
};
}, [ achievement.id, onDismiss ]);
function handleClick(): void {
onDismiss(achievement.id);
}
const crystals = achievement.reward?.crystals;
return (
<div className="game-toast" onClick={handleClick}>
<span className="toast-icon">{achievement.icon}</span>
<div className="toast-content">
<span className="toast-label">{"Achievement Unlocked!"}</span>
<span className="toast-name">{achievement.name}</span>
{crystals !== undefined
&& <span className="toast-reward">
{"💎 +"}
{crystals}
</span>
}
</div>
</div>
);
};
/**
* Renders the achievement toast container with pending achievement notifications.
* @returns The JSX element or null if there are no pending achievements.
*/
const AchievementToast = (): JSX.Element | null => {
const { unlockedAchievements: pendingAchievements, dismissAchievement }
= useGame();
if (pendingAchievements.length === 0) {
return null;
}
return (
<>
{pendingAchievements.map((achievement) => {
return (
<ToastItem
achievement={achievement}
key={achievement.id}
onDismiss={dismissAchievement}
/>
);
})}
</>
);
};
export { AchievementToast };
@@ -0,0 +1,241 @@
/**
* @file Adventurer panel component for hiring and managing adventurers.
* @copyright nhcarrigan
* @license Naomi's Public License
* @author Naomi Carrigan
*/
/* eslint-disable react/no-multi-comp -- Sub-component is tightly coupled to the panel */
/* eslint-disable max-lines-per-function -- Complex component with many render paths */
/* eslint-disable complexity -- Complex component with many render paths */
import { type JSX, useState } from "react";
import { useGame } from "../../context/gameContext.js";
import { LockToggle } from "../ui/lockToggle.js";
import type { Adventurer } from "@elysium/types";
const iconByClass: Record<string, string> = {
cleric: "✝️",
mage: "🔮",
paladin: "🛡️",
ranger: "🏹",
rogue: "🗝️",
warrior: "🗡️",
};
type BatchSize = 1 | 5 | 10 | 25 | 100 | "max";
const batchOptions: Array<BatchSize> = [ 1, 5, 10, 25, 100, "max" ];
/**
* Computes the total cost to buy a batch of adventurers.
* @param adventurer - The adventurer to buy.
* @param quantity - The number to buy.
* @returns The total gold cost.
*/
const computeBatchCost = (adventurer: Adventurer, quantity: number): number => {
let total = 0;
for (let index = 0; index < quantity; index = index + 1) {
const cost = adventurer.baseCost * Math.pow(1.15, adventurer.count + index);
total = total + cost;
}
return total;
};
/**
* Computes the maximum number of adventurers affordable with given gold.
* @param adventurer - The adventurer type.
* @param gold - The available gold.
* @returns The maximum affordable quantity.
*/
const computeMaxAffordable = (adventurer: Adventurer, gold: number): number => {
let total = 0;
let quantity = 0;
for (let index = 0; index < 100_000; index = index + 1) {
const cost = adventurer.baseCost * Math.pow(1.15, adventurer.count + index);
if (total + cost > gold) {
break;
}
total = total + cost;
quantity = quantity + 1;
}
return quantity;
};
interface AdventurerCardProperties {
readonly adventurer: Adventurer;
readonly currentGold: number;
readonly batchSize: BatchSize;
readonly unlockHint: string | undefined;
readonly formatNumber: (n: number)=> string;
}
/**
* Renders a single adventurer card with buy controls.
* @param props - The adventurer card properties.
* @param props.adventurer - The adventurer data.
* @param props.currentGold - The current gold available.
* @param props.batchSize - The selected batch size.
* @param props.unlockHint - Optional quest name that unlocks this adventurer.
* @param props.formatNumber - The number formatting utility function.
* @returns The JSX element.
*/
const AdventurerCard = ({
adventurer,
currentGold,
batchSize,
unlockHint,
formatNumber,
}: AdventurerCardProperties): JSX.Element => {
const { buyAdventurer } = useGame();
const resolvedQuantity
= batchSize === "max"
? computeMaxAffordable(adventurer, currentGold)
: batchSize;
const cost = computeBatchCost(adventurer, resolvedQuantity);
const canAfford = resolvedQuantity > 0 && currentGold >= cost;
function handleBuy(): void {
buyAdventurer(adventurer.id, resolvedQuantity);
}
const maxSuffix
= batchSize === "max" && resolvedQuantity > 0
? ` (×${String(resolvedQuantity)})`
: "";
const buttonLabel = adventurer.unlocked
? `🪙 ${formatNumber(Math.ceil(cost))}${maxSuffix}`
: "🔒 Locked";
// eslint-disable-next-line @typescript-eslint/dot-notation -- "class" is a reserved word
const adventurerIcon = iconByClass[adventurer["class"]] ?? "⚔️";
return (
<div className={`adventurer-card ${adventurer.unlocked
? ""
: "locked"}`}>
<div className="adventurer-icon">{adventurerIcon}</div>
<div className="adventurer-info">
<h3>{adventurer.name}</h3>
<p>
{formatNumber(adventurer.goldPerSecond)}
{" gold/s each"}
</p>
{adventurer.essencePerSecond > 0
&& <p>
{formatNumber(adventurer.essencePerSecond)}
{" essence/s each"}
</p>
}
</div>
<div className="adventurer-count">
{"×"}
{adventurer.count}
</div>
<button
className="buy-button"
disabled={!canAfford || !adventurer.unlocked}
onClick={handleBuy}
type="button"
>
{buttonLabel}
</button>
{!adventurer.unlocked && unlockHint !== undefined
? <p className="unlock-hint">
{"📜 Complete: "}
{unlockHint}
</p>
: null}
</div>
);
};
/**
* Renders the adventurer panel with all available adventurers.
* @returns The JSX element.
*/
const AdventurerPanel = (): JSX.Element => {
const { state, formatNumber } = useGame();
const [ showLocked, setShowLocked ] = useState(true);
const [ batchSize, setBatchSize ] = useState<BatchSize>(1);
if (state === null) {
return (
<section className="panel">
<p>{"Loading..."}</p>
</section>
);
}
const locked = state.adventurers.filter((adventurer) => {
return !adventurer.unlocked;
});
const visible = showLocked
? state.adventurers
: state.adventurers.filter((adventurer) => {
return adventurer.unlocked;
});
const adventurerUnlockHints = new Map<string, string>();
for (const quest of state.quests) {
for (const reward of quest.rewards) {
if (reward.type === "adventurer" && reward.targetId !== undefined) {
adventurerUnlockHints.set(reward.targetId, quest.name);
}
}
}
function handleToggle(): void {
setShowLocked((current) => {
return !current;
});
}
return (
<section className="panel adventurer-panel">
<div className="panel-header">
<h2>{"Adventurers"}</h2>
<LockToggle
lockedCount={locked.length}
onToggle={handleToggle}
showLocked={showLocked}
/>
</div>
<div className="batch-selector">
{batchOptions.map((option) => {
function handleBatchSelect(): void {
setBatchSize(option);
}
return (
<button
className={`batch-button ${batchSize === option
? "active"
: ""}`}
key={option}
onClick={handleBatchSelect}
type="button"
>
{option === "max"
? "xMax"
: `x${String(option)}`}
</button>
);
})}
</div>
<div className="adventurer-list">
{visible.map((adventurer) => {
return (
<AdventurerCard
adventurer={adventurer}
batchSize={batchSize}
currentGold={state.resources.gold}
formatNumber={formatNumber}
key={adventurer.id}
unlockHint={adventurerUnlockHints.get(adventurer.id)}
/>
);
})}
</div>
</section>
);
};
export { AdventurerPanel };
@@ -0,0 +1,159 @@
/**
* @file Apotheosis panel component for the final 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 -- Complex component with many conditional render paths */
import { type JSX, useState } from "react";
import { useGame } from "../../context/gameContext.js";
import { TRANSCENDENCE_UPGRADES } from "../../data/transcendenceUpgrades.js";
const totalEchoUpgrades = TRANSCENDENCE_UPGRADES.length;
/**
* Renders the apotheosis panel for achieving the final game milestone.
* @returns The JSX element.
*/
const ApotheosisPanel = (): JSX.Element => {
const { state, apotheosis } = useGame();
const [ isPending, setIsPending ] = useState(false);
const [ result, setResult ] = useState<number | null>(null);
const [ error, setError ] = useState<string | null>(null);
if (state === null) {
return (
<section className="panel">
<p>{"Loading..."}</p>
</section>
);
}
const purchasedIds = state.transcendence?.purchasedUpgradeIds ?? [];
const purchasedCount = TRANSCENDENCE_UPGRADES.filter((upgrade) => {
return purchasedIds.includes(upgrade.id);
}).length;
const isEligible = purchasedCount >= totalEchoUpgrades;
const apotheosisCount = state.apotheosis?.count ?? 0;
async function handleApotheosis(): Promise<void> {
setIsPending(true);
setError(null);
try {
const data = await apotheosis();
setResult(data.newApotheosisCount);
} catch (caughtError) {
setError(
caughtError instanceof Error
? caughtError.message
: "Apotheosis failed",
);
} finally {
setIsPending(false);
}
}
function handleApotheosisClick(): void {
void handleApotheosis();
}
const plural = apotheosisCount === 1
? ""
: "s";
return (
<section className="panel apotheosis-panel">
<h2>{"✨ Apotheosis"}</h2>
<p className="apotheosis-intro">
{"Apotheosis is the final act — a complete dissolution of everything"
+ " you have built. Prestige, Transcendence, Echoes, upgrades,"
+ " equipment, resources: all of it returns to nothing."
+ " In exchange, you receive only one thing:"}
</p>
<p className="apotheosis-reward">
{"The "}
<strong>{"✨ Apotheosis"}</strong>
{" badge. Proof that you have done it all."}
</p>
<p className="apotheosis-intro">
{"Apotheosis can be achieved multiple times. Each cycle requires"
+ " you to purchase every Transcendence upgrade again before the"
+ " next Apotheosis becomes available. There is no mechanical"
+ " benefit — only the knowledge that you have reached the"
+ " pinnacle, dissolved it, and climbed back up."}
</p>
{apotheosisCount > 0
&& <div className="apotheosis-count">
<span>
{"You have achieved Apotheosis "}
<strong>{apotheosisCount}</strong>
{" time"}
{plural}
{"."}
</span>
</div>
}
<div className="apotheosis-status">
<p>
{"Transcendence upgrades purchased: "}
<strong>
{purchasedCount}
{" / "}
{totalEchoUpgrades}
</strong>
</p>
{isEligible
? null
: <p className="apotheosis-missing">
{"🔒 Purchase all "}
{totalEchoUpgrades}
{" Transcendence upgrades to unlock Apotheosis. ("}
{totalEchoUpgrades - purchasedCount}
{" remaining)"}
</p>
}
{isEligible
? <p className="apotheosis-ready">
{"✅ All Transcendence upgrades purchased. You are ready."}
</p>
: null}
</div>
{isEligible
? <div className="prestige-form">
<p>
{"This action is "}
<strong>{"permanent and irreversible"}</strong>
{"."}
</p>
<button
className="apotheosis-button"
disabled={isPending}
onClick={handleApotheosisClick}
type="button"
>
{isPending
? "Ascending..."
: "✨ Achieve Apotheosis"}
</button>
{error === null
? null
: <p className="error">{error}</p>}
{result !== null
&& <p className="success">
{"Apotheosis achieved. This is cycle "}
<strong>{result}</strong>
{". The infinite loop continues."}
</p>
}
</div>
: null}
</section>
);
};
export { ApotheosisPanel };

Some files were not shown because too many files have changed in this diff Show More