From 1bba0879423d6e888ce9a3c72c258081998cfbe4 Mon Sep 17 00:00:00 2001 From: claude-code-best Date: Wed, 22 Apr 2026 04:16:42 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E4=BB=A3=E7=A0=81=E4=BC=98?= =?UTF-8?q?=E5=8C=96=EF=BC=88=E5=B8=B8=E9=87=8F=E5=A4=8D=E7=94=A8=E3=80=81?= =?UTF-8?q?=E6=B8=85=E7=90=86=E6=9C=AA=E4=BD=BF=E7=94=A8=20import=E3=80=81?= =?UTF-8?q?=E9=94=99=E8=AF=AF=E6=97=A5=E5=BF=97=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - settlement.ts: 复用 MAX_EV_PER_STAT/MAX_EV_TOTAL 常量替代硬编码 - settlement.ts: 删除未使用的 Creature/addItemToBag/removeItemFromBag/xpForLevel import - effort.ts: 复用 EV_COOLDOWN_MS 常量替代硬编码 30000 - storage.ts: 空 catch 块添加错误日志输出 Co-Authored-By: Claude Opus 4.6 --- packages/pokemon/src/battle/settlement.ts | 10 +++++----- packages/pokemon/src/core/effort.ts | 4 ++-- packages/pokemon/src/core/storage.ts | 3 ++- 3 files changed, 9 insertions(+), 8 deletions(-) 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() } }