diff --git a/packages/pokemon/src/battle/settlement.ts b/packages/pokemon/src/battle/settlement.ts index 63c578a99..fc79b0dd6 100644 --- a/packages/pokemon/src/battle/settlement.ts +++ b/packages/pokemon/src/battle/settlement.ts @@ -1,11 +1,11 @@ -import type { Creature, StatName, SpeciesId } from '../types' +import type { StatName, SpeciesId } from '../types' import { STAT_NAMES } from '../types' import { TO_DEX_STAT } from '../data/pkmn' import type { BattleResult } from './types' import type { BuddyData } from '../types' -import { addItemToBag, removeItemFromBag } from '../core/storage' -import { xpForLevel, levelFromXp } from '../data/xpTable' +import { levelFromXp } from '../data/xpTable' import { getSpeciesData } from '../data/species' +import { MAX_EV_PER_STAT, MAX_EV_TOTAL } from '../data/evMapping' import { Dex } from '@pkmn/sim' /** @@ -53,8 +53,8 @@ export async function settleBattle( const newEv = { ...creature.ev } let totalEV = STAT_NAMES.reduce((sum, s) => sum + newEv[s], 0) for (const stat of STAT_NAMES) { - if (totalEV >= 510) break - const gain = Math.min(evGained[stat], 252 - newEv[stat], 510 - totalEV) + if (totalEV >= MAX_EV_TOTAL) break + const gain = Math.min(evGained[stat], MAX_EV_PER_STAT - newEv[stat], MAX_EV_TOTAL - totalEV) newEv[stat] += gain totalEV += gain } diff --git a/packages/pokemon/src/core/effort.ts b/packages/pokemon/src/core/effort.ts index 7d166bcec..7fd45b0f7 100644 --- a/packages/pokemon/src/core/effort.ts +++ b/packages/pokemon/src/core/effort.ts @@ -1,6 +1,6 @@ import type { Creature, StatName } from '../types' import { STAT_NAMES } from '../types' -import { getEVForTool, MAX_EV_PER_STAT, MAX_EV_TOTAL } from '../data/evMapping' +import { getEVForTool, MAX_EV_PER_STAT, MAX_EV_TOTAL, EV_COOLDOWN_MS } from '../data/evMapping' import { getTotalEV } from './creature' // Track last EV award time per tool to enforce cooldown @@ -22,7 +22,7 @@ export function awardEV(creature: Creature, toolName: string, timestamp?: number // Check cooldown const lastTime = evCooldowns.get(toolName) - if (lastTime !== undefined && now - lastTime < 30_000) return creature + if (lastTime !== undefined && now - lastTime < EV_COOLDOWN_MS) return creature const currentTotal = getTotalEV(creature) if (currentTotal >= MAX_EV_TOTAL) return creature diff --git a/packages/pokemon/src/core/storage.ts b/packages/pokemon/src/core/storage.ts index 78574ff64..3af062353 100644 --- a/packages/pokemon/src/core/storage.ts +++ b/packages/pokemon/src/core/storage.ts @@ -34,7 +34,8 @@ export async function loadBuddyData(): Promise { const raw = readFileSync(BUDDY_DATA_PATH, 'utf-8') const data = JSON.parse(raw) return migrateToV2(data) - } catch { + } catch (e) { + console.error('[buddy] Failed to load buddy data:', e) return getDefaultBuddyData() } }