feat: add zone system to bosses and quests

This commit is contained in:
2026-03-06 13:42:40 -08:00
committed by Naomi Carrigan
parent e9e0df31fd
commit 897eba5f64
15 changed files with 239 additions and 4 deletions
+35
View File
@@ -72,6 +72,8 @@ gameRouter.get("/load", async (context) => {
// 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");
const { DEFAULT_ZONES } = await import("../data/zones.js");
const { DEFAULT_BOSSES } = await import("../data/bosses.js");
for (const defaultQuest of DEFAULT_QUESTS) {
if (!state.quests.some((q) => q.id === defaultQuest.id)) {
@@ -80,6 +82,15 @@ gameRouter.get("/load", async (context) => {
}
}
// Backfill zoneId on quests that predate the field
for (const quest of state.quests) {
if (!quest.zoneId) {
const defaults = DEFAULT_QUESTS.find((d) => d.id === quest.id);
quest.zoneId = defaults?.zoneId ?? "verdant_vale";
needsBackfill = true;
}
}
for (const defaultUpgrade of DEFAULT_UPGRADES) {
if (!state.upgrades.some((u) => u.id === defaultUpgrade.id)) {
state.upgrades.push(structuredClone(defaultUpgrade));
@@ -87,6 +98,30 @@ gameRouter.get("/load", async (context) => {
}
}
// Backfill zones on saves that predate the feature
if (!Array.isArray(state.zones) || state.zones.length === 0) {
state.zones = structuredClone(DEFAULT_ZONES);
// Infer unlock state from defeated bosses
for (const zone of state.zones) {
if (zone.unlockBossId != null) {
const unlockBoss = state.bosses.find((b) => b.id === zone.unlockBossId);
if (unlockBoss?.status === "defeated") {
zone.status = "unlocked";
}
}
}
needsBackfill = true;
}
// Backfill zoneId on bosses that predate the field
for (const boss of state.bosses) {
if (!boss.zoneId) {
const defaults = DEFAULT_BOSSES.find((d) => d.id === boss.id);
boss.zoneId = defaults?.zoneId ?? "verdant_vale";
needsBackfill = true;
}
}
const now = Date.now();
const { offlineGold, offlineSeconds } = calculateOfflineGold(state, now);