feat: Introduce dynamic JSON-based configuration for game settings and command toggling via a new admin command.
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { users, transactions, userTimers } from "@/db/schema";
|
||||
import { eq, sql, and } from "drizzle-orm";
|
||||
import { DrizzleClient } from "@/lib/DrizzleClient";
|
||||
import { GameConfig } from "@/config/game";
|
||||
import { config } from "@/lib/config";
|
||||
|
||||
export const economyService = {
|
||||
transfer: async (fromUserId: string, toUserId: string, amount: bigint, tx?: any) => {
|
||||
@@ -110,9 +110,9 @@ export const economyService = {
|
||||
streak = 1;
|
||||
}
|
||||
|
||||
const bonus = (BigInt(streak) - 1n) * GameConfig.economy.daily.streakBonus;
|
||||
const bonus = (BigInt(streak) - 1n) * config.economy.daily.streakBonus;
|
||||
|
||||
const totalReward = GameConfig.economy.daily.amount + bonus;
|
||||
const totalReward = config.economy.daily.amount + bonus;
|
||||
await txFn.update(users)
|
||||
.set({
|
||||
balance: sql`${users.balance} + ${totalReward}`,
|
||||
@@ -122,7 +122,7 @@ export const economyService = {
|
||||
.where(eq(users.id, BigInt(userId)));
|
||||
|
||||
// Set new cooldown (now + 24h)
|
||||
const nextReadyAt = new Date(now.getTime() + GameConfig.economy.daily.cooldownMs);
|
||||
const nextReadyAt = new Date(now.getTime() + config.economy.daily.cooldownMs);
|
||||
|
||||
await txFn.insert(userTimers)
|
||||
.values({
|
||||
|
||||
@@ -3,7 +3,7 @@ import { inventory, items, users } from "@/db/schema";
|
||||
import { eq, and, sql, count } from "drizzle-orm";
|
||||
import { DrizzleClient } from "@/lib/DrizzleClient";
|
||||
import { economyService } from "@/modules/economy/economy.service";
|
||||
import { GameConfig } from "@/config/game";
|
||||
import { config } from "@/lib/config";
|
||||
|
||||
export const inventoryService = {
|
||||
addItem: async (userId: string, itemId: number, quantity: bigint = 1n, tx?: any) => {
|
||||
@@ -18,8 +18,8 @@ export const inventoryService = {
|
||||
|
||||
if (existing) {
|
||||
const newQuantity = (existing.quantity ?? 0n) + quantity;
|
||||
if (newQuantity > GameConfig.inventory.maxStackSize) {
|
||||
throw new Error(`Cannot exceed max stack size of ${GameConfig.inventory.maxStackSize}`);
|
||||
if (newQuantity > config.inventory.maxStackSize) {
|
||||
throw new Error(`Cannot exceed max stack size of ${config.inventory.maxStackSize}`);
|
||||
}
|
||||
|
||||
const [entry] = await txFn.update(inventory)
|
||||
@@ -39,12 +39,12 @@ export const inventoryService = {
|
||||
.from(inventory)
|
||||
.where(eq(inventory.userId, BigInt(userId)));
|
||||
|
||||
if (inventoryCount.count >= GameConfig.inventory.maxSlots) {
|
||||
throw new Error(`Inventory full (Max ${GameConfig.inventory.maxSlots} slots)`);
|
||||
if (inventoryCount.count >= config.inventory.maxSlots) {
|
||||
throw new Error(`Inventory full (Max ${config.inventory.maxSlots} slots)`);
|
||||
}
|
||||
|
||||
if (quantity > GameConfig.inventory.maxStackSize) {
|
||||
throw new Error(`Cannot exceed max stack size of ${GameConfig.inventory.maxStackSize}`);
|
||||
if (quantity > config.inventory.maxStackSize) {
|
||||
throw new Error(`Cannot exceed max stack size of ${config.inventory.maxStackSize}`);
|
||||
}
|
||||
|
||||
const [entry] = await txFn.insert(inventory)
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import { users, userTimers } from "@/db/schema";
|
||||
import { eq, sql, and } from "drizzle-orm";
|
||||
import { DrizzleClient } from "@/lib/DrizzleClient";
|
||||
import { GameConfig } from "@/config/game";
|
||||
import { config } from "@/lib/config";
|
||||
|
||||
export const levelingService = {
|
||||
// Calculate XP required for a specific level
|
||||
getXpForLevel: (level: number) => {
|
||||
return Math.floor(GameConfig.leveling.base * Math.pow(level, GameConfig.leveling.exponent));
|
||||
return Math.floor(config.leveling.base * Math.pow(level, config.leveling.exponent));
|
||||
},
|
||||
|
||||
// Pure XP addition - No cooldown checks
|
||||
@@ -72,13 +72,13 @@ export const levelingService = {
|
||||
}
|
||||
|
||||
// Calculate random XP
|
||||
const amount = BigInt(Math.floor(Math.random() * (GameConfig.leveling.chat.maxXp - GameConfig.leveling.chat.minXp + 1)) + GameConfig.leveling.chat.minXp);
|
||||
const amount = BigInt(Math.floor(Math.random() * (config.leveling.chat.maxXp - config.leveling.chat.minXp + 1)) + config.leveling.chat.minXp);
|
||||
|
||||
// Add XP
|
||||
const result = await levelingService.addXp(id, amount, txFn);
|
||||
|
||||
// Update/Set Cooldown
|
||||
const nextReadyAt = new Date(now.getTime() + GameConfig.leveling.chat.cooldownMs);
|
||||
const nextReadyAt = new Date(now.getTime() + config.leveling.chat.cooldownMs);
|
||||
|
||||
await txFn.insert(userTimers)
|
||||
.values({
|
||||
|
||||
Reference in New Issue
Block a user