Unity and Cocos stay as parallel schemes; apps/minigame ships the Godot 4.7 WeChat pack for DevTools. Co-authored-by: Cursor <cursoragent@cursor.com>
32 lines
1.0 KiB
TypeScript
32 lines
1.0 KiB
TypeScript
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 }
|
|
}
|