generated from nhcarrigan/template
feat: content expansion, prestige shop, and offline earnings improvements
- Expand content to 18 zones, 72 bosses, 95 quests, 32 adventurer tiers - Add prestige shop with 24 runestone upgrades across 5 categories - Add PrestigeUpgrade type, data files, API routes, and frontend panel - Fix offline earnings to include equipment and runestone multipliers - Add offline essence calculation alongside offline gold - Update OfflineModal to display both gold and essence earned - Add IDEAS.md for tracking planned features
This commit is contained in:
@@ -1,9 +1,11 @@
|
||||
import type { GameState, PrestigeRequest } from "@elysium/types";
|
||||
import type { BuyPrestigeUpgradeRequest, GameState, PrestigeRequest } from "@elysium/types";
|
||||
import { Hono } from "hono";
|
||||
import { prisma } from "../db/client.js";
|
||||
import { authMiddleware } from "../middleware/auth.js";
|
||||
import { DEFAULT_PRESTIGE_UPGRADES } from "../data/prestigeUpgrades.js";
|
||||
import {
|
||||
buildPostPrestigeState,
|
||||
computeRunestoneMultipliers,
|
||||
isEligibleForPrestige,
|
||||
} from "../services/prestige.js";
|
||||
|
||||
@@ -61,3 +63,60 @@ prestigeRouter.post("/", async (context) => {
|
||||
newPrestigeCount: newPrestigeData.count,
|
||||
});
|
||||
});
|
||||
|
||||
prestigeRouter.post("/buy-upgrade", async (context) => {
|
||||
const discordId = context.get("discordId") as string;
|
||||
const body = await context.req.json<BuyPrestigeUpgradeRequest>();
|
||||
|
||||
const { upgradeId } = body;
|
||||
if (!upgradeId) {
|
||||
return context.json({ error: "upgradeId is required" }, 400);
|
||||
}
|
||||
|
||||
const upgrade = DEFAULT_PRESTIGE_UPGRADES.find((u) => u.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);
|
||||
}
|
||||
|
||||
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 newRunestones = runestones - upgrade.runestonesCost;
|
||||
const newPurchasedUpgradeIds = [...purchasedUpgradeIds, upgradeId];
|
||||
|
||||
const newState: GameState = {
|
||||
...state,
|
||||
prestige: {
|
||||
...state.prestige,
|
||||
runestones: newRunestones,
|
||||
purchasedUpgradeIds: newPurchasedUpgradeIds,
|
||||
...computeRunestoneMultipliers(newPurchasedUpgradeIds),
|
||||
},
|
||||
};
|
||||
|
||||
await prisma.gameState.update({
|
||||
where: { discordId },
|
||||
data: { state: newState as object, updatedAt: Date.now() },
|
||||
});
|
||||
|
||||
const multipliers = computeRunestoneMultipliers(newPurchasedUpgradeIds);
|
||||
|
||||
return context.json({
|
||||
runestonesRemaining: newRunestones,
|
||||
purchasedUpgradeIds: newPurchasedUpgradeIds,
|
||||
...multipliers,
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user