feat: Introduce GameConfig to centralize constants for leveling, economy, and inventory, adding new transfer and inventory limits.

This commit is contained in:
syntaxbullet
2025-12-13 12:20:30 +01:00
parent 8818d6bb15
commit 5f4efd372f
5 changed files with 68 additions and 29 deletions

View File

@@ -1,18 +1,12 @@
import { users, cooldowns } from "@/db/schema";
import { eq, sql, and } from "drizzle-orm";
import { DrizzleClient } from "@/lib/DrizzleClient";
// Simple configurable curve: Base * (Level ^ Exponent)
const XP_BASE = 100;
const XP_EXPONENT = 2.5;
const CHAT_XP_COOLDOWN_MS = 60000; // 1 minute
const MIN_CHAT_XP = 15;
const MAX_CHAT_XP = 25;
import { GameConfig } from "@/config/game";
export const levelingService = {
// Calculate XP required for a specific level
getXpForLevel: (level: number) => {
return Math.floor(XP_BASE * Math.pow(level, XP_EXPONENT));
return Math.floor(GameConfig.leveling.base * Math.pow(level, GameConfig.leveling.exponent));
},
// Pure XP addition - No cooldown checks
@@ -77,13 +71,13 @@ export const levelingService = {
}
// Calculate random XP
const amount = BigInt(Math.floor(Math.random() * (MAX_CHAT_XP - MIN_CHAT_XP + 1)) + MIN_CHAT_XP);
const amount = BigInt(Math.floor(Math.random() * (GameConfig.leveling.chat.maxXp - GameConfig.leveling.chat.minXp + 1)) + GameConfig.leveling.chat.minXp);
// Add XP
const result = await levelingService.addXp(id, amount, txFn);
// Update/Set Cooldown
const nextReadyAt = new Date(now.getTime() + CHAT_XP_COOLDOWN_MS);
const nextReadyAt = new Date(now.getTime() + GameConfig.leveling.chat.cooldownMs);
await txFn.insert(cooldowns)
.values({