import type { ActionEconomy } from './EconomySystem' import type { PlayerStats } from '../core/types' import { canAfford, applyCash } from './EconomySystem' import { applyEnergy, hasEnergy } from './EnergySystem' import { advanceMinutes } from './TimeSystem' export type WorkResult = { ok: boolean stats: PlayerStats message: string } export function applyAction( stats: PlayerStats, action: ActionEconomy | undefined, ): WorkResult { if (!action) { return { ok: false, stats, message: '未知互动' } } if (!canAfford(stats, action.cashDelta)) { return { ok: false, stats, message: '现金不足' } } if (!hasEnergy(stats, action.energyDelta)) { return { ok: false, stats, message: '精力不足,先去睡觉或吃饭' } } let next = applyCash(stats, action.cashDelta) next = applyEnergy(next, action.energyDelta) const t = advanceMinutes(next.minutes, next.day, action.minutesDelta) next = { ...next, minutes: t.minutes, day: t.day } return { ok: true, stats: next, message: action.message } }