67 Commits

Author SHA1 Message Date
hikari 9bb1d01d2b fix: resolve all 8 open bug tickets (#242–#249) (#250)
CI / Lint, Build & Test (push) Successful in 2m15s
Security Scan and Upload / Security & DefectDojo Upload (push) Successful in 2m13s
## Summary

- **#242** — Crystals in the resource bar now use `formatNumber` to respect the player's notation setting (suffix/scientific/engineering)
- **#243** — Companion unlock progress includes current-run gold (`totalGoldEarned`) on both client and server, so companions unlock at the correct threshold
- **#244** — Empty green reward bubbles no longer render for quest crystal rewards with a zero amount
- **#245/#248** — Auto-save skips when `isAutoPrestigingReference.current` is true, preventing it from racing with an in-flight prestige and breaking the optimistic lock
- **#246** — Generated and uploaded CDN images for `crystal_pulse`, `crystal_surge`, and `crystal_tempest` upgrades
- **#247** — `validateAndSanitize` merges daily challenge progress by taking the max of client vs. server progress per challenge, so stale auto-saves can no longer roll back server-side completions
- **#249** — Cached save signature is cleared after `buyPrestigeUpgrade` succeeds, preventing a stale-signature mismatch on the next auto-save

## Test plan

- [ ] Lint passes (`pnpm lint`)
- [ ] Build passes (`pnpm build`)
- [ ] Tests pass with 100% coverage (`pnpm test`)
- [ ] Crystals display in resource bar respects notation setting
- [ ] No empty reward bubbles on quests that don't award crystals
- [ ] Companion progress bar shows correct value including current-run gold
- [ ] Auto-prestige no longer causes save errors
- [ ] Crafting a recipe updates daily challenge progress persistently (not rolled back by next auto-save)
- [ ] Buying a prestige upgrade does not cause a signature mismatch error on next save
- [ ] Crystal upgrade images display correctly in-game

✨ This PR was created with help from Hikari~ 🌸

Reviewed-on: #250
Co-authored-by: Hikari <hikari@nhcarrigan.com>
Co-committed-by: Hikari <hikari@nhcarrigan.com>
2026-04-13 09:50:20 -07:00
naomi e341db56af release: v0.5.0
CI / Lint, Build & Test (push) Successful in 1m15s
Security Scan and Upload / Security & DefectDojo Upload (push) Failing after 44s
2026-04-06 20:19:18 -07:00
hikari 2bc47b79aa fix: suppress expired-token log noise and redirect expired sessions to login (#241)
Security Scan and Upload / Security & DefectDojo Upload (push) Successful in 1m4s
CI / Lint, Build & Test (push) Successful in 1m11s
## Summary

- **Server**: `authMiddleware` no longer calls `logger.error` for expired tokens — expiry is expected behaviour, not an error. Only tampered signatures and malformed tokens (genuinely suspicious) still log.
- **Client**: `fetchJson` now handles 401 responses by clearing `elysium_token` and `elysium_save_signature` from localStorage and redirecting to `/`. Players whose 30-day token has expired will see the login page instead of a stuck "Invalid or expired token" error screen with no recovery path.

Closes #241

✨ This PR was created with help from Hikari~ 🌸

Reviewed-on: #241
Co-authored-by: Hikari <hikari@nhcarrigan.com>
Co-committed-by: Hikari <hikari@nhcarrigan.com>
2026-04-06 20:17:28 -07:00
hikari 3afe64e48a feat: comprehensive balance and bug fix pass (#240)
Security Scan and Upload / Security & DefectDojo Upload (push) Successful in 1m4s
CI / Lint, Build & Test (push) Successful in 1m10s
## Summary

- **fix(#148)**: Boss fights now return a fresh HMAC signature in the response; both the manual and auto-boss paths update `signatureReference` from it, ending the signature-mismatch loop that stopped auto-boss after the first fight
- **fix(#145)**: Militia `baseCost` lowered from 100g → 65g, smoothing the peasant→militia jump from 10Ɨ to ~6.5Ɨ
- **fix(#144)**: `crystal_shard` buffed from `1.65Ɨ/1.2Ɨ` → `1.9Ɨ/1.3Ɨ` — now competitive as an epic trinket
- **fix(#142)**: Click-power recipe progression smoothed across zones 13–18 and ceiling raised: z13 1.20→1.22, z15 1.22→1.25, z17 1.25→1.28, z18 1.28→1.30
- **close(#143)**: `elder_bark_shield` (1.2Ɨ), `void_fragment_amulet` (1.15Ɨ), and `soul_bound_catalyst` (1.2Ɨ) are all already at or above their target values from a prior pass

Closes #148
Closes #145
Closes #144
Closes #142

Reviewed-on: #240
Co-authored-by: Hikari <hikari@nhcarrigan.com>
Co-committed-by: Hikari <hikari@nhcarrigan.com>
2026-04-06 19:33:05 -07:00
hikari e7164257c5 feat: comprehensive balance pass (#239)
Security Scan and Upload / Security & DefectDojo Upload (push) Successful in 1m9s
CI / Lint, Build & Test (push) Successful in 1m12s
## Summary

Working through all 15 open balance tickets in a coordinated multi-pass approach.

### Pass 1 — Quest failure rates (closes #172)
- Capped all zone quest failure chances at 15% (down from up to 40%)
- Proportional scaling preserved (harder zones still fail more than easier ones)

### Pass 2 — Crystal economy (closes #165, #173, #215)
- Added `crystal_pulse` (3,000 crystals), `crystal_surge` (20,000), `crystal_tempest` (150,000) upgrades to fill the dead zone between 600 and 2M crystal sinks
- Bumped `click_deity`, `prestige_master`, and `prestige_legend` achievement crystal rewards (5K→15K, 5K→15K, 25K→75K)
- Added crystal rewards to `first_steps` (+5) and `goblin_camp` (+10) early quests

### Pass 3 — Runestone/prestige loop (closes #166, #170)
- Bumped `runestonesPerPrestigeLevel` from 15 → 20 (~33% yield increase for mid-game runs)
- Reduced `income_10` cost from 22,500 → 15,000 and `income_11` from 60,000 → 35,000
- Kept client/server parity: `runestonesPerPrestigeLevelClient` in tick.ts updated to match

### Pass 4 — Quest content (#175, #178)
- Both already resolved in commit 666a5b2: quests now reach 5e141 CP across reality_forge, cosmic_maelstrom, primeval_sanctum, and the_absolute — fully covering P60–P212

### Pass 5 — Daily challenges (closes #167)
- Added `crafting` as a new `DailyChallengeType`
- Added 3 crafting challenge templates (craft 1/2/3 recipes)
- Changed generation to guarantee: 1 clicks + 1 crafting + 1 from progression pool
- Added crafting challenge tracking in `craft.ts` (awards crystals on recipe craft)
- Stuck players now have 2/3 daily challenges always completable

### Pass 6 — Transcendence costs (#179)
- Already resolved in commit 666a5b2: echo meta costs are 15/45/100 (was 25/75/200)

### Also closed as stale
- #171 (milestone bonus already quadratic)
- #174 (production multiplier already 1.3^n)
- #176 (expanse_sovereign HP already at 3e39)
- #177 (recipe costs already in expected range)
- #178 (post-absolute quests already present)
- #179 (echo meta costs already reduced)

✨ This PR was created with help from Hikari~ 🌸

Reviewed-on: #239
Co-authored-by: Hikari <hikari@nhcarrigan.com>
Co-committed-by: Hikari <hikari@nhcarrigan.com>
2026-04-06 18:58:04 -07:00
hikari 1195b657a0 feat: another balance and bug fix pass (#238)
Security Scan and Upload / Security & DefectDojo Upload (push) Successful in 1m10s
CI / Lint, Build & Test (push) Successful in 1m13s
Working through open issues — fixes, balance changes, and features.

## Closed

- Closes #161
- Closes #181
- Closes #191
- Closes #199
- Closes #201
- Closes #202
- Closes #203
- Closes #204
- Closes #205
- Closes #206
- Closes #208
- Closes #211
- Closes #212
- Closes #213
- Closes #214
- Closes #216
- Closes #219
- Closes #220
- Closes #221
- Closes #222
- Closes #224
- Closes #225
- Closes #226
- Closes #228
- Closes #229
- Closes #230
- Closes #231
- Closes #232
- Closes #233
- Closes #234
- Closes #235
- Closes #236

✨ This PR was created with help from Hikari~ 🌸

Reviewed-on: #238
Co-authored-by: Hikari <hikari@nhcarrigan.com>
Co-committed-by: Hikari <hikari@nhcarrigan.com>
2026-04-06 18:17:00 -07:00
hikari b0227c1709 chore: update minor and patch dependencies (#237)
Security Scan and Upload / Security & DefectDojo Upload (push) Successful in 1m4s
CI / Lint, Build & Test (push) Successful in 1m11s
## Summary

- Bumped minor/patch versions for `@hono/node-server`, `@types/node`, `@types/react`, `@types/react-dom`, `@vitejs/plugin-react`, `hono`, `jsdom`, `react`, `react-dom`, `tsx`, and `vite`
- Full pipeline (lint → build → test) confirmed passing

## Held back

- **TypeScript** — held at 5.8.2; 6.x is incompatible with the current `@nhcarrigan/eslint-config`
- **Vitest** — held at 3.x; 4.x changes v8 coverage pragma handling, needs investigation
- **Prisma** — held at 6.x; 7.x requires a `prisma.config.ts` migration

✨ This PR was created with help from Hikari~ 🌸

Reviewed-on: #237
Co-authored-by: Hikari <hikari@nhcarrigan.com>
Co-committed-by: Hikari <hikari@nhcarrigan.com>
2026-04-06 12:09:10 -07:00
hikari de5570b5fc fix: filter third-party script errors from frontend telemetry
CI / Lint, Build & Test (push) Successful in 1m14s
Security Scan and Upload / Security & DefectDojo Upload (push) Successful in 1m56s
2026-04-01 13:55:40 -07:00
hikari 133c81fefe chore: bump schema version to 2 for v0.4.0 balance pass
Security Scan and Upload / Security & DefectDojo Upload (push) Successful in 1m9s
CI / Lint, Build & Test (push) Successful in 1m11s
2026-03-31 20:06:13 -07:00
naomi 1408e067b7 release: v0.4.0 2026-03-31 20:00:08 -07:00
hikari 666a5b2d6d fix: runestone formula, prestige/transcendence rebalance, exploration fixes, and comprehensive balance audit (#135)
Security Scan and Upload / Security & DefectDojo Upload (push) Successful in 1m12s
CI / Lint, Build & Test (push) Successful in 1m13s
## What changed and why

### Runestone formula (`prestige.ts`)
- Swapped `sqrt` for `cbrt` — much stronger diminishing returns for large gold values
- Added base cap of **200** (→ ~1,125 max with all upgrades at 5.625Ɨ multiplier)
- Prevents extended AFK sessions from producing runestone windfalls that allow immediate upgrade purchasing and rapid prestige chaining

### Prestige threshold formula (`prestige.ts`)
- Old: `1,000,000 Ɨ 5^n` — exponential, grows impossibly fast, prestige 10+ takes years
- New: `1,000,000 Ɨ (n+1)²` — polynomial, peaks at ~1 day/run around P8–10, then gets *easier* as the production multiplier overtakes it
- Removed `thresholdScaleFactor` constant (no longer needed)

### Production multiplier (`prestige.ts`)
- Old: `1.15^n`
- New: `1.25^n` — compounds faster, ensures the polynomial threshold eventually gets easy in the late game

### Boss prestige requirements (`bosses.ts`)
- Rescaled proportionally from 0–88 range to 0–20 range
- The Absolute One now requires prestige **20** (was 88), making transcendence reachable in a few weeks of idle play

### Echo formula (`transcendence.ts`)
- Constant changed from 853 → **224**
- At the target prestige of 20: `floor(224 / sqrt(20)) = 50 echoes` per transcendence (no meta upgrades)
- With all echo_meta upgrades (3.75Ɨ total): up to **187 echoes** per transcendence

### Transcendence upgrade costs (`transcendenceUpgrades.ts`)
- Old total: **866 echoes** → New total: **400 echoes** (roughly halved across all categories)
- Apotheosis still requires **all 15 upgrades** purchased

### Balance fixes (closes #141, #142, #143, #144, #145)
- Equipment: `philosophers_stone` click multiplier 2.25→2.5, `crystal_shard` 1.55→1.65 (#144)
- Recipes: added `primal_omega_lens` cross-zone click_power recipe at 1.38Ɨ (#142)
- Adventurers: `celestial_guard` base cost adjusted to smooth tier 14→15→16 cost curve (#145)

### Quest reward rebalancing (closes #136, #137)
- Shadow Marshes: buffed `shadow_mere`, `witch_coven`, `plague_ruins` rewards to match combat requirements (#136)
- Astral Void: added gold to `void_rift`, increased rewards across all Astral Void quests (#137)

### Boss reward additions (closes #138, #139, #140)
- Assigned 9 unassigned adventurer-specific upgrades to Crystalline Spire through Eternal Throne bosses that had empty `upgradeRewards` arrays (#140)

### Combat power documentation (closes #153)
- Expanded JSDoc on `computePartyCombatPower` to clarify companion `bossDamage` multiplier behaviour

### Effective adventurer stats (closes #154)
- Added `computeEffectiveAdventurerStats` to `tick.ts` and updated `AdventurerCard` to display effective post-multiplier stats

### Adventurer upgrade timing (closes #158)
- Audited every adventurer-specific upgrade reward — upgrades now land within the same progression window where that adventurer tier is still a meaningful contributor

### Sync and save fixes (closes #147, #148, #151)
- Fixed sync new content count to report only genuinely changed items (#147)
- Fixed signature mismatch after first auto-boss completion (#148)
- Added auto-buy cap (100) on non-max-tier adventurers (#151)

### Auto-adventurer persistence (closes #156)
- Auto-buy preference now preserved across prestige resets

### Broken CDN image (closes #159)
- Uploaded missing `auto_adventurer.jpg` to CDN

### Codex unlock hints (closes #146)
- Locked codex entries now display a hint generated from `sourceType` and `sourceId`

### Exploration bug fixes (closes #160, #161)
- Fixed auto-save race condition discarding exploration materials collected mid-tick (#160)
- Fixed exploration areas failing to unlock when zone was unlocked via boss kill or quest completion (#161)

### Concurrent prestige fix (closes #162)
- Added optimistic locking via `updatedAt` — concurrent prestige requests return 409

### Prestige UX (closes #163)
- Added `reloadSilent` to game context — no loading screen flash after prestige

### Balance adjustments (closes #164, #165, #166, #167)
- Reduced `shadow_mere` CP requirement 5,000,000 → 2,000,000 (#164)
- Buffed crystal drops from Shadow Marshes bosses and quests (#165)
- Increased runestone yield from 10 → 15 per prestige level (#166)
- Daily challenge set always includes a clicks challenge (#167)

### Progression QoL (closes #168, #169)
- Added `computeProjectedRunestones()` and persistent `+N On Prestige` resource bar row (#168)
- Added `enablePrestigeAnnouncements` setting per player (#169)

---

## Comprehensive balance audit (closes #187, #191, #192, #193, #194, #195, #196, #197, #198)

### Crystal economy fixes
- Zeroed crystal rewards for all Zone 7+ boss drops (Celestial Reaches onwards) — crystals are an early/mid-game currency and should not flow freely into the endgame (#187)
- Zeroed crystal rewards for all Zone 9+ quest rewards (Infernal Court onwards) — same rationale (#191)

### Achievement additions and fixes
- Added quest milestone achievements at 75 quests (10,000 crystals) and 100 quests (15,000 crystals)
- Added boss milestone achievement at 50 bosses (15,000 crystals)
- Added prestige milestone achievements at P50, P100, P150, P200 — rewarding **runestones** rather than crystals to match the late-game economy
- Added gold milestone achievements through 1e90 gold earned
- Fixed `quest_eternal` condition from 122 → **112** (actual quest count) — was permanently impossible (#197)
- Fixed `fully_equipped` condition from 65 → **78** (actual equipment count after new items) (#197)
- Fixed `devourer_slayer` description to remove incorrect zone reference

### Upgrade balance
- Fixed Essence Guild multiplier 1.5Ɨ → **2Ɨ** — was identical to the cheaper Merchant Alliance for 5Ɨ the cost (#194)
- Raised Void Ascendancy crystal cost 10M → **50M** — was trivially cheap compared to the parallel Celestial Mandate upgrade (100B essence + 50T gold) (#195)
- Fixed Sunken Temple quest rewards (gold 2M → 60M, essence 1,500 → 25,000, crystals 75 → 400) — was rewarding less than its easier prerequisite Witch Coven (#193)

### Equipment balance
- Buffed Eternal Prism stats to click 5Ɨ, combat **3Ɨ**, gold **2.5Ɨ** — was only marginally better than the free Eternity Stone boss drop for 100M crystals (#196)

### Missing content
- Created **13 missing equipment items** for Zones 15–18 (primordial_chaos through the_absolute) that were referenced by late-game boss `equipmentRewards` arrays but never existed in `equipment.ts` (#198):
  - `chaos_mantle`, `titan_core` (Primordial Chaos)
  - `expanse_blade`, `void_armour_mk2` (Infinite Expanse)
  - `cosmos_blade`, `reality_plate` (Reality Forge)
  - `maelstrom_edge`, `cosmic_plate` (Cosmic Maelstrom)
  - `primeval_blade`, `ancient_aegis` (Primeval Sanctum)
  - `absolute_blade`, `eternity_plate`, `omniversal_core` (The Absolute)
- Stats scale from combat 14Ɨ / gold 9Ɨ (Zone 15) up to combat 28Ɨ / gold 20Ɨ for the final boss drops

### Type system
- Extended `AchievementReward` type to support `runestones` field
- Updated tick engine achievement processing to award both crystals and runestones

---

## Target progression timeline (optimal play, ~16h/day idle)
- First cycle to P20: ~375h (~3.3 weeks)
- Each subsequent cycle gets faster as echo upgrades boost income/combat/threshold
- Expected **~5 transcendences** before apotheosis at 50–187 echoes/transcendence
- **~6 months** to apotheosis for a dedicated player

## Test plan
- [ ] Lint, build, and test pipeline passes (100% coverage maintained)
- [ ] Prestige threshold at P0 is still 1,000,000 gold
- [ ] Prestige runs feel ~1 day long around P8–10 and get easier after
- [ ] The Absolute One is locked until prestige 20
- [ ] Transcendence at P20 awards 50 echoes (no meta upgrades)
- [ ] All 15 transcendence upgrades cost 400 echoes total
- [ ] Bosses in Zones 7+ drop 0 crystals; Zones 1–6 retain crystal drops
- [ ] Quests in Zones 9+ reward 0 crystals; Zones 1–8 retain crystal rewards
- [ ] Sunken Temple rewards more gold/essence/crystals than Witch Coven
- [ ] Essence Guild gives 2Ɨ income (stronger than Merchant Alliance 1.5Ɨ)
- [ ] Void Ascendancy costs 50M crystals
- [ ] Eternal Prism stats are click 5Ɨ, combat 3Ɨ, gold 2.5Ɨ
- [ ] Late-game bosses (primordial_titan through the_absolute_one) drop equipment on kill
- [ ] `quest_eternal` achievement requires 112 quests
- [ ] `fully_equipped` achievement requires 78 equipment pieces
- [ ] P50/P100/P150/P200 prestige achievements reward runestones
- [ ] Adventurer cards show effective post-multiplier stats
- [ ] Exploration areas unlock correctly when their zone is unlocked
- [ ] Concurrent prestige requests return 409
- [ ] No loading screen flash after prestige
- [ ] Daily challenge set always includes a clicks challenge
- [ ] Resource bar shows `+N On Prestige` runestone preview

✨ This PR was crafted with help from Hikari~ 🌸

Reviewed-on: #135
Co-authored-by: Hikari <hikari@nhcarrigan.com>
Co-committed-by: Hikari <hikari@nhcarrigan.com>
2026-03-31 19:57:53 -07:00
naomi 9926e7f639 release: v0.3.2
CI / Lint, Build & Test (push) Successful in 1m13s
Security Scan and Upload / Security & DefectDojo Upload (push) Successful in 2m17s
2026-03-24 18:50:37 -07:00
hikari 6bf1ac5e7d feat: grant Elysian role on auth and prompt non-members to join (#134)
CI / Lint, Build & Test (push) Has been cancelled
Security Scan and Upload / Security & DefectDojo Upload (push) Has been cancelled
## Summary

- Grants the Elysian Discord role to players on login/registration and persists an `inGuild` flag on the Player record
- Connects to the Discord Gateway via WebSocket to keep `inGuild` in sync as players join or leave the server
- Shows a dismissible "Join our community" modal to players who are not yet in the guild
- Hardens `inGuild` exposure through the load endpoint and game context
- Moves all non-secret Discord IDs (guild, role, client, redirect URI) out of env vars and into hardcoded constants; removes them from `prod.env`

## Test plan

- [ ] Lint, build, and test pipeline passes (100% coverage maintained)
- [ ] New player auth grants Elysian role and sets `inGuild: true`
- [ ] Existing player auth re-attempts role grant and updates `inGuild`
- [ ] Join community modal appears for players not in the guild
- [ ] Modal does not reappear within the same browser session after dismissal
- [ ] Gateway correctly sets `inGuild: true/false` on member add/remove events

✨ This issue was created with help from Hikari~ 🌸

Reviewed-on: #134
Co-authored-by: Hikari <hikari@nhcarrigan.com>
Co-committed-by: Hikari <hikari@nhcarrigan.com>
2026-03-24 18:49:51 -07:00
hikari b48beef474 feat: sync and patch all content stats on existing saves (#130)
Security Scan and Upload / Security & DefectDojo Upload (push) Successful in 1m2s
CI / Lint, Build & Test (push) Successful in 1m10s
## Summary

- Sync New Content now **injects** missing entries AND **patches canonical fields** on all existing entries to match current defaults
- Adventurers: stats (baseCost, combatPower, goldPerSecond, essencePerSecond, name, class, level)
- Quests: duration, prerequisites, combat requirement, rewards
- Bosses: HP, damage, rewards, prestige requirement, upgrade rewards
- Zones: unlock conditions (boss/quest required)
- Upgrades: multiplier, costs
- Equipment: bonus, cost, set membership
- Achievements: condition, reward
- Crafting: multipliers recomputed from `craftedRecipeIds` so recipe balance changes apply retroactively

Closes #126

## Test plan

- [ ] On an existing save, click Sync New Content and verify the notification reports patched counts for all content types
- [ ] Verify that rebalanced adventurer/boss/upgrade stats are reflected in the UI after syncing
- [ ] Verify that player-owned state (counts, unlock status, boss HP, quest status) is preserved after syncing
- [ ] Verify crafting multipliers are correct after syncing if any recipes were previously crafted

✨ This issue was created with help from Hikari~ 🌸

Reviewed-on: #130
Co-authored-by: Hikari <hikari@nhcarrigan.com>
Co-committed-by: Hikari <hikari@nhcarrigan.com>
2026-03-24 16:01:48 -07:00
hikari 6e573bea14 chore: more feedback fixes (#129)
Security Scan and Upload / Security & DefectDojo Upload (push) Successful in 1m5s
CI / Lint, Build & Test (push) Successful in 1m9s
## Summary

- Fix `NaN` displayed in Sync New Content / Force Unlock notifications by guarding against undefined counts
- Poll server for exploration claimability before showing Collect button to prevent client/server desync
- Return authoritative materials list from craft API to prevent client desync causing false affordability
- Add test coverage for `sync-new-content` and `explore/claimable` endpoints

Closes #125
Closes #127
Closes #128

## Test plan

- [ ] Trigger a sync with new content and verify the notification shows a real count instead of `NaN`
- [ ] Start an exploration, wait for it to complete, and verify the Collect button only appears after the server confirms claimable
- [ ] Attempt to craft a recipe and verify the material counts in the UI update to match the server's authoritative values

✨ This issue was created with help from Hikari~ 🌸

Reviewed-on: #129
Co-authored-by: Hikari <hikari@nhcarrigan.com>
Co-committed-by: Hikari <hikari@nhcarrigan.com>
2026-03-24 13:20:37 -07:00
hikari 790d35420f fix: patch quest and boss rewards on sync to restore unlock conditions
Security Scan and Upload / Security & DefectDojo Upload (push) Successful in 1m9s
CI / Lint, Build & Test (push) Failing after 1m11s
2026-03-23 18:45:14 -07:00
naomi 9f9edae45e release: v0.3.1
Security Scan and Upload / Security & DefectDojo Upload (push) Successful in 1m6s
CI / Lint, Build & Test (push) Failing after 1m11s
2026-03-23 18:32:15 -07:00
hikari a7a255dab6 fix: sort injected entries by canonical defaults order after sync
Security Scan and Upload / Security & DefectDojo Upload (push) Successful in 1m9s
CI / Lint, Build & Test (push) Failing after 1m13s
2026-03-23 18:18:59 -07:00
hikari e92cf3c9a1 feat: add sync new content debug tool
CI / Lint, Build & Test (push) Failing after 51s
Security Scan and Upload / Security & DefectDojo Upload (push) Successful in 1m9s
Adds a new debug panel button that injects any adventurers, quests,
bosses, equipment, upgrades, achievements, zones, and exploration areas
that exist in the current game data but are missing from an existing
player save (e.g. content added after the save was first created).
2026-03-23 18:10:39 -07:00
naomi 26d30c271d release: v0.3.0
Security Scan and Upload / Security & DefectDojo Upload (push) Successful in 1m6s
CI / Lint, Build & Test (push) Successful in 1m11s
2026-03-23 17:39:55 -07:00
hikari 34d07bec95 balance: comprehensive game balance pass (#103-#123) (#124)
Security Scan and Upload / Security & DefectDojo Upload (push) Successful in 1m3s
CI / Lint, Build & Test (push) Successful in 1m9s
## Summary

Comprehensive balance pass addressing 20 tickets (#103–#122) plus one audit-discovered fix (#123), ensuring no player soft-locks and aligning all content counts with achievements and progression milestones.

### Changes

- **Equipment** (#103–#111): Differentiated all stat pairs so every piece has a unique bonus combination; added missing stats to `eternal_flame` and increased `eternal_prism` multiplier to justify cost tier
- **Recipes** (#112–#115): Added 4 cross-zone crafting recipes requiring materials from multiple zones to incentivise exploration breadth
- **Achievements** (#116–#118): Aligned `fully_equipped` (40→65), `quest_eternal` (72→95), and `boss_eternal` (60→72) thresholds with actual content counts; updated `devourer_slayer` description
- **Quest CP scaling** (#120–#122): Verified and corrected combat power requirements across all zones to follow consistent 4Ɨ/4Ɨ progression pattern
- **Zone file ordering** (#123): Swapped Frozen Peaks and Shadow Marshes quest sections so file order matches the actual unlock chain (no gameplay change)

### Tickets Closed

Closes #103
Closes #104
Closes #105
Closes #106
Closes #107
Closes #108
Closes #109
Closes #110
Closes #111
Closes #112
Closes #113
Closes #114
Closes #115
Closes #116
Closes #117
Closes #118
Closes #120
Closes #121
Closes #122
Closes #123

✨ This PR was created with help from Hikari~ 🌸

Reviewed-on: #124
Co-authored-by: Hikari <hikari@nhcarrigan.com>
Co-committed-by: Hikari <hikari@nhcarrigan.com>
2026-03-23 17:28:29 -07:00
hikari 3ac1d566cb chore: community feedback fixes and UI improvements (#102)
Security Scan and Upload / Security & DefectDojo Upload (push) Successful in 1m3s
CI / Lint, Build & Test (push) Successful in 1m8s
## Summary

Addresses all community feedback tickets from the last deploy, plus several UI improvements made during the same session.

### Bug fixes & balance
- **#97** — Fix auto-adventurer tier priority: sort by combat power instead of current cost so the highest-tier affordable unit is always purchased
- **#98** — Add Dark Templar adventurer (80k CP) to bridge the Volcanic Depths progression wall; rewire upgrade and quest rewards accordingly
- **#99** — Reorder and buff Shadow Assassin (55k CP, level 12) so Witch Coven feels rewarding rather than a regression
- **#100** — Display effective Gold/s (all multipliers applied) in the resource bar
- **#101** — Add Peasant tier 2 (10x, essence) and tier 3 (50x, crystals) upgrades for meaningful late-game scaling

### Other fixes
- Sync game state to server before auto-boss challenges (matching manual challenge behaviour)
- Refresh Discord avatar hash on every game load via bot token so stale CDN URLs are corrected automatically

### UI improvements
- Replace Donate / Discord / Support / View Profile / Edit Profile buttons with a single avatar dropdown menu
- Collapse all resources except Gold into a click-to-toggle dropdown; orange alert dot appears when a hidden resource is capped

## Closes

Closes #97
Closes #98
Closes #99
Closes #100
Closes #101

Reviewed-on: #102
Co-authored-by: Hikari <hikari@nhcarrigan.com>
Co-committed-by: Hikari <hikari@nhcarrigan.com>
2026-03-23 16:07:25 -07:00
naomi 7bd6b2d3e3 release: v0.2.1
CI / Lint, Build & Test (push) Successful in 1m9s
Security Scan and Upload / Security & DefectDojo Upload (push) Successful in 2m6s
2026-03-20 15:23:13 -07:00
hikari 354b7e372e fix: break fire_temple combat power wall (#96)
Security Scan and Upload / Security & DefectDojo Upload (push) Successful in 1m13s
CI / Lint, Build & Test (push) Successful in 1m17s
Closes #95

## Summary

`void_walker` adventurers (130K combat power each) were locked behind `fire_temple`, which requires 4.8B combat power. The best adventurer available before completing that quest was `arcane_scholar` at 45K CP each — meaning players needed ~107K arcane scholars to break through, versus ~37K if they had void walkers. Classic chicken-and-egg wall.

## Changes

- Moved `void_walker` adventurer reward from `fire_temple` to `lava_flows` (the entry quest to Volcanic Depths, no CP requirement)
- Added 40M gold reward to `fire_temple` to replace the removed adventurer unlock

Players now unlock `void_walker` as soon as they enter the zone, giving them the combat power boost before they need to grind toward the temple.

✨ This issue was created with help from Hikari~ 🌸

Reviewed-on: #96
Co-authored-by: Hikari <hikari@nhcarrigan.com>
Co-committed-by: Hikari <hikari@nhcarrigan.com>
2026-03-20 15:17:23 -07:00
hikari dc1782bec9 chore: add auto-adventurer toggle to adventurer panel header (#94)
Security Scan and Upload / Security & DefectDojo Upload (push) Successful in 1m4s
CI / Lint, Build & Test (push) Successful in 1m9s
The auto-adventurer toggle is now surfaced directly in the adventurer shop panel header, mirroring the auto-boss button. It only renders when the `auto_adventurer` prestige upgrade has been purchased, so players who have not reached prestige see no change.

Closes #89

✨ This PR was created with help from Hikari~ 🌸

Reviewed-on: #94
Co-authored-by: Hikari <hikari@nhcarrigan.com>
Co-committed-by: Hikari <hikari@nhcarrigan.com>
2026-03-20 14:35:04 -07:00
hikari 635c630e49 fix: adventurer unlocks not applied by force-unlock tool (#93)
Security Scan and Upload / Security & DefectDojo Upload (push) Successful in 1m3s
CI / Lint, Build & Test (push) Successful in 1m10s
The force-unlock debug route now scans completed quests for adventurer rewards and ensures those tiers are marked as unlocked in game state.

The UI and API response type both surface the new `adventurersUnlocked` count alongside the existing zone/quest/boss/exploration counts.

Closes #88

✨ This PR was created with help from Hikari~ 🌸

Reviewed-on: #93
Co-authored-by: Hikari <hikari@nhcarrigan.com>
Co-committed-by: Hikari <hikari@nhcarrigan.com>
2026-03-20 10:28:17 -07:00
hikari bb60ae3390 fix: auto-quest continues after quest failure (#92)
Security Scan and Upload / Security & DefectDojo Upload (push) Successful in 1m1s
CI / Lint, Build & Test (push) Successful in 1m17s
## Summary

Fixes #87. When a quest failed, the tick loop detected the failure and turned auto-quest off so the "player could reassess". This meant every quest failure required the player to manually re-enable the toggle.

## Root Cause

The tick applies quest failure by resetting the quest to `status: "available"` with `lastFailedAt` set. Auto-quest picks up `available` quests automatically — so turning off auto-quest on failure was entirely unnecessary, it just broke the loop.

## Fix

Remove the auto-quest-off-on-failure block entirely. The quest returns to `available` immediately after failure, so auto-quest naturally retries on the next tick. Players can still disable it manually if they want to stop.

✨ This PR was created with help from Hikari~ 🌸

Reviewed-on: #92
Co-authored-by: Hikari <hikari@nhcarrigan.com>
Co-committed-by: Hikari <hikari@nhcarrigan.com>
2026-03-20 09:35:55 -07:00
hikari ee47c1e8c9 fix: auto-boss no longer halts on client/server save race condition (#91)
Security Scan and Upload / Security & DefectDojo Upload (push) Successful in 1m4s
CI / Lint, Build & Test (push) Successful in 1m10s
## Summary

Fixes #86. When the client state is ahead of the server save, the auto-boss tick would receive a "Boss is not currently available" error from the API. This error was already acknowledged as an expected race condition and suppressed from telemetry — but it was still setting the error state and turning auto-boss off.

## Root Cause

The `catch` handler treated all errors identically: set `autoBossError`, turn off `autoBoss`. The race-condition case should instead silently skip so the next tick can retry naturally.

## Fix

When the error is `"Boss is not currently available"`, return early from the `catch` handler. The `finally` block still runs, resetting `isAutoBossingReference.current = false`, so the next tick retries cleanly.

✨ This PR was created with help from Hikari~ 🌸

Reviewed-on: #91
Co-authored-by: Hikari <hikari@nhcarrigan.com>
Co-committed-by: Hikari <hikari@nhcarrigan.com>
2026-03-20 09:30:57 -07:00
hikari 2236d1dc9f fix: correct quest combat power requirements for SM, VD, and AV (#90)
CI / Lint, Build & Test (push) Successful in 1m10s
Security Scan and Upload / Security & DefectDojo Upload (push) Successful in 1m11s
## Summary

Fixes #85. Quest combat power requirements for Shadow Marshes, Volcanic Depths, and Astral Void were all drastically too low, breaking the zone progression curve.

### Root Cause

All three zones appear to have had their `combatPowerRequired` values entered at the wrong magnitude. Shadow Marshes was using K values where M was intended; Volcanic Depths and Astral Void were similarly off, resulting in later zones being trivially easier than earlier ones.

### Changes

| Zone | Before | After |
|---|---|---|
| Shadow Marshes | 5K / 20K / 80K / 300K | 5M / 20M / 80M / 300M |
| Volcanic Depths | 2M / 8M / 30M / 120M | 1.2B / 4.8B / 18B / 72B |
| Astral Void | 50M / 200M / 800M / 3B | 300B / 1.2T / 4.8T / 18T |

### Progression

All values now maintain a consistent ~Ɨ4 multiplier within each zone and ~Ɨ4 jump between zones, matching the established pattern from Verdant Vale through Frozen Peaks.

✨ This PR was created with help from Hikari~ 🌸

Reviewed-on: #90
Co-authored-by: Hikari <hikari@nhcarrigan.com>
Co-committed-by: Hikari <hikari@nhcarrigan.com>
2026-03-20 09:19:16 -07:00
naomi 621f594018 release: v0.2.0
Security Scan and Upload / Security & DefectDojo Upload (push) Successful in 1m2s
CI / Lint, Build & Test (push) Successful in 1m7s
2026-03-19 21:24:55 -07:00
hikari 1e845b14ce chore: UI clarity improvements (#84)
Security Scan and Upload / Security & DefectDojo Upload (push) Successful in 1m4s
CI / Lint, Build & Test (push) Successful in 1m8s
## Summary

- Move quest failure explanation to a static note above the quest list (cards now show failure % only)
- Show zone unlock requirements (boss + quest) on the Boss and Quest panels, matching the existing Exploration panel behaviour
- Display combat power per adventurer on adventurer cards, alongside gold/s and essence/s

✨ This issue was created with help from Hikari~ 🌸

Reviewed-on: #84
Co-authored-by: Hikari <hikari@nhcarrigan.com>
Co-committed-by: Hikari <hikari@nhcarrigan.com>
2026-03-19 21:22:13 -07:00
hikari 81ae1f18e1 chore: clarify equipment combat bonus applies to boss fights only (#83)
CI / Lint, Build & Test (push) Successful in 1m4s
Security Scan and Upload / Security & DefectDojo Upload (push) Successful in 1m34s
## Summary

Resolves player confusion about equipment combat bonuses not affecting quest combat power. The behaviour is by design — combat multipliers only apply to boss DPS — but this was never communicated anywhere.

- **Equipment bonus labels** now read `+X% Boss Combat` instead of `+X% Combat` (both individual items and set bonuses)
- **About panel** — both equipment entries updated to explicitly state that combat bonuses only affect boss fights, and that quest combat power is determined solely by adventurers

No game logic changed.

Closes #81

✨ This PR was created with help from Hikari~ 🌸

Reviewed-on: #83
Co-authored-by: Hikari <hikari@nhcarrigan.com>
Co-committed-by: Hikari <hikari@nhcarrigan.com>
2026-03-19 19:02:24 -07:00
hikari 0057cfeaaa feat: communicate quest failure mechanics in the UI (#82)
Security Scan and Upload / Security & DefectDojo Upload (push) Successful in 1m2s
CI / Lint, Build & Test (push) Successful in 1m8s
## Summary

Addresses recurring community confusion about quests failing — multiple players asked whether it was a bug or intended behaviour with no in-game explanation.

- **Exports `zoneFailureChance`** from `tick.ts` so the quest panel can read it
- **Quest cards** now show a `šŸŽ² X% failure chance` note on all available quests, with a brief explanation that a failure resets the quest with no rewards
- **"Last attempt failed" hint** now reads `"āš ļø Last attempt failed — no rewards were granted."` so players understand the consequence immediately
- **About panel** updated to document the failure mechanic, including the 10%–40% range across zones

Closes #80

✨ This PR was created with help from Hikari~ 🌸

Reviewed-on: #82
Co-authored-by: Hikari <hikari@nhcarrigan.com>
Co-committed-by: Hikari <hikari@nhcarrigan.com>
2026-03-19 17:57:17 -07:00
hikari 161127dc21 chore: audit frontend error reporting to exclude expected behaviours (#79)
Security Scan and Upload / Security & DefectDojo Upload (push) Successful in 1m2s
CI / Lint, Build & Test (push) Successful in 1m8s
## Summary

Audits all `logError` call sites in `gameContext.tsx` and suppresses telemetry for expected business logic rejections, eliminating alert fatigue without hiding real errors.

### Changes per call site

| Context | Before | After |
|---|---|---|
| `auto_save` | Logged all non-signature errors | Network failures silently swallowed — next tick retries |
| `auto_prestige` | Logged eligibility failures | Silently ignored — eligibility re-checked every tick |
| `auto_boss` | Logged all errors | Filters out `"Boss is not currently available"` (race condition); other errors still logged |
| `challenge_boss` | Logged all errors | Filters out `"Boss is not currently available"` (race condition); other errors still logged |
| `start_exploration` | Logged then rethrew | Removed useless try/catch — error propagates to UI naturally |
| `collect_exploration` | Logged then rethrew | Removed useless try/catch — error propagates to UI naturally |

Genuine errors (`buy_prestige_upgrade`, `transcend`, `apotheosis`, `buy_echo_upgrade`, `craft_recipe`) are unchanged — they still fire telemetry.

Closes #73

✨ This PR was created with help from Hikari~ 🌸

Reviewed-on: #79
Co-authored-by: Hikari <hikari@nhcarrigan.com>
Co-committed-by: Hikari <hikari@nhcarrigan.com>
2026-03-19 16:01:22 -07:00
hikari a8a465f293 feat: display leaderboard update frequency in the UI (#78)
Security Scan and Upload / Security & DefectDojo Upload (push) Successful in 1m4s
CI / Lint, Build & Test (push) Successful in 1m14s
## Summary

Adds a note below the leaderboard subtitle informing players that rankings update when they prestige. This addresses a recurring community question from `tau.deusmortis` and `minjo70`.

Closes #63

✨ This PR was created with help from Hikari~ 🌸

Reviewed-on: #78
Co-authored-by: Hikari <hikari@nhcarrigan.com>
Co-committed-by: Hikari <hikari@nhcarrigan.com>
2026-03-19 15:44:14 -07:00
hikari 79c4b99e8a feat: add essence infusion upgrades as late-prestige essence sink (#77)
Security Scan and Upload / Security & DefectDojo Upload (push) Failing after 11s
CI / Lint, Build & Test (push) Successful in 1m2s
## Summary

Closes #62

Adds five **Essence Infusion** upgrades (I–V) to give essence an ongoing meaningful use deep into a prestige run, when gold upgrades are all purchased and essence reserves are in the trillions with nowhere to go:

| Upgrade | Cost | Multiplier |
|---|---|---|
| Essence Infusion I | 1T essence | Ɨ2 global |
| Essence Infusion II | 5T essence | Ɨ2 global |
| Essence Infusion III | 25T essence | Ɨ2 global |
| Essence Infusion IV | 100T essence | Ɨ3 global |
| Essence Infusion V | 500T essence | Ɨ5 global |

All five start `unlocked: true` (no prerequisite boss or quest required) and cost zero gold and zero crystals — they are purely essence sinks. Combined, they provide a Ɨ120 global income multiplier for players willing to pour their essence reserves into the guild. The About panel's Upgrades section is also updated to inform players these exist.

CDN art assets will need to be generated for IDs `essence_sink_1` through `essence_sink_5` in the `upgrades` folder.

✨ This issue was created with help from Hikari~ 🌸

Reviewed-on: #77
Co-authored-by: Hikari <hikari@nhcarrigan.com>
Co-committed-by: Hikari <hikari@nhcarrigan.com>
2026-03-19 15:39:04 -07:00
hikari 3d114f63d7 feat: post-prestige automation (auto-adventurer) (#76)
Security Scan and Upload / Security & DefectDojo Upload (push) Successful in 1m5s
CI / Lint, Build & Test (push) Successful in 1m9s
## Summary

Closes #61

- Adds the **Autonomous Recruitment** prestige upgrade (50 runestones) to both the API and web data files
- Adds `autoAdventurer?: boolean` to the `GameState` type for backwards-compatible saves
- Adds tick-loop logic in GameContext that automatically purchases the highest-tier unlocked adventurer the player can afford each frame when the toggle is enabled
- Adds `toggleAutoAdventurer` callback and exposes it through the context
- Adds toggle UI in the Prestige Shop (mirrors the existing Auto-Prestige toggle pattern)
- Updates the How to Play guide in the About panel to document the new automation feature

✨ This issue was created with help from Hikari~ 🌸

Reviewed-on: #76
Co-authored-by: Hikari <hikari@nhcarrigan.com>
Co-committed-by: Hikari <hikari@nhcarrigan.com>
2026-03-19 13:38:25 -07:00
hikari 911e089a9e feat: document upgrade stacking behaviour as multiplicative (#75)
Security Scan and Upload / Security & DefectDojo Upload (push) Successful in 1m9s
CI / Lint, Build & Test (push) Successful in 1m10s
## Summary

- Adds a `šŸ’”` stacking note directly in the upgrade panel below the progress counter so players see it without visiting the About page
- Updates the About panel's Upgrades how-to-play entry to replace the vague "compound with each other" with explicit multiplicative stacking language, including an example (two Ɨ2 upgrades = Ɨ4) and a note that global upgrades multiply on top of adventurer-specific ones

## Test plan

- [ ] Verify the stacking note appears in the upgrade panel below the progress counter
- [ ] Verify the About panel Upgrades entry reflects the updated wording
- [ ] Confirm lint, build, and tests all pass

Closes #60

Reviewed-on: #75
Co-authored-by: Hikari <hikari@nhcarrigan.com>
Co-committed-by: Hikari <hikari@nhcarrigan.com>
2026-03-19 13:24:45 -07:00
hikari 14de87d765 feat: communicate exploration zone unlock conditions in-game (#74)
Security Scan and Upload / Security & DefectDojo Upload (push) Successful in 1m4s
CI / Lint, Build & Test (push) Successful in 1m10s
## Summary

- Locked exploration zones now show a `šŸ”’ This zone is locked. Unlock exploration by:` hint above the area list, with the specific `āš”ļø Defeat: {boss}` and `šŸ“œ Complete: {quest}` required
- Updated the About panel's Exploration how-to-play entry to document the zone unlock rule explicitly
- No new data required — unlock conditions are read directly from `zone.unlockBossId` and `zone.unlockQuestId` already in state

## Test plan

- [ ] Verify locked exploration zones display the correct boss and quest unlock hints
- [ ] Verify already-unlocked zones show no hint
- [ ] Verify starter zone (no unlock conditions) shows no hint
- [ ] Verify the About panel Exploration entry reflects the updated description
- [ ] Confirm lint, build, and tests all pass

Closes #59

Reviewed-on: #74
Co-authored-by: Hikari <hikari@nhcarrigan.com>
Co-committed-by: Hikari <hikari@nhcarrigan.com>
2026-03-19 12:18:45 -07:00
hikari c4b4fba4c9 feat: display current party combat power as a persistent stat (#72)
Security Scan and Upload / Security & DefectDojo Upload (push) Successful in 1m4s
CI / Lint, Build & Test (push) Successful in 1m8s
## Summary

- Adds a `āš”ļø Combat Power` entry to the always-visible resource bar
- Value is computed client-side as the sum of each adventurer's `combatPower Ɨ count`
- No new props required — computed directly from `state` via the existing `useGame()` hook
- Players can now see their combat strength at a glance before attempting boss fights or quests

## Test plan

- [ ] Verify the Combat Power stat appears in the resource bar
- [ ] Verify the value increases as more adventurers are recruited
- [ ] Verify the value displays correctly with `formatNumber` for large numbers
- [ ] Confirm lint, build, and tests all pass

Closes #58

Reviewed-on: #72
Co-authored-by: Hikari <hikari@nhcarrigan.com>
Co-committed-by: Hikari <hikari@nhcarrigan.com>
2026-03-19 11:55:57 -07:00
hikari d723656743 feat: show progress toward unlock conditions on achievement cards (#71)
Security Scan and Upload / Security & DefectDojo Upload (push) Successful in 1m13s
CI / Lint, Build & Test (push) Successful in 1m15s
## Summary

- Adds a `getCurrentProgress` helper that mirrors the tick engine's achievement-checking logic to compute the player's current progress for each condition type
- Locked achievement cards now display a `<progress>` bar and a numeric `{current} / {target}` label so players can see exactly how close they are to each achievement
- Unlocked achievements are unaffected — no progress bar shown once earned

## Test plan

- [ ] Verify locked achievement cards display a progress bar and numeric label
- [ ] Verify the progress values match what the tick engine uses for unlock checking
- [ ] Verify unlocked achievement cards show no progress bar
- [ ] Confirm lint, build, and tests all pass

Closes #57

Reviewed-on: #71
Co-authored-by: Hikari <hikari@nhcarrigan.com>
Co-committed-by: Hikari <hikari@nhcarrigan.com>
2026-03-19 11:45:36 -07:00
hikari 7e10757e68 feat: show affected adventurer name on upgrade cards (#70)
Security Scan and Upload / Security & DefectDojo Upload (push) Successful in 1m7s
CI / Lint, Build & Test (push) Successful in 1m9s
## Summary

- Adds a `šŸ—”ļø Affects: {Name}` label to upgrade cards that target a specific adventurer
- Resolves player confusion caused by class-based language (e.g. "doubles cleric output") without specifying which adventurer tiers count as that class
- Label appears in all three card states: available, purchased, and locked

## Test plan

- [ ] Verify adventurer-targeted upgrade cards display the correct adventurer name
- [ ] Verify global, click, boss, and prestige upgrade cards show no affects label
- [ ] Confirm lint, build, and tests all pass

Closes #56

Reviewed-on: #70
Co-authored-by: Hikari <hikari@nhcarrigan.com>
Co-committed-by: Hikari <hikari@nhcarrigan.com>
2026-03-19 11:29:29 -07:00
hikari ca2edb090e fix: correct equipment balance and sort items by stat power (#69)
Security Scan and Upload / Security & DefectDojo Upload (push) Successful in 1m3s
CI / Lint, Build & Test (push) Successful in 1m10s
## Summary

Two improvements to the equipment system in one PR:

### Balance fixes (closes #54)

Full equipment audit revealed 9 items with duplicated stats, regressions, or purchasable items weaker than free boss drops:

| Item | Change | Reason |
|---|---|---|
| Void Conduit | 4x → 7x combat | 100M essence sink was equal to a zone-6 boss drop |
| Void Edge | 2.75x → 3.25x combat | Purchasable was weaker than free Celestial Blade (3x) |
| Astral Robe | 2.25x → 2.75x gold | Boss drop was weaker than purchasable Titan's Aegis (2.5x) |
| Philosopher's Stone | 2x → 2.25x click | Duplicated Frost Crystal's click multiplier |
| Eternal Flame | 1.15x → 1.25x gold | Gold regressed vs Philosopher's Stone (1.25x) |
| Celestial Focus | 2.5x → 3x click | 20M essence sink was weaker than free Angel's Halo (2.75x click + 1.3x gold) |
| Abyssal Tome | 3x → 3.75x gold | 50M essence sink was equal to free Heaven's Mantle (3x) |
| Crystal Matrix | 4x → 4.75x gold | 20M crystal sink was equal to free Sinslayer Aegis (4x) |
| Infernal Gem | 3.5x → 4x click | 5M crystal sink was identical to free Prism Eye |

### Equipment sorting (closes #55)

Equipment cards within each slot now render in ascending order of combined bonus power — the sum of all multiplier bonuses — so stronger items always appear further down the list. Hybrid items such as Volcanic Plate sort correctly without needing a per-slot primary stat.

## Test plan

- [ ] All purchasable weapons/armour/trinkets now exceed the stats of the highest free boss drop at their tier
- [ ] No duplicate stat values between adjacent items in the same progression track
- [ ] Equipment cards within each slot render weakest → strongest
- [ ] Hybrid multi-stat items sort sensibly alongside single-stat items
- [ ] Full pipeline green (lint + build + tests at 100% coverage)

✨ This PR was created with help from Hikari~ 🌸

Reviewed-on: #69
Co-authored-by: Hikari <hikari@nhcarrigan.com>
Co-committed-by: Hikari <hikari@nhcarrigan.com>
2026-03-19 08:51:08 -07:00
hikari cfcf763ce3 fix: use server-computed endsAt for exploration timer to prevent clock drift (#68)
Security Scan and Upload / Security & DefectDojo Upload (push) Successful in 1m4s
CI / Lint, Build & Test (push) Successful in 1m8s
## Summary

- Exploration timers showed more time than the area's stated duration when the server clock was ahead of the client's
- The timer was derived from `startedAt = endsAt - durationMs`, then computed as `durationSeconds - (clientNow - startedAt) / 1000` — any server/client clock skew directly inflated the result
- Now stores `endsAt` (the server-computed completion timestamp) directly in `ExplorationAreaState` and computes the timer as `(endsAt - Date.now()) / 1000`, which is immune to clock drift
- Old saves without `endsAt` fall back gracefully to the previous `startedAt`-based calculation

## Test plan

- [ ] Start a new exploration — timer should show exactly the area's stated duration (no more "1h area shows 1h15m")
- [ ] Refresh the page mid-exploration — timer should resume from the correct remaining time (using server-anchored `endsAt`)
- [ ] Old saves with `startedAt` but no `endsAt` should still display a timer via the fallback path

Closes #53

✨ This PR was created with help from Hikari~ 🌸

Reviewed-on: #68
Co-authored-by: Hikari <hikari@nhcarrigan.com>
Co-committed-by: Hikari <hikari@nhcarrigan.com>
2026-03-18 17:09:48 -07:00
hikari aede55a13d fix: preserve runestone bounty flag for legacy defeated bosses (#67)
Security Scan and Upload / Security & DefectDojo Upload (push) Successful in 1m4s
CI / Lint, Build & Test (push) Successful in 1m9s
## Summary

- Bosses defeated before `bountyRunestonesClaimed` was introduced had `status: "defeated"` but the field `undefined`
- After prestige, the preservation check (`=== true`) missed these bosses, so the first-kill bounty was re-awarded on the next run
- Now also treats `status === "defeated"` as proof the bounty was already earned, covering the migration case

## Test plan

- [ ] Existing test: `preserves bountyRunestonesClaimed flag on bosses across prestige` — still passes
- [ ] New test: `sets bountyRunestonesClaimed on bosses defeated before the flag was introduced` — covers the legacy save migration path
- [ ] Full coverage maintained at 100%

Closes #52

✨ This PR was created with help from Hikari~ 🌸

Reviewed-on: #67
Co-authored-by: Hikari <hikari@nhcarrigan.com>
Co-committed-by: Hikari <hikari@nhcarrigan.com>
2026-03-18 13:50:20 -07:00
hikari 744cbf121f fix: preserve autoQuest and autoBoss settings across prestige (#66)
Security Scan and Upload / Security & DefectDojo Upload (push) Successful in 1m5s
CI / Lint, Build & Test (push) Successful in 1m9s
## Summary

- `buildPostPrestigeState` was constructing the post-prestige `GameState` from `initialGameState`, which hard-codes `autoQuest` and `autoBoss` to `false`
- Neither flag was being carried forward, so both automation settings silently reset after every prestige
- Now both values are explicitly preserved from `currentState` (with `?? false` fallback for safety)

Closes #51

✨ This issue was created with help from Hikari~ 🌸

Reviewed-on: #66
Co-authored-by: Hikari <hikari@nhcarrigan.com>
Co-committed-by: Hikari <hikari@nhcarrigan.com>
2026-03-18 13:26:18 -07:00
hikari 03b6c847b3 feat: debug panel with force unlocks and hard reset (#65)
Security Scan and Upload / Security & DefectDojo Upload (push) Successful in 1m5s
CI / Lint, Build & Test (push) Successful in 1m10s
## Summary
- Adds a new **Debug** tab to the game UI with two self-service tools for players with broken save state
- **Force Unlocks**: scans the player's save and grants any zones, quests, bosses, and exploration areas they've earned but that are still locked — shows a breakdown of what was unlocked (or reports nothing needed fixing)
- **Hard Reset**: wipes progress back to a fresh save (preserving lifetime stats), guarded behind a confirmation modal to prevent accidental clicks

## Files added
- `apps/api/src/routes/debug.ts` — two POST endpoints (`/force-unlocks`, `/hard-reset`)
- `apps/web/src/components/game/debugPanel.tsx` — the Debug tab UI
- `apps/web/src/components/ui/confirmationModal.tsx` — reusable confirmation modal

## Files modified
- `apps/api/src/index.ts` — registers the debug router
- `packages/types/src/interfaces/api.ts` — adds `ForceUnlocksResponse` type
- `packages/types/src/index.ts` — exports the new type
- `apps/web/src/api/client.ts` — adds `forceUnlocks()` and `debugHardReset()` API calls
- `apps/web/src/context/gameContext.tsx` — wires both functions into game context
- `apps/web/src/components/game/gameLayout.tsx` — adds the Debug tab
- `apps/web/src/styles.css` — styles for action buttons, cards, result messages, and confirmation modal

✨ This PR was created with help from Hikari~ 🌸

Reviewed-on: #65
Co-authored-by: Hikari <hikari@nhcarrigan.com>
Co-committed-by: Hikari <hikari@nhcarrigan.com>
2026-03-18 12:37:06 -07:00
hikari 219d299e9f fix: force sync before boss fight and surface challenge errors to UI (#64)
Security Scan and Upload / Security & DefectDojo Upload (push) Successful in 1m2s
CI / Lint, Build & Test (push) Successful in 1m8s
Closes #50

## Summary
- Calls `forceSync()` before every boss challenge so the server always fights against the player's live state (equipped items, upgrades, etc.) rather than a potentially stale snapshot
- Adds a `bossError` state that captures and displays error messages from failed manual boss challenges in the boss panel, matching the existing `autoBossError` display pattern

✨ This PR was created with help from Hikari~ 🌸

Reviewed-on: #64
Co-authored-by: Hikari <hikari@nhcarrigan.com>
Co-committed-by: Hikari <hikari@nhcarrigan.com>
2026-03-18 11:26:12 -07:00
minori 9e5b8ed972 deps: update typescript to 5.9.3 (#32)
CI / Lint, Build & Test (push) Successful in 1m13s
Security Scan and Upload / Security & DefectDojo Upload (push) Successful in 1m12s
## Dependency Update

Updates **typescript** from `5.8.2` to `5.9.3`.

### Type
devDependencies

### Changelog
## Changelog

### v5.9.3

Note: this tag was recreated to point at the correct commit. The npm package contained the correct content.

For release notes, check out the [release announcement](https://devblogs.microsoft.com/typescript/announcing-typescript-5-9/)

* [fixed issues query for Typescript 5.9.0 (Beta)](https://github.com/Microsoft/TypeScript/issues?utf8=%E2%9C%93&q=milestone%3A%22TypeScript+5.9.0%22+is%3Aclosed+).
* [fixed issues query for Typescript 5.9.1 (RC)](https://github.com/Microsoft/TypeScript/issues?utf8=%E2%9C%93&q=milestone%3A%22TypeScript+5.9.1%22+is%3Aclosed+).
* *No specific changes for TypeScript 5.9.2 (Stable)*
* [fixed issues query for Typescript 5.9.3 (Stable)](https://github.com/Microsoft/TypeScript/issues?utf8=%E2%9C%93&q=milestone%3A%22TypeScript+5.9.3%22+is%3Aclosed+).

Downloads are available on:
* [npm](https://www.npmjs.com/package/typescript)

### v5.9.2

Note: this tag was recreated to point at the correct commit. The npm package contained the correct content.

For release notes, check out the [release announcement](https://devblogs.microsoft.com/typescript/announcing-typescript-5-9/)

* [fixed issues query for Typescript 5.9.0 (Beta)](https://github.com/Microsoft/TypeScript/issues?utf8=%E2%9C%93&q=milestone%3A%22TypeScript+5.9.0%22+is%3Aclosed+).
* [fixed issues query for Typescript 5.9.1 (RC)](https://github.com/Microsoft/TypeScript/issues?utf8=%E2%9C%93&q=milestone%3A%22TypeScript+5.9.1%22+is%3Aclosed+).
* *No specific changes for TypeScript 5.9.2 (Stable)*

Downloads are available on:
* [npm](https://www.npmjs.com/package/typescript)

### v5.9-rc

Note: this tag was recreated to point at the correct commit. The npm package contained the correct content.

For release notes, check out the [release announcement](https://devblogs.microsoft.com/typescript/announcing-typescript-5-9-rc/)

* [fixed issues query for Typescript 5.9.0 (Beta)](https://github.com/Microsoft/TypeScript/issues?utf8=%E2%9C%93&q=milestone%3A%22TypeScript+5.9.0%22+is%3Aclosed+).
* [fixed issues query for Typescript 5.9.1 (RC)](https://github.com/Microsoft/TypeScript/issues?utf8=%E2%9C%93&q=milestone%3A%22TypeScript+5.9.1%22+is%3Aclosed+).

Downloads are available on:
* [npm](https://www.npmjs.com/package/typescript)

### v5.9-beta

Note: this tag was recreated to point at the correct commit. The npm package contained the correct content.

For release notes, check out the [release announcement](https://devblogs.microsoft.com/typescript/announcing-typescript-5-9-beta/).

* [fixed issues query for Typescript 5.9.0 (Beta)](https://github.com/Microsoft/TypeScript/issues?utf8=%E2%9C%93&q=milestone%3A%22TypeScript+5.9.0%22+is%3Aclosed+).

Downloads are available on:
* [npm](https://www.npmjs.com/package/typescript)

### v5.8.3

Note: this tag was recreated to point at the correct commit. The npm package contained the correct content.

For release notes, check out the [release announcement](https://devblogs.microsoft.com/typescript/announcing-typescript-5-8/).

* [fixed issues query for Typescript 5.8.0 (Beta)](https://github.com/Microsoft/TypeScript/issues?utf8=%E2%9C%93&q=milestone%3A%22TypeScript+5.8.0%22+is%3Aclosed+).
* [fixed issues query for Typescript 5.8.1 (RC)](https://github.com/Microsoft/TypeScript/issues?utf8=%E2%9C%93&q=milestone%3A%22TypeScript+5.8.1%22+is%3Aclosed+).
* [fixed issues query for Typescript 5.8.2 (Stable)](https://github.com/Microsoft/TypeScript/issues?utf8=%E2%9C%93&q=milestone%3A%22TypeScript+5.8.2%22+is%3Aclosed+).
* [fixed issues query for Typescript 5.8.3 (Stable)](https://github.com/Microsoft/TypeScript/issues?utf8=%E2%9C%93&q=milestone%3A%22TypeScript+5.8.3%22+is%3Aclosed+).

Downloads are available on:
* [npm](https://www.npmjs.com/package/typescript)

---
✨ This PR was created by Minori, your friendly dependency updater! 🌸

Reviewed-on: #32
Co-authored-by: Minori <minori@nhcarrigan.com>
Co-committed-by: Minori <minori@nhcarrigan.com>
2026-03-18 11:21:07 -07:00
naomi a20cf3ef87 release: v0.1.2
Security Scan and Upload / Security & DefectDojo Upload (push) Successful in 1m4s
CI / Lint, Build & Test (push) Successful in 1m10s
2026-03-09 22:26:15 -07:00
hikari 9860a2cb1f feat: persist crafting zone selection in sessionStorage (#49)
Security Scan and Upload / Security & DefectDojo Upload (push) Successful in 1m4s
CI / Lint, Build & Test (push) Successful in 1m8s
## Summary

- Applies the same sticky-zone pattern from #48 to the crafting panel (`elysium_craft_zone` key in sessionStorage)
- Introduces a `handleZoneSelect` wrapper so sessionStorage is updated alongside React state on every zone change
- Gracefully falls back to `verdant_vale` if no stored value exists

## Test plan

- [x] Lint — zero errors, zero warnings
- [x] Build — all packages build cleanly
- [ ] Manual: select a non-default zone in the crafting panel, navigate away and back — zone should still be selected
- [ ] Manual: log out and back in — zone should reset to Verdant Vale

✨ This PR was created with help from Hikari~ 🌸

Reviewed-on: #49
Co-authored-by: Hikari <hikari@nhcarrigan.com>
Co-committed-by: Hikari <hikari@nhcarrigan.com>
2026-03-09 22:25:18 -07:00
hikari 404b31bd13 fix: persist UI preferences across navigation and sessions (#48)
CI / Lint, Build & Test (push) Successful in 1m10s
Security Scan and Upload / Security & DefectDojo Upload (push) Successful in 1m11s
## Summary

- **#35** — Adventure multiplier selection is now persisted in `localStorage` (`"elysium_batch_size"`). The chosen batch size is restored automatically on the next visit, with a graceful fallback to `1` for missing or unrecognisable values.
- **#36** — Zone selection in the boss panel and quest panel is now persisted in `sessionStorage` (`"elysium_boss_zone"` / `"elysium_quest_zone"`). The selected zone survives navigation within a session and resets cleanly when the session ends, defaulting to Verdant Vale if no stored value exists.

## Test plan

- [x] Lint — zero errors, zero warnings
- [x] Build — all packages build cleanly
- [x] Tests — 415 tests passing, 100% coverage across all packages
- [ ] Manual: select a non-default batch size, refresh the page — multiplier should be restored
- [ ] Manual: switch to a non-default zone in the boss panel, navigate away and back — zone should still be selected
- [ ] Manual: repeat for the quest panel
- [ ] Manual: log out and back in — zone selection should reset to Verdant Vale

✨ This PR was created with help from Hikari~ 🌸

Reviewed-on: #48
Co-authored-by: Hikari <hikari@nhcarrigan.com>
Co-committed-by: Hikari <hikari@nhcarrigan.com>
2026-03-09 22:17:12 -07:00
hikari d0790890ee fix: preserve all-time stats, achievements, and boss first-kill across prestige (#47)
Security Scan and Upload / Security & DefectDojo Upload (push) Successful in 1m4s
CI / Lint, Build & Test (push) Successful in 1m8s
Resolves #37, resolves #38, and resolves #39 — three related bugs where prestige incorrectly reset data that should survive all prestige resets.

## Changes

### fix: preserve lifetime player stats across prestige (#37)
After prestige, `GameState.player.lifetime*` fields were stale — they reflected values from *before* the current run. The Prisma Player record was incremented correctly, but the GameState JSON saved to the DB had old values, so the UI showed wrong all-time totals on reload.

`buildPostPrestigeState` now computes the run-stat contributions (bosses defeated, quests completed, adventurers recruited, achievements unlocked, gold earned, clicks) and folds them into the fresh player object before writing the prestige state.

### fix: preserve achievements across prestige (#38)
`buildPostPrestigeState` was reconstructing achievements from `defaultAchievements` (via `initialGameState`), resetting all unlocked achievements on every prestige. Achievements are now carried forward from `currentState.achievements` instead.

### fix: preserve boss first-kill state across prestige (#39)
Added `bountyRunestonesClaimed?: boolean` to the `Boss` type. The boss challenge route now:
- Only awards the first-kill bounty runestones if `bountyRunestonesClaimed !== true`
- Sets `bountyRunestonesClaimed = true` on first defeat

`buildPostPrestigeState` maps the fresh boss list and carries the `bountyRunestonesClaimed` flag forward from the current state, so the bounty is never re-awarded in subsequent prestige runs. The boss panel badge is also hidden for bosses whose bounty is already claimed.

## Test Coverage
All three fixes include new tests covering the new behaviours. API coverage remains at 100%.

✨ This PR was created with help from Hikari~ 🌸

Reviewed-on: #47
Co-authored-by: Hikari <hikari@nhcarrigan.com>
Co-committed-by: Hikari <hikari@nhcarrigan.com>
2026-03-09 21:53:58 -07:00
hikari 4d7e624358 fix: turn off auto-boss/auto-quest on failure and surface status (#46)
Security Scan and Upload / Security & DefectDojo Upload (push) Successful in 1m3s
CI / Lint, Build & Test (push) Successful in 1m7s
## Summary

- Auto-boss now turns itself **off** when a boss fight is **lost**, so the player can reassess rather than the system silently looping. A "šŸ¤– Last fight: [Boss] — āŒ Lost" status line appears in the boss panel.
- Auto-boss also turns off (with an āš ļø error message) when the API call fails outright (e.g. party has no adventurers), replacing the previous behaviour of silently hammering the API every animation frame.
- Auto-quest now turns itself **off** whenever a quest fails the random-chance check, detected inside the tick's `setState` callback immediately after `applyTick`.
- `autoBoss: false` and `autoQuest: false` are now part of `initialGameState`, so these fields persist through save/load cycles from the very first session — preventing a race window where the boss-route DB write could strip them before the first auto-save.
- `toggleAutoBoss` clears both `autoBossLastResult` and `autoBossError` on each toggle so the panel always reflects the current session cleanly.

## Test plan

- [x] `pnpm lint` — 0 errors, 0 warnings
- [x] `pnpm build` — all packages clean
- [x] `pnpm test` — 100% coverage maintained across the board

Closes #40

✨ This issue was created with help from Hikari~ 🌸

Reviewed-on: #46
Co-authored-by: Hikari <hikari@nhcarrigan.com>
Co-committed-by: Hikari <hikari@nhcarrigan.com>
2026-03-09 21:12:03 -07:00
hikari ac94f67797 fix: send webhook milestone notifications silently (#45)
CI / Lint, Build & Test (push) Successful in 1m8s
Security Scan and Upload / Security & DefectDojo Upload (push) Successful in 1m8s
## Summary

- Adds `flags: 4096` (`MessageFlags.SUPPRESS_NOTIFICATIONS`) to the Discord webhook payload in `postMilestoneWebhook`
- Milestone announcements (prestige, transcendence, apotheosis) will now appear in the channel without triggering desktop or mobile push notifications
- Defines the magic number as a documented `suppressNotifications` constant for self-documentation
- Updates the webhook test to assert `flags: 4096` is present in the outgoing payload

Closes #41

## Test plan

- [ ] Lint passes: `pnpm lint`
- [ ] Build passes: `pnpm build`
- [ ] Tests pass with 100% coverage: `pnpm test`
- [ ] Trigger a prestige/transcendence/apotheosis in-game and verify the Discord webhook message arrives without pinging anyone

✨ This issue was created with help from Hikari~ 🌸

Reviewed-on: #45
Co-authored-by: Hikari <hikari@nhcarrigan.com>
Co-committed-by: Hikari <hikari@nhcarrigan.com>
2026-03-09 20:24:13 -07:00
hikari a36c8e72a5 feat: error handling, logging, analytics, OG tags, and sticky sidebar (#44)
Security Scan and Upload / Security & DefectDojo Upload (push) Successful in 1m3s
CI / Lint, Build & Test (push) Successful in 1m8s
## Summary

- Add comprehensive try/catch error handling across all API routes, middleware, and the Hono global error handler, piping every unhandled error to the `@nhcarrigan/logger` service to prevent silent crashes and unhandled Promise rejections
- Add a `logError` utility on the frontend that forwards errors through the overridden `console.error` to the backend telemetry endpoint; apply it to every silent `catch {}` block in the game context, sound, notification, and clipboard utilities, and wrap the React tree in an `ErrorBoundary`
- Add Plausible analytics, Open Graph + Twitter Card meta tags, Tree-Nation widget, and Google Ads to `index.html`
- Make the game sidebar sticky with a `--resource-bar-height` CSS custom property offset so it stays viewport-height without overlapping the resource bar; reset sticky behaviour in the mobile responsive override

## Test plan

- [ ] Lint passes: `pnpm lint`
- [ ] Build passes: `pnpm build`
- [ ] Verify errors thrown in API routes appear in the logger service rather than crashing the process
- [ ] Verify frontend errors appear in the `/api/fe/error` backend log
- [ ] Verify Open Graph tags render correctly when sharing the URL
- [ ] Verify Plausible analytics fires on page load
- [ ] Verify Tree-Nation badge renders in the sidebar
- [ ] Verify sidebar stays fixed while the main content scrolls on desktop
- [ ] Verify mobile layout is unaffected

✨ This issue was created with help from Hikari~ 🌸

Reviewed-on: #44
Co-authored-by: Hikari <hikari@nhcarrigan.com>
Co-committed-by: Hikari <hikari@nhcarrigan.com>
2026-03-09 19:54:42 -07:00
hikari 11e97325cb feat: integrate art assets across all game panels (#43)
Security Scan and Upload / Security & DefectDojo Upload (push) Successful in 1m2s
CI / Lint, Build & Test (push) Successful in 1m6s
## Summary

- Adds `apps/web/src/utils/cdn.ts` with a `cdnImage(folder, id)` helper that builds URLs from `https://cdn.nhcarrigan.com/elysium/`
- Wires CDN art into all 13 game panels (bosses, quests, adventurers, companions, equipment, upgrades, prestige, transcendence, achievements, explorations, crafting, story, codex)
- Zone selector tabs now display 16:9 zone art thumbnails in place of emoji icons
- Adds a fixed background image at 15% opacity via `body::before`
- Documents the art generation and CDN upload process in `CLAUDE.md` for future expansions

Resolves #15

✨ This PR was created with help from Hikari~ 🌸

Reviewed-on: #43
Co-authored-by: Hikari <hikari@nhcarrigan.com>
Co-committed-by: Hikari <hikari@nhcarrigan.com>
2026-03-09 16:21:44 -07:00
hikari 7a1c57be9a feat: render changelog as markdown in about panel (#33)
Security Scan and Upload / Security & DefectDojo Upload (push) Successful in 1m2s
CI / Lint, Build & Test (push) Successful in 1m6s
## Summary

- Installs `react-markdown@10.1.0` in `apps/web`
- Replaces the `<pre>` tag in the changelog section with the `<Markdown>` component for proper rendering
- Updates CSS to style markdown elements (paragraphs, lists, headings, code blocks, links, bold text)

Closes #31

✨ This PR was created with help from Hikari~ 🌸

Reviewed-on: #33
Co-authored-by: Hikari <hikari@nhcarrigan.com>
Co-committed-by: Hikari <hikari@nhcarrigan.com>
2026-03-09 09:35:30 -07:00
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
191 changed files with 61184 additions and 0 deletions
+68
View File
@@ -0,0 +1,68 @@
name: CI
on:
push:
branches:
- main
pull_request:
branches:
- main
jobs:
ci:
name: Lint, Build & Test
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Check dependency pins
uses: naomi-lgbt/dependency-pin-check@main
with:
dev-dependencies: true
peer-dependencies: true
optional-dependencies: true
language: javascript
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: "22"
- name: Set up pnpm
uses: pnpm/action-setup@v4
with:
version: "10"
- name: Install dependencies
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)
run: pnpm --filter @elysium/types lint
- name: Lint (API)
run: pnpm --filter @elysium/api lint
- name: Lint (web)
run: pnpm --filter @elysium/web lint
- name: Build (API)
run: pnpm --filter @elysium/api build
- name: Build (web)
run: pnpm --filter @elysium/web build
- name: Test (types package)
run: pnpm --filter @elysium/types test
- name: Test (API)
run: pnpm --filter @elysium/api test
- name: Test (web)
run: pnpm --filter @elysium/web test
+6
View File
@@ -0,0 +1,6 @@
node_modules/
prod/
dist/
.env
*.env.local
coverage/
+47
View File
@@ -0,0 +1,47 @@
# 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`
## Art Assets
Game art is generated via the Gemini API (`gemini-3-pro-image-preview`, ~$0.134/image at 1K resolution) and hosted on the CDN at `https://cdn.nhcarrigan.com/elysium/`.
### Process
1. Generate images with `curl` to `https://generativelanguage.googleapis.com/v1beta/models/gemini-3-pro-image-preview:generateContent?key=<API_KEY>`, requesting soft-shaded anime style
2. Save responses to `/home/naomi/code/naomi/elysium/img/<category>/<id>.jpg`
3. Upload to R2 with the AWS CLI — credentials are in the global `~/.claude/CLAUDE.md` (never commit them here)
4. Delete the local `img/` directory before committing (images live on CDN only)
### CDN URL Helper
`apps/web/src/utils/cdn.ts` exports `cdnImage(folder, id)` → `https://cdn.nhcarrigan.com/elysium/<folder>/<id>.jpg`
### Directory → Category Mapping
| Game entity | CDN folder |
|---|---|
| Zones | `zones` |
| Bosses | `bosses` |
| Quests | `quests` |
| Adventurers | `adventurers` |
| Companions | `companions` |
| Equipment | `equipment` |
| Upgrades | `upgrades` |
| Prestige upgrades | `prestige-upgrades` |
| Transcendence upgrades | `transcendence-upgrades` |
| Achievements | `achievements` |
| Explorations | `explorations` |
| Materials | `materials` |
| Recipes | `recipes` |
| Story chapter banners | `story-chapters` |
### API Rate Limits
- 250 images/day per API key — use a second key if quota is hit
- Free-tier keys cannot use `gemini-3-pro-image-preview`; key must be on a billing-linked project
## 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.
+3
View File
@@ -0,0 +1,3 @@
import config from "@nhcarrigan/eslint-config";
export default [...config];
+33
View File
@@ -0,0 +1,33 @@
{
"name": "@elysium/api",
"version": "0.5.0",
"private": true,
"type": "module",
"main": "./prod/src/index.js",
"scripts": {
"build": "prisma generate && tsc -p tsconfig.json",
"db:push": "prisma db push",
"dev": "op run --env-file=./prod.env -- tsx watch src/index.ts",
"lint": "eslint --max-warnings 0 src",
"start": "op run --env-file=./prod.env -- node prod/src/index.js",
"test": "vitest run --coverage"
},
"dependencies": {
"@elysium/types": "workspace:*",
"@hono/node-server": "1.19.12",
"@nhcarrigan/logger": "1.1.1",
"@prisma/client": "6.5.0",
"hono": "4.12.11",
"prisma": "6.5.0"
},
"devDependencies": {
"@nhcarrigan/eslint-config": "5.2.0",
"@nhcarrigan/typescript-config": "4.0.0",
"@types/node": "25.5.2",
"@vitest/coverage-v8": "3.0.8",
"eslint": "9.22.0",
"tsx": "4.21.0",
"typescript": "5.8.2",
"vitest": "3.0.8"
}
}
+47
View File
@@ -0,0 +1,47 @@
generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "mongodb"
url = env("DATABASE_URL")
}
model Player {
id String @id @default(auto()) @map("_id") @db.ObjectId
discordId String @unique
username String
discriminator String
avatar String?
characterName String @default("")
pronouns String @default("")
characterRace String @default("")
characterClass String @default("")
bio String @default("")
guildName String @default("")
guildDescription String @default("")
profileSettings Json?
unlockedTitles Json?
activeTitle String @default("")
createdAt Float
lastSavedAt Float
totalGoldEarned 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)
inGuild Boolean @default(false)
}
model GameState {
id String @id @default(auto()) @map("_id") @db.ObjectId
discordId String @unique
state Json
updatedAt Float
}
+9
View File
@@ -0,0 +1,9 @@
DISCORD_CLIENT_SECRET="op://Environment Variables - Naomi/Elysium/discord client secret"
JWT_SECRET="op://Environment Variables - Naomi/Elysium/jwt secret"
DATABASE_URL="op://Environment Variables - Naomi/Elysium/mongo url"
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"
LOG_TOKEN="op://Environment Variables - Naomi/Alert Server/api_auth"
+456
View File
@@ -0,0 +1,456 @@
/**
* @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";
export const defaultAchievements: Array<Achievement> = [
// Click milestones
{
condition: { amount: 1, type: "totalClicks" },
description: "Click the Guild Hall for the first time.",
icon: "šŸ‘†",
id: "first_click",
name: "First Strike",
reward: { crystals: 5 },
unlockedAt: null,
},
{
condition: { amount: 100, type: "totalClicks" },
description: "Click the Guild Hall 100 times.",
icon: "šŸ–±ļø",
id: "click_enthusiast",
name: "Click Enthusiast",
reward: { crystals: 25 },
unlockedAt: null,
},
{
condition: { amount: 1000, type: "totalClicks" },
description: "Click the Guild Hall 1,000 times.",
icon: "⚔",
id: "click_master",
name: "Click Master",
reward: { crystals: 100 },
unlockedAt: null,
},
{
condition: { amount: 10_000, type: "totalClicks" },
description: "Click the Guild Hall 10,000 times.",
icon: "šŸŒ©ļø",
id: "click_legend",
name: "Click Legend",
reward: { crystals: 300 },
unlockedAt: null,
},
// Gold milestones
{
condition: { amount: 100, type: "totalGoldEarned" },
description: "Earn your first 100 gold.",
icon: "šŸŖ™",
id: "first_gold",
name: "First Gold",
reward: { crystals: 5 },
unlockedAt: null,
},
{
condition: { amount: 10_000, type: "totalGoldEarned" },
description: "Earn 10,000 gold in total.",
icon: "šŸ’°",
id: "wealthy",
name: "Wealthy",
reward: { crystals: 25 },
unlockedAt: null,
},
{
condition: { amount: 1_000_000, type: "totalGoldEarned" },
description: "Earn 1,000,000 gold in total.",
icon: "šŸ‘‘",
id: "rich",
name: "Rich",
reward: { crystals: 100 },
unlockedAt: null,
},
{
condition: { amount: 1_000_000_000, type: "totalGoldEarned" },
description: "Earn 1,000,000,000 gold in total.",
icon: "šŸ¦",
id: "billionaire",
name: "Billionaire",
reward: { crystals: 500 },
unlockedAt: null,
},
{
condition: { amount: 1_000_000_000_000, type: "totalGoldEarned" },
description: "Earn 1,000,000,000,000 gold in total.",
icon: "šŸ’Ž",
id: "trillionaire",
name: "Trillionaire",
reward: { crystals: 2000 },
unlockedAt: null,
},
// Quest milestones
{
condition: { amount: 1, type: "questsCompleted" },
description: "Complete your first quest.",
icon: "šŸ“œ",
id: "first_quest",
name: "Adventurous Spirit",
reward: { crystals: 10 },
unlockedAt: null,
},
{
condition: { amount: 5, type: "questsCompleted" },
description: "Complete 5 quests.",
icon: "šŸ“š",
id: "quest_veteran",
name: "Quest Veteran",
reward: { crystals: 50 },
unlockedAt: null,
},
{
condition: { amount: 15, type: "questsCompleted" },
description: "Complete 15 quests.",
icon: "šŸ—ŗļø",
id: "quest_master",
name: "Quest Master",
reward: { crystals: 200 },
unlockedAt: null,
},
// Boss milestones
{
condition: { amount: 1, type: "bossesDefeated" },
description: "Defeat your first boss.",
icon: "āš”ļø",
id: "boss_slayer",
name: "Boss Slayer",
reward: { crystals: 25 },
unlockedAt: null,
},
{
condition: { amount: 5, type: "bossesDefeated" },
description: "Defeat 5 bosses.",
icon: "šŸ—”ļø",
id: "boss_veteran",
name: "Boss Veteran",
reward: { crystals: 150 },
unlockedAt: null,
},
{
condition: { amount: 10, type: "bossesDefeated" },
description: "Defeat 10 bosses.",
icon: "šŸ†",
id: "legendary_hunter",
name: "Legendary Hunter",
reward: { crystals: 500 },
unlockedAt: null,
},
{
condition: { amount: 18, type: "bossesDefeated" },
description: "Defeat the 18 bosses of the mortal realms.",
icon: "🌟",
id: "devourer_slayer",
name: "World Saver",
reward: { crystals: 2000 },
unlockedAt: null,
},
// Adventurer milestones
{
condition: { amount: 50, type: "adventurerTotal" },
description: "Recruit a total of 50 adventurers.",
icon: "šŸ°",
id: "guild_master",
name: "Guild Master",
reward: { crystals: 50 },
unlockedAt: null,
},
{
condition: { amount: 500, type: "adventurerTotal" },
description: "Recruit a total of 500 adventurers.",
icon: "šŸ›”ļø",
id: "army_commander",
name: "Army Commander",
reward: { crystals: 200 },
unlockedAt: null,
},
{
condition: { amount: 5000, type: "adventurerTotal" },
description: "Recruit a total of 5,000 adventurers.",
icon: "āšœļø",
id: "army_legend",
name: "Legendary Commander",
reward: { crystals: 750 },
unlockedAt: null,
},
// Prestige milestones
{
condition: { amount: 1, type: "prestigeCount" },
description: "Prestige for the first time.",
icon: "⭐",
id: "first_prestige",
name: "Born Again",
reward: { crystals: 100 },
unlockedAt: null,
},
// Collection milestones
{
condition: { amount: 4, type: "equipmentOwned" },
description: "Acquire your first piece of boss-dropped equipment.",
icon: "šŸŽ’",
id: "collector",
name: "Collector",
reward: { crystals: 10 },
unlockedAt: null,
},
{
condition: { amount: 12, type: "equipmentOwned" },
description: "Own 12 pieces of equipment.",
icon: "šŸ—ƒļø",
id: "arsenal",
name: "Arsenal",
reward: { crystals: 200 },
unlockedAt: null,
},
{
condition: { amount: 25, type: "equipmentOwned" },
description: "Own 25 pieces of equipment.",
icon: "āš”ļø",
id: "well_armed",
name: "Well Armed",
reward: { crystals: 1000 },
unlockedAt: null,
},
{
condition: { amount: 78, type: "equipmentOwned" },
description: "Own all 78 pieces of equipment.",
icon: "šŸ›”ļø",
id: "fully_equipped",
name: "Fully Equipped",
reward: { crystals: 10_000 },
unlockedAt: null,
},
// Higher click milestones
{
condition: { amount: 100_000, type: "totalClicks" },
description: "Click the Guild Hall 100,000 times.",
icon: "šŸ’„",
id: "click_obsessed",
name: "Click Obsessed",
reward: { crystals: 1000 },
unlockedAt: null,
},
{
condition: { amount: 1_000_000, type: "totalClicks" },
description: "Click the Guild Hall 1,000,000 times.",
icon: "ā˜„ļø",
id: "click_deity",
name: "Click Deity",
reward: { crystals: 15_000 },
unlockedAt: null,
},
// Endgame gold milestones
{
condition: { amount: 1e15, type: "totalGoldEarned" },
description: "Earn 1 quadrillion gold in total.",
icon: "✨",
id: "quadrillionaire",
name: "Quadrillionaire",
reward: { crystals: 10_000 },
unlockedAt: null,
},
{
condition: { amount: 1e18, type: "totalGoldEarned" },
description: "Earn 1 quintillion gold in total.",
icon: "šŸŒ€",
id: "void_hoarder",
name: "Void Hoarder",
reward: { crystals: 50_000 },
unlockedAt: null,
},
{
condition: { amount: 1e30, type: "totalGoldEarned" },
description: "Earn 1 nonillion gold in total.",
icon: "🌌",
id: "cosmic_wealthy",
name: "Cosmic Wealthy",
reward: { crystals: 100_000 },
unlockedAt: null,
},
{
condition: { amount: 1e60, type: "totalGoldEarned" },
description: "Earn a vigintillion gold in total.",
icon: "ā™¾ļø",
id: "infinite_hoarder",
name: "Infinite Hoarder",
reward: { crystals: 250_000 },
unlockedAt: null,
},
{
condition: { amount: 1e90, type: "totalGoldEarned" },
description: "Earn a trigintillion gold in total.",
icon: "šŸ”®",
id: "omniversal_tycoon",
name: "Omniversal Tycoon",
reward: { crystals: 1_000_000 },
unlockedAt: null,
},
// Higher quest milestones
{
condition: { amount: 30, type: "questsCompleted" },
description: "Complete 30 quests.",
icon: "šŸ…",
id: "quest_champion",
name: "Quest Champion",
reward: { crystals: 1000 },
unlockedAt: null,
},
{
condition: { amount: 50, type: "questsCompleted" },
description: "Complete 50 quests.",
icon: "šŸŽ–ļø",
id: "quest_grandmaster",
name: "Quest Grandmaster",
reward: { crystals: 5000 },
unlockedAt: null,
},
{
condition: { amount: 75, type: "questsCompleted" },
description: "Complete 75 quests.",
icon: "🌠",
id: "quest_hero",
name: "Quest Hero",
reward: { crystals: 10_000 },
unlockedAt: null,
},
{
condition: { amount: 100, type: "questsCompleted" },
description: "Complete 100 quests.",
icon: "šŸ’«",
id: "quest_legend",
name: "Quest Legend",
reward: { crystals: 15_000 },
unlockedAt: null,
},
{
condition: { amount: 122, type: "questsCompleted" },
description: "Complete all 122 quests across the known multiverse.",
icon: "🌌",
id: "quest_eternal",
name: "Quest Eternal",
reward: { crystals: 25_000 },
unlockedAt: null,
},
// Higher boss milestones
{
condition: { amount: 20, type: "bossesDefeated" },
description: "Defeat 20 bosses.",
icon: "🦁",
id: "boss_champion",
name: "Champion of the Realm",
reward: { crystals: 1000 },
unlockedAt: null,
},
{
condition: { amount: 30, type: "bossesDefeated" },
description: "Defeat 30 bosses.",
icon: "šŸ”±",
id: "boss_grandmaster",
name: "Grandmaster Hunter",
reward: { crystals: 5000 },
unlockedAt: null,
},
{
condition: { amount: 50, type: "bossesDefeated" },
description: "Defeat 50 bosses.",
icon: "⚔",
id: "boss_legend",
name: "Legendary Vanquisher",
reward: { crystals: 15_000 },
unlockedAt: null,
},
{
condition: { amount: 72, type: "bossesDefeated" },
description: "Defeat all 72 bosses across every plane of existence.",
icon: "šŸ’€",
id: "boss_eternal",
name: "Eternal Vanquisher",
reward: { crystals: 50_000 },
unlockedAt: null,
},
// Higher adventurer milestones
{
condition: { amount: 50_000, type: "adventurerTotal" },
description: "Recruit a total of 50,000 adventurers.",
icon: "⚔",
id: "army_titan",
name: "Titan Commander",
reward: { crystals: 5000 },
unlockedAt: null,
},
// Higher prestige milestones
{
condition: { amount: 5, type: "prestigeCount" },
description: "Prestige 5 times.",
icon: "🌟",
id: "prestige_veteran",
name: "Veteran of Ages",
reward: { crystals: 1000 },
unlockedAt: null,
},
{
condition: { amount: 10, type: "prestigeCount" },
description: "Prestige 10 times.",
icon: "šŸ’«",
id: "prestige_master",
name: "Master of Cycles",
reward: { crystals: 15_000 },
unlockedAt: null,
},
{
condition: { amount: 25, type: "prestigeCount" },
description: "Prestige 25 times.",
icon: "🌠",
id: "prestige_legend",
name: "Legend of Eternity",
reward: { crystals: 75_000 },
unlockedAt: null,
},
{
condition: { amount: 50, type: "prestigeCount" },
description: "Prestige 50 times.",
icon: "✨",
id: "prestige_transcendent",
name: "Transcendent",
reward: { runestones: 100 },
unlockedAt: null,
},
{
condition: { amount: 100, type: "prestigeCount" },
description: "Prestige 100 times.",
icon: "šŸ’Ž",
id: "prestige_eternal",
name: "Eternal Looper",
reward: { runestones: 500 },
unlockedAt: null,
},
{
condition: { amount: 150, type: "prestigeCount" },
description: "Prestige 150 times.",
icon: "🌟",
id: "prestige_immortal",
name: "Immortal Cycler",
reward: { runestones: 2000 },
unlockedAt: null,
},
{
condition: { amount: 200, type: "prestigeCount" },
description: "Prestige 200 times.",
icon: "šŸ‘‘",
id: "prestige_absolute",
name: "Absolute Champion",
reward: { runestones: 10_000 },
unlockedAt: null,
},
];
+407
View File
@@ -0,0 +1,407 @@
/**
* @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";
export const defaultAdventurers: Array<Adventurer> = [
{
baseCost: 10,
class: "warrior",
combatPower: 1,
count: 0,
essencePerSecond: 0,
goldPerSecond: 0.1,
id: "peasant",
level: 1,
name: "Peasant",
unlocked: true,
},
{
baseCost: 65,
class: "warrior",
combatPower: 3,
count: 0,
essencePerSecond: 0,
goldPerSecond: 0.7,
id: "militia",
level: 2,
name: "Militia",
unlocked: false,
},
{
baseCost: 750,
class: "mage",
combatPower: 8,
count: 0,
essencePerSecond: 0.01,
goldPerSecond: 1.5,
id: "apprentice",
level: 3,
name: "Apprentice Mage",
unlocked: false,
},
{
baseCost: 5000,
class: "rogue",
combatPower: 20,
count: 0,
essencePerSecond: 0.02,
goldPerSecond: 4,
id: "scout",
level: 4,
name: "Scout",
unlocked: false,
},
{
baseCost: 35_000,
class: "cleric",
combatPower: 50,
count: 0,
essencePerSecond: 0.05,
goldPerSecond: 10,
id: "acolyte",
level: 5,
name: "Acolyte",
unlocked: false,
},
{
baseCost: 250_000,
class: "ranger",
combatPower: 120,
count: 0,
essencePerSecond: 0.1,
goldPerSecond: 25,
id: "ranger",
level: 6,
name: "Ranger",
unlocked: false,
},
{
baseCost: 1_750_000,
class: "warrior",
combatPower: 300,
count: 0,
essencePerSecond: 0.2,
goldPerSecond: 75,
id: "knight",
level: 7,
name: "Knight",
unlocked: false,
},
{
baseCost: 12_000_000,
class: "mage",
combatPower: 800,
count: 0,
essencePerSecond: 0.5,
goldPerSecond: 200,
id: "archmage",
level: 8,
name: "Archmage",
unlocked: false,
},
{
baseCost: 85_000_000,
class: "paladin",
combatPower: 2000,
count: 0,
essencePerSecond: 1,
goldPerSecond: 600,
id: "paladin",
level: 9,
name: "Paladin",
unlocked: false,
},
{
baseCost: 600_000_000,
class: "ranger",
combatPower: 6000,
count: 0,
essencePerSecond: 3,
goldPerSecond: 2000,
id: "dragon_rider",
level: 10,
name: "Dragon Rider",
unlocked: false,
},
{
baseCost: 2_850_000_000,
class: "mage",
combatPower: 13_000,
count: 0,
essencePerSecond: 6,
goldPerSecond: 4500,
id: "arcane_scholar",
level: 11,
name: "Arcane Scholar",
unlocked: false,
},
{
baseCost: 13_500_000_000,
class: "rogue",
combatPower: 28_000,
count: 0,
essencePerSecond: 11,
goldPerSecond: 9500,
id: "shadow_assassin",
level: 12,
name: "Shadow Assassin",
unlocked: false,
},
{
baseCost: 64_000_000_000,
class: "paladin",
combatPower: 60_000,
count: 0,
essencePerSecond: 20,
goldPerSecond: 20_000,
id: "dark_templar",
level: 13,
name: "Dark Templar",
unlocked: false,
},
{
baseCost: 300_000_000_000,
class: "rogue",
combatPower: 130_000,
count: 0,
essencePerSecond: 35,
goldPerSecond: 40_000,
id: "void_walker",
level: 14,
name: "Void Walker",
unlocked: false,
},
{
baseCost: 1_800_000_000_000,
class: "paladin",
combatPower: 400_000,
count: 0,
essencePerSecond: 100,
goldPerSecond: 120_000,
id: "celestial_guard",
level: 15,
name: "Celestial Guard",
unlocked: false,
},
{
baseCost: 10_000_000_000_000,
class: "warrior",
combatPower: 1_200_000,
count: 0,
essencePerSecond: 300,
goldPerSecond: 400_000,
id: "divine_champion",
level: 16,
name: "Divine Champion",
unlocked: false,
},
{
baseCost: 70_000_000_000_000,
class: "paladin",
combatPower: 4_000_000,
count: 0,
essencePerSecond: 800,
goldPerSecond: 1_200_000,
id: "seraph_knight",
level: 17,
name: "Seraph Knight",
unlocked: false,
},
{
baseCost: 500_000_000_000_000,
class: "rogue",
combatPower: 12_000_000,
count: 0,
essencePerSecond: 2000,
goldPerSecond: 3_500_000,
id: "abyss_diver",
level: 18,
name: "Abyss Diver",
unlocked: false,
},
{
baseCost: 3_500_000_000_000_000,
class: "warrior",
combatPower: 35_000_000,
count: 0,
essencePerSecond: 5000,
goldPerSecond: 10_000_000,
id: "infernal_warden",
level: 19,
name: "Infernal Warden",
unlocked: false,
},
{
baseCost: 25_000_000_000_000_000,
class: "mage",
combatPower: 100_000_000,
count: 0,
essencePerSecond: 12_000,
goldPerSecond: 30_000_000,
id: "crystal_sage",
level: 20,
name: "Crystal Sage",
unlocked: false,
},
{
baseCost: 175_000_000_000_000_000,
class: "rogue",
combatPower: 300_000_000,
count: 0,
essencePerSecond: 30_000,
goldPerSecond: 90_000_000,
id: "void_sentinel",
level: 21,
name: "Void Sentinel",
unlocked: false,
},
{
baseCost: 1_200_000_000_000_000_000,
class: "warrior",
combatPower: 900_000_000,
count: 0,
essencePerSecond: 80_000,
goldPerSecond: 270_000_000,
id: "eternal_champion",
level: 22,
name: "Eternal Champion",
unlocked: false,
},
{
baseCost: 8_500_000_000_000_000_000,
class: "mage",
combatPower: 2_700_000_000,
count: 0,
essencePerSecond: 220_000,
goldPerSecond: 800_000_000,
id: "aether_weaver",
level: 23,
name: "Aether Weaver",
unlocked: false,
},
{
baseCost: 60_000_000_000_000_000_000,
class: "warrior",
combatPower: 8_000_000_000,
count: 0,
essencePerSecond: 600_000,
goldPerSecond: 2_500_000_000,
id: "titan_warrior",
level: 24,
name: "Titan Warrior",
unlocked: false,
},
{
baseCost: 420_000_000_000_000_000_000,
class: "mage",
combatPower: 24_000_000_000,
count: 0,
essencePerSecond: 1_600_000,
goldPerSecond: 7_500_000_000,
id: "nexus_sage",
level: 25,
name: "Nexus Sage",
unlocked: false,
},
{
baseCost: 3_000_000_000_000_000_000_000,
class: "paladin",
combatPower: 72_000_000_000,
count: 0,
essencePerSecond: 4_500_000,
goldPerSecond: 22_000_000_000,
id: "cosmos_knight",
level: 26,
name: "Cosmos Knight",
unlocked: false,
},
{
baseCost: 21_000_000_000_000_000_000_000,
class: "warrior",
combatPower: 200_000_000_000,
count: 0,
essencePerSecond: 12_000_000,
goldPerSecond: 65_000_000_000,
id: "astral_sovereign",
level: 27,
name: "Astral Sovereign",
unlocked: false,
},
{
baseCost: 150_000_000_000_000_000_000_000,
class: "mage",
combatPower: 600_000_000_000,
count: 0,
essencePerSecond: 35_000_000,
goldPerSecond: 200_000_000_000,
id: "primordial_mage",
level: 28,
name: "Primordial Mage",
unlocked: false,
},
{
baseCost: 1_000_000_000_000_000_000_000_000,
class: "paladin",
combatPower: 1_800_000_000_000,
count: 0,
essencePerSecond: 100_000_000,
goldPerSecond: 600_000_000_000,
id: "reality_warden",
level: 29,
name: "Reality Warden",
unlocked: false,
},
{
baseCost: 7_000_000_000_000_000_000_000_000,
class: "ranger",
combatPower: 5_500_000_000_000,
count: 0,
essencePerSecond: 300_000_000,
goldPerSecond: 1_800_000_000_000,
id: "infinity_ranger",
level: 30,
name: "Infinity Ranger",
unlocked: false,
},
{
baseCost: 50_000_000_000_000_000_000_000_000,
class: "paladin",
combatPower: 16_000_000_000_000,
count: 0,
essencePerSecond: 850_000_000,
goldPerSecond: 5_500_000_000_000,
id: "oblivion_paladin",
level: 31,
name: "Oblivion Paladin",
unlocked: false,
},
{
baseCost: 350_000_000_000_000_000_000_000_000,
class: "rogue",
combatPower: 50_000_000_000_000,
count: 0,
essencePerSecond: 2_500_000_000,
goldPerSecond: 16_000_000_000_000,
id: "transcendent_rogue",
level: 32,
name: "Transcendent Rogue",
unlocked: false,
},
{
baseCost: 2_500_000_000_000_000_000_000_000_000,
class: "warrior",
combatPower: 150_000_000_000_000,
count: 0,
essencePerSecond: 7_000_000_000,
goldPerSecond: 50_000_000_000_000,
id: "omniversal_champion",
level: 33,
name: "Omniversal Champion",
unlocked: false,
},
];
File diff suppressed because it is too large Load Diff
+85
View File
@@ -0,0 +1,85 @@
/**
* @file Game data definitions.
* @copyright nhcarrigan
* @license Naomi's Public License
* @author Naomi Carrigan
*/
import type { DailyChallengeType } from "@elysium/types";
interface DailyChallengeTemplate {
type: DailyChallengeType;
label: string;
target: number;
rewardCrystals: number;
}
export const dailyChallengeTemplates: Array<DailyChallengeTemplate> = [
// Clicks — always requires active play
{ label: "Click 500 times", rewardCrystals: 50, target: 500, type: "clicks" },
{
label: "Click 1,000 times",
rewardCrystals: 100,
target: 1000,
type: "clicks",
},
{
label: "Click 5,000 times",
rewardCrystals: 300,
target: 5000,
type: "clicks",
},
// Crafting — requires materials but no zone/boss progression
{ label: "Craft 1 recipe", rewardCrystals: 75, target: 1, type: "crafting" },
{
label: "Craft 2 recipes",
rewardCrystals: 175,
target: 2,
type: "crafting",
},
{
label: "Craft 3 recipes",
rewardCrystals: 350,
target: 3,
type: "crafting",
},
// Boss defeats — requires active combat
{
label: "Defeat 1 boss",
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
{
label: "Complete 3 quests",
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
{ label: "Prestige once", rewardCrystals: 750, target: 1, type: "prestige" },
];
+933
View File
@@ -0,0 +1,933 @@
/**
* @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 { Equipment } from "@elysium/types";
export const defaultEquipment: Array<Equipment> = [
// ── Weapons ───────────────────────────────────────────────────────────────
{
bonus: { combatMultiplier: 1.1 },
description: "A battered blade, but still sharp enough to draw blood.",
equipped: true,
id: "rusty_sword",
name: "Rusty Sword",
owned: true,
rarity: "common",
type: "weapon",
},
{
bonus: { combatMultiplier: 1.25 },
description: "A sturdy weapon issued to veterans of the guild.",
equipped: false,
id: "iron_sword",
name: "Iron Sword",
owned: false,
rarity: "rare",
setId: "iron_vanguard",
type: "weapon",
},
{
bonus: { combatMultiplier: 1.5 },
description:
"A sword imbued with ancient magic that makes every strike count.",
equipped: false,
id: "enchanted_blade",
name: "Enchanted Blade",
owned: false,
rarity: "epic",
type: "weapon",
},
{
bonus: { combatMultiplier: 1.65 },
cost: { crystals: 0, essence: 500, gold: 0 },
description:
"Forged in the Shadow Marshes from condensed darkness. It strikes before it is seen.",
equipped: false,
id: "shadow_dagger",
name: "Shadow Dagger",
owned: false,
rarity: "epic",
setId: "shadow_infiltrator",
type: "weapon",
},
{
bonus: { combatMultiplier: 1.7 },
description:
"A spear tipped with a shard of the Primordial Forge's eternal fire.",
equipped: false,
id: "flame_lance",
name: "Flame Lance",
owned: false,
rarity: "epic",
setId: "volcanic_forger",
type: "weapon",
},
{
bonus: { combatMultiplier: 2 },
description: "A legendary blade that severs even the strongest bonds.",
equipped: false,
id: "vorpal_sword",
name: "Vorpal Sword",
owned: false,
rarity: "legendary",
type: "weapon",
},
{
bonus: { combatMultiplier: 2.5 },
cost: { crystals: 300, essence: 0, gold: 0 },
description:
"A scythe that harvests not flesh but essence itself. Every swing drains the will to resist.",
equipped: false,
id: "soul_reaper",
name: "Soul Reaper",
owned: false,
rarity: "legendary",
type: "weapon",
},
{
bonus: { combatMultiplier: 3 },
description:
"Forged from the heart of a dying star by the Cosmic Horror itself. Its edge exists in three realities simultaneously.",
equipped: false,
id: "celestial_blade",
name: "Celestial Blade",
owned: false,
rarity: "legendary",
type: "weapon",
},
{
bonus: { combatMultiplier: 3.25 },
cost: { crystals: 500, essence: 2000, gold: 0 },
description:
"A blade made of compressed nothingness. It does not cut — it simply unmakes.",
equipped: false,
id: "void_edge",
name: "Void Edge",
owned: false,
rarity: "legendary",
type: "weapon",
},
// ── Armour ────────────────────────────────────────────────────────────────
{
bonus: { goldMultiplier: 1.1 },
description:
"Simple protection that keeps your adventurers moving efficiently.",
equipped: true,
id: "leather_armour",
name: "Leather Armour",
owned: true,
rarity: "common",
type: "armour",
},
{
bonus: { goldMultiplier: 1.25 },
description: "Interlocked rings that guard against most mundane threats.",
equipped: false,
id: "chainmail",
name: "Chainmail",
owned: false,
rarity: "rare",
setId: "iron_vanguard",
type: "armour",
},
{
bonus: { goldMultiplier: 1.35 },
description:
"Cured hide from a Forest Giant, worked into armour that radiates primal authority.",
equipped: false,
id: "hide_armour",
name: "Giant's Hide Armour",
owned: false,
rarity: "rare",
type: "armour",
},
{
bonus: { goldMultiplier: 1.5 },
description: "Full plate protection that inspires confidence — and gold.",
equipped: false,
id: "plate_armour",
name: "Plate Armour",
owned: false,
rarity: "epic",
type: "armour",
},
{
bonus: { goldMultiplier: 1.75 },
cost: { crystals: 0, essence: 400, gold: 0 },
description:
"A cloak woven from the fabric of the Shadow Marshes itself. Wealth flows to those hidden from sight.",
equipped: false,
id: "void_shroud",
name: "Void Shroud",
owned: false,
rarity: "epic",
setId: "shadow_infiltrator",
type: "armour",
},
{
bonus: { combatMultiplier: 1.15, goldMultiplier: 1.65 },
description:
"Armour quenched in magma that hardened into something neither metal nor stone. Burns with inner heat.",
equipped: false,
id: "volcanic_plate",
name: "Volcanic Plate",
owned: false,
rarity: "epic",
setId: "volcanic_forger",
type: "armour",
},
{
bonus: { goldMultiplier: 2 },
description: "Armour forged from the scales of a defeated elder dragon.",
equipped: false,
id: "dragon_scale",
name: "Dragon Scale Armour",
owned: false,
rarity: "legendary",
type: "armour",
},
{
bonus: { goldMultiplier: 2.5 },
cost: { crystals: 250, essence: 0, gold: 0 },
description:
"A shield-armour hybrid blessed by the celestials. Its bearer becomes a fortress.",
equipped: false,
id: "titan_aegis",
name: "Titan's Aegis",
owned: false,
rarity: "legendary",
type: "armour",
},
{
bonus: { goldMultiplier: 2.75 },
description:
"Woven from threads of pure starlight harvested by the Astral Wraith. Income flows like cosmic energy.",
equipped: false,
id: "astral_robe",
name: "Astral Robe",
owned: false,
rarity: "legendary",
type: "armour",
},
// ── Trinkets ──────────────────────────────────────────────────────────────
{
bonus: { clickMultiplier: 1.1 },
description: "A coin that always lands on the side you need.",
equipped: true,
id: "lucky_coin",
name: "Lucky Coin",
owned: true,
rarity: "common",
type: "trinket",
},
{
bonus: { clickMultiplier: 1.25 },
description: "A crystal lens that sharpens magical precision.",
equipped: false,
id: "mages_focus",
name: "Mage's Focus",
owned: false,
rarity: "rare",
setId: "iron_vanguard",
type: "trinket",
},
{
bonus: { clickMultiplier: 1.3 },
description:
"A rune carved from bone-ice by the Bone Colossus. It amplifies strikes with cold precision.",
equipped: false,
id: "frost_rune",
name: "Frost Rune",
owned: false,
rarity: "rare",
type: "trinket",
},
{
bonus: { clickMultiplier: 1.5 },
description: "An orb humming with concentrated arcane energy.",
equipped: false,
id: "arcane_orb",
name: "Arcane Orb",
owned: false,
rarity: "epic",
type: "trinket",
},
{
bonus: { clickMultiplier: 1.45, goldMultiplier: 1.15 },
description:
"An amulet carved from ancient runestones found in the plague ruins. Its inscriptions hum with forgotten power.",
equipped: false,
id: "runestone_amulet",
name: "Runestone Amulet",
owned: false,
rarity: "epic",
type: "trinket",
},
{
bonus: { clickMultiplier: 1.9, goldMultiplier: 1.3 },
description:
"A fragment of the Mud Kraken's crystallised essence. Focuses raw power into devastating strikes.",
equipped: false,
id: "crystal_shard",
name: "Crystal Shard",
owned: false,
rarity: "epic",
setId: "volcanic_forger",
type: "trinket",
},
{
bonus: { clickMultiplier: 1.6 },
cost: { crystals: 0, essence: 350, gold: 0 },
description:
"A compass that points not north but toward the greatest concentration of power — wherever that may be.",
equipped: false,
id: "void_compass",
name: "Void Compass",
owned: false,
rarity: "epic",
setId: "shadow_infiltrator",
type: "trinket",
},
{
bonus: { clickMultiplier: 2, goldMultiplier: 1.2 },
description:
"A perfectly formed crystal harvested from the Ice Queen's throne room. Cold enough to burn.",
equipped: false,
id: "frost_crystal",
name: "Frost Crystal",
owned: false,
rarity: "legendary",
type: "trinket",
},
{
bonus: { clickMultiplier: 2.5, goldMultiplier: 1.4 },
description:
"The legendary stone that transmutes effort into wealth — every action fills the coffers.",
equipped: false,
id: "philosophers_stone",
name: "Philosopher's Stone",
owned: false,
rarity: "legendary",
type: "trinket",
},
{
bonus: { clickMultiplier: 2.25, combatMultiplier: 1.1, goldMultiplier: 1.25 },
description:
"A flame that has never been extinguished, sealed in crystal by the Phoenix Lord. It burns with the power of rebirth.",
equipped: false,
id: "eternal_flame",
name: "Eternal Flame",
owned: false,
rarity: "legendary",
type: "trinket",
},
{
bonus: {
clickMultiplier: 2.5,
combatMultiplier: 1.25,
goldMultiplier: 1.3,
},
description:
"A gem that contains a universe within it. Those who hold it become more than mortal.",
equipped: false,
id: "infinity_gem",
name: "Infinity Gem",
owned: false,
rarity: "legendary",
type: "trinket",
},
// ── Celestial Reaches ─────────────────────────────────────────────────────
{
bonus: { combatMultiplier: 3.5 },
description:
"A weapon forged from a fallen seraph's primary feather — impossibly sharp, burning with divine light.",
equipped: false,
id: "seraph_wing",
name: "Seraph's Wing",
owned: false,
rarity: "legendary",
setId: "celestial_guardian",
type: "weapon",
},
{
bonus: { clickMultiplier: 2.75, goldMultiplier: 1.3 },
description:
"Torn from the Fallen Archangel. It radiates with grief and power in equal measure.",
equipped: false,
id: "angels_halo",
name: "Angel's Halo",
owned: false,
rarity: "legendary",
setId: "celestial_guardian",
type: "trinket",
},
{
bonus: { goldMultiplier: 2.75 },
description:
"Forged in heavenly smithies from light compressed so hard it became solid. Your gold flows like sunbeams.",
equipped: false,
id: "celestial_armour",
name: "Celestial Armour",
owned: false,
rarity: "legendary",
setId: "celestial_guardian",
type: "armour",
},
{
bonus: { combatMultiplier: 4 },
description:
"The First Light's own blade — a weapon of pure divine will given form. It does not cut. It declares.",
equipped: false,
id: "divine_edge",
name: "The Divine Edge",
owned: false,
rarity: "legendary",
type: "weapon",
},
{
bonus: { goldMultiplier: 3 },
description:
"The outermost garment of the celestial realm, woven from captured starlight and divine intention.",
equipped: false,
id: "heaven_mantle",
name: "Heaven's Mantle",
owned: false,
rarity: "legendary",
type: "armour",
},
// ── Abyssal Trench ────────────────────────────────────────────────────────
{
bonus: { combatMultiplier: 4.5 },
description:
"Crystallised from the Depth Leviathan's venom — a weapon that strikes through armour as if it were water.",
equipped: false,
id: "depth_blade",
name: "The Depth Blade",
owned: false,
rarity: "legendary",
setId: "abyssal_predator",
type: "weapon",
},
{
bonus: { clickMultiplier: 3, goldMultiplier: 1.35 },
description:
"The Elder Kraken's eye, preserved in brine from the deepest trench. It sees through all deception.",
equipped: false,
id: "leviathan_eye",
name: "The Leviathan's Eye",
owned: false,
rarity: "legendary",
setId: "abyssal_predator",
type: "trinket",
},
{
bonus: { goldMultiplier: 3.25 },
description:
"Armour forged under conditions that would crush a city. Nothing that wears it can be broken by ordinary force.",
equipped: false,
id: "pressure_plate",
name: "Pressure Plate",
owned: false,
rarity: "legendary",
setId: "abyssal_predator",
type: "armour",
},
{
bonus: { combatMultiplier: 5 },
description:
"The Elder Abomination's own appendage, reshaped by your artificers into something that passes for a weapon.",
equipped: false,
id: "abyssal_edge",
name: "The Abyssal Edge",
owned: false,
rarity: "legendary",
type: "weapon",
},
{
bonus: { goldMultiplier: 3.5 },
description:
"Woven from the darkness at the very bottom of everything. Gold flows to those who wear the dark.",
equipped: false,
id: "abyss_shroud",
name: "The Abyss Shroud",
owned: false,
rarity: "legendary",
type: "armour",
},
// ── Infernal Court ────────────────────────────────────────────────────────
{
bonus: { goldMultiplier: 3.75 },
description:
"The Demon Prince's own hide, worked into armour that whispers the strategies of ten thousand campaigns.",
equipped: false,
id: "demon_hide",
name: "Demon Hide Armour",
owned: false,
rarity: "legendary",
setId: "infernal_conqueror",
type: "armour",
},
{
bonus: { combatMultiplier: 5.5 },
description:
"A fragment of the Hellfire Titan's core — constantly burning with a heat that ignores armour.",
equipped: false,
id: "hellfire_edge",
name: "The Hellfire Edge",
owned: false,
rarity: "legendary",
setId: "infernal_conqueror",
type: "weapon",
},
{
bonus: { clickMultiplier: 3.25, goldMultiplier: 1.4 },
description:
"Crystallised from the Lord of Sin's tears — which had never been shed before. The rarest thing in the infernal court.",
equipped: false,
id: "soul_gem",
name: "The Soul Gem",
owned: false,
rarity: "legendary",
setId: "infernal_conqueror",
type: "trinket",
},
{
bonus: { combatMultiplier: 6 },
description:
"Forged from what The Fallen once was — something good, hardened into a weapon of absolute purpose.",
equipped: false,
id: "infernal_edge",
name: "The Infernal Edge",
owned: false,
rarity: "legendary",
type: "weapon",
},
{
bonus: { goldMultiplier: 4 },
description:
"Armour assembled from The Fallen's regrets. Every piece of it remembers what righteousness felt like.",
equipped: false,
id: "sinslayer_aegis",
name: "The Sinslayer Aegis",
owned: false,
rarity: "legendary",
type: "armour",
},
// ── Crystalline Spire ─────────────────────────────────────────────────────
{
bonus: { combatMultiplier: 6.5 },
description:
"A sword that refracts into thousands of simultaneous strikes. Defenders cannot guard against every angle.",
equipped: false,
id: "prism_blade",
name: "The Prism Blade",
owned: false,
rarity: "legendary",
setId: "crystal_domain",
type: "weapon",
},
{
bonus: { goldMultiplier: 4.5 },
description:
"Armour that intersects with adjacent realities — attacks pass through versions of you that chose differently.",
equipped: false,
id: "faceted_armour",
name: "The Faceted Armour",
owned: false,
rarity: "legendary",
setId: "crystal_domain",
type: "armour",
},
{
bonus: { clickMultiplier: 3.5, goldMultiplier: 1.5 },
description:
"A lens from the Diamond Colossus's own perception — through it, your guild sees every moment simultaneously.",
equipped: false,
id: "prism_eye",
name: "The Prism Eye",
owned: false,
rarity: "legendary",
setId: "crystal_domain",
type: "trinket",
},
{
bonus: { combatMultiplier: 7 },
description:
"The Crystal Sovereign's own instrument of computation — repurposed for something it calculated was inevitable.",
equipped: false,
id: "crystal_sovereign_blade",
name: "The Sovereign's Blade",
owned: false,
rarity: "legendary",
type: "weapon",
},
{
bonus: { goldMultiplier: 5 },
description:
"Armour compressed from crystallised possibilities — the optimal defensive configuration across all timelines.",
equipped: false,
id: "diamond_plate",
name: "Diamond Plate",
owned: false,
rarity: "legendary",
type: "armour",
},
// ── Void Sanctum ──────────────────────────────────────────────────────────
{
bonus: { combatMultiplier: 8 },
description:
"A weapon of pure absence — it does not strike, it simply removes the thing it is aimed at from existence.",
equipped: false,
id: "void_annihilator",
name: "The Void Annihilator",
owned: false,
rarity: "legendary",
setId: "void_emperor",
type: "weapon",
},
{
bonus: { goldMultiplier: 5.5 },
description:
"Woven from the Eternal Shade itself — armour that exists in every moment simultaneously, impossible to find.",
equipped: false,
id: "eternal_shroud",
name: "The Eternal Shroud",
owned: false,
rarity: "legendary",
setId: "void_emperor",
type: "armour",
},
{
bonus: { clickMultiplier: 4, goldMultiplier: 1.6 },
description:
"Crystallised from the Void Progenitor's core — the original absence, given form. It makes the impossible routine.",
equipped: false,
id: "void_heart_gem",
name: "The Void Heart Gem",
owned: false,
rarity: "legendary",
setId: "void_emperor",
type: "trinket",
},
{
bonus: { combatMultiplier: 9 },
description:
"The Void Emperor's own sceptre of authority, seized in the moment of its defeat. It commands even nothingness.",
equipped: false,
id: "sanctum_breaker",
name: "The Sanctum Breaker",
owned: false,
rarity: "legendary",
type: "weapon",
},
{
bonus: { goldMultiplier: 6 },
description:
"The armour the Void Emperor wore for all of existence — now worn by something that dared to challenge all of existence.",
equipped: false,
id: "void_emperor_plate",
name: "Void Emperor's Plate",
owned: false,
rarity: "legendary",
type: "armour",
},
// ── Eternal Throne ────────────────────────────────────────────────────────
{
bonus: { goldMultiplier: 7 },
description:
"The Throne Warden's own defensive shell — protection that has never been breached across all of time.",
equipped: false,
id: "eternal_armour",
name: "Eternal Armour",
owned: false,
rarity: "legendary",
setId: "eternal_throne",
type: "armour",
},
{
bonus: { combatMultiplier: 10 },
description:
"The Eternal Knight's sword — a weapon that has served the throne since the concept of service was invented.",
equipped: false,
id: "throne_blade",
name: "The Throne Blade",
owned: false,
rarity: "legendary",
setId: "eternal_throne",
type: "weapon",
},
{
bonus: { combatMultiplier: 12 },
description:
"The Apex's own instrument — not a weapon in any sense your guild understands, but it functions as one now.",
equipped: false,
id: "apex_sword",
name: "The Apex Sword",
owned: false,
rarity: "legendary",
type: "weapon",
},
{
bonus: { goldMultiplier: 8 },
description:
"Armour assembled from the Eternal Throne itself — the absolute seat of power, now serving those who claimed it.",
equipped: false,
id: "apex_plate",
name: "The Apex Plate",
owned: false,
rarity: "legendary",
type: "armour",
},
{
bonus: { clickMultiplier: 5, combatMultiplier: 1.5, goldMultiplier: 2 },
description:
"The source of the Apex's power — the thing that makes the Eternal Throne eternal. It is yours now. All of it.",
equipped: false,
id: "eternity_stone",
name: "The Eternity Stone",
owned: false,
rarity: "legendary",
setId: "eternal_throne",
type: "trinket",
},
// ── Primordial Chaos ──────────────────────────────────────────────────────
{
bonus: { goldMultiplier: 9 },
description:
"The Primordial Titan's carapace — formed before the concept of armour existed. It simply is what armour aspires to be.",
equipped: false,
id: "chaos_mantle",
name: "The Chaos Mantle",
owned: false,
rarity: "legendary",
setId: "primordial_chaos",
type: "armour",
},
{
bonus: { clickMultiplier: 5, combatMultiplier: 2, goldMultiplier: 2.5 },
description:
"The crystallised core of the Titan itself — the first stable thing to emerge from chaos. It radiates in every direction simultaneously.",
equipped: false,
id: "titan_core",
name: "The Titan Core",
owned: false,
rarity: "legendary",
setId: "primordial_chaos",
type: "trinket",
},
// ── Infinite Expanse ──────────────────────────────────────────────────────
{
bonus: { combatMultiplier: 14 },
description:
"Forged from the Expanse Sovereign's own reach — a blade that has no beginning and no end, only edge.",
equipped: false,
id: "expanse_blade",
name: "The Expanse Blade",
owned: false,
rarity: "legendary",
setId: "infinite_expanse",
type: "weapon",
},
{
bonus: { goldMultiplier: 10 },
description:
"A second iteration of the void's armour — the first was not enough. This one has never been tested to its limit.",
equipped: false,
id: "void_armour_mk2",
name: "Void Armour Mk. II",
owned: false,
rarity: "legendary",
setId: "infinite_expanse",
type: "armour",
},
// ── Reality Forge ─────────────────────────────────────────────────────────
{
bonus: { combatMultiplier: 16 },
description:
"The Reality Architect's primary instrument — a sword that does not cut through things but rewrites what they are.",
equipped: false,
id: "cosmos_blade",
name: "The Cosmos Blade",
owned: false,
rarity: "legendary",
setId: "reality_forge",
type: "weapon",
},
{
bonus: { goldMultiplier: 12 },
description:
"Plated from the substance of reality itself — wearing it makes you feel slightly more real than everything around you.",
equipped: false,
id: "reality_plate",
name: "The Reality Plate",
owned: false,
rarity: "legendary",
setId: "reality_forge",
type: "armour",
},
// ── Cosmic Maelstrom ──────────────────────────────────────────────────────
{
bonus: { combatMultiplier: 18 },
description:
"Torn from the eye of the Cosmic Annihilator — a weapon that carries the force of an ending universe in every swing.",
equipped: false,
id: "maelstrom_edge",
name: "The Maelstrom Edge",
owned: false,
rarity: "legendary",
setId: "cosmic_maelstrom",
type: "weapon",
},
{
bonus: { goldMultiplier: 14 },
description:
"Armour that has weathered the destruction of countless realities. It has learned not to flinch.",
equipped: false,
id: "cosmic_plate",
name: "The Cosmic Plate",
owned: false,
rarity: "legendary",
setId: "cosmic_maelstrom",
type: "armour",
},
// ── Primeval Sanctum ──────────────────────────────────────────────────────
{
bonus: { combatMultiplier: 22 },
description:
"The first weapon — older than the concept of war, older than the concept of a weapon. It remembers what it was made for.",
equipped: false,
id: "primeval_blade",
name: "The Primeval Blade",
owned: false,
rarity: "legendary",
setId: "primeval_sanctum",
type: "weapon",
},
{
bonus: { goldMultiplier: 17 },
description:
"The shield-form of the Primeval God — absolute protection from before the concept of harm existed.",
equipped: false,
id: "ancient_aegis",
name: "The Ancient Aegis",
owned: false,
rarity: "legendary",
setId: "primeval_sanctum",
type: "armour",
},
// ── The Absolute ──────────────────────────────────────────────────────────
{
bonus: { combatMultiplier: 28 },
description:
"There is no name for what this was before it became a sword. There is no name for what it is now. It ends things.",
equipped: false,
id: "absolute_blade",
name: "The Absolute Blade",
owned: false,
rarity: "legendary",
setId: "the_absolute",
type: "weapon",
},
{
bonus: { goldMultiplier: 20 },
description:
"Eternity given the shape of armour — it has always existed, it will always exist, and it has always protected its wearer.",
equipped: false,
id: "eternity_plate",
name: "The Eternity Plate",
owned: false,
rarity: "legendary",
setId: "the_absolute",
type: "armour",
},
{
bonus: { clickMultiplier: 6, combatMultiplier: 3, goldMultiplier: 3 },
description:
"The heart of everything — a thing so fundamental that its removal from the Absolute One ended all things, briefly. Briefly.",
equipped: false,
id: "omniversal_core",
name: "The Omniversal Core",
owned: false,
rarity: "legendary",
setId: "the_absolute",
type: "trinket",
},
// ── Purchasable endgame sinks ─────────────────────────────────────────────
{
bonus: { clickMultiplier: 4.25 },
cost: { crystals: 0, essence: 20_000_000, gold: 0 },
description:
"A lens of compressed celestial light that sharpens every strike with divine precision.",
equipped: false,
id: "celestial_focus",
name: "Celestial Focus",
owned: false,
rarity: "legendary",
type: "trinket",
},
{
bonus: { goldMultiplier: 3.75 },
cost: { crystals: 0, essence: 50_000_000, gold: 0 },
description:
"A book written in the language of the deep — reading it aligns your guild's operations with abyssal efficiency.",
equipped: false,
id: "abyssal_tome",
name: "Abyssal Tome",
owned: false,
rarity: "legendary",
type: "armour",
},
{
bonus: { combatMultiplier: 10.5 },
cost: { crystals: 0, essence: 100_000_000, gold: 0 },
description:
"A weapon that channels void energy — the absence of resistance makes every strike devastating.",
equipped: false,
id: "void_conduit",
name: "Void Conduit",
owned: false,
rarity: "legendary",
type: "weapon",
},
{
bonus: { clickMultiplier: 4, goldMultiplier: 1.5 },
cost: { crystals: 5_000_000, essence: 0, gold: 0 },
description:
"A gem forged in the heart of the Infernal Court — it burns with productivity and righteous fury in equal measure.",
equipped: false,
id: "infernal_gem",
name: "Infernal Gem",
owned: false,
rarity: "legendary",
type: "trinket",
},
{
bonus: { goldMultiplier: 7.5 },
cost: { crystals: 20_000_000, essence: 0, gold: 0 },
description:
"Armour structured around a crystalline lattice of optimal income calculations. Every gold piece finds you faster.",
equipped: false,
id: "crystal_matrix",
name: "Crystal Matrix",
owned: false,
rarity: "legendary",
type: "armour",
},
{
bonus: { clickMultiplier: 5, combatMultiplier: 3, goldMultiplier: 2.5 },
cost: { crystals: 100_000_000, essence: 0, gold: 0 },
description:
"An artifact from beyond all known planes — it refracts power through all dimensions simultaneously.",
equipped: false,
id: "eternal_prism",
name: "The Eternal Prism",
owned: false,
rarity: "legendary",
type: "trinket",
},
];
+111
View File
@@ -0,0 +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";
export const defaultEquipmentSets: Array<EquipmentSet> = [
{
bonuses: {
2: { goldMultiplier: 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" ],
},
{
bonuses: {
2: { goldMultiplier: 1.15 },
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" ],
},
{
bonuses: {
2: { combatMultiplier: 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" ],
},
{
bonuses: {
2: { combatMultiplier: 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" ],
},
{
bonuses: {
2: { goldMultiplier: 1.2 },
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" ],
},
{
bonuses: {
2: { combatMultiplier: 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" ],
},
{
bonuses: {
2: { clickMultiplier: 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" ],
},
{
bonuses: {
2: { goldMultiplier: 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" ],
},
{
bonuses: {
2: { combatMultiplier: 1.35, goldMultiplier: 1.25 },
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
+108
View File
@@ -0,0 +1,108 @@
/**
* @file Initial game state data.
* @copyright nhcarrigan
* @license Naomi's Public License
* @author Naomi Carrigan
*/
import { defaultAchievements } from "./achievements.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";
const initialPrestige: PrestigeData = {
count: 0,
productionMultiplier: 1,
purchasedUpgradeIds: [],
runestones: 0,
};
const initialTranscendence: TranscendenceData = {
count: 0,
echoCombatMultiplier: 1,
echoIncomeMultiplier: 1,
echoMetaMultiplier: 1,
echoPrestigeRunestoneMultiplier: 1,
echoPrestigeThresholdMultiplier: 1,
echoes: 0,
purchasedUpgradeIds: [],
};
const initialApotheosis: ApotheosisData = {
count: 0,
};
const initialExploration: ExplorationState = {
areas: defaultExplorations.map((area) => {
return {
id: area.id,
status:
area.zoneId === "verdant_vale"
? ("available" as const)
: ("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 },
autoBoss: false,
autoQuest: false,
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 1–7 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",
},
];
+250
View File
@@ -0,0 +1,250 @@
/**
* @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";
export const defaultPrestigeUpgrades: Array<PrestigeUpgrade> = [
// ── Global Income Tiers ───────────────────────────────────────────────────
{
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,
},
{
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,
},
{
category: "income",
description: "The runes sing with accumulated wisdom. All production Ɨ2.",
id: "income_3",
multiplier: 2,
name: "Runestone Blessing III",
runestonesCost: 60,
},
{
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,
},
{
category: "income",
description:
"The surge intensifies, pushing limits thought impossible. All production Ɨ5.",
id: "income_5",
multiplier: 5,
name: "Runic Surge II",
runestonesCost: 350,
},
{
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,
},
{
category: "income",
description:
"You decipher ancient runic inscriptions that unlock vast potential. All production Ɨ25.",
id: "income_7",
multiplier: 25,
name: "Ancient Inscription I",
runestonesCost: 2000,
},
{
category: "income",
description:
"Deeper inscriptions reveal secrets of primordial power. All production Ɨ50.",
id: "income_8",
multiplier: 50,
name: "Ancient Inscription II",
runestonesCost: 5000,
},
{
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,
},
{
category: "income",
description:
"The oldest runes, carved before memory began, yield their secrets at last. All production Ɨ200.",
id: "income_10",
multiplier: 200,
name: "Eternal Rune I",
runestonesCost: 15_000,
},
{
category: "income",
description:
"Eternal runes resonate with the heartbeat of creation itself. All production Ɨ500.",
id: "income_11",
multiplier: 500,
name: "Eternal Rune II",
runestonesCost: 35_000,
},
// ── Click Power ───────────────────────────────────────────────────────────
{
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,
},
{
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,
},
{
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,
},
{
category: "click",
description:
"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 ────────────────────────────────────────────────────
{
category: "essence",
description:
"Runestone resonance amplifies your essence gathering. Essence production Ɨ2.",
id: "essence_1",
multiplier: 2,
name: "Essence Attunement I",
runestonesCost: 20,
},
{
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,
},
{
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,
},
{
category: "essence",
description:
"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 ────────────────────────────────────────────────────
{
category: "crystals",
description:
"Runestones vibrate in harmony with crystal structures. Crystal rewards Ɨ2.",
id: "crystal_1",
multiplier: 2,
name: "Crystal Resonance I",
runestonesCost: 30,
},
{
category: "crystals",
description:
"The resonance deepens, shattering crystal barriers. Crystal rewards Ɨ5.",
id: "crystal_2",
multiplier: 5,
name: "Crystal Resonance II",
runestonesCost: 200,
},
{
category: "crystals",
description:
"Pure resonance crystallises reality into abundance. Crystal rewards Ɨ25.",
id: "crystal_3",
multiplier: 25,
name: "Crystal Resonance III",
runestonesCost: 1200,
},
// ── Utility Unlocks ───────────────────────────────────────────────────────
{
category: "utility",
description:
"Unlock the Auto-Adventurer toggle. When enabled, the tick engine will automatically purchase the highest-tier adventurer you can currently afford.",
id: "auto_adventurer",
multiplier: 1,
name: "Autonomous Recruitment",
runestonesCost: 50,
},
{
category: "utility",
description:
"Unlock the Auto-Prestige toggle. When enabled, you will automatically ascend the moment you reach the prestige threshold — using your current character name.",
id: "auto_prestige",
multiplier: 1,
name: "Autonomous Ascension",
runestonesCost: 100,
},
// ── Runestone Meta-Upgrade ────────────────────────────────────────────────
{
category: "runestones",
description:
"Your runestone attunement grows with each prestige. Earn 25% more runestones from future prestiges.",
id: "runestone_gain_1",
multiplier: 1.25,
name: "Runic Legacy",
runestonesCost: 50,
},
{
category: "runestones",
description:
"Your legend transcends individual lifetimes. Earn 50% more runestones from future prestiges.",
id: "runestone_gain_2",
multiplier: 1.5,
name: "Eternal Legacy",
runestonesCost: 500,
},
];
File diff suppressed because it is too large Load Diff
+560
View File
@@ -0,0 +1,560 @@
/**
* @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.2 },
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.15 },
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.15 },
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.2 },
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.25 },
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.2 },
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.28 },
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.3 },
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.22 },
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.35 },
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.25 },
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.4 },
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.28 },
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",
},
// ── Cross-zone recipes ─────────────────────────────────────────────────────
{
bonus: { type: "gold_income", value: 1.28 },
description:
"Verdant sap from the oldest trees, refined in ember crystal heat and bound by legendary ore from the volcanic forges. The resulting tincture fuses the forest's patient growth with fire's relentless drive — gold accumulates with unusual enthusiasm.",
id: "verdant_pyre_seal",
name: "Verdant Pyre Seal",
requiredMaterials: [
{ materialId: "verdant_sap", quantity: 8 },
{ materialId: "ember_crystal", quantity: 6 },
{ materialId: "legendary_ore", quantity: 2 },
],
zoneId: "volcanic_depths",
},
{
bonus: { type: "click_power", value: 1.22 },
description:
"A void shard frozen into glacial ice and then submerged in shadow essence — the cold of nothing meeting the dark of everything. The resulting weave sharpens strikes with an emptiness that the shadows themselves cannot resist.",
id: "voidfrost_weave",
name: "Voidfrost Weave",
requiredMaterials: [
{ materialId: "glacial_ice", quantity: 8 },
{ materialId: "void_shard", quantity: 3 },
{ materialId: "shadow_essence", quantity: 5 },
],
zoneId: "shadow_marshes",
},
{
bonus: { type: "essence_income", value: 1.28 },
description:
"A choir shard from the celestial reaches lowered into the crushing dark of the abyssal trench and set alongside an ancient tooth. The celestial harmonic does not stop in the deep — it deepens. Essence flows toward it from every direction simultaneously.",
id: "choir_of_the_deep",
name: "Choir of the Deep",
requiredMaterials: [
{ materialId: "celestial_dust", quantity: 8 },
{ materialId: "choir_shard", quantity: 2 },
{ materialId: "ancient_tooth", quantity: 2 },
{ materialId: "pressure_gem", quantity: 5 },
],
zoneId: "abyssal_trench",
},
{
bonus: { type: "click_power", value: 1.38 },
description:
"A primeval relic submerged at the absolute boundary of existence alongside omega crystals and boundary shards — the first and last thing, unified. Every action your guild takes through it is simultaneously the most ancient and most final thing that has ever happened. It does not miss.",
id: "primal_omega_lens",
name: "Primal Omega Lens",
requiredMaterials: [
{ materialId: "primeval_relic", quantity: 2 },
{ materialId: "boundary_shard", quantity: 4 },
{ materialId: "omega_crystal", quantity: 2 },
],
zoneId: "the_absolute",
},
{
bonus: { type: "combat_power", value: 1.65 },
description:
"An eternity splinter from the eternal throne, set at the boundary between everything and nothing with an omega crystal and bound by boundary shards. Where eternity meets the absolute, something is forged that has never existed and will never exist again. Your party fights as if they know this.",
id: "eternal_omega",
name: "Eternal Omega",
requiredMaterials: [
{ materialId: "crown_fragment", quantity: 6 },
{ materialId: "eternity_splinter", quantity: 2 },
{ materialId: "boundary_shard", quantity: 4 },
{ materialId: "omega_crystal", quantity: 2 },
],
zoneId: "the_absolute",
},
// Zone 18: the_absolute
{
bonus: { type: "click_power", value: 1.3 },
description:
"Absolute fragments ground and set in an omega crystal lattice — an instrument of pure finality. Every action your guild takes through it carries the weight of an ending. It does not miss.",
id: "absolute_focus",
name: "Absolute Focus",
requiredMaterials: [
{ materialId: "absolute_fragment", quantity: 8 },
{ materialId: "omega_crystal", quantity: 3 },
],
zoneId: "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.55 },
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 = 2;
+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: 2,
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: 4,
description:
"Your transcendent experience resonates through your guild, boosting income by 50%.",
id: "echo_income_2",
multiplier: 1.5,
name: "Resonance",
},
{
category: "income",
cost: 8,
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: 16,
description:
"Ethereal energy overflows from your transcendence, tripling your guild's income.",
id: "echo_income_4",
multiplier: 3,
name: "Ethereal Overflow",
},
{
category: "income",
cost: 32,
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: 2,
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: 6,
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: 12,
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: 3,
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: 6,
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: 3,
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: 6,
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: 15,
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: 45,
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: 100,
description:
"You have mastered the infinite spiral of transcendence, doubling all future echo yields.",
id: "echo_meta_3",
multiplier: 2,
name: "Infinite Spiral",
},
];
+915
View File
@@ -0,0 +1,915 @@
/**
* @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 { Upgrade } from "@elysium/types";
export const defaultUpgrades: Array<Upgrade> = [
// ── Click upgrades ────────────────────────────────────────────────────────
{
costCrystals: 0,
costEssence: 0,
costGold: 100,
description: "Your strikes find weak points. Doubles click power.",
id: "click_1",
multiplier: 2,
name: "Keen Eye",
purchased: false,
target: "click",
unlocked: true,
},
{
costCrystals: 0,
costEssence: 0,
costGold: 1000,
description:
"Years of combat sharpen your instincts. Doubles click power again.",
id: "click_2",
multiplier: 2,
name: "Battle Hardened",
purchased: false,
target: "click",
unlocked: false,
},
{
costCrystals: 0,
costEssence: 10,
costGold: 50_000,
description: "A weapon of ancient power. Triples click power.",
id: "click_3",
multiplier: 3,
name: "Legendary Weapon",
purchased: false,
target: "click",
unlocked: false,
},
{
costCrystals: 50,
costEssence: 0,
costGold: 0,
description:
"Channel crystallised power into every strike. Doubles click power.",
id: "crystal_focus",
multiplier: 2,
name: "Crystal Focus",
purchased: false,
target: "click",
unlocked: true,
},
// ── Global gold upgrades ──────────────────────────────────────────────────
{
costCrystals: 0,
costEssence: 0,
costGold: 500,
description: "Formalising the guild structure increases all income by 25%.",
id: "global_1",
multiplier: 1.25,
name: "Guild Charter",
purchased: false,
target: "global",
unlocked: false,
},
{
costCrystals: 0,
costEssence: 5,
costGold: 10_000,
description: "Trade routes boost all income by 50%.",
id: "global_2",
multiplier: 1.5,
name: "Merchant Alliance",
purchased: false,
target: "global",
unlocked: false,
},
{
costCrystals: 0,
costEssence: 100,
costGold: 1_000_000,
description: "The king himself backs your guild. All income doubled.",
id: "global_3",
multiplier: 2,
name: "Royal Patronage",
purchased: false,
target: "global",
unlocked: false,
},
{
costCrystals: 0,
costEssence: 50,
costGold: 50_000,
description:
"Forge partnerships with mage guilds across the realm. All income +50%.",
id: "essence_guild",
multiplier: 2,
name: "Essence Guild",
purchased: false,
target: "global",
unlocked: false,
},
{
costCrystals: 0,
costEssence: 250,
costGold: 500_000,
description:
"A council of the realm's greatest minds organises your operations. All income doubled.",
id: "grand_council",
multiplier: 2,
name: "Grand Council",
purchased: false,
target: "global",
unlocked: false,
},
{
costCrystals: 250,
costEssence: 0,
costGold: 0,
description:
"Align crystalline frequencies across your guild. All income +50%.",
id: "crystal_resonance",
multiplier: 1.5,
name: "Crystal Resonance",
purchased: false,
target: "global",
unlocked: false,
},
{
costCrystals: 600,
costEssence: 0,
costGold: 0,
description: "Master the art of crystal amplification. All income doubled.",
id: "crystal_mastery",
multiplier: 2,
name: "Crystal Mastery",
purchased: false,
target: "global",
unlocked: false,
},
// ── Adventurer-specific upgrades ──────────────────────────────────────────
{
adventurerId: "peasant",
costCrystals: 0,
costEssence: 0,
costGold: 200,
description: "Peasants work twice as hard with proper equipment.",
id: "peasant_1",
multiplier: 2,
name: "Better Tools",
purchased: false,
target: "adventurer",
unlocked: false,
},
{
adventurerId: "peasant",
costCrystals: 0,
costEssence: 20,
costGold: 0,
description:
"Organised labour guilds and proper scheduling make peasants ten times more productive.",
id: "peasant_2",
multiplier: 10,
name: "Guild Organisation",
purchased: false,
target: "adventurer",
unlocked: false,
},
{
adventurerId: "peasant",
costCrystals: 50,
costEssence: 0,
costGold: 0,
description:
"Magical augmentation through crystalline resonance supercharges even the humblest worker.",
id: "peasant_3",
multiplier: 50,
name: "Crystal Augmentation",
purchased: false,
target: "adventurer",
unlocked: false,
},
{
adventurerId: "militia",
costCrystals: 0,
costEssence: 0,
costGold: 1000,
description: "Formal training doubles militia effectiveness.",
id: "militia_1",
multiplier: 2,
name: "Militia Training",
purchased: false,
target: "adventurer",
unlocked: false,
},
{
adventurerId: "apprentice",
costCrystals: 0,
costEssence: 2,
costGold: 5000,
description: "Ancient books of magic double mage output.",
id: "apprentice_1",
multiplier: 2,
name: "Arcane Tomes",
purchased: false,
target: "adventurer",
unlocked: false,
},
{
adventurerId: "acolyte",
costCrystals: 0,
costEssence: 3,
costGold: 8000,
description: "Sacred ceremonies double the output of your clerics.",
id: "acolyte_1",
multiplier: 2,
name: "Holy Rites",
purchased: false,
target: "adventurer",
unlocked: false,
},
{
adventurerId: "ranger",
costCrystals: 0,
costEssence: 5,
costGold: 15_000,
description: "Advanced scouting techniques double ranger effectiveness.",
id: "scout_1",
multiplier: 2,
name: "Stealth Training",
purchased: false,
target: "adventurer",
unlocked: false,
},
{
adventurerId: "knight",
costCrystals: 0,
costEssence: 10,
costGold: 50_000,
description:
"Superior forging techniques double the output of your knights.",
id: "knight_1",
multiplier: 2,
name: "Tempered Steel",
purchased: false,
target: "adventurer",
unlocked: false,
},
{
adventurerId: "archmage",
costCrystals: 0,
costEssence: 75,
costGold: 100_000,
description: "Tap into the world's leylines to double archmage output.",
id: "archmage_1",
multiplier: 2,
name: "Leyline Binding",
purchased: false,
target: "adventurer",
unlocked: false,
},
{
adventurerId: "paladin",
costCrystals: 0,
costEssence: 150,
costGold: 200_000,
description:
"Divine blessings from the gods themselves double paladin output.",
id: "paladin_1",
multiplier: 2,
name: "Holy Vanguard",
purchased: false,
target: "adventurer",
unlocked: false,
},
{
adventurerId: "dragon_rider",
costCrystals: 0,
costEssence: 200,
costGold: 500_000,
description:
"The unbreakable bond between rider and dragon doubles their combined output.",
id: "dragon_rider_1",
multiplier: 2,
name: "Bond of Wings",
purchased: false,
target: "adventurer",
unlocked: false,
},
{
adventurerId: "arcane_scholar",
costCrystals: 0,
costEssence: 1000,
costGold: 0,
description: "Access to forbidden libraries doubles scholar output.",
id: "arcane_scholar_1",
multiplier: 2,
name: "Ancient Tomes",
purchased: false,
target: "adventurer",
unlocked: false,
},
{
adventurerId: "shadow_assassin",
costCrystals: 0,
costEssence: 5000,
costGold: 0,
description: "Mastery of the shadow arts doubles assassin effectiveness.",
id: "shadow_assassin_1",
multiplier: 2,
name: "Shadow Arts",
purchased: false,
target: "adventurer",
unlocked: false,
},
{
adventurerId: "dark_templar",
costCrystals: 0,
costEssence: 25_000,
costGold: 0,
description:
"A sworn oath to the darkness of the marshes doubles templar output.",
id: "dark_templar_1",
multiplier: 2,
name: "Templar's Oath",
purchased: false,
target: "adventurer",
unlocked: false,
},
{
adventurerId: "void_walker",
costCrystals: 0,
costEssence: 100_000,
costGold: 0,
description:
"Walking through the void itself doubles the output of your void walkers.",
id: "void_walker_1",
multiplier: 2,
name: "Void Step",
purchased: false,
target: "adventurer",
unlocked: false,
},
{
adventurerId: "celestial_guard",
costCrystals: 0,
costEssence: 500_000,
costGold: 0,
description:
"A blessing from the celestials themselves doubles guard output.",
id: "celestial_guard_1",
multiplier: 2,
name: "Divine Ward",
purchased: false,
target: "adventurer",
unlocked: false,
},
{
adventurerId: "divine_champion",
costCrystals: 0,
costEssence: 2_000_000,
costGold: 0,
description: "An unbreakable oath to the divine doubles champion output.",
id: "divine_champion_1",
multiplier: 2,
name: "Champion's Oath",
purchased: false,
target: "adventurer",
unlocked: false,
},
// ── Click upgrades (new zones) ────────────────────────────────────────────
{
costCrystals: 0,
costEssence: 5_000_000,
costGold: 100_000_000,
description:
"Blessed by the celestials themselves. Click power quadrupled.",
id: "click_4",
multiplier: 4,
name: "Celestial Strike",
purchased: false,
target: "click",
unlocked: false,
},
{
costCrystals: 10_000_000,
costEssence: 0,
costGold: 0,
description:
"A strike that burns with infernal fire. Click power quintupled.",
id: "click_5",
multiplier: 5,
name: "Infernal Slash",
purchased: false,
target: "click",
unlocked: false,
},
// ── Global upgrades (new zones) ───────────────────────────────────────────
{
costCrystals: 0,
costEssence: 10_000_000,
costGold: 500_000_000,
description:
"A covenant with celestial forces multiplies your guild's potential. All income doubled.",
id: "divine_covenant",
multiplier: 2,
name: "Divine Covenant",
purchased: false,
target: "global",
unlocked: false,
},
{
costCrystals: 0,
costEssence: 50_000_000,
costGold: 100_000_000_000,
description:
"The empire formally sponsors your guild at the highest level. All income x2.5.",
id: "global_4",
multiplier: 2.5,
name: "Imperial Decree",
purchased: false,
target: "global",
unlocked: false,
},
{
costCrystals: 2_000_000,
costEssence: 0,
costGold: 0,
description:
"A pact with the denizens of the deepest trench. All income doubled.",
id: "abyssal_pact",
multiplier: 2,
name: "Abyssal Pact",
purchased: false,
target: "global",
unlocked: false,
},
{
costCrystals: 0,
costEssence: 100_000_000_000,
costGold: 50_000_000_000_000,
description:
"The celestials themselves decree your guild's dominion over all realms. All income x3.",
id: "celestial_mandate",
multiplier: 3,
name: "Celestial Mandate",
purchased: false,
target: "global",
unlocked: false,
},
{
costCrystals: 50_000_000,
costEssence: 0,
costGold: 0,
description: "Transcend mortal limits through void energy. All income x3.",
id: "void_ascendancy",
multiplier: 3,
name: "Void Ascendancy",
purchased: false,
target: "global",
unlocked: false,
},
{
costCrystals: 0,
costEssence: 500_000_000_000,
costGold: 1_000_000_000_000_000,
description:
"Perfect harmony with celestial forces amplifies all output. All income x2.5.",
id: "divine_harmony",
multiplier: 2.5,
name: "Divine Harmony",
purchased: false,
target: "global",
unlocked: false,
},
{
costCrystals: 50_000_000,
costEssence: 0,
costGold: 0,
description: "Channel infernal rage into production. All income doubled.",
id: "infernal_fury",
multiplier: 2,
name: "Infernal Fury",
purchased: false,
target: "global",
unlocked: false,
},
// ── Purchasable essence/crystal sink upgrades ─────────────────────────────
{
costCrystals: 3000,
costEssence: 0,
costGold: 0,
description: "Crystalline energy pulses through your guild's operations. All income +50%.",
id: "crystal_pulse",
multiplier: 1.5,
name: "Crystal Pulse",
purchased: false,
target: "global",
unlocked: true,
},
{
costCrystals: 20_000,
costEssence: 0,
costGold: 0,
description:
"Crystal resonance surges into every process your guild undertakes. All income doubled.",
id: "crystal_surge",
multiplier: 2,
name: "Crystal Surge",
purchased: false,
target: "global",
unlocked: true,
},
{
costCrystals: 150_000,
costEssence: 0,
costGold: 0,
description: "Your guild's operations are saturated with crystalline power. All income x3.",
id: "crystal_tempest",
multiplier: 3,
name: "Crystal Tempest",
purchased: false,
target: "global",
unlocked: true,
},
{
costCrystals: 0,
costEssence: 5_000_000,
costGold: 0,
description: "Tap into a vast network of essence flows. All income +50%.",
id: "essence_nexus",
multiplier: 1.5,
name: "Essence Nexus",
purchased: false,
target: "global",
unlocked: true,
},
{
costCrystals: 0,
costEssence: 50_000_000,
costGold: 0,
description:
"Flood your guild's operations with raw essence power. All income doubled.",
id: "essence_overdrive",
multiplier: 2,
name: "Essence Overdrive",
purchased: false,
target: "global",
unlocked: true,
},
{
costCrystals: 0,
costEssence: 500_000_000,
costGold: 0,
description: "Harness the oldest essence in existence. All income x3.",
id: "primal_essence",
multiplier: 3,
name: "Primal Essence",
purchased: false,
target: "global",
unlocked: true,
},
{
costCrystals: 50_000_000,
costEssence: 0,
costGold: 0,
description:
"Push crystal resonance beyond its limits. All income doubled.",
id: "crystal_overdrive",
multiplier: 2,
name: "Crystal Overdrive",
purchased: false,
target: "global",
unlocked: true,
},
{
costCrystals: 200_000_000,
costEssence: 0,
costGold: 0,
description: "Forge an eternal pact that triples all income permanently.",
id: "eternal_bond",
multiplier: 3,
name: "Eternal Bond",
purchased: false,
target: "global",
unlocked: true,
},
{
costCrystals: 1_000_000_000,
costEssence: 0,
costGold: 0,
description:
"The supreme decree from the Eternal Throne itself. All income x5.",
id: "apex_mandate",
multiplier: 5,
name: "Apex Mandate",
purchased: false,
target: "global",
unlocked: true,
},
// ── New adventurer upgrades ───────────────────────────────────────────────
{
adventurerId: "seraph_knight",
costCrystals: 0,
costEssence: 10_000_000,
costGold: 0,
description:
"Seraph knights gain divine flight, doubling their effectiveness.",
id: "seraph_knight_1",
multiplier: 2,
name: "Seraphic Wings",
purchased: false,
target: "adventurer",
unlocked: false,
},
{
adventurerId: "abyss_diver",
costCrystals: 0,
costEssence: 25_000_000,
costGold: 0,
description:
"Full adaptation to abyssal pressure doubles diver effectiveness.",
id: "abyss_diver_1",
multiplier: 2,
name: "Pressure Adaptation",
purchased: false,
target: "adventurer",
unlocked: false,
},
{
adventurerId: "infernal_warden",
costCrystals: 2_000_000,
costEssence: 0,
costGold: 0,
description:
"Tempered in hellfire itself, warden effectiveness is doubled.",
id: "infernal_warden_1",
multiplier: 2,
name: "Infernal Tempering",
purchased: false,
target: "adventurer",
unlocked: false,
},
{
adventurerId: "crystal_sage",
costCrystals: 5_000_000,
costEssence: 0,
costGold: 0,
description:
"Complete mastery of prismatic crystallomancy doubles sage output.",
id: "crystal_sage_1",
multiplier: 2,
name: "Prismatic Mastery",
purchased: false,
target: "adventurer",
unlocked: false,
},
{
adventurerId: "void_sentinel",
costCrystals: 15_000_000,
costEssence: 0,
costGold: 0,
description:
"Perfect resonance with the void doubles sentinel effectiveness.",
id: "void_sentinel_1",
multiplier: 2,
name: "Void Resonance",
purchased: false,
target: "adventurer",
unlocked: false,
},
{
adventurerId: "eternal_champion",
costCrystals: 50_000_000,
costEssence: 0,
costGold: 0,
description: "An oath that transcends time itself doubles champion output.",
id: "eternal_champion_1",
multiplier: 2,
name: "Eternal Oath",
purchased: false,
target: "adventurer",
unlocked: false,
},
{
adventurerId: "aether_weaver",
costCrystals: 200_000_000,
costEssence: 0,
costGold: 0,
description:
"Complete mastery of aetheric forces doubles the weaver's output.",
id: "aether_weaver_1",
multiplier: 2,
name: "Aetheric Mastery",
purchased: false,
target: "adventurer",
unlocked: false,
},
{
adventurerId: "titan_warrior",
costCrystals: 700_000_000,
costEssence: 0,
costGold: 0,
description:
"The fury of a titan unleashed — warrior effectiveness doubled.",
id: "titan_warrior_1",
multiplier: 2,
name: "Titanic Fury",
purchased: false,
target: "adventurer",
unlocked: false,
},
{
adventurerId: "nexus_sage",
costCrystals: 2_500_000_000,
costEssence: 0,
costGold: 0,
description:
"The sage converges all ley lines through their body — output doubled.",
id: "nexus_sage_1",
multiplier: 2,
name: "Nexus Convergence",
purchased: false,
target: "adventurer",
unlocked: false,
},
{
adventurerId: "cosmos_knight",
costCrystals: 9_000_000_000,
costEssence: 0,
costGold: 0,
description:
"Tempered by the heat of dying stars, the knight's effectiveness is doubled.",
id: "cosmos_knight_1",
multiplier: 2,
name: "Cosmic Tempering",
purchased: false,
target: "adventurer",
unlocked: false,
},
{
adventurerId: "astral_sovereign",
costCrystals: 3e10,
costEssence: 0,
costGold: 0,
description:
"Ascension to true sovereignty over the astral plane doubles output.",
id: "astral_sovereign_1",
multiplier: 2,
name: "Sovereign Ascension",
purchased: false,
target: "adventurer",
unlocked: false,
},
{
adventurerId: "primordial_mage",
costCrystals: 1e11,
costEssence: 0,
costGold: 0,
description:
"Awakening of the mage's primordial heritage doubles their power.",
id: "primordial_mage_1",
multiplier: 2,
name: "Primordial Awakening",
purchased: false,
target: "adventurer",
unlocked: false,
},
{
adventurerId: "reality_warden",
costCrystals: 4e11,
costEssence: 0,
costGold: 0,
description:
"The warden binds themselves to the structure of reality — effectiveness doubled.",
id: "reality_warden_1",
multiplier: 2,
name: "Reality Binding",
purchased: false,
target: "adventurer",
unlocked: false,
},
{
adventurerId: "infinity_ranger",
costCrystals: 1.5e12,
costEssence: 0,
costGold: 0,
description:
"The ranger's arrows travel through infinity itself — output doubled.",
id: "infinity_ranger_1",
multiplier: 2,
name: "Infinite Aim",
purchased: false,
target: "adventurer",
unlocked: false,
},
{
adventurerId: "oblivion_paladin",
costCrystals: 5e12,
costEssence: 0,
costGold: 0,
description:
"Consecrated by the void between all things — paladin effectiveness doubled.",
id: "oblivion_paladin_1",
multiplier: 2,
name: "Oblivion Consecration",
purchased: false,
target: "adventurer",
unlocked: false,
},
{
adventurerId: "transcendent_rogue",
costCrystals: 2e13,
costEssence: 0,
costGold: 0,
description:
"The rogue becomes one with the space between states — effectiveness doubled.",
id: "transcendent_rogue_1",
multiplier: 2,
name: "Transcendent Shadow",
purchased: false,
target: "adventurer",
unlocked: false,
},
{
adventurerId: "omniversal_champion",
costCrystals: 8e13,
costEssence: 0,
costGold: 0,
description:
"Dominion over all versions of all universes — champion output doubled.",
id: "omniversal_champion_1",
multiplier: 2,
name: "Omniversal Dominion",
purchased: false,
target: "adventurer",
unlocked: false,
},
// ── Essence Sinks ─────────────────────────────────────────────────────────
{
costCrystals: 0,
costEssence: 1e12,
costGold: 0,
description:
"Channel a vast reservoir of essence into the guild's core — all production Ɨ2.",
id: "essence_sink_1",
multiplier: 2,
name: "Essence Infusion I",
purchased: false,
target: "global",
unlocked: true,
},
{
costCrystals: 0,
costEssence: 5e12,
costGold: 0,
description:
"A deeper infusion saturates every operation with raw essence — all production Ɨ2.",
id: "essence_sink_2",
multiplier: 2,
name: "Essence Infusion II",
purchased: false,
target: "global",
unlocked: true,
},
{
costCrystals: 0,
costEssence: 2.5e13,
costGold: 0,
description:
"Essence floods the ley-lines binding your guild — all production Ɨ2.",
id: "essence_sink_3",
multiplier: 2,
name: "Essence Infusion III",
purchased: false,
target: "global",
unlocked: true,
},
{
costCrystals: 0,
costEssence: 1e14,
costGold: 0,
description:
"The guild breathes essence as its very lifeblood — all production Ɨ3.",
id: "essence_sink_4",
multiplier: 3,
name: "Essence Infusion IV",
purchased: false,
target: "global",
unlocked: true,
},
{
costCrystals: 0,
costEssence: 5e14,
costGold: 0,
description:
"Essence transcends material form and reshapes reality itself — all production Ɨ5.",
id: "essence_sink_5",
multiplier: 5,
name: "Essence Infusion V",
purchased: false,
target: "global",
unlocked: true,
},
];
+191
View File
@@ -0,0 +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";
export const defaultZones: Array<Zone> = [
{
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.",
emoji: "🌿",
id: "verdant_vale",
name: "The Verdant Vale",
status: "unlocked",
unlockBossId: null,
unlockQuestId: null,
},
{
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.",
emoji: "šŸ›ļø",
id: "shattered_ruins",
name: "The Shattered Ruins",
status: "locked",
unlockBossId: "forest_giant",
unlockQuestId: "ancient_ruins",
},
{
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.",
emoji: "ā„ļø",
id: "frozen_peaks",
name: "The Frozen Peaks",
status: "locked",
unlockBossId: "elder_dragon",
unlockQuestId: "dragon_lair",
},
{
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.",
emoji: "šŸŒ‘",
id: "shadow_marshes",
name: "The Shadow Marshes",
status: "locked",
unlockBossId: "void_titan",
unlockQuestId: "storm_citadel",
},
{
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.",
emoji: "šŸŒ‹",
id: "volcanic_depths",
name: "The Volcanic Depths",
status: "locked",
unlockBossId: "mud_kraken",
unlockQuestId: "plague_ruins",
},
{
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.",
emoji: "🌌",
id: "astral_void",
name: "The Astral Void",
status: "locked",
unlockBossId: "phoenix_lord",
unlockQuestId: "the_forge",
},
{
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.",
emoji: "✨",
id: "celestial_reaches",
name: "The Celestial Reaches",
status: "locked",
unlockBossId: "the_devourer",
unlockQuestId: "the_end",
},
{
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.",
emoji: "🌊",
id: "abyssal_trench",
name: "The Abyssal Trench",
status: "locked",
unlockBossId: "the_first_light",
unlockQuestId: "celestial_archive",
},
{
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.",
emoji: "šŸ‘æ",
id: "infernal_court",
name: "The Infernal Court",
status: "locked",
unlockBossId: "elder_abomination",
unlockQuestId: "abyssal_chronicle",
},
{
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.",
emoji: "šŸ’Ž",
id: "crystalline_spire",
name: "The Crystalline Spire",
status: "locked",
unlockBossId: "the_fallen",
unlockQuestId: "infernal_codex",
},
{
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.",
emoji: "šŸŒ€",
id: "void_sanctum",
name: "The Void Sanctum",
status: "locked",
unlockBossId: "crystal_sovereign",
unlockQuestId: "the_prism_vault",
},
{
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.",
emoji: "šŸ‘‘",
id: "eternal_throne",
name: "The Eternal Throne",
status: "locked",
unlockBossId: "void_emperor",
unlockQuestId: "heart_of_void",
},
{
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.",
emoji: "šŸŒŖļø",
id: "primordial_chaos",
name: "The Primordial Chaos",
status: "locked",
unlockBossId: "the_apex",
unlockQuestId: "eternal_dominion",
},
{
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.",
emoji: "ā™¾ļø",
id: "infinite_expanse",
name: "The Infinite Expanse",
status: "locked",
unlockBossId: "primordial_titan",
unlockQuestId: "chaos_chronicle",
},
{
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.",
emoji: "āš’ļø",
id: "reality_forge",
name: "The Reality Forge",
status: "locked",
unlockBossId: "expanse_sovereign",
unlockQuestId: "expanse_codex",
},
{
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.",
emoji: "šŸŒ€",
id: "cosmic_maelstrom",
name: "The Cosmic Maelstrom",
status: "locked",
unlockBossId: "reality_architect",
unlockQuestId: "forge_chronicle",
},
{
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.",
emoji: "šŸ—æ",
id: "primeval_sanctum",
name: "The Primeval Sanctum",
status: "locked",
unlockBossId: "cosmic_annihilator",
unlockQuestId: "maelstrom_codex",
},
{
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.",
emoji: "⚫",
id: "the_absolute",
name: "The Absolute",
status: "locked",
unlockBossId: "primeval_god",
unlockQuestId: "sanctum_chronicle",
},
];
+9
View File
@@ -0,0 +1,9 @@
/**
* @file Prisma database client singleton.
* @copyright nhcarrigan
* @license Naomi's Public License
* @author Naomi Carrigan
*/
import { PrismaClient } from "@prisma/client";
export const prisma = new PrismaClient();
+83
View File
@@ -0,0 +1,83 @@
/**
* @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 { Hono } from "hono";
import { cors } from "hono/cors";
import { logger as honoLogger } from "hono/logger";
import { aboutRouter } from "./routes/about.js";
import { apotheosisRouter } from "./routes/apotheosis.js";
import { authRouter } from "./routes/auth.js";
import { bossRouter } from "./routes/boss.js";
import { craftRouter } from "./routes/craft.js";
import { debugRouter } from "./routes/debug.js";
import { exploreRouter } from "./routes/explore.js";
import { frontendRouter } from "./routes/frontend.js";
import { gameRouter } from "./routes/game.js";
import { leaderboardRouter } from "./routes/leaderboards.js";
import { prestigeRouter } from "./routes/prestige.js";
import { profileRouter } from "./routes/profile.js";
import { timersRouter } from "./routes/timers.js";
import { transcendenceRouter } from "./routes/transcendence.js";
import { connectGateway } from "./services/gateway.js";
import { logger } from "./services/logger.js";
const app = new Hono();
app.use("*", honoLogger());
app.use(
"*",
cors({
allowHeaders: [ "Authorization", "Content-Type" ],
allowMethods: [ "GET", "POST", "PUT", "DELETE", "OPTIONS" ],
origin: process.env.CORS_ORIGIN ?? "http://localhost:5173",
}),
);
app.route("/about", aboutRouter);
app.route("/debug", debugRouter);
app.route("/fe", frontendRouter);
app.route("/auth", authRouter);
app.route("/game", gameRouter);
app.route("/boss", bossRouter);
app.route("/explore", exploreRouter);
app.route("/craft", craftRouter);
app.route("/prestige", prestigeRouter);
app.route("/transcendence", transcendenceRouter);
app.route("/apotheosis", apotheosisRouter);
app.route("/leaderboards", leaderboardRouter);
app.route("/profile", profileRouter);
app.route("/timers", timersRouter);
app.get("/health", (context) => {
return context.json({ status: "ok" });
});
app.onError((error, context) => {
void logger.error(
"hono_unhandled_error",
error instanceof Error
? error
: new Error(String(error)),
);
return context.json({ error: "Internal server error" }, 500);
});
const port = Number(process.env.PORT ?? 3001);
try {
serve({ fetch: app.fetch, port: port }, () => {
process.stdout.write(`Elysium API running on port ${String(port)}\n`);
connectGateway();
});
} catch (error) {
void logger.error(
"server_startup",
error instanceof Error
? error
: new Error(String(error)),
);
}
+53
View File
@@ -0,0 +1,53 @@
/**
* @file Authentication middleware for validating JWT tokens.
* @copyright nhcarrigan
* @license Naomi's Public License
* @author Naomi Carrigan
*/
import { verifyToken } from "../services/jwt.js";
import { logger } from "../services/logger.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");
if (authorization?.startsWith("Bearer ") !== true) {
return context.json(
{ error: "Missing or invalid Authorization header" },
401,
);
}
const token = authorization.slice(7);
try {
const payload = verifyToken(token);
context.set("discordId", payload.discordId);
} catch (error) {
const isExpiredToken
= error instanceof Error && error.message === "Token has expired";
if (!isExpiredToken) {
void logger.error(
"auth_middleware",
error instanceof Error
? error
: new Error(String(error)),
);
}
return context.json({ error: "Invalid or expired token" }, 401);
}
// eslint-disable-next-line @typescript-eslint/no-confusing-void-expression -- Need the consistent return!
return await next();
};
+70
View File
@@ -0,0 +1,70 @@
/**
* @file About route providing API version and release information.
* @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 { logger } from "../services/logger.js";
import type { AboutResponse, GiteaRelease } from "@elysium/types";
// eslint-disable-next-line capitalized-comments -- v8 ignore
/* v8 ignore next -- @preserve */
const apiVersion = process.env.npm_package_version ?? "unknown";
const giteaReleasesUrl = "https://git.nhcarrigan.com/api/v1/repos/nhcarrigan/elysium/releases";
const cacheTtlMs = 5 * 60 * 1000;
interface ReleasesCache {
data: Array<GiteaRelease>;
timestamp: number;
}
let releasesCache: ReleasesCache = { data: [], timestamp: 0 };
const fetchReleases = async(): Promise<Array<GiteaRelease>> => {
const now = Date.now();
if (releasesCache.data.length > 0 && now - releasesCache.timestamp < cacheTtlMs) {
return releasesCache.data;
}
try {
const response = await fetch(giteaReleasesUrl);
if (!response.ok) {
return releasesCache.data;
}
const rawData: unknown = await response.json();
/* eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- External API response */
const data = rawData as Array<GiteaRelease>;
releasesCache = { data: data, timestamp: now };
return releasesCache.data;
} catch {
return releasesCache.data;
}
};
const aboutRouter = new Hono();
aboutRouter.get("/", async(context) => {
try {
const releases = await fetchReleases();
const body: AboutResponse = {
apiVersion,
releases,
};
return context.json(body);
// eslint-disable-next-line capitalized-comments -- v8 ignore
/* v8 ignore next 9 -- @preserve */
} catch (error) {
void logger.error(
"about",
error instanceof Error
? error
: new Error(String(error)),
);
return context.json({ error: "Internal server error" }, 500);
}
});
export { aboutRouter };
+133
View File
@@ -0,0 +1,133 @@
/**
* @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 max-statements -- Route handler requires many statements */
/* 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 { logger } from "../services/logger.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) => {
try {
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 },
});
const apotheosisCount = updatedApotheosisData.count;
void logger.metric("apotheosis", 1, { apotheosisCount, 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 });
} catch (error) {
void logger.error(
"apotheosis",
error instanceof Error
? error
: new Error(String(error)),
);
return context.json({ error: "Internal server error" }, 500);
}
});
export { apotheosisRouter };
+149
View File
@@ -0,0 +1,149 @@
/**
* @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 { initialGameState } from "../data/initialState.js";
import { prisma } from "../db/client.js";
import {
buildOAuthUrl,
exchangeCode,
fetchDiscordUser,
} from "../services/discord.js";
import { signToken } from "../services/jwt.js";
import { logger } from "../services/logger.js";
import { grantElysianRole } from "../services/webhook.js";
import type { Player } from "@elysium/types";
const authRouter = new Hono();
authRouter.get("/url", (context) => {
try {
const url = buildOAuthUrl();
return context.json({ url });
} catch {
return context.json({ error: "Failed to build OAuth URL" }, 500);
}
});
authRouter.get("/callback", async(context) => {
const code = context.req.query("code");
if (code === undefined || code === "") {
return context.json({ error: "Missing code parameter" }, 400);
}
try {
const tokenData = await exchangeCode(code);
const discordUser = await fetchDiscordUser(tokenData.access_token);
const existing = await prisma.player.findUnique({
where: { discordId: discordUser.id },
});
const now = Date.now();
if (!existing) {
const player = await prisma.player.create({
data: {
avatar: discordUser.avatar,
characterName: discordUser.username,
createdAt: now,
discordId: discordUser.id,
discriminator: discordUser.discriminator,
lastSavedAt: now,
totalClicks: 0,
totalGoldEarned: 0,
username: discordUser.username,
},
});
const playerShape: Player = {
avatar: player.avatar ?? null,
characterName: player.characterName,
createdAt: player.createdAt,
discordId: player.discordId,
discriminator: player.discriminator,
lastSavedAt: player.lastSavedAt,
lifetimeAchievementsUnlocked: player.lifetimeAchievementsUnlocked,
lifetimeAdventurersRecruited: player.lifetimeAdventurersRecruited,
lifetimeBossesDefeated: player.lifetimeBossesDefeated,
lifetimeClicks: player.lifetimeClicks,
lifetimeGoldEarned: player.lifetimeGoldEarned,
lifetimeQuestsCompleted: player.lifetimeQuestsCompleted,
totalClicks: player.totalClicks,
totalGoldEarned: player.totalGoldEarned,
username: player.username,
};
const freshState = initialGameState(
playerShape,
playerShape.characterName,
);
await prisma.gameState.create({
data: {
discordId: player.discordId,
/* eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- Prisma requires never type */
state: freshState as unknown as never,
updatedAt: now,
},
});
const inGuild = await grantElysianRole(player.discordId);
await prisma.player.update({
data: { inGuild },
where: { discordId: player.discordId },
});
const jwtToken = signToken(player.discordId);
void logger.log("info", `New player registered: ${player.discordId}`);
void logger.metric("user_registered", 1, { discordId: player.discordId });
// 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 inGuild = await grantElysianRole(discordUser.id);
const updated = await prisma.player.update({
data: {
avatar: discordUser.avatar,
discriminator: discordUser.discriminator,
inGuild: inGuild,
username: discordUser.username,
},
where: { discordId: discordUser.id },
});
const jwtToken = signToken(updated.discordId);
void logger.log("info", `Player logged in: ${updated.discordId}`);
void logger.metric("user_login", 1, { discordId: updated.discordId });
// 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 (error) {
void logger.error(
"auth_callback",
error instanceof Error
? error
: new Error(String(error)),
);
// 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`);
}
});
export { authRouter };
+437
View File
@@ -0,0 +1,437 @@
/**
* @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 */
/* eslint-disable max-lines -- Boss route with full combat logic and helpers exceeds line limit */
import { createHmac } from "node:crypto";
import {
computeSetBonuses,
getActiveCompanionBonus,
type BossChallengeResponse,
type GameState,
} from "@elysium/types";
import { Hono } from "hono";
import { defaultBosses } from "../data/bosses.js";
import { defaultEquipmentSets } from "../data/equipmentSets.js";
import { defaultExplorations } from "../data/explorations.js";
import { prisma } from "../db/client.js";
import { authMiddleware } from "../middleware/auth.js";
import { updateChallengeProgress } from "../services/dailyChallenges.js";
import { logger } from "../services/logger.js";
import type { HonoEnvironment } from "../types/hono.js";
/**
* Computes the HMAC-SHA256 of data using the given secret.
* @param data - The data string to sign.
* @param secret - The HMAC secret key.
* @returns The hex-encoded HMAC digest.
*/
const computeHmac = (data: string, secret: string): string => {
return createHmac("sha256", secret).update(data).
digest("hex");
};
/**
* Exponential base for the prestige combat multiplier: Math.pow(base, prestigeCount).
* Replaces the former linear formula (1 + count * 0.1) to enable late-game zone progression.
* Must be kept in sync with prestigeCombatBase in apps/web/src/engine/tick.ts.
*/
const prestigeCombatBase = 4;
const bossRouter = new Hono<HonoEnvironment>();
bossRouter.use("*", authMiddleware);
const calculatePartyStats = (
state: GameState,
): { partyDPS: number; partyMaxHp: number } => {
let globalMultiplier = 1;
for (const upgrade of state.upgrades) {
if (upgrade.purchased && upgrade.target === "global") {
globalMultiplier = globalMultiplier * upgrade.multiplier;
}
}
const prestigeMultiplier = Math.pow(prestigeCombatBase, state.prestige.count);
// Apply equipped weapon's combat bonus
// eslint-disable-next-line capitalized-comments -- v8 ignore
/* v8 ignore next 7 -- @preserve */
const equipmentCombatMultiplier = state.equipment.
filter((item) => {
return item.equipped && item.bonus.combatMultiplier !== undefined;
}).
reduce((mult, item) => {
return mult * (item.bonus.combatMultiplier ?? 1);
}, 1);
// eslint-disable-next-line capitalized-comments -- v8 ignore
/* 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 partyMaxHp = 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 = adventurerMultiplier * upgrade.multiplier;
}
}
const adventurerContribution
= adventurer.combatPower
* adventurer.count
* adventurerMultiplier
* globalMultiplier
* prestigeMultiplier;
partyDPS = partyDPS + adventurerContribution;
const adventurerHp = adventurer.level * 50 * adventurer.count;
partyMaxHp = partyMaxHp + adventurerHp;
}
// 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 };
};
bossRouter.post("/challenge", async(context) => {
try {
const discordId = context.get("discordId");
const body = await context.req.json<{ bossId: string }>();
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions -- Runtime body validation
if (!body.bossId) {
return context.json({ error: "Invalid request body" }, 400);
}
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;
const boss = state.bosses.find((b) => {
return b.id === body.bossId;
});
if (!boss) {
return context.json({ error: "Boss not found" }, 404);
}
if (boss.status !== "available" && boss.status !== "in_progress") {
return context.json({ error: "Boss is not currently available" }, 400);
}
if (boss.prestigeRequirement > state.prestige.count) {
return context.json({ error: "Prestige requirement not met" }, 403);
}
const { partyDPS, partyMaxHp } = calculatePartyStats(state);
if (
partyDPS === 0
|| partyMaxHp === 0
|| !Number.isFinite(partyDPS)
|| !Number.isFinite(partyMaxHp)
) {
return context.json(
{ error: "Your party has no adventurers ready to fight" },
400,
);
}
const bossHpBefore = boss.currentHp;
const bossDPS = boss.damagePerSecond;
const timeToKillBoss = bossHpBefore / partyDPS;
const timeToKillParty = partyMaxHp / bossDPS;
const won = timeToKillBoss <= timeToKillParty;
// eslint-disable-next-line @typescript-eslint/init-declarations -- Conditionally assigned in if/else branches
let partyHpRemaining: number;
// eslint-disable-next-line @typescript-eslint/init-declarations -- Conditionally assigned in if/else branches
let bossHpAtBattleEnd: 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"];
// eslint-disable-next-line @typescript-eslint/init-declarations -- Conditionally assigned based on win/loss
let casualties: BossChallengeResponse["casualties"];
if (won) {
bossHpAtBattleEnd = 0;
bossUpdatedHp = 0;
const bossDamageDealt = bossDPS * timeToKillBoss;
partyHpRemaining = Math.max(0, partyMaxHp - bossDamageDealt);
boss.status = "defeated";
boss.currentHp = 0;
const crystalMult = state.prestige.runestonesCrystalMultiplier ?? 1;
state.resources.gold = state.resources.gold + boss.goldReward;
state.resources.essence = state.resources.essence + boss.essenceReward;
const crystalAward = boss.crystalReward * crystalMult;
state.resources.crystals = state.resources.crystals + crystalAward;
state.player.totalGoldEarned = state.player.totalGoldEarned + boss.goldReward;
for (const upgradeId of boss.upgradeRewards) {
const upgrade = state.upgrades.find((u) => {
return u.id === upgradeId;
});
if (upgrade) {
upgrade.unlocked = true;
}
}
// Grant equipment rewards — auto-equip if the slot is currently empty
// eslint-disable-next-line capitalized-comments -- v8 ignore
/* v8 ignore next 14 -- @preserve */
for (const equipmentId of boss.equipmentRewards) {
const equipment = state.equipment.find((item) => {
return item.id === equipmentId;
});
if (equipment) {
equipment.owned = true;
const slotAlreadyEquipped = state.equipment.some((item) => {
return item.type === equipment.type && item.equipped;
});
if (!slotAlreadyEquipped) {
equipment.equipped = true;
}
}
}
// Unlock next boss in the same zone (zone-based sequential progression)
const zoneBosses = state.bosses.filter((b) => {
return b.zoneId === boss.zoneId;
});
const zoneIndex = zoneBosses.findIndex((b) => {
return b.id === body.bossId;
});
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)
*/
// 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
const questSatisfied
= zone.unlockQuestId === null
|| state.quests.some((q) => {
return q.id === zone.unlockQuestId && q.status === "completed";
});
if (!questSatisfied) {
continue;
}
zone.status = "unlocked";
// Unlock exploration areas for the newly unlocked zone
for (const area of state.exploration?.areas ?? []) {
const areaDefinition = defaultExplorations.find((explorationArea) => {
return explorationArea.id === area.id;
});
// eslint-disable-next-line capitalized-comments -- v8 ignore
/* v8 ignore next 3 -- @preserve */
if (areaDefinition?.zoneId === zone.id && area.status === "locked") {
area.status = "available";
}
}
const updatedZoneBosses = state.bosses.filter((b) => {
return b.zoneId === zone.id;
});
const [ firstUpdatedBoss ] = updatedZoneBosses;
if (
firstUpdatedBoss
&& firstUpdatedBoss.prestigeRequirement <= state.prestige.count
) {
firstUpdatedBoss.status = "available";
}
}
// Update daily boss challenge progress
if (state.dailyChallenges) {
const { crystalsAwarded, updatedChallenges } = updateChallengeProgress(
state.dailyChallenges,
"bossesDefeated",
1,
);
state.dailyChallenges = updatedChallenges;
state.resources.crystals = state.resources.crystals + crystalsAwarded;
}
// First-kill bounty — only awarded once across all prestiges
const staticBoss = defaultBosses.find((b) => {
return b.id === body.bossId;
});
// eslint-disable-next-line capitalized-comments -- v8 ignore
/* v8 ignore next 7 -- @preserve */
const bountyRunestones
= boss.bountyRunestonesClaimed === true
? 0
: staticBoss?.bountyRunestones ?? 0;
if (bountyRunestones > 0) {
boss.bountyRunestonesClaimed = true;
}
state.prestige.runestones = state.prestige.runestones + bountyRunestones;
rewards = {
bountyRunestones: bountyRunestones,
crystals: crystalAward,
equipmentIds: boss.equipmentRewards,
essence: boss.essenceReward,
gold: boss.goldReward,
upgradeIds: boss.upgradeRewards,
};
} else {
const partyDamageDealt = partyDPS * timeToKillParty;
bossHpAtBattleEnd = Math.max(0, bossHpBefore - partyDamageDealt);
bossUpdatedHp = boss.maxHp;
partyHpRemaining = 0;
boss.status = "available";
boss.currentHp = boss.maxHp;
// How close was the party to winning? (0 = hopeless, 1 = nearly won)
const victoryProgress = Math.min(1, timeToKillParty / timeToKillBoss);
// Casualty rate scales from ~0% (nearly won) to 60% (completely outmatched)
const casualtyFraction = (1 - victoryProgress) * 0.6;
casualties = [];
for (const adventurer of state.adventurers) {
if (adventurer.count === 0) {
continue;
}
const killed = Math.floor(adventurer.count * casualtyFraction);
if (killed > 0) {
adventurer.count = Math.max(1, adventurer.count - killed);
casualties.push({ adventurerId: adventurer.id, killed: killed });
}
}
}
const now = Date.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 },
});
const secret = process.env.ANTI_CHEAT_SECRET;
const updatedSignature = secret === undefined
? undefined
: computeHmac(JSON.stringify(state), secret);
const { bossId } = body;
void logger.metric("boss_challenge", 1, { bossId, discordId, won });
const bossMaxHp = boss.maxHp;
const bossNewHp = bossUpdatedHp;
const response: BossChallengeResponse = {
bossDPS,
bossHpAtBattleEnd,
bossHpBefore,
bossMaxHp,
bossNewHp,
partyDPS,
partyHpRemaining,
partyMaxHp,
won,
};
if (rewards !== undefined) {
response.rewards = rewards;
}
if (casualties !== undefined) {
response.casualties = casualties;
}
if (updatedSignature !== undefined) {
response.signature = updatedSignature;
}
return context.json(response);
} catch (error) {
void logger.error(
"boss_challenge",
error instanceof Error
? error
: new Error(String(error)),
);
return context.json({ error: "Internal server error" }, 500);
}
});
export { bossRouter };
+191
View File
@@ -0,0 +1,191 @@
/**
* @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 { updateChallengeProgress } from "../services/dailyChallenges.js";
import { logger } from "../services/logger.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) => {
try {
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;
if (state.dailyChallenges !== undefined) {
const { updatedChallenges, crystalsAwarded } = updateChallengeProgress(
state.dailyChallenges,
"crafting",
1,
);
state.dailyChallenges = updatedChallenges;
state.resources.crystals = state.resources.crystals + crystalsAwarded;
}
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 },
});
void logger.metric("recipe_crafted", 1, { discordId, recipeId });
const bonusType = recipe.bonus.type;
const bonusValue = recipe.bonus.value;
const { materials } = state.exploration;
const {
craftedGoldMultiplier,
craftedEssenceMultiplier,
craftedClickMultiplier,
craftedCombatMultiplier,
} = updatedMultipliers;
const response: CraftRecipeResponse = {
bonusType,
bonusValue,
craftedClickMultiplier,
craftedCombatMultiplier,
craftedEssenceMultiplier,
craftedGoldMultiplier,
materials,
recipeId,
};
return context.json(response);
} catch (error) {
void logger.error(
"craft",
error instanceof Error
? error
: new Error(String(error)),
);
return context.json({ error: "Internal server error" }, 500);
}
});
export { craftRouter };
File diff suppressed because it is too large Load Diff
+441
View File
@@ -0,0 +1,441 @@
/**
* @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 */
/* eslint-disable max-lines -- Route file requires multiple handlers */
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 { logger } from "../services/logger.js";
import type { HonoEnvironment } from "../types/hono.js";
import type {
ExploreClaimableResponse,
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.get("/claimable", async(context) => {
try {
const discordId = context.get("discordId");
const areaId = context.req.query("areaId");
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions -- Runtime query 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) {
const response: ExploreClaimableResponse = { claimable: false };
return context.json(response);
}
const area = state.exploration.areas.find((a) => {
return a.id === areaId;
});
if (!area || area.status !== "in_progress") {
const response: ExploreClaimableResponse = { claimable: false };
return context.json(response);
}
// 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;
const claimable = Date.now() >= expiresAt;
const response: ExploreClaimableResponse = { claimable };
return context.json(response);
} catch (error) {
void logger.error(
"explore_claimable",
error instanceof Error
? error
: new Error(String(error)),
);
return context.json({ error: "Internal server error" }, 500);
}
});
exploreRouter.post("/start", async(context) => {
try {
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();
// eslint-disable-next-line stylistic/no-mixed-operators -- duration * 1000 is clear
const endsAt = now + explorationArea.durationSeconds * 1000;
area.status = "in_progress";
area.startedAt = now;
area.endsAt = endsAt;
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: ExploreStartResponse = {
areaId,
endsAt,
};
return context.json(response);
} catch (error) {
void logger.error(
"explore_start",
error instanceof Error
? error
: new Error(String(error)),
);
return context.json({ error: "Internal server error" }, 500);
}
});
exploreRouter.post("/collect", async(context) => {
try {
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);
} catch (error) {
void logger.error(
"explore_collect",
error instanceof Error
? error
: new Error(String(error)),
);
return context.json({ error: "Internal server error" }, 500);
}
});
export { exploreRouter };
+55
View File
@@ -0,0 +1,55 @@
/**
* @file Frontend logging routes that pipe client-side logs to the telemetry service.
* @copyright nhcarrigan
* @license Naomi's Public License
* @author Naomi Carrigan
*/
import { Hono } from "hono";
import { logger } from "../services/logger.js";
const validLevels = new Set([ "debug", "info", "warn" ]);
const frontendRouter = new Hono();
frontendRouter.post("/log", async(context) => {
try {
const body = await context.req.json<{ level: string; message: string }>();
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions -- Runtime body validation
if (!body.level || !body.message || !validLevels.has(body.level)) {
return context.json({ error: "level and message are required" }, 400);
}
/* eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- validated above */
void logger.log(body.level as "debug" | "info" | "warn", `[FE] ${body.message}`);
return context.json({ ok: true });
} catch (error) {
void logger.error(
"frontend_log",
error instanceof Error
? error
: new Error(String(error)),
);
return context.json({ error: "Internal server error" }, 500);
}
});
frontendRouter.post("/error", async(context) => {
try {
const body = await context.req.json<{ context: string; message: string }>();
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions -- Runtime body validation
if (!body.context || !body.message) {
return context.json({ error: "context and message are required" }, 400);
}
void logger.error(`[FE] ${body.context}`, new Error(body.message));
return context.json({ ok: true });
} catch (error) {
void logger.error(
"frontend_error",
error instanceof Error
? error
: new Error(String(error)),
);
return context.json({ error: "Internal server error" }, 500);
}
});
export { frontendRouter };
File diff suppressed because it is too large Load Diff
+138
View File
@@ -0,0 +1,138 @@
/**
* @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 { logger } from "../services/logger.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) => {
try {
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 });
} catch (error) {
void logger.error(
"leaderboards",
error instanceof Error
? error
: new Error(String(error)),
);
return context.json({ error: "Internal server error" }, 500);
}
});
export { leaderboardRouter };
+273
View File
@@ -0,0 +1,273 @@
/**
* @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 */
/* eslint-disable complexity -- Route handlers have inherent complexity */
import { Hono } from "hono";
import { defaultPrestigeUpgrades } from "../data/prestigeUpgrades.js";
import { prisma } from "../db/client.js";
import { authMiddleware } from "../middleware/auth.js";
import { updateChallengeProgress } from "../services/dailyChallenges.js";
import { logger } from "../services/logger.js";
import {
buildPostPrestigeState,
calculatePrestigeThreshold,
computeRunestoneMultipliers,
isEligibleForPrestige,
} from "../services/prestige.js";
import { postMilestoneWebhook } from "../services/webhook.js";
import type { HonoEnvironment } from "../types/hono.js";
import type { BuyPrestigeUpgradeRequest, GameState } from "@elysium/types";
const prestigeRouter = new Hono<HonoEnvironment>();
prestigeRouter.use("*", authMiddleware);
prestigeRouter.post("/", async(context) => {
try {
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 (!isEligibleForPrestige(state)) {
const thresholdMultiplier
= state.transcendence?.echoPrestigeThresholdMultiplier ?? 1;
const required = calculatePrestigeThreshold(
state.prestige.count,
thresholdMultiplier,
);
return context.json(
{
error: `Not eligible for prestige — collect ${required.toLocaleString()} total gold first`,
},
400,
);
}
// Update daily prestige challenge progress before resetting the run
let updatedDailyChallenges = state.dailyChallenges;
let challengeCrystals = 0;
if (updatedDailyChallenges) {
const result = updateChallengeProgress(
updatedDailyChallenges,
"prestige",
1,
);
updatedDailyChallenges = result.updatedChallenges;
challengeCrystals = result.crystalsAwarded;
}
const {
milestoneRunestones,
prestigeData,
prestigeState,
runestonesEarned,
} = buildPostPrestigeState(state, state.player.characterName);
// Preserve daily challenges across the prestige reset and apply any crystal rewards
const finalState: GameState = {
...prestigeState,
...updatedDailyChallenges === undefined
? {}
: { dailyChallenges: updatedDailyChallenges },
resources: {
...prestigeState.resources,
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 { updatedAt } = record;
/*
* Use the record's current updatedAt as an optimistic lock — if another
* concurrent prestige request already committed, this update will match
* 0 rows and we can safely reject the duplicate without a double webhook.
*/
const updateResult = await prisma.gameState.updateMany({
/* eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- Prisma requires object */
data: { state: finalState as object, updatedAt: now },
where: { discordId, updatedAt },
});
if (updateResult.count === 0) {
return context.json({ error: "Prestige already in progress" }, 409);
}
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 — never reset
lifetimeGoldEarned: { increment: state.player.totalGoldEarned },
lifetimeQuestsCompleted: { increment: runQuestsCompleted },
totalClicks: 0,
// Reset current-run counters
totalGoldEarned: 0,
},
where: { discordId },
});
const prestigeCount = prestigeData.count;
void logger.metric("prestige", 1, { discordId, prestigeCount });
const playerRecord = await prisma.player.findUnique({
select: { profileSettings: true },
where: { discordId },
});
/* eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- Runtime shape check for JSON field */
const playerSettings = playerRecord?.profileSettings as
Record<string, unknown> | null | undefined;
const announcementsEnabled
= playerSettings?.enablePrestigeAnnouncements !== false;
if (announcementsEnabled) {
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({
milestoneRunestones: milestoneRunestones,
newPrestigeCount: prestigeData.count, // eslint-disable-line unicorn/no-keyword-prefix -- API response field name required by client
runestones: runestonesEarned,
});
} catch (error) {
void logger.error(
"prestige",
error instanceof Error
? error
: new Error(String(error)),
);
return context.json({ error: "Internal server error" }, 500);
}
});
prestigeRouter.post("/buy-upgrade", async(context) => {
try {
const discordId = context.get("discordId");
const body = await context.req.json<BuyPrestigeUpgradeRequest>();
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 = defaultPrestigeUpgrades.find((prestigeUpgrade) => {
return prestigeUpgrade.id === upgradeId;
});
if (!upgrade) {
return context.json({ error: "Unknown prestige 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;
const { purchasedUpgradeIds, runestones } = state.prestige;
if (purchasedUpgradeIds.includes(upgradeId)) {
return context.json({ error: "Upgrade already purchased" }, 400);
}
if (runestones < upgrade.runestonesCost) {
return context.json({ error: "Not enough runestones" }, 400);
}
const updatedRunestones = runestones - upgrade.runestonesCost;
const updatedPurchasedUpgradeIds = [ ...purchasedUpgradeIds, upgradeId ];
const updatedState: GameState = {
...state,
prestige: {
...state.prestige,
purchasedUpgradeIds: updatedPurchasedUpgradeIds,
runestones: updatedRunestones,
...computeRunestoneMultipliers(updatedPurchasedUpgradeIds),
},
};
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 },
});
const multipliers = computeRunestoneMultipliers(updatedPurchasedUpgradeIds);
void logger.metric("prestige_upgrade_purchased", 1, {
discordId,
upgradeId,
});
return context.json({
purchasedUpgradeIds: updatedPurchasedUpgradeIds,
runestonesRemaining: updatedRunestones,
...multipliers,
});
} catch (error) {
void logger.error(
"prestige_buy_upgrade",
error instanceof Error
? error
: new Error(String(error)),
);
return context.json({ error: "Internal server error" }, 500);
}
});
export { prestigeRouter };
+293
View File
@@ -0,0 +1,293 @@
/**
* @file Profile routes handling player profile retrieval and updates.
* @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 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";
import { Hono } from "hono";
import { gameTitles } from "../data/titles.js";
import { prisma } from "../db/client.js";
import { authMiddleware } from "../middleware/auth.js";
import { logger } from "../services/logger.js";
import { parseUnlockedTitles } from "../services/titles.js";
import type { HonoEnvironment } from "../types/hono.js";
const profileRouter = new Hono<HonoEnvironment>();
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 => {
if (raw === null || typeof raw !== "object" || Array.isArray(raw)) {
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,
enablePrestigeAnnouncements: rawObject.enablePrestigeAnnouncements !== false,
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,
};
};
/**
* 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) => {
try {
const { discordId } = context.req.param();
const [ player, gameStateRecord ] = await Promise.all([
prisma.player.findUnique({ where: { discordId } }),
prisma.gameState.findUnique({ where: { discordId } }),
]);
if (!player) {
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 prestigeCount = state?.prestige.count ?? 0;
const transcendenceCount = state?.transcendence?.count ?? 0;
const apotheosisCount = state?.apotheosis?.count ?? 0;
const profileSettings = parseProfileSettings(player.profileSettings);
const bossesDefeated
= state?.bosses.filter((boss) => {
return boss.status === "defeated";
}).length ?? 0;
const questsCompleted
= 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({
achievementsUnlocked: achievementsUnlocked,
activeTitle: player.activeTitle,
adventurersRecruited: adventurersRecruited,
apotheosisCount: apotheosisCount,
avatar: player.avatar,
bio: player.bio ?? "",
bossesDefeated: bossesDefeated,
characterClass: player.characterClass,
characterName: player.characterName,
characterRace: player.characterRace ?? "",
completedChapters: completedChapters,
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,
});
} catch (error) {
void logger.error(
"profile_get",
error instanceof Error
? error
: new Error(String(error)),
);
return context.json({ error: "Internal server error" }, 500);
}
});
profileRouter.put("/", authMiddleware, async(context) => {
try {
const discordId = context.get("discordId");
const body = await context.req.json<UpdateProfileRequest>();
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions -- Runtime body validation
if (!body.characterName) {
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,
enablePrestigeAnnouncements: body.profileSettings.enablePrestigeAnnouncements ?? true,
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({
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 },
});
return context.json({
activeTitle: updated.activeTitle,
bio: updated.bio,
characterClass: updated.characterClass,
characterName: updated.characterName,
characterRace: updated.characterRace,
guildDescription: updated.guildDescription,
guildName: updated.guildName,
profileSettings: profileSettings,
pronouns: updated.pronouns,
});
} catch (error) {
void logger.error(
"profile_update",
error instanceof Error
? error
: new Error(String(error)),
);
return context.json({ error: "Internal server error" }, 500);
}
});
export { profileRouter };
+127
View File
@@ -0,0 +1,127 @@
/**
* @file Public read-only timer API for external tooling (bots, automations, etc.).
* @copyright nhcarrigan
* @license Naomi's Public License
* @author Naomi Carrigan
*/
import { Hono } from "hono";
import { defaultExplorations } from "../data/explorations.js";
import { prisma } from "../db/client.js";
import { logger } from "../services/logger.js";
import type { HonoEnvironment } from "../types/hono.js";
import type { GameState } from "@elysium/types";
const timersRouter = new Hono<HonoEnvironment>();
const explorationNameMap = new Map(
defaultExplorations.map((area) => {
return [ area.id, area.name ];
}),
);
/**
* Extracts active quest timers from a game state.
* @param state - The player's game state.
* @param now - The current timestamp in milliseconds.
* @returns An array of active quest timer objects.
*/
const getQuestTimers = (
state: GameState,
now: number,
): Array<{
endsAt: number;
name: string;
questId: string;
timeLeft: number;
}> => {
return state.quests.
filter((quest) => {
return quest.status === "active" && quest.startedAt !== undefined;
}).
map((quest) => {
const durationMs = quest.durationSeconds * 1000;
// eslint-disable-next-line capitalized-comments -- v8 ignore
/* v8 ignore next -- @preserve */
const endsAt = (quest.startedAt ?? 0) + durationMs;
return {
endsAt: endsAt,
name: quest.name,
questId: quest.id,
timeLeft: Math.max(0, endsAt - now),
};
});
};
/**
* Extracts active exploration timers from a game state.
* @param state - The player's game state.
* @param now - The current timestamp in milliseconds.
* @returns An array of active exploration timer objects.
*/
const getExplorationTimers = (
state: GameState,
now: number,
): Array<{
areaId: string;
endsAt: number;
name: string;
timeLeft: number;
}> => {
return (state.exploration?.areas ?? []).
filter((area) => {
return area.status === "in_progress" && area.endsAt !== undefined;
}).
map((area) => {
// eslint-disable-next-line capitalized-comments -- v8 ignore
/* v8 ignore next -- @preserve */
const endsAt = area.endsAt ?? 0;
return {
areaId: area.id,
endsAt: endsAt,
name: explorationNameMap.get(area.id) ?? area.id,
timeLeft: Math.max(0, endsAt - now),
};
});
};
/**
* Returns active quest and exploration timers for a given player.
* This endpoint is public and read-only — no authentication required.
* Rate limiting is enforced at the infrastructure level.
*/
timersRouter.get("/:userId", async(context) => {
try {
const { userId } = context.req.param();
if (userId.length === 0 || !/^\d+$/u.test(userId)) {
return context.json({ error: "Invalid user ID" }, 400);
}
const record = await prisma.gameState.findUnique({
where: { discordId: userId },
});
if (record === null) {
return context.json({ error: "Player not found" }, 404);
}
/* eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- Prisma returns JsonValue */
const state = record.state as unknown as GameState;
const now = Date.now();
return context.json({
explorations: getExplorationTimers(state, now),
quests: getQuestTimers(state, now),
});
} catch (error) {
void logger.error(
"timers",
error instanceof Error
? error
: new Error(String(error)),
);
return context.json({ error: "Internal server error" }, 500);
}
});
export { timersRouter };
+221
View File
@@ -0,0 +1,221 @@
/**
* @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 { logger } from "../services/logger.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) => {
try {
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(
{
// eslint-disable-next-line stylistic/max-len -- Error message cannot be shortened
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 },
});
const transcendenceCount = transcendenceData.count;
void logger.metric("transcendence", 1, { discordId, transcendenceCount });
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,
});
} catch (error) {
void logger.error(
"transcendence",
error instanceof Error
? error
: new Error(String(error)),
);
return context.json({ error: "Internal server error" }, 500);
}
});
transcendenceRouter.post("/buy-upgrade", async(context) => {
try {
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);
}
// eslint-disable-next-line stylistic/max-len -- Variable name mirrors the data source for clarity
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 },
});
void logger.metric("transcendence_upgrade_purchased", 1, {
discordId,
upgradeId,
});
return context.json({
echoesRemaining: updatedEchoes,
purchasedUpgradeIds: updatedPurchasedIds,
...updatedMultipliers,
});
} catch (error) {
void logger.error(
"transcendence_buy_upgrade",
error instanceof Error
? error
: new Error(String(error)),
);
return context.json({ error: "Internal server error" }, 500);
}
});
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 };
+195
View File
@@ -0,0 +1,195 @@
/**
* @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 {
DailyChallenge,
DailyChallengeState,
DailyChallengeType,
GameState,
} from "@elysium/types";
/**
* Returns today's date string in PST/PDT so challenges roll over at midnight Pacific.
* @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 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 x = Math.sin(seed + 1) * 10_000;
return x - Math.floor(x);
};
/**
* Converts a date string into a stable numeric seed.
* @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 (Fisher-Yates).
* @param array - The array to shuffle.
* @param seed - The seed controlling shuffle order.
* @returns A new shuffled array.
*/
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;
};
const nonProgressionChallengeTypes: Array<DailyChallengeType> = [
"crafting",
];
const progressionChallengeTypes: Array<DailyChallengeType> = [
"bossesDefeated",
"questsCompleted",
"prestige",
];
/**
* Generates 3 daily challenges for the given date string, deterministically.
* Always includes a "clicks" challenge and a "crafting" challenge (both
* completable regardless of zone/boss progression), then picks 1 more from
* the progression types. This ensures stuck players always have 2 completable
* challenges available.
* @param dateString - The date string (YYYY-MM-DD) to generate challenges for.
* @returns An array of 3 DailyChallenge objects.
*/
const generateDailyChallenges = (
dateString: string,
): Array<DailyChallenge> => {
const seed = dateSeed(dateString);
const selectedTypes: Array<DailyChallengeType> = [
"clicks",
...shuffleWithSeed(
[ ...nonProgressionChallengeTypes ],
seed + 500,
).slice(0, 1),
...shuffleWithSeed(
[ ...progressionChallengeTypes ],
seed,
).slice(0, 1),
];
return selectedTypes.map((type, index) => {
const templates = dailyChallengeTemplates.filter((template) => {
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]!;
return {
completed: false,
id: `${dateString}_${type}`,
label: template.label,
progress: 0,
rewardCrystals: template.rewardCrystals,
target: template.target,
type: template.type,
};
});
};
/**
* Returns the current daily challenge state, generating fresh challenges when
* the stored date does not match today.
* @param state - The current game state.
* @returns The current or freshly-generated DailyChallengeState.
*/
const getOrResetDailyChallenges = (
state: GameState,
): DailyChallengeState => {
const today = getTodayString();
if (state.dailyChallenges?.date === today) {
return state.dailyChallenges;
}
return { challenges: generateDailyChallenges(today), date: today };
};
/**
* Increments progress for challenges matching the given type.
* 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.
*/
const updateChallengeProgress = (
challengeState: DailyChallengeState,
type: DailyChallengeType,
amount: number,
): { updatedChallenges: DailyChallengeState; crystalsAwarded: number } => {
let crystalsAwarded = 0;
const updatedChallenges: DailyChallengeState = {
...challengeState,
challenges: challengeState.challenges.map((challenge) => {
if (challenge.type !== type || challenge.completed) {
return challenge;
}
const updatedProgress = Math.min(
challenge.progress + amount,
challenge.target,
);
const nowCompleted = updatedProgress >= challenge.target;
if (nowCompleted) {
crystalsAwarded = crystalsAwarded + challenge.rewardCrystals;
}
return {
...challenge,
completed: nowCompleted,
progress: updatedProgress,
};
}),
};
return { crystalsAwarded, updatedChallenges };
};
export {
generateDailyChallenges,
getOrResetDailyChallenges,
updateChallengeProgress,
};
+157
View File
@@ -0,0 +1,157 @@
/**
* @file Discord OAuth helpers for token exchange, user fetching, and URL building.
* @copyright nhcarrigan
* @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 */
import { logger } from "./logger.js";
const discordClientId = "1479551654264049908";
const discordRedirectUri = "https://elysium.nhcarrigan.com/api/auth/callback";
interface DiscordTokenResponse {
access_token: string;
token_type: string;
expires_in: number;
refresh_token: string;
scope: string;
}
interface DiscordUser {
id: string;
username: string;
discriminator: string;
avatar: string | null;
}
/**
* Exchanges a Discord OAuth authorisation code for an access token.
* @param code - The authorisation code received from Discord's OAuth callback.
* @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 clientSecret = process.env.DISCORD_CLIENT_SECRET;
if (clientSecret === undefined || clientSecret === "") {
throw new Error("Discord OAuth environment variables are required");
}
const parameters = new URLSearchParams({
client_id: discordClientId,
client_secret: clientSecret,
code: code,
grant_type: "authorization_code",
redirect_uri: discordRedirectUri,
});
try {
const response = await fetch("https://discord.com/api/v10/oauth2/token", {
body: parameters.toString(),
headers: { "Content-Type": "application/x-www-form-urlencoded" },
method: "POST",
});
if (!response.ok) {
throw new Error(`Discord token exchange failed: ${response.statusText}`);
}
/* eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- Response JSON matches DiscordTokenResponse shape */
return await (response.json() as Promise<DiscordTokenResponse>);
} catch (error) {
void logger.error(
"discord_exchange_code",
error instanceof Error
? error
: new Error(String(error)),
);
throw error;
}
};
/**
* 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> => {
try {
const response = await fetch("https://discord.com/api/v10/users/@me", {
headers: { Authorization: `Bearer ${accessToken}` },
});
if (!response.ok) {
throw new Error(`Discord user fetch failed: ${response.statusText}`);
}
/* eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- Response JSON matches DiscordUser shape */
return await (response.json() as Promise<DiscordUser>);
} catch (error) {
void logger.error(
"discord_fetch_user",
error instanceof Error
? error
: new Error(String(error)),
);
throw error;
}
};
/**
* Fetches a Discord user's profile by their Discord ID using the bot token.
* Returns null on any failure so callers are never blocked by Discord API issues.
* @param discordId - The Discord user ID to look up.
* @returns The Discord user object, or null if the fetch fails.
*/
const fetchDiscordUserById = async(
discordId: string,
): Promise<DiscordUser | null> => {
const botToken = process.env.DISCORD_BOT_TOKEN;
if (botToken === undefined || botToken === "") {
return null;
}
try {
const response = await fetch(
`https://discord.com/api/v10/users/${discordId}`,
{ headers: { Authorization: `Bot ${botToken}` } },
);
if (!response.ok) {
return null;
}
/* eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- Response JSON matches DiscordUser shape */
return await (response.json() as Promise<DiscordUser>);
} catch (error) {
void logger.error(
"discord_fetch_user_by_id",
error instanceof Error
? error
: new Error(String(error)),
);
return null;
}
};
/**
* Builds the Discord OAuth authorisation URL.
* @returns The full OAuth URL to redirect the user to.
* @throws {Error} If OAuth environment variables are missing.
*/
const buildOAuthUrl = (): string => {
const parameters = new URLSearchParams({
client_id: discordClientId,
redirect_uri: discordRedirectUri,
response_type: "code",
scope: "identify",
});
return `https://discord.com/api/oauth2/authorize?${parameters.toString()}`;
};
export type { DiscordTokenResponse, DiscordUser };
export { buildOAuthUrl, exchangeCode, fetchDiscordUser, fetchDiscordUserById };
+182
View File
@@ -0,0 +1,182 @@
/**
* @file Discord Gateway WebSocket client for listening to guild member events.
* @copyright nhcarrigan
* @license Naomi's Public License
* @author Naomi Carrigan
*/
/* eslint-disable max-lines-per-function -- WebSocket gateway requires sequential event handler setup */
import { prisma } from "../db/client.js";
import { logger } from "./logger.js";
const discordGuildId = "1354624415861833870";
/**
* Discord Gateway opcodes used by this client.
*/
const gatewayOpcodes = {
dispatch: 0,
heartbeat: 1,
heartbeatAck: 11,
hello: 10,
identify: 2,
} as const;
/**
* GUILD_MEMBERS privileged intent bitmask.
*/
/* eslint-disable-next-line no-bitwise -- Bitwise shift required for Discord intent bitmask */
const guildMembersIntent = 1 << 1;
/**
* Updates the inGuild flag for a player when they join the configured guild.
* No-ops silently if the Discord user has no player record.
* @param discordId - The Discord user ID of the member who joined.
* @param guildId - The ID of the guild they joined.
* @returns A promise that resolves when the update attempt completes.
*/
const handleGuildMemberAdd = async(
discordId: string,
guildId: string,
): Promise<void> => {
if (guildId !== discordGuildId) {
return;
}
try {
await prisma.player.updateMany({
data: { inGuild: true },
where: { discordId },
});
} catch (error) {
void logger.error(
"gateway_member_add",
error instanceof Error
? error
: new Error(String(error)),
);
}
};
/**
* Updates the inGuild flag for a player when they leave the configured guild.
* No-ops silently if the Discord user has no player record.
* @param discordId - The Discord user ID of the member who left.
* @param guildId - The ID of the guild they left.
* @returns A promise that resolves when the update attempt completes.
*/
const handleGuildMemberRemove = async(
discordId: string,
guildId: string,
): Promise<void> => {
if (guildId !== discordGuildId) {
return;
}
try {
await prisma.player.updateMany({
data: { inGuild: false },
where: { discordId },
});
} catch (error) {
void logger.error(
"gateway_member_remove",
error instanceof Error
? error
: new Error(String(error)),
);
}
};
// eslint-disable-next-line capitalized-comments -- v8 ignore directive must be lowercase
/* v8 ignore next 95 -- @preserve */
/**
* Connects to the Discord Gateway and listens for guild member events.
* Reconnects automatically on close or error.
* Requires the GUILD_MEMBERS privileged intent to be enabled in the Discord Developer Portal.
*/
const connectGateway = (): void => {
const botToken = process.env.DISCORD_BOT_TOKEN;
if (botToken === undefined || botToken === "") {
void logger.log("info", "Gateway: no bot token configured, skipping");
return;
}
const ws = new WebSocket("wss://gateway.discord.gg/?v=10&encoding=json");
let heartbeatInterval: ReturnType<typeof setInterval> | null = null;
let lastSequence: number | null = null;
const stopHeartbeat = (): void => {
if (heartbeatInterval !== null) {
clearInterval(heartbeatInterval);
heartbeatInterval = null;
}
};
ws.addEventListener("message", (event) => {
/* eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- Gateway payload is JSON */
const payload = JSON.parse(event.data as string) as {
op: number;
d: unknown;
s: number | null;
t: string | null;
};
if (payload.s !== null) {
lastSequence = payload.s;
}
if (payload.op === gatewayOpcodes.hello) {
/* eslint-disable-next-line @typescript-eslint/consistent-type-assertions, @typescript-eslint/naming-convention -- HELLO d shape; Discord API snake_case */
const helloData = payload.d as { heartbeat_interval: number };
const heartbeatMs = helloData.heartbeat_interval;
heartbeatInterval = setInterval(() => {
ws.send(JSON.stringify({
d: lastSequence,
op: gatewayOpcodes.heartbeat,
}));
}, heartbeatMs);
ws.send(JSON.stringify({
d: {
intents: guildMembersIntent,
properties: { browser: "elysium", device: "elysium", os: "linux" },
token: botToken,
},
op: gatewayOpcodes.identify,
}));
}
if (payload.op === gatewayOpcodes.dispatch && payload.t !== null) {
/* eslint-disable-next-line @typescript-eslint/consistent-type-assertions, @typescript-eslint/naming-convention -- dispatch payload shape; Discord API snake_case */
const data = payload.d as { user?: { id: string }; guild_id?: string };
const discordId = data.user?.id;
const guildId = data.guild_id;
if (discordId === undefined || guildId === undefined) {
return;
}
if (payload.t === "GUILD_MEMBER_ADD") {
void handleGuildMemberAdd(discordId, guildId);
} else if (payload.t === "GUILD_MEMBER_REMOVE") {
void handleGuildMemberRemove(discordId, guildId);
}
}
});
ws.addEventListener("close", () => {
stopHeartbeat();
void logger.log("info", "Gateway: connection closed, reconnecting in 5s");
setTimeout(connectGateway, 5000);
});
ws.addEventListener("error", (event) => {
const message
= event instanceof ErrorEvent
? event.message
: "WebSocket error";
void logger.error("gateway_error", new Error(message));
stopHeartbeat();
ws.close();
});
};
export { connectGateway, handleGuildMemberAdd, handleGuildMemberRemove };
+92
View File
@@ -0,0 +1,92 @@
/**
* @file JWT token signing and verification utilities.
* @copyright nhcarrigan
* @license Naomi's Public License
* @author Naomi Carrigan
*/
import { createHmac } from "node:crypto";
interface JwtPayload {
discordId: string;
iat: number;
exp: number;
}
const base64UrlEncode = (data: string): string => {
return Buffer.from(data).toString("base64url");
};
const base64UrlDecode = (data: string): string => {
return Buffer.from(data, "base64url").toString("utf8");
};
/**
* Signs a JWT token for the given Discord ID.
* @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");
}
const header = base64UrlEncode(JSON.stringify({ alg: "HS256", typ: "JWT" }));
// 30 days expiry
const thirtyDaysInSeconds = 60 * 60 * 24 * 30;
const payload = base64UrlEncode(
JSON.stringify({
discordId: discordId,
exp: Math.floor(Date.now() / 1000) + thirtyDaysInSeconds,
iat: Math.floor(Date.now() / 1000),
}),
);
const signature = createHmac("sha256", secret).
update(`${header}.${payload}`).
digest("base64url");
return `${header}.${payload}.${signature}`;
};
/**
* Verifies a JWT token and returns the decoded payload.
* @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");
}
const parts = token.split(".");
if (parts.length !== 3) {
throw new Error("Invalid token format");
}
/* 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).
update(`${header}.${payload}`).
digest("base64url");
if (signature !== expectedSignature) {
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;
if (decoded.exp < Math.floor(Date.now() / 1000)) {
throw new Error("Token has expired");
}
return decoded;
};
export { signToken, verifyToken };
+12
View File
@@ -0,0 +1,12 @@
/**
* @file Logger service for handling logging.
* @copyright nhcarrigan
* @license Naomi's Public License
* @author Naomi Carrigan
*/
import { Logger } from "@nhcarrigan/logger";
const logger = new Logger("Elysium", process.env.LOG_TOKEN ?? "");
export { logger };
+92
View File
@@ -0,0 +1,92 @@
/**
* @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";
/**
* Maximum offline accrual cap: 8 hours.
*/
const maxOfflineSeconds = 8 * 60 * 60;
/**
* Calculates the gold and essence earned whilst the player was offline.
* Capped at 8 hours to prevent exploit via system clock manipulation.
* 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.
*/
const calculateOfflineEarnings = (
state: GameState,
nowMs: number,
): { offlineGold: number; offlineEssence: number; offlineSeconds: number } => {
const elapsedSeconds = Math.min(
(nowMs - state.lastTickAt) / 1000,
maxOfflineSeconds,
);
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- Defensive check for runtime nullable fields
const equipmentGoldMultiplier = (state.equipment ?? []).
filter((item) => {
return item.equipped;
}).
reduce((mult, item) => {
return mult * (item.bonus.goldMultiplier ?? 1);
}, 1);
const runestonesIncome = state.prestige.runestonesIncomeMultiplier ?? 1;
const runestonesEssence = state.prestige.runestonesEssenceMultiplier ?? 1;
let goldPerSecond = 0;
let essencePerSecond = 0;
for (const adventurer of state.adventurers) {
if (!adventurer.unlocked || adventurer.count === 0) {
continue;
}
const upgradeMultiplier = state.upgrades.
filter((upgrade) => {
const isGlobal = upgrade.target === "global";
const isForAdventurer
= upgrade.target === "adventurer"
&& upgrade.adventurerId === adventurer.id;
const affectsAdventurer = isGlobal || isForAdventurer;
return upgrade.purchased && affectsAdventurer;
}).
reduce((mult, upgrade) => {
return mult * upgrade.multiplier;
}, 1);
const prestige = state.prestige.productionMultiplier;
const goldContribution
= adventurer.goldPerSecond
* adventurer.count
* upgradeMultiplier
* prestige
* runestonesIncome
* equipmentGoldMultiplier;
goldPerSecond = goldPerSecond + goldContribution;
const essenceContribution
= adventurer.essencePerSecond
* adventurer.count
* upgradeMultiplier
* prestige
* runestonesEssence;
essencePerSecond = essencePerSecond + essenceContribution;
}
return {
offlineEssence: essencePerSecond * elapsedSeconds,
offlineGold: goldPerSecond * elapsedSeconds,
offlineSeconds: elapsedSeconds,
};
};
export { calculateOfflineEarnings };
+335
View File
@@ -0,0 +1,335 @@
/**
* @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 */
/* eslint-disable complexity -- buildPostPrestigeState has many optional fields that each add a branch point */
import { initialGameState } from "../data/initialState.js";
import { defaultPrestigeUpgrades } from "../data/prestigeUpgrades.js";
import type {
GameState,
PrestigeData,
PrestigeUpgradeCategory,
} from "@elysium/types";
const basePrestigeGoldThreshold = 1_000_000;
const runestonesPerPrestigeLevel = 20;
const milestoneInterval = 5;
const milestoneRunestonesPerInterval = 25;
/*
* Hard cap on the base runestone yield (before multipliers) to prevent
* extreme AFK accumulation from producing game-breaking runestone counts.
* With all upgrades (5.625Ɨ max) this caps out at ~1,125 per prestige.
*/
const maxBaseRunestones = 200;
/**
* Calculates the gold threshold required for the next prestige.
* Formula: BASE * (count + 1)^2.5 — steeper growth to keep late prestiges
* meaningful even as the production multiplier scales.
* @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.
*/
const calculatePrestigeThreshold = (
prestigeCount: number,
thresholdMultiplier = 1,
): number => {
return (
basePrestigeGoldThreshold
* Math.pow(prestigeCount + 1, 2.5)
* thresholdMultiplier
);
};
/**
* 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 = (
purchasedUpgradeIds: Array<string>,
category: PrestigeUpgradeCategory,
): number => {
return defaultPrestigeUpgrades.filter((upgrade) => {
const matchesCategory = upgrade.category === category;
const isPurchased = purchasedUpgradeIds.includes(upgrade.id);
return matchesCategory && isPurchased;
}).reduce((mult, upgrade) => {
return mult * upgrade.multiplier;
}, 1);
};
/**
* 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;
runestonesClickMultiplier: number;
runestonesEssenceMultiplier: number;
runestonesCrystalMultiplier: number;
} => {
return {
runestonesClickMultiplier: getCategoryMultiplier(
purchasedUpgradeIds,
"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.
* Formula: min(floor(cbrt(totalGoldEarned / threshold)) * RUNESTONES_PER_PRESTIGE_LEVEL, MAX_BASE) * multipliers.
* Uses cube root for stronger diminishing returns than sqrt, and caps the base before multipliers
* to prevent extended AFK sessions from producing runestone windfalls.
* @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.
*/
const calculateRunestones = (parameters: RunestoneParameters): number => {
const {
totalGoldEarned,
prestigeCount,
purchasedUpgradeIds,
echoRunestoneMultiplier = 1,
} = parameters;
const threshold = calculatePrestigeThreshold(prestigeCount);
const base = Math.min(
Math.floor(Math.cbrt(totalGoldEarned / threshold))
* runestonesPerPrestigeLevel,
maxBaseRunestones,
);
const runestoneMult = getCategoryMultiplier(
purchasedUpgradeIds,
"runestones",
);
return Math.floor(base * runestoneMult * echoRunestoneMultiplier);
};
/**
* Calculates the new prestige production multiplier.
* Formula: 1.3^prestigeCount — exponential scaling per prestige that eventually
* overtakes the polynomial threshold growth, making late prestiges progressively easier.
* @param prestigeCount - The new prestige count.
* @returns The production multiplier for the new prestige level.
*/
const calculateProductionMultiplier = (
prestigeCount: number,
): number => {
return Math.pow(1.3, prestigeCount);
};
/**
* Returns the milestone runestone bonus for the given prestige count.
* 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.
*/
const calculateMilestoneBonus = (prestigeCount: number): number => {
if (prestigeCount % milestoneInterval !== 0) {
return 0;
}
const milestoneNumber = prestigeCount / milestoneInterval;
return milestoneNumber * milestoneNumber * milestoneRunestonesPerInterval;
};
/**
* Generates the reset game state after a prestige.
* 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.
*/
const buildPostPrestigeState = (
currentState: GameState,
characterName: string,
): {
prestigeState: GameState;
prestigeData: PrestigeData;
runestonesEarned: number;
milestoneRunestones: number;
} => {
const {
autoPrestigeEnabled,
autoPrestigeMaxRunestonesOnly,
count: currentPrestigeCount,
purchasedUpgradeIds,
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),
...autoPrestigeEnabled === undefined
? {}
: { autoPrestigeEnabled },
...autoPrestigeMaxRunestonesOnly === undefined
? {}
: { autoPrestigeMaxRunestonesOnly },
};
const freshState = initialGameState(currentState.player, characterName);
/*
* Preserve first-kill (bounty claimed) status across the prestige reset so
* the one-time bounty is never re-awarded in subsequent runs.
*/
const bossesWithBountyClaimed = freshState.bosses.map((freshBoss) => {
const currentBoss = currentState.bosses.find((candidate) => {
return candidate.id === freshBoss.id;
});
if (
currentBoss?.bountyRunestonesClaimed === true
|| currentBoss?.status === "defeated"
) {
return { ...freshBoss, bountyRunestonesClaimed: true };
}
return freshBoss;
});
// Compute current-run contributions to accumulate into lifetime totals
const runBossesDefeated = currentState.bosses.filter((boss) => {
return boss.status === "defeated";
}).length;
const runQuestsCompleted = currentState.quests.filter((quest) => {
return quest.status === "completed";
}).length;
let runAdventurersRecruited = 0;
for (const adventurer of currentState.adventurers) {
runAdventurersRecruited = runAdventurersRecruited + adventurer.count;
}
const runAchievementsUnlocked = currentState.achievements.filter(
(achievement) => {
return achievement.unlockedAt !== null;
},
).length;
const prestigeState: GameState = {
...freshState,
// Achievements are permanent — earned achievements survive all prestiges
achievements: currentState.achievements,
/*
* Preserve automation preferences across prestige — the player explicitly
* opted into these settings and would not expect them to silently reset.
*/
autoAdventurer: currentState.autoAdventurer ?? false,
autoBoss: currentState.autoBoss ?? false,
autoQuest: currentState.autoQuest ?? false,
// Boss statuses reset for gameplay, but first-kill claimed flag is preserved
bosses: bossesWithBountyClaimed,
lastTickAt: Date.now(),
/*
* Fold current-run totals into lifetime stats so the GameState reflects
* the true all-time values immediately after prestige.
*/
player: {
...freshState.player,
lifetimeAchievementsUnlocked:
freshState.player.lifetimeAchievementsUnlocked
+ runAchievementsUnlocked,
lifetimeAdventurersRecruited:
freshState.player.lifetimeAdventurersRecruited
+ runAdventurersRecruited,
lifetimeBossesDefeated:
freshState.player.lifetimeBossesDefeated + runBossesDefeated,
lifetimeClicks:
freshState.player.lifetimeClicks + currentState.player.totalClicks,
lifetimeGoldEarned:
freshState.player.lifetimeGoldEarned
+ currentState.player.totalGoldEarned,
lifetimeQuestsCompleted:
freshState.player.lifetimeQuestsCompleted + runQuestsCompleted,
},
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 {
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 = 224;
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,
};
+152
View File
@@ -0,0 +1,152 @@
/**
* @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 */
import { logger } from "./logger.js";
const discordApi = "https://discord.com/api/v10";
/**
* Discord MessageFlags.SUPPRESS_NOTIFICATIONS — messages are delivered without
* triggering desktop or mobile push notifications.
*/
const suppressNotifications = 4096;
/**
* The Discord role ID for the Elysian role granted to all Elysium players.
*/
const discordGuildId = "1354624415861833870";
const elysianRoleId = "1486144823684628490";
const apotheosisRoleId = "1479966598210129991";
/**
* Grants the Elysian Discord role to the given player and returns whether they are in the guild.
* Fails silently so role grant errors do not affect the auth flow.
* @param discordId - The Discord user ID to grant the role to.
* @returns True if the player is in the guild and the role was granted, false otherwise.
*/
const grantElysianRole = async(discordId: string): Promise<boolean> => {
const botToken = process.env.DISCORD_BOT_TOKEN;
if (botToken === undefined || botToken === "") {
return false;
}
try {
const response = await fetch(
`${discordApi}/guilds/${discordGuildId}/members/${discordId}/roles/${elysianRoleId}`,
{
headers: {
"Authorization": `Bot ${botToken}`,
"User-Agent": "DiscordBot (https://elysium.nhcarrigan.com, 1.0.0)",
},
method: "PUT",
},
);
return response.ok || response.status === 204;
} catch (error) {
void logger.error(
"webhook_elysian_role",
error instanceof Error
? error
: new Error(String(error)),
);
return false;
}
};
/**
* 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;
if (botToken === undefined || botToken === "") {
return;
}
try {
await fetch(
`${discordApi}/guilds/${discordGuildId}/members/${discordId}/roles/${apotheosisRoleId}`,
{
headers: {
"Authorization": `Bot ${botToken}`,
"User-Agent": "DiscordBot (https://elysium.nhcarrigan.com, 1.0.0)",
},
method: "PUT",
},
);
} catch (error) {
void logger.error(
"webhook_apotheosis_role",
error instanceof Error
? error
: new Error(String(error)),
);
// 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: content,
flags: suppressNotifications,
}),
headers: { "Content-Type": "application/json" },
method: "POST",
});
} catch (error) {
void logger.error(
"webhook_milestone",
error instanceof Error
? error
: new Error(String(error)),
);
// Graceful degradation — webhook failure must not affect the game action
}
};
export { grantApotheosisRole, grantElysianRole, postMilestoneWebhook };
+10
View File
@@ -0,0 +1,10 @@
/**
* @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 };
}
+100
View File
@@ -0,0 +1,100 @@
/* 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(),
}));
vi.mock("../../src/services/logger.js", () => ({
logger: {
error: vi.fn().mockResolvedValue(undefined),
},
}));
describe("authMiddleware", () => {
beforeEach(() => {
vi.resetModules();
vi.clearAllMocks();
});
const makeApp = async () => {
const { authMiddleware } = await import("../../src/middleware/auth.js");
const { verifyToken } = await import("../../src/services/jwt.js");
const { logger } = await import("../../src/services/logger.js");
const app = new Hono<{ Variables: { discordId: string } }>();
app.use("*", authMiddleware);
app.get("/test", (c) => c.json({ discordId: c.get("discordId") }));
return { app, logger, 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 and logs when verifyToken throws a non-expiry error", async () => {
const { app, logger, 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);
/* eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- logger mock requires cast */
expect((logger.error as ReturnType<typeof vi.fn>)).toHaveBeenCalledWith(
"auth_middleware",
expect.any(Error),
);
});
it("returns 401 and logs when verifyToken throws a non-Error value", async () => {
const { app, logger, verifyToken } = await makeApp();
vi.mocked(verifyToken).mockImplementationOnce(() => {
throw "raw string error";
});
const res = await app.fetch(new Request("http://localhost/test", {
headers: { Authorization: "Bearer bad_token" },
}));
expect(res.status).toBe(401);
/* eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- logger mock requires cast */
expect((logger.error as ReturnType<typeof vi.fn>)).toHaveBeenCalledWith(
"auth_middleware",
expect.any(Error),
);
});
it("returns 401 without logging when token has expired", async () => {
const { app, logger, verifyToken } = await makeApp();
vi.mocked(verifyToken).mockImplementationOnce(() => {
throw new Error("Token has expired");
});
const res = await app.fetch(new Request("http://localhost/test", {
headers: { Authorization: "Bearer expired_token" },
}));
expect(res.status).toBe(401);
/* eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- logger mock requires cast */
expect((logger.error as ReturnType<typeof vi.fn>)).not.toHaveBeenCalled();
});
});
+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");
});
});
+119
View File
@@ -0,0 +1,119 @@
/* 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 500 when the database throws", async () => {
vi.mocked(prisma.gameState.findUnique).mockRejectedValueOnce(new Error("DB error"));
const res = await post();
expect(res.status).toBe(500);
});
it("returns 500 when the database throws a non-Error value", async () => {
vi.mocked(prisma.gameState.findUnique).mockRejectedValueOnce("raw string error");
const res = await post();
expect(res.status).toBe(500);
});
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);
});
});
+126
View File
@@ -0,0 +1,126 @@
/* 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");
});
it("redirects with error when callback throws a non-Error value", async () => {
const { app, exchangeCode } = await makeApp();
exchangeCode.mockRejectedValueOnce("raw string error");
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");
});
});
});
+406
View File
@@ -0,0 +1,406 @@
/* 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);
});
it("handles zone unlock gracefully when exploration state is undefined", 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: null }] as GameState["zones"],
quests: [],
exploration: undefined,
});
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 exploration areas when a zone is unlocked on boss defeat", 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: null }] as GameState["zones"],
quests: [],
exploration: {
areas: [{ id: "test_area", status: "locked" as const }],
materials: [],
craftedRecipeIds: [],
craftedGoldMultiplier: 1,
craftedEssenceMultiplier: 1,
craftedClickMultiplier: 1,
craftedCombatMultiplier: 1,
},
});
vi.mocked(prisma.gameState.findUnique).mockResolvedValueOnce({ state } as never);
let savedState: GameState | undefined;
vi.mocked(prisma.gameState.update).mockImplementationOnce(async (args) => {
/* eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- Test assertion */
savedState = (args as { data: { state: GameState } }).data.state;
return {} as never;
});
const res = await challenge({ bossId: "test_boss" });
expect(res.status).toBe(200);
// Exploration area should remain locked — no matching defaultExploration for "test_area"
const area = savedState?.exploration?.areas.find((a) => a.id === "test_area");
expect(area?.status).toBe("locked");
});
it("includes HMAC signature in response when ANTI_CHEAT_SECRET is set", async () => {
process.env.ANTI_CHEAT_SECRET = "test_secret";
const state = makeState({
bosses: [makeBoss()] as GameState["bosses"],
adventurers: [makeAdventurer()] as GameState["adventurers"],
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 { signature: string | undefined };
expect(body.signature).toBeDefined();
delete process.env.ANTI_CHEAT_SECRET;
});
it("omits signature in response when ANTI_CHEAT_SECRET is not set", async () => {
delete process.env.ANTI_CHEAT_SECRET;
const state = makeState({
bosses: [makeBoss()] as GameState["bosses"],
adventurers: [makeAdventurer()] as GameState["adventurers"],
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 { signature: string | undefined };
expect(body.signature).toBeUndefined();
});
it("returns 500 when the database throws", async () => {
vi.mocked(prisma.gameState.findUnique).mockRejectedValueOnce(new Error("DB error"));
const res = await challenge({ bossId: "test_boss" });
expect(res.status).toBe(500);
});
it("returns 500 when the database throws a non-Error value", async () => {
vi.mocked(prisma.gameState.findUnique).mockRejectedValueOnce("raw string error");
const res = await challenge({ bossId: "test_boss" });
expect(res.status).toBe(500);
});
it("does not re-award bounty runestones when bountyRunestonesClaimed is true", async () => {
const state = makeState({
bosses: [makeBoss({
bountyRunestonesClaimed: true,
currentHp: 100,
damagePerSecond: 1,
maxHp: 100,
})] as GameState["bosses"],
adventurers: [makeAdventurer()] as GameState["adventurers"],
prestige: { count: 0, productionMultiplier: 1, purchasedUpgradeIds: [], runestones: 5 },
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: { bountyRunestones: number } };
expect(body.won).toBe(true);
expect(body.rewards.bountyRunestones).toBe(0);
});
});
+186
View File
@@ -0,0 +1,186 @@
/* 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");
});
it("updates crafting challenge progress and awards crystals when dailyChallenges is defined", async () => {
const state = makeState({
dailyChallenges: {
date: "2024-01-15",
challenges: [
{
completed: false,
id: "2024-01-15_crafting",
label: "Craft 1 recipe",
progress: 0,
rewardCrystals: 75,
target: 1,
type: "crafting",
},
],
},
});
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 updateArg = vi.mocked(prisma.gameState.update).mock.calls[0]![0] as {
data: { state: GameState };
};
expect(updateArg.data.state.dailyChallenges?.challenges[0]?.completed).toBe(true);
expect(updateArg.data.state.resources.crystals).toBe(75);
});
it("returns 500 when the database throws", async () => {
vi.mocked(prisma.gameState.findUnique).mockRejectedValueOnce(new Error("DB error"));
const res = await post({ recipeId: TEST_RECIPE_ID });
expect(res.status).toBe(500);
});
it("returns 500 when the database throws a non-Error value", async () => {
vi.mocked(prisma.gameState.findUnique).mockRejectedValueOnce("raw string error");
const res = await post({ recipeId: TEST_RECIPE_ID });
expect(res.status).toBe(500);
});
});
File diff suppressed because it is too large Load Diff
+545
View File
@@ -0,0 +1,545 @@
/* 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),
}));
const getClaimable = (areaId?: string) => {
const url = areaId === undefined
? "http://localhost/explore/claimable"
: `http://localhost/explore/claimable?areaId=${areaId}`;
return app.fetch(new Request(url));
};
describe("GET /claimable", () => {
it("returns 400 when areaId is missing", async () => {
const res = await getClaimable();
expect(res.status).toBe(400);
});
it("returns 404 for unknown area", async () => {
const res = await getClaimable("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 getClaimable(TEST_AREA_ID);
expect(res.status).toBe(404);
});
it("returns claimable=false when no exploration state exists", async () => {
const state = makeState({ exploration: undefined });
vi.mocked(prisma.gameState.findUnique).mockResolvedValueOnce({ state } as never);
const res = await getClaimable(TEST_AREA_ID);
expect(res.status).toBe(200);
const body = await res.json() as { claimable: boolean };
expect(body.claimable).toBe(false);
});
it("returns claimable=false when area is not in_progress", async () => {
const state = makeState();
vi.mocked(prisma.gameState.findUnique).mockResolvedValueOnce({ state } as never);
const res = await getClaimable(TEST_AREA_ID);
expect(res.status).toBe(200);
const body = await res.json() as { claimable: boolean };
expect(body.claimable).toBe(false);
});
it("returns claimable=false when exploration is still in progress", async () => {
const state = makeState({
exploration: {
areas: [{ id: TEST_AREA_ID, status: "in_progress", startedAt: Date.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 getClaimable(TEST_AREA_ID);
expect(res.status).toBe(200);
const body = await res.json() as { claimable: boolean };
expect(body.claimable).toBe(false);
});
it("returns claimable=true when exploration is complete", async () => {
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);
const res = await getClaimable(TEST_AREA_ID);
expect(res.status).toBe(200);
const body = await res.json() as { claimable: boolean };
expect(body.claimable).toBe(true);
});
it("returns 500 when the database throws", async () => {
vi.mocked(prisma.gameState.findUnique).mockRejectedValueOnce(new Error("DB error"));
const res = await getClaimable(TEST_AREA_ID);
expect(res.status).toBe(500);
});
it("returns 500 when the database throws a non-Error value", async () => {
vi.mocked(prisma.gameState.findUnique).mockRejectedValueOnce("raw string error");
const res = await getClaimable(TEST_AREA_ID);
expect(res.status).toBe(500);
});
});
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("persists endsAt to the DB state on exploration start", 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 };
const updateCall = vi.mocked(prisma.gameState.update).mock.calls[0]?.[0];
/* eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- Test accesses nested mock data */
const savedState = (updateCall?.data as { state?: { exploration?: { areas?: Array<{ id: string; endsAt?: number }> } } }).state;
const savedArea = savedState?.exploration?.areas?.find((a) => {
return a.id === TEST_AREA_ID;
});
expect(savedArea?.endsAt).toBe(body.endsAt);
});
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();
});
it("returns 500 when the database throws on collect", async () => {
vi.mocked(prisma.gameState.findUnique).mockRejectedValueOnce(new Error("DB error"));
const res = await postCollect({ areaId: TEST_AREA_ID });
expect(res.status).toBe(500);
});
it("returns 500 when the database throws a non-Error value on collect", async () => {
vi.mocked(prisma.gameState.findUnique).mockRejectedValueOnce("raw string error");
const res = await postCollect({ areaId: TEST_AREA_ID });
expect(res.status).toBe(500);
});
});
describe("POST /start error path", () => {
it("returns 500 when the database throws on start", async () => {
vi.mocked(prisma.gameState.findUnique).mockRejectedValueOnce(new Error("DB error"));
const res = await postStart({ areaId: TEST_AREA_ID });
expect(res.status).toBe(500);
});
it("returns 500 when the database throws a non-Error value on start", async () => {
vi.mocked(prisma.gameState.findUnique).mockRejectedValueOnce("raw string error");
const res = await postStart({ areaId: TEST_AREA_ID });
expect(res.status).toBe(500);
});
});
});
+136
View File
@@ -0,0 +1,136 @@
/* 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/logger.js", () => ({
logger: {
log: vi.fn().mockResolvedValue(undefined),
error: vi.fn().mockResolvedValue(undefined),
},
}));
describe("frontend route", () => {
let loggerMock: { log: ReturnType<typeof vi.fn>; error: ReturnType<typeof vi.fn> };
beforeEach(async () => {
vi.clearAllMocks();
const { logger } = await import("../../src/services/logger.js");
loggerMock = logger as typeof loggerMock;
});
const makeApp = async () => {
const { frontendRouter } = await import("../../src/routes/frontend.js");
const app = new Hono();
app.route("/frontend", frontendRouter);
return app;
};
const postLog = async (body: unknown, contentType = "application/json") => {
const app = await makeApp();
return app.fetch(new Request("http://localhost/frontend/log", {
method: "POST",
headers: { "Content-Type": contentType },
body: typeof body === "string" ? body : JSON.stringify(body),
}));
};
const postError = async (body: unknown, contentType = "application/json") => {
const app = await makeApp();
return app.fetch(new Request("http://localhost/frontend/error", {
method: "POST",
headers: { "Content-Type": contentType },
body: typeof body === "string" ? body : JSON.stringify(body),
}));
};
describe("POST /log", () => {
it("returns 200 when level is debug and message is present", async () => {
const res = await postLog({ level: "debug", message: "test debug" });
expect(res.status).toBe(200);
const body = await res.json() as { ok: boolean };
expect(body.ok).toBe(true);
});
it("returns 200 when level is info and message is present", async () => {
const res = await postLog({ level: "info", message: "test info" });
expect(res.status).toBe(200);
const body = await res.json() as { ok: boolean };
expect(body.ok).toBe(true);
});
it("returns 200 when level is warn and message is present", async () => {
const res = await postLog({ level: "warn", message: "test warn" });
expect(res.status).toBe(200);
const body = await res.json() as { ok: boolean };
expect(body.ok).toBe(true);
});
it("returns 400 when level is invalid", async () => {
const res = await postLog({ level: "error", message: "test" });
expect(res.status).toBe(400);
const body = await res.json() as { error: string };
expect(body.error).toBe("level and message are required");
});
it("returns 400 when level is missing", async () => {
const res = await postLog({ message: "test" });
expect(res.status).toBe(400);
});
it("returns 400 when message is missing", async () => {
const res = await postLog({ level: "info" });
expect(res.status).toBe(400);
});
it("returns 500 when request body is invalid JSON", async () => {
const res = await postLog("not valid json at all", "application/json");
expect(res.status).toBe(500);
const body = await res.json() as { error: string };
expect(body.error).toBe("Internal server error");
});
it("returns 500 and covers non-Error branch when logger throws a raw value", async () => {
loggerMock.log.mockImplementationOnce(() => { throw "raw string error"; });
const res = await postLog({ level: "info", message: "test" });
expect(res.status).toBe(500);
const body = await res.json() as { error: string };
expect(body.error).toBe("Internal server error");
});
});
describe("POST /error", () => {
it("returns 200 with valid context and message", async () => {
const res = await postError({ context: "SomeComponent", message: "Something went wrong" });
expect(res.status).toBe(200);
const body = await res.json() as { ok: boolean };
expect(body.ok).toBe(true);
});
it("returns 400 when context field is missing", async () => {
const res = await postError({ message: "Something went wrong" });
expect(res.status).toBe(400);
const body = await res.json() as { error: string };
expect(body.error).toBe("context and message are required");
});
it("returns 400 when message field is missing", async () => {
const res = await postError({ context: "SomeComponent" });
expect(res.status).toBe(400);
});
it("returns 500 when request body is invalid JSON", async () => {
const res = await postError("not valid json at all", "application/json");
expect(res.status).toBe(500);
const body = await res.json() as { error: string };
expect(body.error).toBe("Internal server error");
});
it("returns 500 and covers non-Error branch when logger throws a raw value", async () => {
loggerMock.error.mockImplementationOnce(() => { throw "raw string error"; });
const res = await postError({ context: "SomeComponent", message: "Something went wrong" });
expect(res.status).toBe(500);
const body = await res.json() as { error: string };
expect(body.error).toBe("Internal server error");
});
});
});
+600
View File
@@ -0,0 +1,600 @@
/* 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();
}),
}));
vi.mock("../../src/services/discord.js", () => ({
fetchDiscordUserById: vi.fn().mockResolvedValue(null),
}));
const DISCORD_ID = "test_discord_id";
const CURRENT_SCHEMA_VERSION = 2;
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);
});
it("syncs updated avatar from Discord into the returned state", 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, avatar: "old_hash" }) as never,
);
vi.mocked(prisma.gameState.update).mockResolvedValueOnce({} as never);
vi.mocked(prisma.player.update).mockResolvedValueOnce({} as never);
const { fetchDiscordUserById } = await import("../../src/services/discord.js");
vi.mocked(fetchDiscordUserById).mockResolvedValueOnce({
id: DISCORD_ID, username: "u", discriminator: "0", avatar: "new_hash",
});
const res = await app.fetch(new Request("http://localhost/game/load"));
expect(res.status).toBe(200);
const body = await res.json() as { state: GameState };
expect(body.state.player.avatar).toBe("new_hash");
});
it("continues loading when the avatar DB update fails", 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, avatar: "old_hash" }) as never,
);
vi.mocked(prisma.gameState.update).mockResolvedValueOnce({} as never);
vi.mocked(prisma.player.update).mockRejectedValueOnce(new Error("db error"));
const { fetchDiscordUserById } = await import("../../src/services/discord.js");
vi.mocked(fetchDiscordUserById).mockResolvedValueOnce({
id: DISCORD_ID, username: "u", discriminator: "0", avatar: "new_hash",
});
const res = await app.fetch(new Request("http://localhost/game/load"));
expect(res.status).toBe(200);
});
it("continues loading when the avatar DB update fails with a non-Error value", 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, avatar: "old_hash" }) as never,
);
vi.mocked(prisma.gameState.update).mockResolvedValueOnce({} as never);
vi.mocked(prisma.player.update).mockRejectedValueOnce("raw string error");
const { fetchDiscordUserById } = await import("../../src/services/discord.js");
vi.mocked(fetchDiscordUserById).mockResolvedValueOnce({
id: DISCORD_ID, username: "u", discriminator: "0", avatar: "new_hash",
});
const res = await app.fetch(new Request("http://localhost/game/load"));
expect(res.status).toBe(200);
});
it("keeps stored avatar when Discord returns null", 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, avatar: "stored_hash" }) as never,
);
vi.mocked(prisma.gameState.update).mockResolvedValueOnce({} as never);
const { fetchDiscordUserById } = await import("../../src/services/discord.js");
vi.mocked(fetchDiscordUserById).mockResolvedValueOnce(null);
const res = await app.fetch(new Request("http://localhost/game/load"));
expect(res.status).toBe(200);
const body = await res.json() as { state: GameState };
expect(body.state.player.avatar).toBe("stored_hash");
});
});
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("restores previous upgrades when incoming prestige count is lower (stale post-prestige save)", async () => {
const prevUpgrades = [
{ id: "click_1", purchased: false, unlocked: true, target: "click", multiplier: 2 },
] as GameState["upgrades"];
const prevState = makeState({
prestige: { count: 1, runestones: 10, productionMultiplier: 1.3, purchasedUpgradeIds: [] },
upgrades: prevUpgrades,
});
const incomingState = makeState({
prestige: { count: 0, runestones: 0, productionMultiplier: 1, purchasedUpgradeIds: [] },
upgrades: [
{ id: "click_1", purchased: true, unlocked: true, target: "click", multiplier: 2 },
] as GameState["upgrades"],
});
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);
});
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("GET /load error path", () => {
it("returns 500 when the database throws during load", async () => {
vi.mocked(prisma.gameState.findUnique).mockRejectedValueOnce(new Error("DB error"));
vi.mocked(prisma.player.findUnique).mockRejectedValueOnce(new Error("DB error"));
const res = await app.fetch(new Request("http://localhost/game/load"));
expect(res.status).toBe(500);
});
it("returns 500 when the database throws a non-Error value during load", async () => {
vi.mocked(prisma.gameState.findUnique).mockRejectedValueOnce("raw string error");
vi.mocked(prisma.player.findUnique).mockRejectedValueOnce("raw string error");
const res = await app.fetch(new Request("http://localhost/game/load"));
expect(res.status).toBe(500);
});
});
describe("POST /save error path", () => {
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 500 when the database throws during save", async () => {
const state = makeState();
vi.mocked(prisma.gameState.findUnique).mockRejectedValueOnce(new Error("DB error"));
const res = await save({ state });
expect(res.status).toBe(500);
});
it("returns 500 when the database throws a non-Error value during save", async () => {
const state = makeState();
vi.mocked(prisma.gameState.findUnique).mockRejectedValueOnce("raw string error");
const res = await save({ state });
expect(res.status).toBe(500);
});
});
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");
});
it("returns 500 when the database throws during reset", async () => {
vi.mocked(prisma.player.findUnique).mockRejectedValueOnce(new Error("DB error"));
const res = await reset();
expect(res.status).toBe(500);
});
it("returns 500 when the database throws a non-Error value during reset", async () => {
vi.mocked(prisma.player.findUnique).mockRejectedValueOnce("raw string error");
const res = await reset();
expect(res.status).toBe(500);
});
});
});
+210
View File
@@ -0,0 +1,210 @@
/* 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("returns 500 when the database throws", async () => {
vi.mocked(prisma.player.findMany).mockRejectedValueOnce(new Error("DB error"));
const res = await get();
expect(res.status).toBe(500);
});
it("returns 500 when the database throws a non-Error value", async () => {
vi.mocked(prisma.player.findMany).mockRejectedValueOnce("raw string error");
const res = await get();
expect(res.status).toBe(500);
});
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);
});
});
+210
View File
@@ -0,0 +1,210 @@
/* 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(), update: vi.fn(), updateMany: 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: { findUnique: ReturnType<typeof vi.fn>; update: ReturnType<typeof vi.fn> };
gameState: { findUnique: ReturnType<typeof vi.fn>; update: ReturnType<typeof vi.fn>; updateMany: 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 400 with echoPrestigeThresholdMultiplier applied when transcendence is present", async () => {
const state = makeState({
player: { discordId: DISCORD_ID, username: "u", discriminator: "0", avatar: null, totalGoldEarned: 500_000, totalClicks: 0, characterName: "T" },
transcendence: { count: 1, echoes: 0, purchasedUpgradeIds: [], echoIncomeMultiplier: 1, echoCombatMultiplier: 1, echoPrestigeThresholdMultiplier: 2, echoPrestigeRunestoneMultiplier: 1, echoMetaMultiplier: 1 },
});
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, updatedAt: 0 } as never);
vi.mocked(prisma.gameState.updateMany).mockResolvedValueOnce({ count: 1 } 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("returns 409 when a concurrent prestige already committed", async () => {
const state = makeState();
vi.mocked(prisma.gameState.findUnique).mockResolvedValueOnce({ state, updatedAt: 0 } as never);
vi.mocked(prisma.gameState.updateMany).mockResolvedValueOnce({ count: 0 } as never);
const res = await post("");
expect(res.status).toBe(409);
});
it("returns 500 when the database throws during prestige", async () => {
vi.mocked(prisma.gameState.findUnique).mockRejectedValueOnce(new Error("DB error"));
const res = await post("");
expect(res.status).toBe(500);
});
it("returns 500 when the database throws a non-Error value during prestige", async () => {
vi.mocked(prisma.gameState.findUnique).mockRejectedValueOnce("raw string error");
const res = await post("");
expect(res.status).toBe(500);
});
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, updatedAt: 0 } as never);
vi.mocked(prisma.gameState.updateMany).mockResolvedValueOnce({ count: 1 } 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);
});
it("skips webhook when enablePrestigeAnnouncements is false", async () => {
const { postMilestoneWebhook } = await import("../../src/services/webhook.js");
const state = makeState();
vi.mocked(prisma.gameState.findUnique).mockResolvedValueOnce({ state, updatedAt: 0 } as never);
vi.mocked(prisma.gameState.updateMany).mockResolvedValueOnce({ count: 1 } as never);
vi.mocked(prisma.player.update).mockResolvedValueOnce({} as never);
vi.mocked(prisma.player.findUnique).mockResolvedValueOnce({ profileSettings: { enablePrestigeAnnouncements: false } } as never);
const res = await post("");
expect(res.status).toBe(200);
expect(postMilestoneWebhook).not.toHaveBeenCalledWith(expect.anything(), "prestige", expect.anything());
});
});
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");
});
it("returns 500 when the database throws during buy-upgrade", async () => {
vi.mocked(prisma.gameState.findUnique).mockRejectedValueOnce(new Error("DB error"));
const res = await post("/buy-upgrade", { upgradeId: "income_1" });
expect(res.status).toBe(500);
});
it("returns 500 when the database throws a non-Error value during buy-upgrade", async () => {
vi.mocked(prisma.gameState.findUnique).mockRejectedValueOnce("raw string error");
const res = await post("/buy-upgrade", { upgradeId: "income_1" });
expect(res.status).toBe(500);
});
});
});
+290
View File
@@ -0,0 +1,290 @@
/* 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("returns 500 when the database throws during profile get", async () => {
vi.mocked(prisma.player.findUnique).mockRejectedValueOnce(new Error("DB error"));
const res = await app.fetch(new Request(`http://localhost/profile/${DISCORD_ID}`));
expect(res.status).toBe(500);
});
it("returns 500 when the database throws a non-Error value during profile get", async () => {
vi.mocked(prisma.player.findUnique).mockRejectedValueOnce("raw string error");
const res = await app.fetch(new Request(`http://localhost/profile/${DISCORD_ID}`));
expect(res.status).toBe(500);
});
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");
});
it("returns 500 when the database throws during profile update", async () => {
vi.mocked(prisma.player.update).mockRejectedValueOnce(new Error("DB error"));
const res = await put({
characterName: "NewName",
profileSettings: { numberFormat: "suffix" },
});
expect(res.status).toBe(500);
});
it("returns 500 when the database throws a non-Error value during profile update", async () => {
vi.mocked(prisma.player.update).mockRejectedValueOnce("raw string error");
const res = await put({
characterName: "NewName",
profileSettings: { numberFormat: "suffix" },
});
expect(res.status).toBe(500);
});
});
});
+189
View File
@@ -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 { beforeEach, describe, expect, it, vi } from "vitest";
import { Hono } from "hono";
vi.mock("../../src/db/client.js", () => ({
prisma: {
gameState: { findUnique: vi.fn() },
},
}));
vi.mock("../../src/services/logger.js", () => ({
logger: {
error: vi.fn().mockResolvedValue(undefined),
log: vi.fn().mockResolvedValue(undefined),
},
}));
const makeState = (overrides: Record<string, unknown> = {}) => ({
quests: [],
exploration: { areas: [] },
...overrides,
});
describe("timers route", () => {
let app: Hono;
let prisma: { gameState: { findUnique: ReturnType<typeof vi.fn> } };
beforeEach(async () => {
vi.clearAllMocks();
const { timersRouter } = await import("../../src/routes/timers.js");
const { prisma: p } = await import("../../src/db/client.js");
prisma = p as typeof prisma;
app = new Hono();
app.route("/timers", timersRouter);
});
const get = (userId: string) =>
app.fetch(new Request(`http://localhost/timers/${userId}`));
it("returns 400 for a non-numeric user ID", async () => {
const res = await get("not-a-number");
expect(res.status).toBe(400);
const body = await res.json() as { error: string };
expect(body.error).toBe("Invalid user ID");
});
it("returns 404 when player is not found", async () => {
vi.mocked(prisma.gameState.findUnique).mockResolvedValueOnce(null);
const res = await get("123456789");
expect(res.status).toBe(404);
const body = await res.json() as { error: string };
expect(body.error).toBe("Player not found");
});
it("returns empty arrays when no active quests or explorations", async () => {
vi.mocked(prisma.gameState.findUnique).mockResolvedValueOnce({
state: makeState(),
});
const res = await get("123456789");
expect(res.status).toBe(200);
const body = await res.json() as { quests: unknown[]; explorations: unknown[] };
expect(body.quests).toEqual([]);
expect(body.explorations).toEqual([]);
});
it("returns active quest timers with endsAt computed from startedAt + duration", async () => {
const startedAt = Date.now() - 30_000;
const state = makeState({
quests: [
{
id: "q1",
name: "Forest Patrol",
status: "active",
startedAt: startedAt,
durationSeconds: 600,
},
],
});
vi.mocked(prisma.gameState.findUnique).mockResolvedValueOnce({ state });
const res = await get("123456789");
expect(res.status).toBe(200);
const body = await res.json() as {
quests: Array<{ questId: string; name: string; endsAt: number; timeLeft: number }>;
};
expect(body.quests).toHaveLength(1);
expect(body.quests[0]?.questId).toBe("q1");
expect(body.quests[0]?.name).toBe("Forest Patrol");
expect(body.quests[0]?.endsAt).toBe(startedAt + 600_000);
expect(body.quests[0]?.timeLeft).toBeGreaterThan(0);
});
it("filters out quests that are not in_progress", async () => {
const state = makeState({
quests: [
{ id: "q1", name: "Done Quest", status: "completed", startedAt: 0, durationSeconds: 60 },
{ id: "q2", name: "Idle Quest", status: "available", durationSeconds: 60 },
],
});
vi.mocked(prisma.gameState.findUnique).mockResolvedValueOnce({ state });
const res = await get("123456789");
const body = await res.json() as { quests: unknown[] };
expect(body.quests).toHaveLength(0);
});
it("returns timeLeft of 0 for already-completed quests still marked in_progress", async () => {
const startedAt = Date.now() - 700_000;
const state = makeState({
quests: [
{
id: "q1",
name: "Old Quest",
status: "active",
startedAt: startedAt,
durationSeconds: 600,
},
],
});
vi.mocked(prisma.gameState.findUnique).mockResolvedValueOnce({ state });
const res = await get("123456789");
const body = await res.json() as {
quests: Array<{ timeLeft: number }>;
};
expect(body.quests[0]?.timeLeft).toBe(0);
});
it("returns active exploration timers", async () => {
const endsAt = Date.now() + 120_000;
const state = makeState({
exploration: {
areas: [
{ id: "verdant_meadows", status: "in_progress", endsAt },
{ id: "unknown_area_xyz", status: "in_progress", endsAt },
],
},
});
vi.mocked(prisma.gameState.findUnique).mockResolvedValueOnce({ state });
const res = await get("123456789");
const body = await res.json() as {
explorations: Array<{ areaId: string; name: string; endsAt: number; timeLeft: number }>;
};
expect(body.explorations).toHaveLength(2);
expect(body.explorations[0]?.areaId).toBe("verdant_meadows");
expect(body.explorations[0]?.endsAt).toBe(endsAt);
expect(body.explorations[0]?.timeLeft).toBeGreaterThan(0);
// Unknown area falls back to ID as name
expect(body.explorations[1]?.name).toBe("unknown_area_xyz");
});
it("filters out explorations not in_progress", async () => {
const state = makeState({
exploration: {
areas: [
{ id: "area1", status: "available" },
{ id: "area2", status: "completed" },
],
},
});
vi.mocked(prisma.gameState.findUnique).mockResolvedValueOnce({ state });
const res = await get("123456789");
const body = await res.json() as { explorations: unknown[] };
expect(body.explorations).toHaveLength(0);
});
it("handles missing exploration state gracefully", async () => {
const state = { quests: [] };
vi.mocked(prisma.gameState.findUnique).mockResolvedValueOnce({ state });
const res = await get("123456789");
expect(res.status).toBe(200);
const body = await res.json() as { explorations: unknown[] };
expect(body.explorations).toHaveLength(0);
});
it("returns 500 on database error", async () => {
vi.mocked(prisma.gameState.findUnique).mockRejectedValueOnce(
new Error("DB failure"),
);
const res = await get("123456789");
expect(res.status).toBe(500);
const body = await res.json() as { error: string };
expect(body.error).toBe("Internal server error");
});
it("returns 500 and logs non-Error throws", async () => {
vi.mocked(prisma.gameState.findUnique).mockRejectedValueOnce("string error");
const res = await get("123456789");
expect(res.status).toBe(500);
});
});
+177
View File
@@ -0,0 +1,177 @@
/* 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);
});
it("returns 500 when the database throws during transcendence", async () => {
vi.mocked(prisma.gameState.findUnique).mockRejectedValueOnce(new Error("DB error"));
const res = await post("");
expect(res.status).toBe(500);
});
it("returns 500 when the database throws a non-Error value during transcendence", async () => {
vi.mocked(prisma.gameState.findUnique).mockRejectedValueOnce("raw string error");
const res = await post("");
expect(res.status).toBe(500);
});
});
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(98); // 100 - 2
expect(body.purchasedUpgradeIds).toContain("echo_income_1");
});
it("returns 500 when the database throws during buy-upgrade", async () => {
vi.mocked(prisma.gameState.findUnique).mockRejectedValueOnce(new Error("DB error"));
const res = await post("/buy-upgrade", { upgradeId: "echo_income_1" });
expect(res.status).toBe(500);
});
it("returns 500 when the database throws a non-Error value during buy-upgrade", async () => {
vi.mocked(prisma.gameState.findUnique).mockRejectedValueOnce("raw string error");
const res = await post("/buy-upgrade", { upgradeId: "echo_income_1" });
expect(res.status).toBe(500);
});
});
});
+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,186 @@
/* 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("always includes a clicks challenge regardless of date", 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");
expect(day1.some((c) => c.type === "clicks")).toBe(true);
expect(day2.some((c) => c.type === "clicks")).toBe(true);
});
it("always includes a crafting challenge regardless of date", 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");
expect(day1.some((c) => c.type === "crafting")).toBe(true);
expect(day2.some((c) => c.type === "crafting")).toBe(true);
});
it("progression challenge slot varies across different dates", async () => {
vi.setSystemTime(LA_MIDNIGHT_2024_01_15);
const { generateDailyChallenges } = await import("../../src/services/dailyChallenges.js");
// 2024-01-01 picks bossesDefeated, 2024-01-02 picks prestige (verified by seed)
const day1 = generateDailyChallenges("2024-01-01");
const day2 = generateDailyChallenges("2024-01-02");
const day1ProgressionType = day1.find((c) => {
return c.type !== "clicks" && c.type !== "crafting";
})?.type;
const day2ProgressionType = day2.find((c) => {
return c.type !== "clicks" && c.type !== "crafting";
})?.type;
expect(day1ProgressionType).not.toBe(day2ProgressionType);
});
});
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);
});
});
+134
View File
@@ -0,0 +1,134 @@
/* 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("returns a URL with correct query params", async () => {
const { buildOAuthUrl } = await import("../../src/services/discord.js");
const url = buildOAuthUrl();
expect(url).toContain("client_id=1479551654264049908");
expect(url).toContain("response_type=code");
expect(url).toContain("scope=identify");
});
});
describe("exchangeCode", () => {
it("throws when DISCORD_CLIENT_SECRET is missing", async () => {
delete process.env["DISCORD_CLIENT_SECRET"];
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_SECRET"] = "secret";
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_SECRET"] = "secret";
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");
});
it("re-throws when fetch rejects with a non-Error value", async () => {
mockFetch.mockRejectedValueOnce("raw string error");
const { fetchDiscordUser } = await import("../../src/services/discord.js");
await expect(fetchDiscordUser("some_token")).rejects.toBe("raw string error");
});
});
describe("exchangeCode non-Error throw", () => {
it("re-throws when fetch rejects with a non-Error value", async () => {
process.env["DISCORD_CLIENT_SECRET"] = "secret";
mockFetch.mockRejectedValueOnce("raw string error");
const { exchangeCode } = await import("../../src/services/discord.js");
await expect(exchangeCode("some_code")).rejects.toBe("raw string error");
});
});
describe("fetchDiscordUserById", () => {
it("returns null when DISCORD_BOT_TOKEN is missing", async () => {
delete process.env["DISCORD_BOT_TOKEN"];
const { fetchDiscordUserById } = await import("../../src/services/discord.js");
const result = await fetchDiscordUserById("123456");
expect(result).toBeNull();
});
it("returns null when DISCORD_BOT_TOKEN is empty", async () => {
process.env["DISCORD_BOT_TOKEN"] = "";
const { fetchDiscordUserById } = await import("../../src/services/discord.js");
const result = await fetchDiscordUserById("123456");
expect(result).toBeNull();
});
it("returns null when response is not ok", async () => {
process.env["DISCORD_BOT_TOKEN"] = "bot_token";
mockFetch.mockResolvedValueOnce({ ok: false, statusText: "Not Found" });
const { fetchDiscordUserById } = await import("../../src/services/discord.js");
const result = await fetchDiscordUserById("123456");
expect(result).toBeNull();
});
it("returns null when fetch throws", async () => {
process.env["DISCORD_BOT_TOKEN"] = "bot_token";
mockFetch.mockRejectedValueOnce(new Error("network error"));
const { fetchDiscordUserById } = await import("../../src/services/discord.js");
const result = await fetchDiscordUserById("123456");
expect(result).toBeNull();
});
it("returns null when fetch throws a non-Error value", async () => {
process.env["DISCORD_BOT_TOKEN"] = "bot_token";
mockFetch.mockRejectedValueOnce("raw string error");
const { fetchDiscordUserById } = await import("../../src/services/discord.js");
const result = await fetchDiscordUserById("123456");
expect(result).toBeNull();
});
it("returns the user on success", async () => {
process.env["DISCORD_BOT_TOKEN"] = "bot_token";
const user = { id: "123456", username: "testuser", discriminator: "0", avatar: "abc123" };
mockFetch.mockResolvedValueOnce({ ok: true, json: () => Promise.resolve(user) });
const { fetchDiscordUserById } = await import("../../src/services/discord.js");
const result = await fetchDiscordUserById("123456");
expect(result).toMatchObject({ id: "123456", avatar: "abc123" });
});
});
});
+105
View File
@@ -0,0 +1,105 @@
/* eslint-disable max-lines-per-function -- Test suites naturally have many cases */
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
vi.mock("../../src/db/client.js", () => ({
prisma: {
player: { updateMany: vi.fn() },
},
}));
vi.mock("../../src/services/logger.js", () => ({
logger: {
error: vi.fn().mockResolvedValue(undefined),
log: vi.fn().mockResolvedValue(undefined),
},
}));
import { prisma } from "../../src/db/client.js";
const discordGuildId = "1354624415861833870";
describe("gateway service", () => {
beforeEach(() => {
vi.resetAllMocks();
});
afterEach(() => {
vi.clearAllMocks();
});
describe("handleGuildMemberAdd", () => {
it("sets inGuild to true for the matching guild", async () => {
vi.mocked(prisma.player.updateMany).mockResolvedValueOnce({ count: 1 });
const { handleGuildMemberAdd } = await import("../../src/services/gateway.js");
await handleGuildMemberAdd("user123", discordGuildId);
expect(prisma.player.updateMany).toHaveBeenCalledWith({
data: { inGuild: true },
where: { discordId: "user123" },
});
});
it("no-ops when guild id does not match the configured guild", async () => {
const { handleGuildMemberAdd } = await import("../../src/services/gateway.js");
await handleGuildMemberAdd("user123", "other_guild");
expect(prisma.player.updateMany).not.toHaveBeenCalled();
});
it("logs error when prisma throws an Error", async () => {
const dbError = new Error("DB failure");
vi.mocked(prisma.player.updateMany).mockRejectedValueOnce(dbError);
const { handleGuildMemberAdd } = await import("../../src/services/gateway.js");
const { logger } = await import("../../src/services/logger.js");
await handleGuildMemberAdd("user123", discordGuildId);
expect(logger.error).toHaveBeenCalledWith("gateway_member_add", dbError);
});
it("logs error when prisma throws a non-Error", async () => {
vi.mocked(prisma.player.updateMany).mockRejectedValueOnce("raw error");
const { handleGuildMemberAdd } = await import("../../src/services/gateway.js");
const { logger } = await import("../../src/services/logger.js");
await handleGuildMemberAdd("user123", discordGuildId);
expect(logger.error).toHaveBeenCalledWith(
"gateway_member_add",
new Error("raw error"),
);
});
});
describe("handleGuildMemberRemove", () => {
it("sets inGuild to false for the matching guild", async () => {
vi.mocked(prisma.player.updateMany).mockResolvedValueOnce({ count: 1 });
const { handleGuildMemberRemove } = await import("../../src/services/gateway.js");
await handleGuildMemberRemove("user123", discordGuildId);
expect(prisma.player.updateMany).toHaveBeenCalledWith({
data: { inGuild: false },
where: { discordId: "user123" },
});
});
it("no-ops when guild id does not match the configured guild", async () => {
const { handleGuildMemberRemove } = await import("../../src/services/gateway.js");
await handleGuildMemberRemove("user123", "other_guild");
expect(prisma.player.updateMany).not.toHaveBeenCalled();
});
it("logs error when prisma throws an Error", async () => {
const dbError = new Error("DB failure");
vi.mocked(prisma.player.updateMany).mockRejectedValueOnce(dbError);
const { handleGuildMemberRemove } = await import("../../src/services/gateway.js");
const { logger } = await import("../../src/services/logger.js");
await handleGuildMemberRemove("user123", discordGuildId);
expect(logger.error).toHaveBeenCalledWith("gateway_member_remove", dbError);
});
it("logs error when prisma throws a non-Error", async () => {
vi.mocked(prisma.player.updateMany).mockRejectedValueOnce("raw error");
const { handleGuildMemberRemove } = await import("../../src/services/gateway.js");
const { logger } = await import("../../src/services/logger.js");
await handleGuildMemberRemove("user123", discordGuildId);
expect(logger.error).toHaveBeenCalledWith(
"gateway_member_remove",
new Error("raw error"),
);
});
});
});
+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);
});
});
+426
View File
@@ -0,0 +1,426 @@
/* 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,
lifetimeGoldEarned = 0,
totalClicks = 0,
) => ({
avatar: null,
characterName: "Tester",
discordId: "test_id",
discriminator: "0",
lifetimeAchievementsUnlocked: 0,
lifetimeAdventurersRecruited: 0,
lifetimeBossesDefeated: 0,
lifetimeClicks: 0,
lifetimeGoldEarned: lifetimeGoldEarned,
lifetimeQuestsCompleted: 0,
totalClicks: totalClicks,
totalGoldEarned: totalGoldEarned,
username: "testuser",
});
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", () => {
// base Ɨ (0+1)^2.5 = 1_000_000 Ɨ 1 = 1_000_000
expect(calculatePrestigeThreshold(0)).toBe(1_000_000);
});
it("returns base Ɨ 2^2.5 at count 1", () => {
// base Ɨ (1+1)^2.5 = 1_000_000 Ɨ 2^2.5
expect(calculatePrestigeThreshold(1)).toBeCloseTo(1_000_000 * Math.pow(2, 2.5));
});
it("returns base Ɨ 3^2.5 at count 2", () => {
// base Ɨ (2+1)^2.5 = 1_000_000 Ɨ 3^2.5
expect(calculatePrestigeThreshold(2)).toBeCloseTo(1_000_000 * Math.pow(3, 2.5));
});
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(cbrt(4_000_000 / 1_000_000)) Ɨ 20 = floor(cbrt(4)) Ɨ 20 = 1 Ɨ 20 = 20
const result = calculateRunestones({ totalGoldEarned: 4_000_000, prestigeCount: 0, purchasedUpgradeIds: [] });
expect(result).toBe(20);
});
it("applies echo runestone multiplier", () => {
// floor(cbrt(4)) Ɨ 20 = 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 "runestone_gain_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).toBe(25);
});
it("caps base runestones before multipliers", () => {
// cbrt(9_261_000_000 / 1_000_000) = cbrt(9261) = 21 → 21 Ɨ 20 = 420, capped at 200
const result = calculateRunestones({ totalGoldEarned: 9_261_000_000, prestigeCount: 0, purchasedUpgradeIds: [] });
expect(result).toBe(200);
});
});
describe("calculateProductionMultiplier", () => {
it("returns 1 at count 0", () => {
expect(calculateProductionMultiplier(0)).toBe(1);
});
it("returns 1.3 at count 1", () => {
expect(calculateProductionMultiplier(1)).toBeCloseTo(1.3);
});
it("scales exponentially", () => {
expect(calculateProductionMultiplier(10)).toBeCloseTo(Math.pow(1.3, 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 100 at prestige 10", () => {
expect(calculateMilestoneBonus(10)).toBe(100);
});
it("returns 225 at prestige 15", () => {
expect(calculateMilestoneBonus(15)).toBe(225);
});
});
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 autoPrestigeMaxRunestonesOnly when set", () => {
const state = makeMinimalState({
prestige: { autoPrestigeMaxRunestonesOnly: true, count: 0, productionMultiplier: 1, purchasedUpgradeIds: [], runestones: 0 },
});
const { prestigeData } = buildPostPrestigeState(state, "Tester");
expect(prestigeData.autoPrestigeMaxRunestonesOnly).toBe(true);
});
it("omits autoPrestigeMaxRunestonesOnly when not set", () => {
const state = makeMinimalState();
const { prestigeData } = buildPostPrestigeState(state, "Tester");
expect(prestigeData.autoPrestigeMaxRunestonesOnly).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);
});
it("accumulates current-run gold into lifetime total", () => {
const state = makeMinimalState({
player: makePlayer(4_000_000, 1_000_000),
});
const { prestigeState } = buildPostPrestigeState(state, "Tester");
expect(prestigeState.player.lifetimeGoldEarned).toBe(5_000_000);
});
it("accumulates current-run clicks into lifetime total", () => {
const state = makeMinimalState({
player: makePlayer(4_000_000, 0, 500),
});
const { prestigeState } = buildPostPrestigeState(state, "Tester");
expect(prestigeState.player.lifetimeClicks).toBe(500);
});
it("accumulates defeated bosses into lifetime total", () => {
const defeatedBoss = {
bountyRunestones: 0,
crystalReward: 0,
currentHp: 0,
damagePerSecond: 10,
description: "A boss",
equipmentRewards: [] as string[],
essenceReward: 0,
goldReward: 100,
id: "boss_1",
maxHp: 100,
name: "Boss One",
prestigeRequirement: 0,
status: "defeated" as const,
upgradeRewards: [] as string[],
zoneId: "zone_1",
};
const state = makeMinimalState({ bosses: [ defeatedBoss ] });
const { prestigeState } = buildPostPrestigeState(state, "Tester");
expect(prestigeState.player.lifetimeBossesDefeated).toBe(1);
});
it("preserves bountyRunestonesClaimed flag on bosses across prestige", () => {
const claimedBoss = {
bountyRunestones: 5,
bountyRunestonesClaimed: true,
crystalReward: 0,
currentHp: 0,
damagePerSecond: 10,
description: "A boss",
equipmentRewards: [] as string[],
essenceReward: 0,
goldReward: 100,
id: "troll_king",
maxHp: 100,
name: "Troll King",
prestigeRequirement: 0,
status: "defeated" as const,
upgradeRewards: [] as string[],
zoneId: "verdant_vale",
};
const state = makeMinimalState({ bosses: [ claimedBoss ] as GameState["bosses"] });
const { prestigeState } = buildPostPrestigeState(state, "Tester");
const matchingBoss = prestigeState.bosses.find((boss) => {
return boss.id === "troll_king";
});
expect(matchingBoss?.bountyRunestonesClaimed).toBe(true);
});
it("sets bountyRunestonesClaimed on bosses defeated before the flag was introduced", () => {
const legacyDefeatedBoss = {
bountyRunestones: 5,
crystalReward: 0,
currentHp: 0,
damagePerSecond: 10,
description: "A boss",
equipmentRewards: [] as string[],
essenceReward: 0,
goldReward: 100,
id: "troll_king",
maxHp: 100,
name: "Troll King",
prestigeRequirement: 0,
status: "defeated" as const,
upgradeRewards: [] as string[],
zoneId: "verdant_vale",
};
const state = makeMinimalState({ bosses: [ legacyDefeatedBoss ] as GameState["bosses"] });
const { prestigeState } = buildPostPrestigeState(state, "Tester");
const matchingBoss = prestigeState.bosses.find((boss) => {
return boss.id === "troll_king";
});
expect(matchingBoss?.bountyRunestonesClaimed).toBe(true);
});
it("accumulates completed quests into lifetime total", () => {
const quest = {
id: "q_1",
name: "A Quest",
description: "Do the thing",
status: "completed" as const,
zoneId: "zone_1",
};
const state = makeMinimalState({ quests: [ quest ] as GameState["quests"] });
const { prestigeState } = buildPostPrestigeState(state, "Tester");
expect(prestigeState.player.lifetimeQuestsCompleted).toBe(1);
});
it("accumulates recruited adventurers into lifetime total", () => {
const adventurer = {
combatPower: 10,
count: 5,
essencePerSecond: 0,
goldPerSecond: 1,
id: "adv_1",
level: 1,
unlocked: true,
};
const state = makeMinimalState({ adventurers: [ adventurer ] as GameState["adventurers"] });
const { prestigeState } = buildPostPrestigeState(state, "Tester");
expect(prestigeState.player.lifetimeAdventurersRecruited).toBe(5);
});
it("preserves achievements from current state across prestige", () => {
const achievement = {
description: "Did a thing",
id: "ach_persisted",
name: "Achiever",
requirement: 1,
type: "totalClicks" as const,
unlockedAt: Date.now(),
};
const state = makeMinimalState({ achievements: [ achievement ] as GameState["achievements"] });
const { prestigeState } = buildPostPrestigeState(state, "Tester");
expect(prestigeState.achievements).toEqual([ achievement ]);
});
it("accumulates unlocked achievements into lifetime total", () => {
const achievement = {
description: "Did a thing",
id: "ach_1",
name: "Achiever",
requirement: 1,
type: "totalClicks" as const,
unlockedAt: Date.now(),
};
const state = makeMinimalState({ achievements: [ achievement ] as GameState["achievements"] });
const { prestigeState } = buildPostPrestigeState(state, "Tester");
expect(prestigeState.player.lifetimeAchievementsUnlocked).toBe(1);
});
});
+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,177 @@
/* 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(224 / sqrt(1)) = 224
expect(calculateEchoes(0, 1)).toBe(224);
});
it("calculates echoes at count 1", () => {
// floor(224 / sqrt(1)) = 224
expect(calculateEchoes(1, 1)).toBe(224);
});
it("decreases echoes with higher prestige count", () => {
const echoesAt1 = calculateEchoes(1, 1);
const echoesAt4 = calculateEchoes(4, 1);
expect(echoesAt4).toBeLessThan(echoesAt1);
// floor(224 / sqrt(4)) = floor(224 / 2) = 112
expect(echoesAt4).toBe(112);
});
it("applies echoMetaMultiplier", () => {
const base = calculateEchoes(1, 1);
const withMult = calculateEchoes(1, 2);
expect(withMult).toBe(base * 2);
});
it("returns 50 echoes at the target prestige 20", () => {
// floor(224 / sqrt(20)) = floor(224 / 4.472) = floor(50.09) = 50
expect(calculateEchoes(20, 1)).toBe(50);
});
});
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);
});
});
+171
View File
@@ -0,0 +1,171 @@
/* 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"];
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 bot token is set", async () => {
process.env["DISCORD_BOT_TOKEN"] = "bot_token";
mockFetch.mockResolvedValueOnce({ ok: true });
const { grantApotheosisRole } = await import("../../src/services/webhook.js");
await grantApotheosisRole("user789");
expect(mockFetch).toHaveBeenCalledWith(
"https://discord.com/api/v10/guilds/1354624415861833870/members/user789/roles/1479966598210129991",
expect.objectContaining({
method: "PUT",
headers: expect.objectContaining({ Authorization: "Bot bot_token" }),
}),
);
});
it("swallows fetch errors gracefully", async () => {
process.env["DISCORD_BOT_TOKEN"] = "tok";
mockFetch.mockRejectedValueOnce(new Error("Network error"));
const { grantApotheosisRole } = await import("../../src/services/webhook.js");
await expect(grantApotheosisRole("user")).resolves.toBeUndefined();
});
it("swallows non-Error fetch rejections gracefully", async () => {
process.env["DISCORD_BOT_TOKEN"] = "tok";
mockFetch.mockRejectedValueOnce("raw string error");
const { grantApotheosisRole } = await import("../../src/services/webhook.js");
await expect(grantApotheosisRole("user")).resolves.toBeUndefined();
});
});
describe("grantElysianRole", () => {
it("does nothing when bot token is missing", async () => {
delete process.env["DISCORD_BOT_TOKEN"];
const { grantElysianRole } = await import("../../src/services/webhook.js");
const result = await grantElysianRole("user123");
expect(mockFetch).not.toHaveBeenCalled();
expect(result).toBe(false);
});
it("returns true when Discord API responds with ok", async () => {
process.env["DISCORD_BOT_TOKEN"] = "bot_token";
mockFetch.mockResolvedValueOnce({ ok: true, status: 200 });
const { grantElysianRole } = await import("../../src/services/webhook.js");
const result = await grantElysianRole("user789");
expect(mockFetch).toHaveBeenCalledWith(
"https://discord.com/api/v10/guilds/1354624415861833870/members/user789/roles/1486144823684628490",
expect.objectContaining({
method: "PUT",
headers: expect.objectContaining({ Authorization: "Bot bot_token" }),
}),
);
expect(result).toBe(true);
});
it("returns true when Discord API responds with 204", async () => {
process.env["DISCORD_BOT_TOKEN"] = "tok";
mockFetch.mockResolvedValueOnce({ ok: false, status: 204 });
const { grantElysianRole } = await import("../../src/services/webhook.js");
const result = await grantElysianRole("user");
expect(result).toBe(true);
});
it("returns false when Discord API responds with an error status", async () => {
process.env["DISCORD_BOT_TOKEN"] = "tok";
mockFetch.mockResolvedValueOnce({ ok: false, status: 403 });
const { grantElysianRole } = await import("../../src/services/webhook.js");
const result = await grantElysianRole("user");
expect(result).toBe(false);
});
it("returns false and swallows fetch errors gracefully", async () => {
process.env["DISCORD_BOT_TOKEN"] = "tok";
mockFetch.mockRejectedValueOnce(new Error("Network error"));
const { grantElysianRole } = await import("../../src/services/webhook.js");
const result = await grantElysianRole("user");
expect(result).toBe(false);
});
it("returns false and swallows non-Error fetch rejections", async () => {
process.env["DISCORD_BOT_TOKEN"] = "tok";
mockFetch.mockRejectedValueOnce("raw string error");
const { grantElysianRole } = await import("../../src/services/webhook.js");
const result = await grantElysianRole("user");
expect(result).toBe(false);
});
});
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; flags: number };
expect(body.content).toContain("<@user123>");
expect(body.content).toContain("prestiged");
expect(body.flags).toBe(4096);
});
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();
});
it("swallows non-Error fetch rejections gracefully", async () => {
process.env["DISCORD_MILESTONE_WEBHOOK"] = "https://discord.com/webhook/abc";
mockFetch.mockRejectedValueOnce("raw string error");
const { postMilestoneWebhook } = await import("../../src/services/webhook.js");
await expect(postMilestoneWebhook("user", "prestige", counts)).resolves.toBeUndefined();
});
});
});
+8
View File
@@ -0,0 +1,8 @@
{
"extends": "@nhcarrigan/typescript-config",
"compilerOptions": {
"outDir": "./prod",
"rootDir": "."
},
"exclude": ["test/**/*.ts"]
}
+23
View File
@@ -0,0 +1,23 @@
import { defineConfig } from "vitest/config";
export default defineConfig({
test: {
coverage: {
provider: "v8",
include: ["src/**/*.ts"],
exclude: [
"src/types/**/*.ts",
"src/db/client.ts",
"src/index.ts",
"src/data/materials.ts",
],
thresholds: {
statements: 100,
branches: 100,
functions: 100,
lines: 100,
},
},
include: ["test/**/*.spec.ts"],
},
});
+43
View File
@@ -0,0 +1,43 @@
import config from "@nhcarrigan/eslint-config";
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,
},
],
},
},
];
+46
View File
@@ -0,0 +1,46 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Elysium — Idle RPG</title>
<meta name="description" content="An idle fantasy RPG — hire adventurers, defeat bosses, and ascend to glory." />
<!-- Open Graph -->
<meta property="og:title" content="Elysium — Idle RPG" />
<meta property="og:description" content="An idle fantasy RPG — hire adventurers, defeat bosses, and ascend to glory." />
<meta property="og:type" content="website" />
<meta property="og:url" content="https://elysium.nhcarrigan.com" />
<meta property="og:image" content="https://cdn.nhcarrigan.com/elysium/background.jpg" />
<meta property="og:site_name" content="Elysium" />
<!-- Twitter Card -->
<meta name="twitter:card" content="summary_large_image" />
<meta name="twitter:title" content="Elysium — Idle RPG" />
<meta name="twitter:description" content="An idle fantasy RPG — hire adventurers, defeat bosses, and ascend to glory." />
<meta name="twitter:image" content="https://cdn.nhcarrigan.com/elysium/background.jpg" />
<!-- Plausible Analytics -->
<script defer data-domain="elysium.nhcarrigan.com" src="https://plausible.io/js/script.js"></script>
<!-- Tree-Nation -->
<script defer src="https://widgets.tree-nation.com/js/widgets/v1/widgets.min.js?v=1.0"></script>
<script>
(function () {
var interval = setInterval(function () {
if (typeof TreeNation !== "undefined") {
clearInterval(interval);
TreeNation.renderAll();
}
}, 100);
}());
</script>
<!-- Google Ads -->
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-3569924701890974" crossorigin="anonymous"></script>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>
+32
View File
@@ -0,0 +1,32 @@
{
"name": "@elysium/web",
"version": "0.5.0",
"private": true,
"type": "module",
"scripts": {
"build": "tsc -p tsconfig.json && vite build",
"dev": "vite",
"lint": "eslint --max-warnings 0 src",
"preview": "vite preview",
"test": "vitest run --coverage"
},
"dependencies": {
"@elysium/types": "workspace:*",
"react": "19.2.4",
"react-dom": "19.2.4",
"react-markdown": "10.1.0"
},
"devDependencies": {
"@nhcarrigan/eslint-config": "5.2.0",
"@nhcarrigan/typescript-config": "4.0.0",
"@types/react": "19.2.14",
"@types/react-dom": "19.2.3",
"@vitejs/plugin-react": "6.0.1",
"@vitest/coverage-v8": "3.0.8",
"eslint": "9.22.0",
"jsdom": "29.0.1",
"typescript": "5.8.2",
"vite": "8.0.5",
"vitest": "3.0.8"
}
}
+379
View File
@@ -0,0 +1,379 @@
/**
* @file API client for communicating with the Elysium backend.
* @copyright nhcarrigan
* @license Naomi's Public License
* @author Naomi Carrigan
*/
import type {
AboutResponse,
ApotheosisRequest,
ApotheosisResponse,
AuthResponse,
BossChallengeRequest,
BossChallengeResponse,
BuyEchoUpgradeRequest,
BuyEchoUpgradeResponse,
BuyPrestigeUpgradeRequest,
BuyPrestigeUpgradeResponse,
CraftRecipeRequest,
CraftRecipeResponse,
ExploreClaimableResponse,
ExploreCollectRequest,
ExploreCollectResponse,
ExploreStartRequest,
ExploreStartResponse,
ForceUnlocksResponse,
LoadResponse,
PrestigeRequest,
PrestigeResponse,
PublicProfileResponse,
SaveRequest,
SaveResponse,
SyncNewContentResponse,
TranscendenceRequest,
TranscendenceResponse,
UpdateProfileRequest,
UpdateProfileResponse,
} from "@elysium/types";
const baseUrl = "/api";
/**
* Represents a 4xx API error so callers can distinguish expected server
* rejections from unexpected failures. ValidationErrors are downgraded to
* console.warn and are not forwarded to the error-email pipeline.
*/
class ValidationError extends Error {
public readonly statusCode: number;
/**
* Creates a new ValidationError.
* @param message - The error message from the server response.
* @param statusCode - The HTTP status code (4xx) returned by the server.
*/
public constructor(message: string, statusCode: number) {
super(message);
this.name = "ValidationError";
this.statusCode = statusCode;
}
}
const getToken = (): string | null => {
return globalThis.localStorage.getItem("elysium_token");
};
/* eslint-disable @typescript-eslint/naming-convention -- HTTP header names require specific casing */
const buildHeaders = (): Record<string, string> => {
const token = getToken();
return {
"Content-Type": "application/json",
...token !== null && token.length > 0
? { Authorization: `Bearer ${token}` }
: {},
};
};
/* eslint-enable @typescript-eslint/naming-convention -- HTTP header names require specific casing */
const fetchJson = async <T>(
path: string,
options?: RequestInit,
): Promise<T> => {
const response = await fetch(`${baseUrl}${path}`, {
...options,
headers: { ...buildHeaders(), ...options?.headers },
});
if (!response.ok) {
/* eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- JSON error response requires type assertion */
const errorBody = (await response.json().catch(() => {
return { error: "Unknown error" };
})) as Record<string, unknown>;
const message
= typeof errorBody.error === "string"
? errorBody.error
: "Unknown error";
if (response.status === 401) {
globalThis.localStorage.removeItem("elysium_token");
globalThis.localStorage.removeItem("elysium_save_signature");
globalThis.location.href = "/";
}
if (response.status >= 400 && response.status < 500) {
throw new ValidationError(message, response.status);
}
throw new Error(message);
}
/* eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- JSON response requires type assertion */
return await (response.json() as Promise<T>);
};
/**
* Fetches the about information from the API.
* @returns The about response data.
*/
const getAbout = async(): Promise<AboutResponse> => {
return await fetchJson<AboutResponse>("/about");
};
/**
* 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;
};
/**
* Handles the Discord OAuth callback and stores the auth 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;
};
/**
* 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");
};
/**
* 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",
});
};
/**
* 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,
): Promise<BossChallengeResponse> => {
return await fetchJson<BossChallengeResponse>("/boss/challenge", {
body: JSON.stringify(body),
method: "POST",
});
};
/**
* 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",
});
};
/**
* 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,
): Promise<BuyPrestigeUpgradeResponse> => {
return await fetchJson<BuyPrestigeUpgradeResponse>("/prestige/buy-upgrade", {
body: JSON.stringify(body),
method: "POST",
});
};
/**
* 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",
});
};
/**
* Checks whether a given exploration area is ready to claim on the server.
* @param areaId - The area ID to check.
* @returns Whether the exploration is claimable.
*/
const checkExplorationClaimable = async(
areaId: string,
): Promise<ExploreClaimableResponse> => {
return await fetchJson<ExploreClaimableResponse>(
`/explore/claimable?areaId=${encodeURIComponent(areaId)}`,
);
};
/**
* 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",
});
};
/**
* Sends a request to fix any missing unlocks in the player's game state.
* @returns The corrected game state and counts of what was unlocked.
*/
const forceUnlocks = async(): Promise<ForceUnlocksResponse> => {
return await fetchJson<ForceUnlocksResponse>("/debug/force-unlocks", {
method: "POST",
});
};
/**
* Syncs any content added after the player's save was created into their save.
* @returns The updated game state and counts of what was added per content type.
*/
const syncNewContent = async(): Promise<SyncNewContentResponse> => {
return await fetchJson<SyncNewContentResponse>("/debug/sync-new-content", {
method: "POST",
});
};
/**
* Performs a complete hard reset of the player's game state via the debug endpoint.
* @returns The fresh game state as a LoadResponse.
*/
const debugHardReset = async(): Promise<LoadResponse> => {
return await fetchJson<LoadResponse>("/debug/hard-reset", { 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,
): Promise<PublicProfileResponse> => {
return await fetchJson<PublicProfileResponse>(`/profile/${discordId}`);
};
/**
* Updates the current player's profile.
* @param body - The update profile request payload.
* @returns The update profile response data.
*/
const updateProfile = async(
body: UpdateProfileRequest,
): Promise<UpdateProfileResponse> => {
return await fetchJson<UpdateProfileResponse>("/profile", {
body: JSON.stringify(body),
method: "PUT",
});
};
export {
ValidationError,
achieveApotheosis,
buyEchoUpgrade,
buyPrestigeUpgrade,
challengeBoss,
checkExplorationClaimable,
collectExploration,
craftRecipe,
debugHardReset,
forceUnlocks,
syncNewContent,
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 };
+70
View File
@@ -0,0 +1,70 @@
/**
* @file React Error Boundary for catching unhandled render-time errors.
* @copyright nhcarrigan
* @license Naomi's Public License
* @author Naomi Carrigan
*/
import { Component, type ErrorInfo, type ReactNode } from "react";
import { logError } from "../utils/logError.js";
interface ErrorBoundaryProperties {
readonly children: ReactNode;
}
interface ErrorBoundaryState {
hasError: boolean;
}
/**
* Catches unhandled render-time errors in the React tree, logs them to the
* backend telemetry service, and renders a fallback UI.
*/
class ErrorBoundary extends Component<
ErrorBoundaryProperties,
ErrorBoundaryState
> {
// eslint-disable-next-line jsdoc/require-jsdoc -- React Error Boundary constructor is standard boilerplate
public constructor(properties: ErrorBoundaryProperties) {
super(properties);
this.state = { hasError: false };
}
/**
* Updates state so the next render shows the fallback UI.
* @returns The updated error boundary state.
*/
public static getDerivedStateFromError(): ErrorBoundaryState {
return { hasError: true };
}
/**
* Logs the error to the backend telemetry service.
* @param error - The error that was thrown during render.
* @param info - React error info containing the component stack trace.
*/
// eslint-disable-next-line @typescript-eslint/class-methods-use-this -- React lifecycle method cannot be static
public override componentDidCatch(error: Error, info: ErrorInfo): void {
logError("react_error_boundary", error, info.componentStack);
}
/**
* Renders the fallback UI when an error is caught, otherwise renders children.
* @returns The JSX element.
*/
public override render(): ReactNode {
const { hasError } = this.state;
const { children } = this.props;
if (hasError) {
return (
<div className="error-screen">
<p>{"Something went wrong. Please refresh the page."}</p>
</div>
);
}
return children;
}
}
export { ErrorBoundary };
+389
View File
@@ -0,0 +1,389 @@
/**
* @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 Markdown from "react-markdown";
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 stack multiplicatively — two Ɨ2 upgrades"
+ " targeting the same adventurer combine to give Ɨ4, not Ɨ3. Global"
+ " upgrades multiply on top of adventurer-specific ones, so stacking"
+ " both types compounds the effect significantly. Late in a run, look"
+ " for the Essence Infusion upgrades — five powerful global multipliers"
+ " purchasable purely with essence, giving that resource an ongoing"
+ " use when gold upgrades are all bought.",
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."
+ " Each quest has a failure chance that increases in later zones"
+ " (from 10% in the starting zone up to 40% in the hardest zones)."
+ " If a quest fails, no rewards are granted and the quest resets —"
+ " your party must be sent again to retry it.",
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 boss combat DPS. Rarer"
+ " equipment provides stronger bonuses. Note: combat bonuses only"
+ " affect boss fights — quest combat power is determined solely by"
+ " your adventurers. 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."
+ " Exploration zones are locked until the corresponding main-game"
+ " zone is unlocked — which requires defeating that zone's final boss"
+ " and completing its final quest. The Exploration tab shows the"
+ " specific boss and quest required for each locked zone.",
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, boss combat DPS, or click"
+ " power. Combat bonuses only affect boss fights — quest combat power"
+ " is determined solely by your adventurers. 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, Boss Encounters, and Prestige Shop"
+ " 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. Auto-Adventurer (unlocked via the Prestige Shop for 50"
+ " runestones) automatically purchases the highest-tier adventurer you"
+ " can currently afford each tick, keeping your income growing after a"
+ " prestige without any manual clicks.",
title: "šŸ¤– Auto-Quest, Auto-Boss & Auto-Adventurer",
},
{
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 20). 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",
},
{
body:
"Have a question, found a bug, or want to suggest a feature? Join the"
+ " NHCarrigan community Discord at https://chat.nhcarrigan.com or open"
+ " a support ticket at https://support.nhcarrigan.com. You can also"
+ " report issues directly on the project repository. We'd love to hear"
+ " from you!",
title: "šŸ’¬ Community & Support",
},
];
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
&& <div className="about-release-body">
<Markdown>{release.body}</Markdown>
</div>
}
</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,244 @@
/**
* @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 { cdnImage } from "../../utils/cdn.js";
import { LockToggle } from "../ui/lockToggle.js";
import type { Achievement, GameState } 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";
}
};
/**
* Returns the player's current progress value toward an achievement's unlock condition,
* mirroring the logic used by the tick engine's checkAchievements function.
* @param achievement - The achievement to evaluate progress for.
* @param state - The current game state.
* @returns The current numeric progress toward the achievement condition.
*/
const getCurrentProgress = (
achievement: Achievement,
state: GameState,
): number => {
const { condition } = achievement;
switch (condition.type) {
case "totalGoldEarned":
return state.player.totalGoldEarned;
case "totalClicks":
return state.player.totalClicks;
case "bossesDefeated":
return state.bosses.filter((boss) => {
return boss.status === "defeated";
}).length;
case "questsCompleted":
return state.quests.filter((quest) => {
return quest.status === "completed";
}).length;
case "adventurerTotal":
return state.adventurers.reduce((sum, adventurer) => {
return sum + adventurer.count;
}, 0);
case "prestigeCount":
return state.prestige.count;
case "equipmentOwned":
return state.equipment.filter((item) => {
return item.owned;
}).length;
default:
return 0;
}
};
interface AchievementCardProperties {
readonly achievement: Achievement;
readonly formatNumber: (n: number)=> string;
readonly progressValue: number;
}
/**
* 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.
* @param props.progressValue - The player's current progress toward the unlock condition.
* @returns The JSX element.
*/
// eslint-disable-next-line max-lines-per-function -- Progress bar adds necessary lines for locked state
const AchievementCard = ({
achievement,
formatNumber,
progressValue,
}: AchievementCardProperties): JSX.Element => {
const isUnlocked = achievement.unlockedAt !== null;
const crystals = achievement.reward?.crystals;
const cappedProgress = Math.min(progressValue, achievement.condition.amount);
return (
<div className={`achievement-card ${isUnlocked
? "unlocked"
: "locked"}`}>
<img
alt={achievement.name}
className="card-thumbnail"
src={cdnImage("achievements", achievement.id)}
/>
<div className="achievement-info">
<h3>{achievement.name}</h3>
<p>{achievement.description}</p>
<p className="achievement-condition">
{conditionDescription(achievement, formatNumber)}
</p>
{!isUnlocked
&& <div className="achievement-progress">
<progress
max={achievement.condition.amount}
value={cappedProgress}
/>
<span className="achievement-progress-label">
{formatNumber(progressValue)}
{" / "}
{formatNumber(achievement.condition.amount)}
</span>
</div>
}
{crystals !== undefined
&& <p className="achievement-reward">
{"šŸ’Ž +"}
{crystals}
{" Crystals"}
</p>
}
</div>
<div className="achievement-status">
{isUnlocked
? <>
<span className="achievement-unlocked-badge">{"āœ“ Unlocked"}</span>
{achievement.unlockedAt !== null
&& <span className="achievement-unlocked-at">
{new Date(achievement.unlockedAt).toLocaleDateString("en-GB", {
day: "numeric",
month: "short",
year: "numeric",
})}
</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}
progressValue={getCurrentProgress(achievement, state)}
/>
);
})}
</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,308 @@
/**
* @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 { computeEffectiveAdventurerStats } from "../../engine/tick.js";
import { cdnImage } from "../../utils/cdn.js";
import { LockToggle } from "../ui/lockToggle.js";
import type { Adventurer } from "@elysium/types";
type BatchSize = 1 | 5 | 10 | 25 | 100 | "max";
const batchOptions: Array<BatchSize> = [ 1, 5, 10, 25, 100, "max" ];
/**
* Parses a localStorage string back into a valid BatchSize, defaulting to 1.
* @param stored - The raw string from localStorage (or null if absent).
* @returns A valid BatchSize value.
*/
const parseBatchSize = (stored: string | null): BatchSize => {
if (stored === "max") {
return "max";
}
const numeric = Number(stored);
if (numeric === 5) {
return 5;
}
if (numeric === 10) {
return 10;
}
if (numeric === 25) {
return 25;
}
if (numeric === 100) {
return 100;
}
return 1;
};
/**
* 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 EffectiveAdventurerStats {
readonly combatPower: number;
readonly essencePerSecond: number;
readonly goldPerSecond: number;
}
interface AdventurerCardProperties {
readonly adventurer: Adventurer;
readonly currentGold: number;
readonly batchSize: BatchSize;
readonly unlockHint: string | undefined;
readonly formatNumber: (n: number)=> string;
readonly effectiveStats: EffectiveAdventurerStats;
}
/**
* 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.
* @param props.effectiveStats - The post-multiplier per-unit stats.
* @returns The JSX element.
*/
const AdventurerCard = ({
adventurer,
currentGold,
batchSize,
unlockHint,
formatNumber,
effectiveStats,
}: 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";
return (
<div className={`adventurer-card ${adventurer.unlocked
? ""
: "locked"}`}>
<img
alt={adventurer.name}
className="card-thumbnail"
src={cdnImage("adventurers", adventurer.id)}
/>
<div className="adventurer-info">
<h3>{adventurer.name}</h3>
<p>
{formatNumber(effectiveStats.goldPerSecond)}
{" gold/s each"}
</p>
{adventurer.essencePerSecond > 0
&& <p>
{formatNumber(effectiveStats.essencePerSecond)}
{" essence/s each"}
</p>
}
<p>
{formatNumber(effectiveStats.combatPower)}
{" combat power 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, toggleAutoAdventurer } = useGame();
const [ showLocked, setShowLocked ] = useState(true);
const [ batchSize, setBatchSize ] = useState<BatchSize>(() => {
return parseBatchSize(localStorage.getItem("elysium_batch_size"));
});
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);
}
}
}
const autoAdventurerUnlocked = state.prestige.purchasedUpgradeIds.includes(
"auto_adventurer",
);
const autoAdventurerOn = state.autoAdventurer === true;
function handleToggle(): void {
setShowLocked((current) => {
return !current;
});
}
return (
<section className="panel adventurer-panel">
<div className="panel-header">
<h2>{"Adventurers"}</h2>
<div className="panel-header-controls">
{autoAdventurerUnlocked
? <button
className={`auto-toggle-btn ${
autoAdventurerOn
? "auto-toggle-on"
: "auto-toggle-off"
}`}
onClick={toggleAutoAdventurer}
title={
"Automatically purchase the highest-tier"
+ " affordable adventurer"
}
type="button"
>
{"šŸ¤– Auto: "}
{autoAdventurerOn
? "ON"
: "OFF"}
</button>
: null
}
<LockToggle
lockedCount={locked.length}
onToggle={handleToggle}
showLocked={showLocked}
/>
</div>
</div>
<div className="batch-selector">
{batchOptions.map((option) => {
function handleBatchSelect(): void {
setBatchSize(option);
localStorage.setItem("elysium_batch_size", String(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}
effectiveStats={computeEffectiveAdventurerStats(
state,
adventurer.id,
)}
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 };
@@ -0,0 +1,293 @@
/**
* @file Battle modal component displaying animated battle results.
* @copyright nhcarrigan
* @license Naomi's Public License
* @author Naomi Carrigan
*/
/* eslint-disable max-lines-per-function -- Complex battle animation and result display */
/* eslint-disable complexity -- Battle result display requires many conditional paths */
import { type JSX, useEffect, useState } from "react";
import { type BattleResult, useGame } from "../../context/gameContext.js";
import { sendNotification } from "../../utils/notification.js";
import { playSound } from "../../utils/sound.js";
/**
* Converts HP values to a percentage for display.
* @param current - The current HP value.
* @param maximum - The maximum HP value.
* @returns The percentage as a number between 0 and 100.
*/
const toHpPercent = (current: number, maximum: number): number => {
if (maximum === 0) {
return 0;
}
const scaled = current * 100;
return scaled / maximum;
};
/**
* Returns a colour hex string based on the HP percentage.
* Green above 50%, yellow 25–50%, red below 25%.
* @param percent - Current HP as a percentage (0–100).
* @returns A hex colour string.
*/
const getHpColour = (percent: number): string => {
if (percent > 50) {
return "#27ae60";
}
if (percent > 25) {
return "#f39c12";
}
return "#e74c3c";
};
interface BattleModalProperties {
readonly battle: BattleResult;
readonly onDismiss: ()=> void;
}
/**
* Renders the battle modal with HP bars and animated battle results.
* @param props - The battle modal properties.
* @param props.battle - The battle result data to display.
* @param props.onDismiss - Callback to dismiss the modal.
* @returns The JSX element.
*/
const BattleModal = ({
battle,
onDismiss,
}: BattleModalProperties): JSX.Element => {
const { result, bossName } = battle;
const {
enableNotifications,
enableSounds,
flushBossLoreToasts,
formatInteger,
formatNumber,
} = useGame();
const [ phase, setPhase ] = useState<"animating" | "result">("animating");
const bossStartPercent = toHpPercent(result.bossHpBefore, result.bossMaxHp);
const bossEndPercent = toHpPercent(
result.bossHpAtBattleEnd,
result.bossMaxHp,
);
const partyEndPercent = toHpPercent(
result.partyHpRemaining,
result.partyMaxHp,
);
const [ bossHpPercent, setBossHpPercent ] = useState(bossStartPercent);
const [ partyHpPercent, setPartyHpPercent ] = useState(100);
useEffect(() => {
const animationDurationMs = 5000;
const intervalMs = 50;
const totalSteps = animationDurationMs / intervalMs;
const bossHpRange = bossEndPercent - bossStartPercent;
const bossDelta = bossHpRange / totalSteps;
const partyHpRange = partyEndPercent - 100;
const partyDelta = partyHpRange / totalSteps;
let currentStep = 0;
// eslint-disable-next-line @typescript-eslint/init-declarations -- assigned inside timeout
let intervalId: ReturnType<typeof setInterval> | undefined;
const tick = (): void => {
currentStep = currentStep + 1;
if (currentStep >= totalSteps) {
setBossHpPercent(bossEndPercent);
setPartyHpPercent(partyEndPercent);
clearInterval(intervalId);
} else {
const bossStep = bossDelta * currentStep;
setBossHpPercent(bossStartPercent + bossStep);
const partyStep = partyDelta * currentStep;
setPartyHpPercent(100 + partyStep);
}
};
const startTimeout = setTimeout(() => {
intervalId = setInterval(tick, intervalMs);
}, 200);
const revealTimeout = setTimeout(() => {
setPhase("result");
flushBossLoreToasts();
if (result.won) {
if (enableSounds) {
playSound("bossVictory");
}
if (enableNotifications) {
sendNotification("āš”ļø Boss Defeated!", `You defeated ${bossName}!`);
}
}
}, 5200);
return (): void => {
clearTimeout(startTimeout);
clearTimeout(revealTimeout);
clearInterval(intervalId);
};
}, [
bossEndPercent,
bossName,
bossStartPercent,
enableNotifications,
enableSounds,
flushBossLoreToasts,
partyEndPercent,
result.won,
]);
const bossHpBarColour = getHpColour(bossHpPercent);
const partyHpBarColour = getHpColour(partyHpPercent);
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={{
backgroundColor: bossHpBarColour,
width: `${bossHpPercent.toFixed(1)}%`,
}}
/>
</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={{
backgroundColor: partyHpBarColour,
width: `${partyHpPercent.toFixed(1)}%`,
}}
/>
</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 === undefined
? null
: <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>
{"šŸ’Ž "}
{formatInteger(result.rewards.crystals)}
{" crystals"}
</span>
}
{result.rewards.bountyRunestones > 0
&& <span className="battle-bounty">
{"šŸ”® "}
{formatInteger(result.rewards.bountyRunestones)}
{" runestones (first kill!)"}
</span>
}
</div>
}
</>
: <>
<h3>{"šŸ’€ Defeat"}</h3>
<p>{"Your party was defeated. The boss has reset."}</p>
{result.casualties !== undefined
&& result.casualties.length > 0
? <div className="battle-casualties">
<p>{"Casualties:"}</p>
{result.casualties.map((casualty) => {
return (
<span key={casualty.adventurerId}>
{"ā˜ ļø "}
{casualty.killed} {casualty.adventurerId}
{" lost"}
</span>
);
})}
</div>
: null}
</>
}
<button
className="dismiss-button"
onClick={onDismiss}
type="button"
>
{"Continue"}
</button>
</div>
}
</div>
</div>
);
};
export { BattleModal };
+420
View File
@@ -0,0 +1,420 @@
/**
* @file Boss panel component for viewing and challenging zone bosses.
* @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 -- Boss card requires many conditional render paths */
/* eslint-disable max-statements -- Boss panel requires many variable declarations */
/* eslint-disable max-lines -- Boss panel with sub-component and helper function */
import { type JSX, useState } from "react";
import { useGame } from "../../context/gameContext.js";
import { computePartyCombatPower } from "../../engine/tick.js";
import { cdnImage } from "../../utils/cdn.js";
import { LockToggle } from "../ui/lockToggle.js";
import { ZoneSelector } from "./zoneSelector.js";
import type { Boss } from "@elysium/types";
interface BossCardProperties {
readonly boss: Boss;
readonly prestigeCount: number;
readonly onChallenge: (bossId: string)=> void;
readonly isChallenging: boolean;
readonly unlockHint: string | undefined;
readonly formatInteger: (n: number)=> string;
readonly formatNumber: (n: number)=> string;
}
/**
* Renders a single boss card.
* @param props - The boss card properties.
* @param props.boss - The boss data.
* @param props.prestigeCount - The current prestige count for lock checking.
* @param props.onChallenge - Callback to challenge this boss.
* @param props.isChallenging - Whether this boss is currently being challenged.
* @param props.unlockHint - Optional hint for how to unlock this boss.
* @param props.formatInteger - The integer formatting utility function.
* @param props.formatNumber - The number formatting utility function.
* @returns The JSX element.
*/
const BossCard = ({
boss,
prestigeCount,
onChallenge,
isChallenging,
unlockHint,
formatInteger,
formatNumber,
}: BossCardProperties): JSX.Element => {
const scaled = boss.currentHp * 100;
const hpPercent = scaled / boss.maxHp;
const isPrestigeLocked = boss.prestigeRequirement > prestigeCount;
const canChallenge
= (boss.status === "available" || boss.status === "in_progress")
&& !isChallenging;
function handleChallenge(): void {
onChallenge(boss.id);
}
return (
<div className={`boss-card boss-${boss.status}`}>
<img
alt={boss.name}
className="card-thumbnail"
src={cdnImage("bosses", boss.id)}
/>
<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>
: null}
{!isPrestigeLocked
&& boss.status === "locked"
&& unlockHint !== undefined
? <p className="unlock-hint">{unlockHint}</p>
: null}
</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>
{"šŸ’Ž "}
{formatInteger(boss.crystalReward)}
</span>
}
{boss.equipmentRewards.length > 0
&& <span>
{"šŸ—”ļø "}
{boss.equipmentRewards.length}
{" Equipment"}
</span>
}
{boss.status !== "defeated"
&& boss.bountyRunestones > 0
&& boss.bountyRunestonesClaimed !== true
&& <span className="boss-bounty">
{"šŸ”® "}
{boss.bountyRunestones}
{" (first kill)"}
</span>
}
</div>
{(boss.status === "available" || boss.status === "in_progress")
&& <button
className="attack-button"
disabled={!canChallenge}
onClick={handleChallenge}
type="button"
>
{isChallenging
? "āš”ļø Battling…"
: "āš”ļø Challenge"}
</button>
}
{boss.status === "defeated"
&& <span className="boss-badge defeated">{"ā˜ ļø Defeated"}</span>
}
</div>
);
};
/**
* Renders the boss panel with zone selection and boss list.
* @returns The JSX element.
*/
const BossPanel = (): JSX.Element => {
const {
state,
challengeBoss,
formatInteger,
formatNumber,
toggleAutoBoss,
autoBossLastResult,
autoBossError,
bossError,
} = useGame();
const [ challengingBossId, setChallengingBossId ] = useState<string | null>(
null,
);
const [ activeZoneId, setActiveZoneId ] = useState(() => {
return sessionStorage.getItem("elysium_boss_zone") ?? "verdant_vale";
});
const [ showLocked, setShowLocked ] = useState(true);
if (state === null) {
return (
<section className="panel">
<p>{"Loading..."}</p>
</section>
);
}
async function handleChallenge(bossId: string): Promise<void> {
setChallengingBossId(bossId);
try {
await challengeBoss(bossId);
} finally {
setChallengingBossId(null);
}
}
function handleChallengeClick(bossId: string): void {
void handleChallenge(bossId);
}
const {
adventurers,
autoBoss,
bosses,
prestige: playerPrestige,
quests,
zones,
} = state;
const activeZone = zones.find((zone) => {
return zone.id === activeZoneId;
});
const zoneIsLocked = activeZone?.status === "locked";
const unlockBoss = activeZone?.unlockBossId === null
|| activeZone?.unlockBossId === undefined
? undefined
: bosses.find((boss) => {
return boss.id === activeZone.unlockBossId;
});
const unlockQuest = activeZone?.unlockQuestId === null
|| activeZone?.unlockQuestId === undefined
? undefined
: quests.find((quest) => {
return quest.id === activeZone.unlockQuestId;
});
const zoneBosses = bosses.filter((boss) => {
return boss.zoneId === activeZoneId;
});
const lockedCount = zoneBosses.filter((boss) => {
return boss.status === "locked";
}).length;
const visibleBosses = showLocked
? zoneBosses
: zoneBosses.filter((boss) => {
return boss.status !== "locked";
});
const bossUnlockHints = new Map<string, string>();
for (const zone of zones) {
const { id: zoneId, unlockBossId, unlockQuestId } = zone;
const allZoneBosses = bosses.filter((boss) => {
return boss.zoneId === zoneId;
});
for (let index = 0; index < allZoneBosses.length; index = index + 1) {
const boss = allZoneBosses[index];
if (boss === undefined || boss.status !== "locked") {
continue;
}
if (index === 0) {
const parts: Array<string> = [];
if (unlockBossId !== null) {
const gateBoss = bosses.find((candidate) => {
return candidate.id === unlockBossId;
});
if (gateBoss !== undefined) {
parts.push(`āš”ļø Defeat: ${gateBoss.name}`);
}
}
if (unlockQuestId !== null) {
const gateQuest = quests.find((candidate) => {
return candidate.id === unlockQuestId;
});
if (gateQuest !== undefined) {
parts.push(`šŸ“œ Complete: ${gateQuest.name}`);
}
}
if (parts.length > 0) {
bossUnlockHints.set(boss.id, parts.join(" & "));
}
} else {
const previousBoss = allZoneBosses[index - 1];
if (previousBoss !== undefined) {
bossUnlockHints.set(boss.id, `āš”ļø Defeat: ${previousBoss.name} first`);
}
}
}
}
function handleZoneSelect(zoneId: string): void {
setActiveZoneId(zoneId);
sessionStorage.setItem("elysium_boss_zone", zoneId);
}
function handleToggle(): void {
setShowLocked((current) => {
return !current;
});
}
const autoBossOn = autoBoss === true;
const partyDps = computePartyCombatPower(state);
let partyHp = 0;
for (const { level, count } of adventurers) {
// eslint-disable-next-line stylistic/no-mixed-operators -- level * 50 * count is clear
partyHp = partyHp + level * 50 * count;
}
const { count: prestigeCount } = playerPrestige;
return (
<section className="panel boss-panel">
<div className="panel-header">
<h2>{"Boss Encounters"}</h2>
<div className="panel-header-controls">
<button
className={`auto-toggle-btn ${
autoBossOn
? "auto-toggle-on"
: "auto-toggle-off"
}`}
onClick={toggleAutoBoss}
title="Automatically challenge the highest available boss"
type="button"
>
{"šŸ¤– Auto: "}
{autoBossOn
? "ON"
: "OFF"}
</button>
<LockToggle
lockedCount={lockedCount}
onToggle={handleToggle}
showLocked={showLocked}
/>
</div>
</div>
{bossError === null
? null
: <p className="auto-boss-error">
{"āš ļø "}
{bossError}
</p>
}
{autoBossError === null
? null
: <p className="auto-boss-error">
{"āš ļø Auto-boss stopped: "}
{autoBossError}
</p>
}
{autoBossLastResult !== null && autoBossError === null
? <p className="auto-boss-status">
{"šŸ¤– Last fight: "}
{autoBossLastResult.bossName}
{autoBossLastResult.won
? " — āœ… Won"
: " — āŒ Lost"}
</p>
: null}
<ZoneSelector
activeZoneId={activeZoneId}
onSelectZone={handleZoneSelect}
zones={zones}
/>
{zoneIsLocked && (unlockBoss !== undefined || unlockQuest !== undefined)
? <div className="exploration-zone-locked-hint">
<p>{"šŸ”’ This zone is locked. Unlock bosses by:"}</p>
{unlockBoss === undefined
? null
: <p>
{"āš”ļø Defeat: "}
{unlockBoss.name}
</p>
}
{unlockQuest === undefined
? null
: <p>
{"šŸ“œ Complete: "}
{unlockQuest.name}
</p>
}
</div>
: null
}
<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) => {
const { id: bossId } = boss;
return (
<BossCard
boss={boss}
formatInteger={formatInteger}
formatNumber={formatNumber}
isChallenging={challengingBossId === bossId}
key={bossId}
onChallenge={handleChallengeClick}
prestigeCount={prestigeCount}
unlockHint={bossUnlockHints.get(bossId)}
/>
);
})}
{visibleBosses.length === 0
&& <p className="empty-zone">{"No bosses to show in this zone."}</p>
}
</div>
</section>
);
};
export { BossPanel };
@@ -0,0 +1,351 @@
/**
* @file Public character page for viewing a player's character sheet.
* @copyright nhcarrigan
* @license Naomi's Public License
* @author Naomi Carrigan
*/
/* eslint-disable max-lines-per-function -- Complex component with many render paths */
/* eslint-disable max-lines -- Story section adds lines beyond the file limit */
/* eslint-disable complexity -- Many conditional render paths for optional fields */
import {
STORY_CHAPTERS,
type EquipmentBonus,
type EquipmentType,
type PublicProfileResponse,
} from "@elysium/types";
import { type JSX, useEffect, useState } from "react";
import { logError } from "../../utils/logError.js";
interface CharacterPageProperties {
readonly discordId: string;
}
const slotIcons: Record<EquipmentType, string> = {
armour: "šŸ›”ļø",
trinket: "šŸ’",
weapon: "āš”ļø",
};
/**
* Formats an equipment bonus as a human-readable string.
* @param bonus - The equipment bonus to format.
* @returns The formatted bonus string.
*/
const formatBonus = (bonus: EquipmentBonus): string => {
const parts: Array<string> = [];
if (bonus.goldMultiplier !== undefined) {
const pct = Math.round((bonus.goldMultiplier - 1) * 100);
parts.push(`+${String(pct)}% Gold Income`);
}
if (bonus.combatMultiplier !== undefined) {
const pct = Math.round((bonus.combatMultiplier - 1) * 100);
parts.push(`+${String(pct)}% Combat Power`);
}
if (bonus.clickMultiplier !== undefined) {
const pct = Math.round((bonus.clickMultiplier - 1) * 100);
parts.push(`+${String(pct)}% Click Power`);
}
return parts.join(" Ā· ");
};
/**
* Renders the public character page for a given Discord user.
* @param props - The character page properties.
* @param props.discordId - The Discord ID of the player to display.
* @returns The JSX element.
*/
const CharacterPage = ({ discordId }: CharacterPageProperties): JSX.Element => {
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(response) => {
if (!response.ok) {
throw new Error("Player not found");
}
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- API response requires cast
return await (response.json() as Promise<PublicProfileResponse>);
}).
then(setProfile).
catch((error_: unknown) => {
setError(
error_ instanceof Error
? error_.message
: "Failed to load character sheet",
);
});
}, [ discordId ]);
function handleCopy(): void {
void navigator.clipboard.writeText(window.location.href).
then(() => {
setCopied(true);
setTimeout(() => {
setCopied(false);
}, 2000);
}).
catch((error_: unknown) => {
logError("clipboard_copy", error_);
});
}
if (error !== null) {
return (
<div className="character-page">
<div className="character-page-error">
<p>
{"āš ļø "}
{error}
</p>
<a className="character-page-link" href="/">
{"← Play Elysium"}
</a>
</div>
</div>
);
}
if (profile === null) {
return (
<div className="character-page">
<div className="character-page-loading">
{"Loading character sheet…"}
</div>
</div>
);
}
const discordIndex = Number.parseInt(discordId, 10) % 5;
const avatarUrl
= profile.avatar === null
? `https://cdn.discordapp.com/embed/avatars/${String(discordIndex)}.png`
: `https://cdn.discordapp.com/avatars/${discordId}/${profile.avatar}.png?size=128`;
const subtitleParts = [
profile.characterRace,
profile.characterClass,
].filter((part) => {
return part !== "";
});
const subtitle = subtitleParts.join(" Ā· ");
const activeTitleEntry
= profile.activeTitle === ""
? undefined
: profile.unlockedTitles.find((title) => {
return title.id === profile.activeTitle;
});
const activeTitleName
= activeTitleEntry === undefined
? null
: activeTitleEntry.name;
const hasBadge
= profile.apotheosisCount > 0
|| profile.transcendenceCount > 0
|| profile.prestigeCount > 0;
const displayName
= profile.characterName === ""
? profile.username
: profile.characterName;
return (
<div className="character-page">
<div className="character-page-card">
<div className="character-page-header">
<img
alt={`${displayName}'s avatar`}
className="character-page-avatar"
src={avatarUrl}
/>
<div className="character-page-identity">
<h1 className="character-page-name">{displayName}</h1>
{activeTitleName === null
? null
: <p className="character-page-title">{activeTitleName}</p>
}
{profile.pronouns === ""
? null
: <p className="character-page-pronouns">{profile.pronouns}</p>
}
{subtitle === ""
? null
: <p className="character-page-subtitle">{subtitle}</p>
}
{hasBadge
? <div className="character-page-badges">
{profile.apotheosisCount > 0
&& <span
className={
"character-page-badge character-page-badge--apotheosis"
}
>
{"✨ Apotheosis "}
{profile.apotheosisCount}
</span>
}
{profile.transcendenceCount > 0
&& <span
className={
"character-page-badge"
+ " character-page-badge--transcendence"
}
>
{"🌌 Transcendence "}
{profile.transcendenceCount}
</span>
}
{profile.prestigeCount > 0
&& <span
className={
"character-page-badge character-page-badge--prestige"
}
>
{"⭐ Prestige "}
{profile.prestigeCount}
</span>
}
</div>
: null}
</div>
</div>
{profile.bio === ""
? null
: <div className="character-page-section">
<h2 className="character-page-section-title">{"āš”ļø About"}</h2>
<p className="character-page-bio">{profile.bio}</p>
</div>
}
{profile.guildName === ""
? null
: <div className="character-page-section">
<h2 className="character-page-section-title">{"šŸ° Guild"}</h2>
<p className="character-page-guild-name">{profile.guildName}</p>
{profile.guildDescription === ""
? null
: <p className="character-page-guild-desc">
{profile.guildDescription}
</p>
}
</div>
}
{profile.equippedItems.length > 0
&& <div className="character-page-section">
<h2 className="character-page-section-title">{"šŸ—”ļø Equipment"}</h2>
<div className="character-page-equipment-list">
{profile.equippedItems.map((item) => {
return (
<div
className="character-page-equipment-item"
key={item.name}
>
<div className="character-page-equipment-header">
<span className="character-page-equipment-slot">
{slotIcons[item.type]}
</span>
<span
className={
"character-page-equipment-name"
+ ` character-sheet-rarity--${item.rarity}`
}
>
{item.name}
</span>
<span
className={
"character-page-equipment-rarity"
+ ` character-sheet-rarity--${item.rarity}`
}
>
{item.rarity}
</span>
</div>
<p className="character-page-equipment-bonus">
{formatBonus(item.bonus)}
</p>
</div>
);
})}
</div>
</div>
}
{profile.completedChapters.length === 0
? null
: <div className="character-page-section">
<h2 className="character-page-section-title">{"šŸ“– Story"}</h2>
{profile.completedChapters.map((completion) => {
const chapter = STORY_CHAPTERS.find((candidate) => {
return candidate.id === completion.chapterId;
});
if (chapter === undefined) {
return null;
}
const choice = chapter.choices.find((candidate) => {
return candidate.id === completion.choiceId;
});
if (choice === undefined) {
return null;
}
return (
<div
className="character-sheet-story-entry"
key={completion.chapterId}
>
<span className="character-sheet-story-chapter">
{chapter.title}
</span>
<span className="character-sheet-story-choice">
{choice.label}
</span>
<p className="character-sheet-story-outcome">
{choice.description}
</p>
</div>
);
})}
</div>
}
<div className="character-page-divider" />
<p className="character-page-player-line">
{"Played by "}
<span className="character-page-username">
{"@"}
{profile.username}
</span>
</p>
<div className="character-page-actions">
<button
className="character-page-share-btn"
onClick={handleCopy}
type="button"
>
{copied
? "āœ“ Copied!"
: "šŸ”— Share Character"}
</button>
<a
className="character-page-profile-link"
href={`/profile/${discordId}`}
>
{"šŸ“Š View Stats"}
</a>
<a className="character-page-play-link" href="/">
{"āš”ļø Play Elysium"}
</a>
</div>
</div>
</div>
);
};
export { CharacterPage };
@@ -0,0 +1,696 @@
/**
* @file Character sheet panel for viewing and editing the player's character.
* @copyright nhcarrigan
* @license Naomi's Public License
* @author Naomi Carrigan
*/
/* eslint-disable max-lines-per-function -- Complex component with many fields */
/* eslint-disable complexity -- Many conditional render paths for optional fields */
/* eslint-disable max-statements -- Component requires many state declarations */
/* eslint-disable max-lines -- Large component with editing and view modes */
import {
DEFAULT_PROFILE_SETTINGS,
STORY_CHAPTERS,
type EquipmentBonus,
type EquipmentRarity,
type EquipmentType,
type ProfileSettings,
} from "@elysium/types";
import { type ChangeEvent, type JSX, useEffect, useRef, useState } from "react";
import { updateProfile } from "../../api/client.js";
import { useGame } from "../../context/gameContext.js";
import { logError } from "../../utils/logError.js";
interface EquippedItem {
name: string;
type: EquipmentType;
rarity: EquipmentRarity;
bonus: EquipmentBonus;
}
interface CharacterSheetData {
characterName: string;
pronouns: string;
characterRace: string;
characterClass: string;
bio: string;
guildName: string;
guildDescription: string;
activeTitle: string;
unlockedTitles: Array<{ id: string; name: string }>;
equippedItems: Array<EquippedItem>;
}
const emptySheet: CharacterSheetData = {
activeTitle: "",
bio: "",
characterClass: "",
characterName: "",
characterRace: "",
equippedItems: [],
guildDescription: "",
guildName: "",
pronouns: "",
unlockedTitles: [],
};
const slotIcons: Record<EquipmentType, string> = {
armour: "šŸ›”ļø",
trinket: "šŸ’",
weapon: "āš”ļø",
};
/**
* Formats an equipment bonus as a human-readable string.
* @param bonus - The equipment bonus to format.
* @returns The formatted bonus string.
*/
const formatBonus = (bonus: EquipmentBonus): string => {
const parts: Array<string> = [];
if (bonus.goldMultiplier !== undefined) {
const pct = Math.round((bonus.goldMultiplier - 1) * 100);
parts.push(`+${String(pct)}% Gold Income`);
}
if (bonus.combatMultiplier !== undefined) {
const pct = Math.round((bonus.combatMultiplier - 1) * 100);
parts.push(`+${String(pct)}% Combat Power`);
}
if (bonus.clickMultiplier !== undefined) {
const pct = Math.round((bonus.clickMultiplier - 1) * 100);
parts.push(`+${String(pct)}% Click Power`);
}
return parts.join(" Ā· ");
};
/**
* Renders the character sheet panel for viewing and editing player profile.
* @returns The JSX element.
*/
const CharacterSheetPanel = (): JSX.Element => {
const { state, loginStreak } = useGame();
const player = state?.player;
const [ sheet, setSheet ] = useState<CharacterSheetData>(emptySheet);
const [ draft, setDraft ] = useState<CharacterSheetData>(emptySheet);
const [ editing, setEditing ] = useState(false);
const [ loading, setLoading ] = useState(true);
const [ saving, setSaving ] = useState(false);
const [ error, setError ] = useState<string | null>(null);
const [ saved, setSaved ] = useState(false);
const [ copied, setCopied ] = useState(false);
const savedSettingsReference = useRef<ProfileSettings>({
...DEFAULT_PROFILE_SETTINGS,
});
useEffect(() => {
if (player?.discordId === undefined || player.discordId === "") {
return;
}
fetch(`/api/profile/${player.discordId}`).
then(async(response) => {
if (!response.ok) {
return;
}
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- API response cast
const data = (await response.json()) as {
characterName: string;
pronouns: string;
characterRace: string;
characterClass: string;
bio: string;
guildName: string;
guildDescription: string;
profileSettings: ProfileSettings;
activeTitle: string;
unlockedTitles: Array<{ id: string; name: string }>;
equippedItems: Array<EquippedItem>;
};
const loaded: CharacterSheetData = {
activeTitle: data.activeTitle,
bio: data.bio,
characterClass: data.characterClass,
characterName: data.characterName,
characterRace: data.characterRace,
equippedItems: data.equippedItems,
guildDescription: data.guildDescription,
guildName: data.guildName,
pronouns: data.pronouns,
unlockedTitles: data.unlockedTitles,
};
setSheet(loaded);
setDraft(loaded);
savedSettingsReference.current = {
...DEFAULT_PROFILE_SETTINGS,
...data.profileSettings,
};
}).
catch(() => {
/* Fall back to empty */
}).
finally(() => {
setLoading(false);
});
}, [ player?.discordId ]);
function handleEdit(): void {
setDraft({ ...sheet });
setEditing(true);
setError(null);
setSaved(false);
}
function handleCancel(): void {
setEditing(false);
setError(null);
}
async function handleSave(): Promise<void> {
setSaving(true);
setError(null);
try {
const characterName
= draft.characterName === ""
? player?.characterName ?? ""
: draft.characterName;
await updateProfile({
activeTitle: draft.activeTitle,
bio: draft.bio,
characterClass: draft.characterClass,
characterName: characterName,
characterRace: draft.characterRace,
guildDescription: draft.guildDescription,
guildName: draft.guildName,
profileSettings: savedSettingsReference.current,
pronouns: draft.pronouns,
});
setSheet({ ...draft });
setSaved(true);
setTimeout(() => {
setEditing(false);
setSaved(false);
}, 900);
} catch (error_) {
setError(error_ instanceof Error
? error_.message
: "Failed to save");
} finally {
setSaving(false);
}
}
function handleSaveClick(): void {
void handleSave();
}
function handleShareClick(): void {
const discordId = player?.discordId ?? "";
const url = `${window.location.origin}/character/${discordId}`;
void navigator.clipboard.writeText(url).
then(() => {
setCopied(true);
setTimeout(() => {
setCopied(false);
}, 2000);
}).
catch((error_: unknown) => {
logError("clipboard_copy", error_);
});
}
function handleNameChange(event: ChangeEvent<HTMLInputElement>): void {
const { value } = event.target;
setDraft((current) => {
return { ...current, characterName: value };
});
}
function handlePronounsChange(event: ChangeEvent<HTMLInputElement>): void {
const { value } = event.target;
setDraft((current) => {
return { ...current, pronouns: value };
});
}
function handleRaceChange(event: ChangeEvent<HTMLInputElement>): void {
const { value } = event.target;
setDraft((current) => {
return { ...current, characterRace: value };
});
}
function handleClassChange(event: ChangeEvent<HTMLInputElement>): void {
const { value } = event.target;
setDraft((current) => {
return { ...current, characterClass: value };
});
}
function handleBioChange(event: ChangeEvent<HTMLTextAreaElement>): void {
const { value } = event.target;
setDraft((current) => {
return { ...current, bio: value };
});
}
function handleTitleChange(event: ChangeEvent<HTMLSelectElement>): void {
const { value } = event.target;
setDraft((current) => {
return { ...current, activeTitle: value };
});
}
function handleGuildNameChange(event: ChangeEvent<HTMLInputElement>): void {
const { value } = event.target;
setDraft((current) => {
return { ...current, guildName: value };
});
}
function handleGuildDescChange(
event: ChangeEvent<HTMLTextAreaElement>,
): void {
const { value } = event.target;
setDraft((current) => {
return { ...current, guildDescription: value };
});
}
if (loading) {
return (
<section className="panel">
<p>{"Loading character sheet…"}</p>
</section>
);
}
if (editing) {
const isSaveDisabled = saving || draft.characterName.trim() === "";
let saveLabel = "Save";
if (saving) {
saveLabel = "Saving…";
}
if (saved) {
saveLabel = "āœ“ Saved!";
}
return (
<section className="panel character-sheet-panel">
<div className="panel-header">
<h2>{"šŸ“‹ Character Sheet"}</h2>
</div>
<div className="character-sheet-form">
<div className="character-sheet-section">
<h3 className="character-sheet-section-title">{"āš”ļø Character"}</h3>
<label className="character-sheet-label" htmlFor="cs-name">
{"Character Name"}
</label>
<input
className="character-sheet-input"
id="cs-name"
maxLength={32}
onChange={handleNameChange}
placeholder="Your character's name"
type="text"
value={draft.characterName}
/>
<span className="character-sheet-hint">
{draft.characterName.length}
{" / 32"}
</span>
<label className="character-sheet-label" htmlFor="cs-pronouns">
{"Pronouns"}
</label>
<input
className="character-sheet-input"
id="cs-pronouns"
maxLength={20}
onChange={handlePronounsChange}
placeholder="e.g. she/her, he/him, they/them"
type="text"
value={draft.pronouns}
/>
<span className="character-sheet-hint">
{draft.pronouns.length}
{" / 20"}
</span>
<label className="character-sheet-label" htmlFor="cs-race">
{"Race"}
</label>
<input
className="character-sheet-input"
id="cs-race"
maxLength={32}
onChange={handleRaceChange}
placeholder="e.g. Elf, Dwarf, Human, Tiefling…"
type="text"
value={draft.characterRace}
/>
<span className="character-sheet-hint">
{draft.characterRace.length}
{" / 32"}
</span>
<label className="character-sheet-label" htmlFor="cs-class">
{"Class"}
</label>
<input
className="character-sheet-input"
id="cs-class"
maxLength={32}
onChange={handleClassChange}
placeholder="e.g. Paladin, Archmage, Shadow Rogue…"
type="text"
value={draft.characterClass}
/>
<span className="character-sheet-hint">
{draft.characterClass.length}
{" / 32"}
</span>
<label className="character-sheet-label" htmlFor="cs-bio">
{"About Your Character"}
</label>
<textarea
className="character-sheet-textarea"
id="cs-bio"
maxLength={200}
onChange={handleBioChange}
placeholder={
"Describe your character's story, personality, or appearance…"
}
rows={4}
value={draft.bio}
/>
<span className="character-sheet-hint">
{draft.bio.length}
{" / 200"}
</span>
{draft.unlockedTitles.length > 0
&& <>
<label className="character-sheet-label" htmlFor="cs-title">
{"Active Title"}
</label>
<select
className="character-sheet-input"
id="cs-title"
onChange={handleTitleChange}
value={draft.activeTitle}
>
<option value="">{"— None —"}</option>
{draft.unlockedTitles.map((title) => {
return (
<option key={title.id} value={title.id}>
{title.name}
</option>
);
})}
</select>
</>
}
</div>
<div className="character-sheet-section">
<h3 className="character-sheet-section-title">{"šŸ° Guild"}</h3>
<label className="character-sheet-label" htmlFor="cs-guild-name">
{"Guild Name"}
</label>
<input
className="character-sheet-input"
id="cs-guild-name"
maxLength={64}
onChange={handleGuildNameChange}
placeholder="Name your guild"
type="text"
value={draft.guildName}
/>
<span className="character-sheet-hint">
{draft.guildName.length}
{" / 64"}
</span>
<label className="character-sheet-label" htmlFor="cs-guild-desc">
{"Guild Description"}
</label>
<textarea
className="character-sheet-textarea"
id="cs-guild-desc"
maxLength={500}
onChange={handleGuildDescChange}
placeholder="Describe your guild's history, goals, or lore…"
rows={6}
value={draft.guildDescription}
/>
<span className="character-sheet-hint">
{draft.guildDescription.length}
{" / 500"}
</span>
</div>
{error === null
? null
: <p className="character-sheet-error">{error}</p>
}
<div className="character-sheet-actions">
<button
className="character-sheet-cancel"
onClick={handleCancel}
type="button"
>
{"Cancel"}
</button>
<button
className="character-sheet-save"
disabled={isSaveDisabled}
onClick={handleSaveClick}
type="button"
>
{saveLabel}
</button>
</div>
</div>
</section>
);
}
const subtitleParts = [ sheet.characterRace, sheet.characterClass ].filter(
(part) => {
return part !== "";
},
);
const subtitle = subtitleParts.join(" Ā· ");
const completedChapters = state?.story?.completedChapters ?? [];
return (
<section className="panel character-sheet-panel">
<div className="panel-header">
<h2>{"šŸ“‹ Character Sheet"}</h2>
<div className="character-sheet-header-actions">
<button
className="character-sheet-edit-btn"
onClick={handleShareClick}
type="button"
>
{copied
? "āœ“ Copied!"
: "šŸ”— Share"}
</button>
<a className="character-sheet-edit-btn" href="/leaderboards">
{"šŸ† Boards"}
</a>
<button
className="character-sheet-edit-btn"
onClick={handleEdit}
type="button"
>
{"āœļø Edit"}
</button>
</div>
</div>
<div className="character-sheet-view">
<div className="character-sheet-section">
<h3 className="character-sheet-section-title">{"āš”ļø Character"}</h3>
<div className="character-sheet-field">
<span className="character-sheet-field-label">{"Name"}</span>
<span className="character-sheet-field-value">
{sheet.characterName === ""
? <em className="character-sheet-empty">{"Not set"}</em>
: sheet.characterName
}
</span>
</div>
<div className="character-sheet-field">
<span className="character-sheet-field-label">{"Streak"}</span>
<span className="character-sheet-streak">
{"šŸ”„ "}
{loginStreak}
{"-day login streak"}
</span>
</div>
{sheet.activeTitle === ""
? null
: <div className="character-sheet-field">
<span className="character-sheet-field-label">{"Title"}</span>
<span
className={"character-sheet-field-value character-sheet-title"}
>
{sheet.unlockedTitles.find((title) => {
return title.id === sheet.activeTitle;
})?.name ?? sheet.activeTitle}
</span>
</div>
}
{sheet.pronouns === ""
? null
: <div className="character-sheet-field">
<span className="character-sheet-field-label">{"Pronouns"}</span>
<span className="character-sheet-field-value">
{sheet.pronouns}
</span>
</div>
}
{subtitle === ""
? null
: <div className="character-sheet-field">
<span className="character-sheet-field-label">{"Identity"}</span>
<span className="character-sheet-field-value">{subtitle}</span>
</div>
}
{sheet.bio === ""
? null
: <div className="character-sheet-bio">
<span className="character-sheet-field-label">{"About"}</span>
<p className="character-sheet-bio-text">{sheet.bio}</p>
</div>
}
</div>
<div className="character-sheet-section">
<h3 className="character-sheet-section-title">{"šŸ—”ļø Equipment"}</h3>
{sheet.equippedItems.length > 0
? <div className="character-sheet-equipment-list">
{sheet.equippedItems.map((item) => {
return (
<div
className="character-sheet-equipment-item"
key={item.type}
>
<div className="character-sheet-equipment-header">
<span className="character-sheet-equipment-slot">
{slotIcons[item.type]}
</span>
<span
className={
"character-sheet-equipment-name"
+ ` character-sheet-rarity--${item.rarity}`
}
>
{item.name}
</span>
<span
className={
"character-sheet-equipment-rarity"
+ ` character-sheet-rarity--${item.rarity}`
}
>
{item.rarity}
</span>
</div>
<p className="character-sheet-equipment-bonus">
{formatBonus(item.bonus)}
</p>
</div>
);
})}
</div>
: <p className="character-sheet-empty">
{"No equipment found. Defeat bosses to earn gear!"}
</p>
}
</div>
<div className="character-sheet-section">
<h3 className="character-sheet-section-title">{"šŸ° Guild"}</h3>
{sheet.guildName === ""
? <p className="character-sheet-empty">
{"No guild registered yet. Click āœļø Edit to add one!"}
</p>
: <>
<div className="character-sheet-field">
<span className="character-sheet-field-label">{"Name"}</span>
<span className="character-sheet-field-value">
{sheet.guildName}
</span>
</div>
{sheet.guildDescription === ""
? null
: <div className="character-sheet-bio">
<span className="character-sheet-field-label">{"Lore"}</span>
<p className="character-sheet-bio-text">
{sheet.guildDescription}
</p>
</div>
}
</>
}
</div>
{completedChapters.length === 0
? null
: <div className="character-sheet-section">
<h3 className="character-sheet-section-title">
{"šŸ“– Story Choices"}
</h3>
{completedChapters.map((completion) => {
const chapter = STORY_CHAPTERS.find((candidate) => {
return candidate.id === completion.chapterId;
});
if (chapter === undefined) {
return null;
}
const choice = chapter.choices.find((candidate) => {
return candidate.id === completion.choiceId;
});
if (choice === undefined) {
return null;
}
const characterName
= player?.characterName === ""
|| player?.characterName === undefined
? "the guild leader"
: player.characterName;
const outcome = choice.outcome.replaceAll(
"{characterName}",
characterName,
);
return (
<div
className="character-sheet-story-entry"
key={completion.chapterId}
>
<span className="character-sheet-story-chapter">
{chapter.title}
</span>
<span className="character-sheet-story-choice">
{choice.label}
</span>
<p className="character-sheet-story-outcome">{outcome}</p>
</div>
);
})}
</div>
}
</div>
</section>
);
};
export { CharacterSheetPanel };
+136
View File
@@ -0,0 +1,136 @@
/**
* @file Click area component - the main guild hall click target.
* @copyright nhcarrigan
* @license Naomi's Public License
* @author Naomi Carrigan
*/
/* eslint-disable max-lines-per-function -- Complex useCallback with float management */
import {
type JSX,
type MouseEvent,
useCallback,
useRef,
useState,
} from "react";
import { useGame } from "../../context/gameContext.js";
import { calculateClickPower } from "../../engine/tick.js";
// eslint-disable-next-line @typescript-eslint/naming-convention, no-underscore-dangle -- Vite define constant
declare const __WEB_VERSION__: string;
interface FloatText {
id: number;
x: number;
y: number;
text: string;
}
/**
* Renders the guild hall click area with floating gold text on click.
* @returns The JSX element.
*/
const ClickArea = (): JSX.Element => {
const {
state,
handleClick,
formatNumber,
saveSchemaVersion,
currentSchemaVersion,
} = useGame();
const [ floats, setFloats ] = useState<Array<FloatText>>([]);
const nextIdReference = useRef(0);
const handleClickWithFloat = useCallback(
(event: MouseEvent<HTMLButtonElement>) => {
if (state === null) {
return;
}
const rect = event.currentTarget.getBoundingClientRect();
const x = event.clientX - rect.left;
const y = event.clientY - rect.top;
const id = nextIdReference.current;
nextIdReference.current = nextIdReference.current + 1;
const clickPower = calculateClickPower(state);
const text = `+${formatNumber(clickPower)}`;
setFloats((previous) => {
return [ ...previous, { id, text, x, y } ];
});
handleClick();
setTimeout(() => {
// eslint-disable-next-line max-nested-callbacks -- Float cleanup requires nesting within setTimeout
setFloats((previous) => {
// eslint-disable-next-line max-nested-callbacks -- Float cleanup requires nesting within setTimeout
return previous.filter((floatItem) => {
return floatItem.id !== id;
});
});
}, 900);
},
[ state, handleClick, formatNumber ],
);
if (state === null) {
return <div className="click-area-placeholder" />;
}
const clickPower = calculateClickPower(state);
return (
<section className="click-area">
<h1 className="game-title">{"Elysium"}</h1>
<p className="game-version">
{"v"}
{__WEB_VERSION__}
</p>
{currentSchemaVersion > 0
&& <p className="game-schema-version">
{"Save: v"}
{saveSchemaVersion}
{" / Latest: v"}
{currentSchemaVersion}
</p>
}
<h2>{"Guild Hall"}</h2>
<div className="click-button-wrapper">
<button
aria-label={`Click to earn ${formatNumber(clickPower)} gold`}
className="click-button"
onClick={handleClickWithFloat}
type="button"
>
<img
alt="Guild Hall"
className="click-button-image"
src="https://cdn.nhcarrigan.com/avatars/elysium.png"
/>
</button>
{floats.map((floatItem) => {
return (
<span
className="click-float"
key={floatItem.id}
style={{ left: floatItem.x, top: floatItem.y }}
>
{floatItem.text}
</span>
);
})}
</div>
<p className="click-power">
{"+"}
{formatNumber(clickPower)}
{" gold/click"}
</p>
<p className="early-access-notice">
{"āš ļø Early Access — this build is subject to change. "}
<strong>
{"All game progress WILL be reset upon v1.0.0 release."}
</strong>
</p>
</section>
);
};
export { ClickArea };
+231
View File
@@ -0,0 +1,231 @@
/**
* @file Codex panel component displaying discovered lore entries.
* @copyright nhcarrigan
* @license Naomi's Public License
* @author Naomi Carrigan
*/
/* eslint-disable max-lines-per-function -- Complex component with zone and entry rendering */
import { type JSX, useState } from "react";
import { useGame } from "../../context/gameContext.js";
import { CODEX_ENTRIES, ZONE_LABELS } from "../../data/codex.js";
import { cdnImage } from "../../utils/cdn.js";
import type { CodexEntry } from "@elysium/types";
/**
* Converts a fraction to a percentage value.
* @param numerator - The numerator value.
* @param denominator - The denominator value.
* @returns The percentage as a number between 0 and 100.
*/
const toPercent = (numerator: number, denominator: number): number => {
if (denominator === 0) {
return 0;
}
const scaled = numerator * 100;
return scaled / denominator;
};
const sourceBadge: Record<CodexEntry["sourceType"], string> = {
adventurer: "šŸ‘„",
boss: "āš”ļø",
equipment: "šŸ›”ļø",
exploration: "🧭",
prestige: "šŸ”®",
quest: "šŸ“œ",
recipe: "āš—ļø",
upgrade: "šŸ”§",
zone: "šŸ—ŗļø",
};
const sourceTypeFolder: Record<CodexEntry["sourceType"], string> = {
adventurer: "adventurers",
boss: "bosses",
equipment: "equipment",
exploration: "explorations",
prestige: "prestige-upgrades",
quest: "quests",
recipe: "recipes",
upgrade: "upgrades",
zone: "zones",
};
/**
* Converts a snake_case ID to a Title Case display name.
* @param id - The snake_case identifier to format.
* @returns The formatted display name.
*/
const formatId = (id: string): string => {
return id.split("_").
map((word) => {
return word.charAt(0).toUpperCase() + word.slice(1);
}).
join(" ");
};
/**
* Generates a human-readable unlock hint for a locked codex entry.
* @param entry - The locked codex entry.
* @returns A string describing how to unlock the entry.
*/
const buildUnlockHint = (entry: CodexEntry): string => {
const name = formatId(entry.sourceId);
switch (entry.sourceType) {
case "boss": return `Defeat ${name}`;
case "quest": return `Complete: ${name}`;
case "equipment": return `Obtain: ${name}`;
case "adventurer": return `Recruit a ${name}`;
case "upgrade": return `Purchase: ${name}`;
case "prestige": return `Purchase runestone upgrade: ${name}`;
case "zone": return `Explore: ${name}`;
case "exploration": return `Discover: ${name}`;
case "recipe": return `Craft: ${name}`;
default: return "Keep playing to unlock";
}
};
/**
* Renders the codex panel with lore entries grouped by zone.
* @returns The JSX element.
*/
const CodexPanel = (): JSX.Element => {
const { state } = useGame();
const [ expandedId, setExpandedId ] = useState<string | null>(null);
if (state === null) {
return (
<section className="panel">
<p>{"Loading..."}</p>
</section>
);
}
const unlockedIds = new Set(state.codex?.unlockedEntryIds ?? []);
const totalEntries = CODEX_ENTRIES.length;
const unlockedCount = CODEX_ENTRIES.filter((entry) => {
return unlockedIds.has(entry.id);
}).length;
const progressPercent = toPercent(unlockedCount, totalEntries);
const entriesByZone = Object.entries(ZONE_LABELS).
map(([ zoneId, zoneName ]) => {
const entries = CODEX_ENTRIES.filter((entry) => {
return entry.zoneId === zoneId;
});
const unlockedEntries = entries.filter((entry) => {
return unlockedIds.has(entry.id);
});
return {
entries,
unlockedEntries,
zoneId,
zoneName,
};
}).
filter(({ entries }) => {
return entries.length > 0;
});
return (
<section className="panel codex-panel">
<h2>{"šŸ“– Codex"}</h2>
<div className="codex-progress">
<p className="codex-progress-text">
{"Lore discovered: "}
<strong>
{unlockedCount}
{" / "}
{totalEntries}
</strong>
</p>
<div className="codex-progress-bar">
<div
className="codex-progress-fill"
style={{ width: `${String(Math.round(progressPercent))}%` }}
/>
</div>
</div>
{entriesByZone.map(({ zoneId, zoneName, entries, unlockedEntries }) => {
return (
<div className="codex-zone" key={zoneId}>
<h3 className="codex-zone-header">
{zoneName}
<span className="codex-zone-count">
{unlockedEntries.length}
{"/"}
{entries.length}
</span>
</h3>
<div className="codex-entries">
{entries.map((entry) => {
const isUnlocked = unlockedIds.has(entry.id);
const isExpanded = expandedId === entry.id;
if (!isUnlocked) {
return (
<div className="codex-entry locked" key={entry.id}>
<div className="codex-entry-header">
<span className="codex-lock">{"šŸ”’"}</span>
<span className="codex-entry-title">{"???"}</span>
</div>
<p className="codex-unlock-hint">
{buildUnlockHint(entry)}
</p>
</div>
);
}
function handleExpand(): void {
setExpandedId(isExpanded
? null
: entry.id);
}
return (
<div
className={`codex-entry unlocked ${
isExpanded
? "expanded"
: ""
}`}
key={entry.id}
onClick={handleExpand}
>
<div className="codex-entry-header">
<span className="codex-source-badge">
{sourceBadge[entry.sourceType]}
</span>
<span className="codex-entry-title">{entry.title}</span>
<span className="codex-chevron">
{isExpanded
? "ā–²"
: "ā–¼"}
</span>
</div>
{isExpanded
? <>
<img
alt={entry.title}
className="codex-entry-image"
src={cdnImage(
sourceTypeFolder[entry.sourceType],
entry.sourceId,
)}
/>
<p className="codex-entry-content">{entry.content}</p>
</>
: null}
</div>
);
})}
</div>
</div>
);
})}
</section>
);
};
export { CodexPanel };
@@ -0,0 +1,83 @@
/**
* @file Codex toast notification component for new lore discoveries.
* @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 { CODEX_ENTRIES } from "../../data/codex.js";
interface CodexToastItemProperties {
readonly entryId: string;
readonly onDismiss: (id: string)=> void;
}
/**
* Renders a single codex lore toast notification.
* @param props - The toast item properties.
* @param props.entryId - The codex entry ID to display.
* @param props.onDismiss - Callback to dismiss the toast.
* @returns The JSX element or null if entry is not found.
*/
const CodexToastItem = ({
entryId,
onDismiss,
}: CodexToastItemProperties): JSX.Element | null => {
const entry = CODEX_ENTRIES.find((codexEntry) => {
return codexEntry.id === entryId;
});
useEffect(() => {
const timer = setTimeout(() => {
onDismiss(entryId);
}, 4000);
return (): void => {
clearTimeout(timer);
};
}, [ entryId, onDismiss ]);
if (entry === undefined) {
return null;
}
function handleClick(): void {
onDismiss(entryId);
}
return (
<div className="game-toast" onClick={handleClick}>
<span className="toast-icon">{"šŸ“–"}</span>
<div className="toast-content">
<span className="toast-label">{"✨ Lore Unlocked!"}</span>
<span className="toast-name">{entry.title}</span>
</div>
</div>
);
};
/**
* Renders the codex toast container with pending lore notifications.
* @returns The JSX element or null if there are no pending entries.
*/
const CodexToast = (): JSX.Element | null => {
const { unlockedCodexEntryIds: pendingEntryIds, dismissCodexEntry }
= useGame();
if (pendingEntryIds.length === 0) {
return null;
}
return (
<>
{pendingEntryIds.map((id) => {
return (
<CodexToastItem entryId={id} key={id} onDismiss={dismissCodexEntry} />
);
})}
</>
);
};
export { CodexToast };
@@ -0,0 +1,226 @@
/**
* @file Companion panel component for managing active companions.
* @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 companion card with conditional renders */
/* eslint-disable complexity -- Companion card has many conditional render paths */
import { COMPANIONS, type Companion } from "@elysium/types";
import { useGame } from "../../context/gameContext.js";
import { cdnImage } from "../../utils/cdn.js";
import type { JSX } from "react";
const bonusLabels: Record<string, string> = {
bossDamage: "Boss Damage",
clickGold: "Click Gold",
essenceIncome: "Essence Income",
passiveGold: "Passive Gold",
questTime: "Quest Time",
};
const unlockLabels: Record<string, string> = {
apotheosis: "apotheosis",
lifetimeBosses: "lifetime bosses defeated",
lifetimeGold: "lifetime gold earned",
lifetimeQuests: "lifetime quests completed",
prestige: "prestige(s)",
transcendence: "transcendence(s)",
};
interface CompanionCardProperties {
readonly companion: Companion;
readonly isUnlocked: boolean;
readonly isActive: boolean;
readonly onSelect: ()=> void;
readonly formatNumber: (n: number)=> string;
readonly currentProgress: number;
}
/**
* Renders a single companion card.
* @param props - The companion card properties.
* @param props.companion - The companion data.
* @param props.isUnlocked - Whether this companion is unlocked.
* @param props.isActive - Whether this companion is currently active.
* @param props.onSelect - Callback when the companion is selected/deselected.
* @param props.formatNumber - The number formatting utility function.
* @param props.currentProgress - The player's current progress toward the unlock threshold.
* @returns The JSX element.
*/
const CompanionCard = ({
companion,
isUnlocked,
isActive,
onSelect,
formatNumber,
currentProgress,
}: CompanionCardProperties): JSX.Element => {
const bonusSign = companion.bonus.type === "questTime"
? "-"
: "+";
const bonusPercent = Math.round(companion.bonus.value * 100);
const bonusLabel = bonusLabels[companion.bonus.type] ?? companion.bonus.type;
return (
<div
className={`companion-card ${
isUnlocked
? "companion-unlocked"
: "companion-locked"
} ${isActive
? "companion-active"
: ""}`}
>
<div className="companion-header">
<img
alt={companion.name}
className="card-thumbnail"
src={cdnImage("companions", companion.id)}
/>
<div className="companion-name-block">
<span className="companion-name">{companion.name}</span>
<span className="companion-title">{companion.title}</span>
</div>
{isActive
? <span className="companion-active-badge">{"Active"}</span>
: null}
</div>
<p className="companion-description">{companion.description}</p>
<div className="companion-bonus">
<span className="companion-bonus-label">{bonusLabel}</span>
<span className="companion-bonus-value">
{bonusSign}
{bonusPercent}
{"%"}
</span>
</div>
{isUnlocked
? <button
className={`companion-select-btn ${
isActive
? "companion-select-active"
: ""
}`}
onClick={onSelect}
type="button"
>
{isActive
? "Deactivate"
: "Activate"}
</button>
: <div className="companion-unlock-requirement">
<p>
{"šŸ”’ Unlock: "}
{companion.unlock.type === "lifetimeGold"
? formatNumber(companion.unlock.threshold)
: String(companion.unlock.threshold)}{" "}
{unlockLabels[companion.unlock.type] ?? companion.unlock.type}
</p>
<div className="companion-progress">
<progress
max={companion.unlock.threshold}
value={Math.min(currentProgress, companion.unlock.threshold)}
/>
<span className="companion-progress-label">
{companion.unlock.type === "lifetimeGold"
? formatNumber(currentProgress)
: String(currentProgress)}
{" / "}
{companion.unlock.type === "lifetimeGold"
? formatNumber(companion.unlock.threshold)
: String(companion.unlock.threshold)}
</span>
</div>
</div>
}
</div>
);
};
/**
* Renders the companion panel with all companions.
* @returns The JSX element.
*/
const CompanionPanel = (): JSX.Element => {
const { formatNumber, setActiveCompanion, state } = useGame();
if (state === null) {
return (
<section className="panel">
<p>{"Loading..."}</p>
</section>
);
}
const unlockedIds = state.companions?.unlockedCompanionIds ?? [];
const activeId = state.companions?.activeCompanionId ?? null;
const progressByUnlockType: Record<string, number> = {
apotheosis: state.apotheosis?.count ?? 0,
lifetimeBosses: state.player.lifetimeBossesDefeated,
// eslint-disable-next-line stylistic/max-len -- Long expression; splitting would reduce readability
lifetimeGold: state.player.lifetimeGoldEarned + state.player.totalGoldEarned,
lifetimeQuests: state.player.lifetimeQuestsCompleted,
prestige: state.prestige.count,
transcendence: state.transcendence?.count ?? 0,
};
function handleSelect(companionId: string): void {
setActiveCompanion(activeId === companionId
? null
: companionId);
}
const activeCompanion
= activeId === null
? undefined
: COMPANIONS.find((companion) => {
return companion.id === activeId;
});
return (
<div className="companion-panel">
<h2>{"šŸ‘„ Companions"}</h2>
<p className="companion-intro">
{"Companions provide powerful bonuses while active."
+ " You can only have one companion active at a time."}
{activeId === null
? null
: <>
{" Currently active: "}
<strong>{activeCompanion?.name ?? activeId}</strong>
{"."}
</>
}
</p>
<div className="companion-grid">
{COMPANIONS.map((companion) => {
function handleCompanionSelect(): void {
handleSelect(companion.id);
}
return (
<CompanionCard
companion={companion}
currentProgress={
progressByUnlockType[companion.unlock.type] ?? 0
}
formatNumber={formatNumber}
isActive={activeId === companion.id}
isUnlocked={unlockedIds.includes(companion.id)}
key={companion.id}
onSelect={handleCompanionSelect}
/>
);
})}
</div>
</div>
);
};
export { CompanionPanel };

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