mirror of
https://github.com/claude-code-best/claude-code.git
synced 2026-06-15 12:55:51 +00:00
refactor: 代码优化(常量复用、清理未使用 import、错误日志)
- 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 <noreply@anthropic.com>
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -34,7 +34,8 @@ export async function loadBuddyData(): Promise<BuddyData> {
|
||||
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()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user