Refactor item property parsing and centralize utility functions
- Moved `parseItemProps` function to `core/utils.ts` for reuse across modules. - Updated various services to import and utilize the centralized `parseItemProps`. - Introduced new utility functions for handling consumable cooldowns and healing calculations. - Enhanced mob management with a new repository system, allowing for dynamic loading and validation of mob definitions from the database. - Added admin functions for creating, updating, listing, and deleting mobs, with validation using Zod. - Implemented tests for mob management functionalities. - Improved error handling and logging throughout the mob and consumable services.
This commit is contained in:
41
scripts/mobAdminTest.ts
Normal file
41
scripts/mobAdminTest.ts
Normal file
@@ -0,0 +1,41 @@
|
||||
import {
|
||||
createOrUpdateMob,
|
||||
listMobs,
|
||||
getMob,
|
||||
deleteMob,
|
||||
ensureMobRepoUpToDate,
|
||||
} from "../src/game/mobs/admin";
|
||||
|
||||
async function run() {
|
||||
console.log("Ensuring repo up-to-date...");
|
||||
await ensureMobRepoUpToDate();
|
||||
|
||||
const testMob = {
|
||||
key: "test.goblin",
|
||||
name: "Goblin Test",
|
||||
tier: 1,
|
||||
base: { hp: 12, attack: 3 },
|
||||
} as any;
|
||||
|
||||
console.log("Creating test mob...");
|
||||
const created = await createOrUpdateMob(testMob);
|
||||
console.log("Created:", created.key);
|
||||
|
||||
console.log("Listing mobs (sample):");
|
||||
const all = await listMobs();
|
||||
console.log(`Total mobs: ${all.length}`);
|
||||
console.log(all.map((m) => m.key).join(", "));
|
||||
|
||||
console.log("Fetching test.mob...");
|
||||
const fetched = await getMob("test.goblin");
|
||||
console.log("Fetched:", !!fetched, fetched ? fetched : "(no data)");
|
||||
|
||||
console.log("Deleting test mob...");
|
||||
const deleted = await deleteMob("test.goblin");
|
||||
console.log("Deleted?", deleted);
|
||||
}
|
||||
|
||||
run().catch((e) => {
|
||||
console.error(e);
|
||||
process.exit(1);
|
||||
});
|
||||
18
scripts/testMobData.ts
Normal file
18
scripts/testMobData.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import {
|
||||
initializeMobRepository,
|
||||
getMobInstance,
|
||||
listMobKeys,
|
||||
} from "../src/game/mobs/mobData";
|
||||
|
||||
async function run() {
|
||||
console.log("Initializing mob repository...");
|
||||
await initializeMobRepository();
|
||||
console.log("Available mob keys:", listMobKeys());
|
||||
const inst = getMobInstance("slime.green", 3);
|
||||
console.log("Sample slime.green @ lvl3 ->", inst);
|
||||
}
|
||||
|
||||
run().catch((e) => {
|
||||
console.error(e);
|
||||
process.exit(1);
|
||||
});
|
||||
Reference in New Issue
Block a user