feat: Add scripts for mob dependency management and server setup

- Implemented `findMobDependencies.ts` to identify foreign key constraints referencing the Mob table and log dependent rows.
- Created `fullServerSetup.ts` for idempotent server setup, including economy items, item recipes, game areas, mobs, and optional demo mob attacks.
- Developed `removeInvalidMobsWithDeps.ts` to delete invalid mobs and their dependencies, backing up affected scheduled mob attacks.
- Added unit tests in `testMobUnit.ts` and `mob.test.ts` for mob functionality, including stats computation and instance retrieval.
- Introduced reward modification tests in `testRewardMods.ts` and `rewardMods.unit.ts` to validate drop selection and coin multiplier behavior.
- Enhanced command handling for mob deletion in `mobDelete.ts` and setup examples in `setup.ts`, ensuring proper permissions and feedback.
- Created utility functions in `testHelpers.ts` for deterministic drop selection from mob definitions.
This commit is contained in:
Shni
2025-10-14 14:58:38 -05:00
parent f36fa24e46
commit 852b1d02a2
24 changed files with 2158 additions and 177 deletions

66
scripts/testRewardMods.ts Normal file
View File

@@ -0,0 +1,66 @@
import {
initializeMobRepository,
getMobInstance,
listMobKeys,
} from "../src/game/mobs/mobData";
import { runMinigame } from "../src/game/minigames/service";
import { prisma } from "../src/core/database/prisma";
async function run() {
console.log("Initializing mob repository...");
await initializeMobRepository();
console.log("Available mob keys:", listMobKeys());
// Mock user/guild for smoke (these should exist in your test DB or the functions will create wallet entries etc.)
const userId = "test-user";
const guildId = "test-guild";
try {
console.log("Ensuring minimal game area 'mine.cavern' exists...");
// create minimal area and level if not present
let area = await prisma.gameArea.findFirst({
where: { key: "mine.cavern", OR: [{ guildId }, { guildId: null }] },
orderBy: [{ guildId: "desc" }],
});
if (!area) {
area = await prisma.gameArea.create({
data: {
key: "mine.cavern",
guildId: null,
name: "Cavern of Tests",
type: "MINE",
config: {},
metadata: {},
} as any,
});
}
let lvl = await prisma.gameAreaLevel.findFirst({
where: { areaId: area.id, level: 1 },
});
if (!lvl) {
lvl = await prisma.gameAreaLevel.create({
data: {
areaId: area.id,
level: 1,
requirements: {} as any,
rewards: {
draws: 1,
table: [{ type: "coins", amount: 5, weight: 1 }],
} as any,
mobs: { draws: 0, table: [] } as any,
} as any,
});
}
console.log("Running minigame mine.cavern level 1 as smoke test...");
const res = await runMinigame(userId, guildId, "mine.cavern", 1);
console.log("Minigame result:", JSON.stringify(res, null, 2));
} catch (e) {
console.error("runMinigame failed:", e);
}
}
run().catch((e) => {
console.error(e);
process.exit(1);
});