generated from nhcarrigan/template
feat: add equipment, achievements, and visual polish
- Equipment system: 12 items across weapon/armour/trinket slots with common/rare/epic/legendary rarities; starter commons auto-equipped, higher tiers drop from boss victories - Achievement system: 15 milestones with typed conditions; checked each tick and crystal rewards applied automatically - Achievement toast: slide-in notification, auto-dismisses after 4s - Floating click text: +X gold floats on each manual click - Expanded quests (9 total) and upgrades (12 total) - Upgrade panel now shows locked upgrades so players can see their progression path - formatNumber utility (K/M/B/T) used consistently across all panels - Backfill logic for existing saves to add new content gracefully - types package now emits .d.ts declarations
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
import type { GameState, SaveRequest } from "@elysium/types";
|
||||
import { Hono } from "hono";
|
||||
import { prisma } from "../db/client.js";
|
||||
import { DEFAULT_ACHIEVEMENTS } from "../data/achievements.js";
|
||||
import { DEFAULT_ADVENTURERS } from "../data/adventurers.js";
|
||||
import { DEFAULT_EQUIPMENT } from "../data/equipment.js";
|
||||
import { authMiddleware } from "../middleware/auth.js";
|
||||
import { calculateOfflineGold } from "../services/offlineProgress.js";
|
||||
|
||||
@@ -18,6 +21,72 @@ gameRouter.get("/load", async (context) => {
|
||||
}
|
||||
|
||||
const state = record.state as unknown as GameState;
|
||||
|
||||
let needsBackfill = false;
|
||||
|
||||
// Backfill combatPower on saves that predate the field
|
||||
for (const adventurer of state.adventurers) {
|
||||
if (adventurer.combatPower == null) {
|
||||
const defaults = DEFAULT_ADVENTURERS.find((d) => d.id === adventurer.id);
|
||||
adventurer.combatPower = defaults?.combatPower ?? 1;
|
||||
needsBackfill = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Backfill equipment on saves that predate the feature
|
||||
if (!Array.isArray(state.equipment) || state.equipment.length === 0) {
|
||||
state.equipment = structuredClone(DEFAULT_EQUIPMENT);
|
||||
needsBackfill = true;
|
||||
} else {
|
||||
// Merge in any equipment items missing from existing saves (new items added later)
|
||||
for (const defaultItem of DEFAULT_EQUIPMENT) {
|
||||
if (!state.equipment.some((e) => e.id === defaultItem.id)) {
|
||||
state.equipment.push(structuredClone(defaultItem));
|
||||
needsBackfill = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Backfill achievements on saves that predate the feature
|
||||
if (!Array.isArray(state.achievements) || state.achievements.length === 0) {
|
||||
state.achievements = structuredClone(DEFAULT_ACHIEVEMENTS);
|
||||
needsBackfill = true;
|
||||
} else {
|
||||
// Merge in any achievements missing from existing saves
|
||||
for (const defaultAchievement of DEFAULT_ACHIEVEMENTS) {
|
||||
if (!state.achievements.some((a) => a.id === defaultAchievement.id)) {
|
||||
state.achievements.push(structuredClone(defaultAchievement));
|
||||
needsBackfill = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Backfill equipmentRewards on bosses that predate the field
|
||||
for (const boss of state.bosses) {
|
||||
if (!Array.isArray(boss.equipmentRewards)) {
|
||||
boss.equipmentRewards = [];
|
||||
needsBackfill = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Backfill new quests and upgrades from defaults (add missing ones)
|
||||
const { DEFAULT_QUESTS } = await import("../data/quests.js");
|
||||
const { DEFAULT_UPGRADES } = await import("../data/upgrades.js");
|
||||
|
||||
for (const defaultQuest of DEFAULT_QUESTS) {
|
||||
if (!state.quests.some((q) => q.id === defaultQuest.id)) {
|
||||
state.quests.push(structuredClone(defaultQuest));
|
||||
needsBackfill = true;
|
||||
}
|
||||
}
|
||||
|
||||
for (const defaultUpgrade of DEFAULT_UPGRADES) {
|
||||
if (!state.upgrades.some((u) => u.id === defaultUpgrade.id)) {
|
||||
state.upgrades.push(structuredClone(defaultUpgrade));
|
||||
needsBackfill = true;
|
||||
}
|
||||
}
|
||||
|
||||
const now = Date.now();
|
||||
|
||||
const { offlineGold, offlineSeconds } = calculateOfflineGold(state, now);
|
||||
@@ -29,6 +98,13 @@ gameRouter.get("/load", async (context) => {
|
||||
|
||||
state.lastTickAt = now;
|
||||
|
||||
if (needsBackfill || offlineGold > 0) {
|
||||
await prisma.gameState.update({
|
||||
where: { discordId },
|
||||
data: { state: state as object, updatedAt: now },
|
||||
});
|
||||
}
|
||||
|
||||
return context.json({ state, offlineGold, offlineSeconds });
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user