import { GameClock } from '../core/clock' import { productionTick } from './systems/production' import { deathTick, woundHealTick } from './systems/lifecycle' import { cultivationTick } from './systems/cultivation' import { missionTick } from './systems/missions' import { eventRoll } from './systems/events' import { diplomacyTick } from './systems/diplomacy' import { yearStartMarriage } from './systems/marriage' import type { World } from './world' /** 原语义保留:满门凋零后仅存生产/寿元与收尾 */ function ifAlive(fn: (w: World) => void): (w: World) => void { return (w: World) => { if (w.aliveMembers().length > 0) fn(w) } } /** 能力开关:禁用即拔插(对应 capability id) */ function viaCap(capId: string, fn: (w: World) => void): (w: World) => void { return (w: World) => { if (w.sysEnabled(capId)) fn(w) } } /** * 装备时钟:年度钩子与月度 phase 的注册顺序即执行顺序(确定性)。 * 时间线:婚配养育 → 声望岁贡 → 岁末族簿 —— 再逐月:生产→寿元→修炼→任务→事件→外交→收尾 */ export function buildClock(): GameClock { const clock = new GameClock() clock.onYearStart(viaCap('marriage', (w) => yearStartMarriage(w))) clock.onYearStart( viaCap('marriage', (w) => { w.state.family.reputation += w.postBonus('familyRep') const zhenCount = w .aliveMembers() .filter((c) => c.aspiration === 'zhen').length w.state.family.reputation += Math.round(zhenCount * 0.3 * 100) / 100 }) ) clock.onYearStart(viaCap('annals', (w) => w.publishYearReport())) clock.register('production', viaCap('production', (w: World) => productionTick(w))) clock.register('aging', viaCap('aging', (w: World) => deathTick(w))) clock.register('aging', viaCap('aging', (w: World) => woundHealTick(w))) clock.register('cultivation', viaCap('cultivation', ifAlive((w: World) => cultivationTick(w)))) clock.register('missions', viaCap('missions', ifAlive((w: World) => missionTick(w)))) clock.register('events', viaCap('events', ifAlive((w: World) => eventRoll(w)))) clock.register('diplomacy', viaCap('diplomacy', ifAlive((w: World) => diplomacyTick(w)))) clock.register('epilogue', (w: World) => w.epilogueTick()) return clock }