forked from syntaxbullet/AuroraBot-discord
feat: Introduce GameConfig to centralize constants for leveling, economy, and inventory, adding new transfer and inventory limits.
This commit is contained in:
@@ -1,10 +1,7 @@
|
||||
import { users, transactions, cooldowns } from "@/db/schema";
|
||||
import { eq, sql, and } from "drizzle-orm";
|
||||
import { DrizzleClient } from "@/lib/DrizzleClient";
|
||||
|
||||
const DAILY_REWARD_AMOUNT = 100n;
|
||||
const STREAK_BONUS = 10n;
|
||||
const DAILY_COOLDOWN = 24 * 60 * 60 * 1000; // 24 hours in ms
|
||||
import { GameConfig } from "@/config/game";
|
||||
|
||||
export const economyService = {
|
||||
transfer: async (fromUserId: string, toUserId: string, amount: bigint, tx?: any) => {
|
||||
@@ -112,9 +109,9 @@ export const economyService = {
|
||||
streak = 1;
|
||||
}
|
||||
|
||||
const bonus = (BigInt(streak) - 1n) * STREAK_BONUS;
|
||||
const bonus = (BigInt(streak) - 1n) * GameConfig.economy.daily.streakBonus;
|
||||
|
||||
const totalReward = DAILY_REWARD_AMOUNT + bonus;
|
||||
const totalReward = GameConfig.economy.daily.amount + bonus;
|
||||
|
||||
// Update User w/ Economy Service (reuse modifyUserBalance if we split it out, but here manual is fine for atomic combined streak update)
|
||||
// Actually, we can just update directly here as we are already refining specific fields like streak.
|
||||
@@ -127,7 +124,7 @@ export const economyService = {
|
||||
.where(eq(users.id, BigInt(userId)));
|
||||
|
||||
// Set new cooldown (now + 24h)
|
||||
const nextReadyAt = new Date(now.getTime() + DAILY_COOLDOWN);
|
||||
const nextReadyAt = new Date(now.getTime() + GameConfig.economy.daily.cooldownMs);
|
||||
|
||||
await txFn.insert(cooldowns)
|
||||
.values({
|
||||
|
||||
Reference in New Issue
Block a user