feat: goddess sync, sanitize, and apotheosis init (chunk 3)

- initialState: add initialGoddessState() with all goddess sub-objects
- apotheosis: init GoddessState on first apotheosis, preserve on subsequent
- game: add goddessSpread block in validateAndSanitize (server-only fields capped, forward-only boss/quest/achievement enforcement)
- debug: add injectMissingGoddessExplorationAreas helper and inject all 8 goddess content arrays in syncNewContent
- vitest.config.ts: remove 8 goddess data files from coverage exclude (now imported via initialState)
- tests: full coverage for all new code (482 tests, 100% coverage)
This commit is contained in:
2026-04-13 14:23:02 -07:00
committed by Naomi Carrigan
parent c5d1f53eef
commit 7da1f3942d
9 changed files with 666 additions and 32 deletions
+114 -18
View File
@@ -18,6 +18,14 @@ import { defaultAdventurers } from "../data/adventurers.js";
import { defaultBosses } from "../data/bosses.js";
import { defaultEquipment } from "../data/equipment.js";
import { defaultExplorations } from "../data/explorations.js";
import { defaultGoddessAchievements } from "../data/goddessAchievements.js";
import { defaultGoddessBosses } from "../data/goddessBosses.js";
import { defaultGoddessDisciples } from "../data/goddessDisciples.js";
import { defaultGoddessEquipment } from "../data/goddessEquipment.js";
import { defaultGoddessExplorationAreas } from "../data/goddessExplorations.js";
import { defaultGoddessQuests } from "../data/goddessQuests.js";
import { defaultGoddessUpgrades } from "../data/goddessUpgrades.js";
import { defaultGoddessZones } from "../data/goddessZones.js";
import { initialGameState } from "../data/initialState.js";
import { defaultQuests } from "../data/quests.js";
import { defaultRecipes } from "../data/recipes.js";
@@ -567,6 +575,33 @@ const injectMissingExplorationAreas = (state: GameState): number => {
return added;
};
/**
* Injects any goddess exploration areas from the defaults that are missing from
* the player's goddess exploration state, seeding each new area as locked.
* @param state - The player's current game state (mutated in place).
* @returns The number of goddess exploration areas that were added.
*/
const injectMissingGoddessExplorationAreas = (state: GameState): number => {
// eslint-disable-next-line capitalized-comments -- v8 ignore
/* v8 ignore next 3 -- @preserve */
if (state.goddess === undefined) {
return 0;
}
const existingIds = new Set(state.goddess.exploration.areas.map((area) => {
// eslint-disable-next-line capitalized-comments -- v8 ignore
/* v8 ignore next -- @preserve */
return area.id;
}));
let added = 0;
for (const area of defaultGoddessExplorationAreas) {
if (!existingIds.has(area.id)) {
state.goddess.exploration.areas.push({ id: area.id, status: "locked" });
added = added + 1;
}
}
return added;
};
/**
* Patches rewards on existing quests whose reward lists have grown since the
* save was created (e.g. A new upgrade added as a reward to an old quest).
@@ -967,27 +1002,36 @@ const recomputeCraftingMultipliers = (state: GameState): number => {
* @param state - The player's current game state (mutated in place).
* @returns Counts of how many entries were added or patched per content type.
*/
/* eslint-disable-next-line max-statements -- Sync function requires one operation per content type */
const syncNewContent = (
state: GameState,
): {
achievementsAdded: number;
achievementsPatched: number;
adventurersAdded: number;
adventurerStatsPatched: number;
bossesAdded: number;
bossesPatched: number;
bossRewardsPatched: number;
craftingRecipesReapplied: number;
equipmentAdded: number;
equipmentPatched: number;
explorationAreasAdded: number;
questRewardsPatched: number;
questsAdded: number;
questsPatched: number;
upgradesAdded: number;
upgradesPatched: number;
zonesAdded: number;
zonesPatched: number;
achievementsAdded: number;
achievementsPatched: number;
adventurersAdded: number;
adventurerStatsPatched: number;
bossesAdded: number;
bossesPatched: number;
bossRewardsPatched: number;
craftingRecipesReapplied: number;
equipmentAdded: number;
equipmentPatched: number;
explorationAreasAdded: number;
goddessAchievementsAdded: number;
goddessBossesAdded: number;
goddessDiscipesAdded: number;
goddessEquipmentAdded: number;
goddessExplorationAreasAdded: number;
goddessQuestsAdded: number;
goddessUpgradesAdded: number;
goddessZonesAdded: number;
questRewardsPatched: number;
questsAdded: number;
questsPatched: number;
upgradesAdded: number;
upgradesPatched: number;
zonesAdded: number;
zonesPatched: number;
} => {
const adventurerStatsPatched = patchAdventurerStats(state);
const questsPatched = patchQuestStats(state);
@@ -1007,6 +1051,34 @@ const syncNewContent = (
const questsAdded = injectMissingEntries(state.quests, defaultQuests);
const upgradesAdded = injectMissingEntries(state.upgrades, defaultUpgrades);
const zonesAdded = injectMissingEntries(state.zones, defaultZones);
// Inject missing goddess content for players who have completed Apotheosis
let goddessAchievementsAdded = 0;
let goddessBossesAdded = 0;
let goddessDiscipesAdded = 0;
let goddessEquipmentAdded = 0;
let goddessExplorationAreasAdded = 0;
let goddessQuestsAdded = 0;
let goddessUpgradesAdded = 0;
let goddessZonesAdded = 0;
if (state.goddess) {
goddessAchievementsAdded
= injectMissingEntries(state.goddess.achievements, defaultGoddessAchievements);
goddessBossesAdded
= injectMissingEntries(state.goddess.bosses, defaultGoddessBosses);
goddessDiscipesAdded
= injectMissingEntries(state.goddess.disciples, defaultGoddessDisciples);
goddessEquipmentAdded
= injectMissingEntries(state.goddess.equipment, defaultGoddessEquipment);
goddessExplorationAreasAdded = injectMissingGoddessExplorationAreas(state);
goddessQuestsAdded
= injectMissingEntries(state.goddess.quests, defaultGoddessQuests);
goddessUpgradesAdded
= injectMissingEntries(state.goddess.upgrades, defaultGoddessUpgrades);
goddessZonesAdded
= injectMissingEntries(state.goddess.zones, defaultGoddessZones);
}
return {
achievementsAdded,
achievementsPatched,
@@ -1019,6 +1091,14 @@ const syncNewContent = (
equipmentAdded,
equipmentPatched,
explorationAreasAdded,
goddessAchievementsAdded,
goddessBossesAdded,
goddessDiscipesAdded,
goddessEquipmentAdded,
goddessExplorationAreasAdded,
goddessQuestsAdded,
goddessUpgradesAdded,
goddessZonesAdded,
questRewardsPatched,
questsAdded,
questsPatched,
@@ -1120,6 +1200,14 @@ debugRouter.post("/sync-new-content", async(context) => {
equipmentAdded,
equipmentPatched,
explorationAreasAdded,
goddessAchievementsAdded,
goddessBossesAdded,
goddessDiscipesAdded,
goddessEquipmentAdded,
goddessExplorationAreasAdded,
goddessQuestsAdded,
goddessUpgradesAdded,
goddessZonesAdded,
questRewardsPatched,
questsAdded,
questsPatched,
@@ -1154,6 +1242,14 @@ debugRouter.post("/sync-new-content", async(context) => {
equipmentAdded,
equipmentPatched,
explorationAreasAdded,
goddessAchievementsAdded,
goddessBossesAdded,
goddessDiscipesAdded,
goddessEquipmentAdded,
goddessExplorationAreasAdded,
goddessQuestsAdded,
goddessUpgradesAdded,
goddessZonesAdded,
questRewardsPatched,
questsAdded,
questsPatched,
+167
View File
@@ -720,6 +720,172 @@ const validateAndSanitize = (
dailyChallengesSpread = { dailyChallenges: previous.dailyChallenges };
}
/*
* Goddess state: preserve server-only currencies (divinity, stardust, prayers) at
* previous values, and apply the same forward-only rules to bosses/quests/achievements
* and exploration materials that the mortal realm uses.
* Prayers income will be computed and allowed to grow once Chunk 7 adds goddess tick logic.
*/
// eslint-disable-next-line capitalized-comments -- v8 ignore
/* v8 ignore next 145 -- @preserve */
let goddessSpread: object = {};
const previousGoddess = previous.goddess;
const incomingGoddess = incoming.goddess;
if (!incomingGoddess && previousGoddess) {
goddessSpread = { goddess: previousGoddess };
} else if (incomingGoddess) {
const goddessBosses = incomingGoddess.bosses.map((boss) => {
const matchingBoss = previousGoddess?.bosses.find((storedBoss) => {
return storedBoss.id === boss.id;
});
if (!matchingBoss) {
return boss;
}
if (matchingBoss.status === "defeated" && boss.status !== "defeated") {
return { ...boss, currentHp: 0, status: "defeated" as const };
}
return boss;
});
const goddessQuests = incomingGoddess.quests.map((quest) => {
const matchingQuest = previousGoddess?.quests.find((storedQuest) => {
return storedQuest.id === quest.id;
});
if (!matchingQuest) {
return quest;
}
// eslint-disable-next-line stylistic/max-len -- Long condition; splitting would reduce readability
if (matchingQuest.status === "completed" && quest.status !== "completed") {
return { ...matchingQuest };
}
return quest;
});
// eslint-disable-next-line stylistic/max-len -- Long variable name; splitting would reduce readability
const goddessAchievements = incomingGoddess.achievements.map((achievement) => {
const matchingAchievement = previousGoddess?.achievements.find(
(storedAchievement) => {
return storedAchievement.id === achievement.id;
},
);
if (!matchingAchievement) {
return achievement;
}
const wasUnlocked = matchingAchievement.unlockedAt !== null;
const isNowNull = achievement.unlockedAt === null;
if (wasUnlocked && isNowNull) {
return { ...achievement, unlockedAt: matchingAchievement.unlockedAt };
}
const isFuture
= achievement.unlockedAt !== null && achievement.unlockedAt > now;
if (isFuture) {
const safeUnlockedAt = matchingAchievement.unlockedAt ?? null;
return { ...achievement, unlockedAt: safeUnlockedAt };
}
return achievement;
});
const previousGoddessExploration = previousGoddess?.exploration;
let goddessExploration = incomingGoddess.exploration;
if (previousGoddessExploration) {
const previousMaterialMap = new Map(
previousGoddessExploration.materials.map((mat) => {
return [ mat.materialId, mat.quantity ] as const;
}),
);
// eslint-disable-next-line stylistic/max-len -- Long variable name; splitting would reduce readability
const materials = incomingGoddess.exploration.materials.map((material) => {
const previousQuantity
= previousMaterialMap.get(material.materialId) ?? 0;
return {
...material,
quantity: Math.min(material.quantity, previousQuantity),
};
});
const goddessRecipeIds = [
...new Set([
...previousGoddessExploration.craftedRecipeIds,
...incomingGoddess.exploration.craftedRecipeIds,
]),
];
goddessExploration = {
...incomingGoddess.exploration,
// eslint-disable-next-line stylistic/max-len -- Long field name; splitting would reduce readability
craftedCombatMultiplier: previousGoddessExploration.craftedCombatMultiplier,
// eslint-disable-next-line stylistic/max-len -- Long field name; splitting would reduce readability
craftedDivinityMultiplier: previousGoddessExploration.craftedDivinityMultiplier,
// eslint-disable-next-line stylistic/max-len -- Long field name; splitting would reduce readability
craftedPrayersMultiplier: previousGoddessExploration.craftedPrayersMultiplier,
craftedRecipeIds: goddessRecipeIds,
materials: materials,
};
}
const consecration = previousGoddess
? {
...incomingGoddess.consecration,
count: Math.min(
incomingGoddess.consecration.count,
previousGoddess.consecration.count,
),
divinity: Math.min(
incomingGoddess.consecration.divinity,
previousGoddess.consecration.divinity,
),
productionMultiplier: previousGoddess.consecration.productionMultiplier,
}
: incomingGoddess.consecration;
const enlightenment = previousGoddess
? {
...incomingGoddess.enlightenment,
count: Math.min(
incomingGoddess.enlightenment.count,
previousGoddess.enlightenment.count,
),
stardust: Math.min(
incomingGoddess.enlightenment.stardust,
previousGoddess.enlightenment.stardust,
),
stardustCombatMultiplier:
previousGoddess.enlightenment.stardustCombatMultiplier,
stardustConsecrationDivinityMultiplier:
previousGoddess.enlightenment.stardustConsecrationDivinityMultiplier,
stardustConsecrationThresholdMultiplier:
previousGoddess.enlightenment.stardustConsecrationThresholdMultiplier,
stardustMetaMultiplier:
previousGoddess.enlightenment.stardustMetaMultiplier,
stardustPrayersMultiplier:
previousGoddess.enlightenment.stardustPrayersMultiplier,
}
: incomingGoddess.enlightenment;
goddessSpread = {
goddess: {
...incomingGoddess,
achievements: goddessAchievements,
bosses: goddessBosses,
consecration: consecration,
enlightenment: enlightenment,
exploration: goddessExploration,
lifetimeBossesDefeated: Math.min(
incomingGoddess.lifetimeBossesDefeated,
previousGoddess?.lifetimeBossesDefeated ?? 0,
),
lifetimePrayersEarned: Math.min(
incomingGoddess.lifetimePrayersEarned,
previousGoddess?.lifetimePrayersEarned ?? 0,
),
lifetimeQuestsCompleted: Math.min(
incomingGoddess.lifetimeQuestsCompleted,
previousGoddess?.lifetimeQuestsCompleted ?? 0,
),
quests: goddessQuests,
totalPrayersEarned: Math.min(
incomingGoddess.totalPrayersEarned,
previousGoddess?.totalPrayersEarned ?? 0,
),
},
};
}
return {
...incoming,
achievements,
@@ -733,6 +899,7 @@ const validateAndSanitize = (
...explorationSpread,
...storySpread,
...dailyChallengesSpread,
...goddessSpread,
};
};