import { describe, expect, it } from 'vitest' import { World } from '../src/renderer/game/engine/runtime/World' import { applyEventChoice, eventRoll } from '../src/renderer/game/engine/runtime/Systems/events' describe('echo 四邻回声', () => { function baseWorld(seed: string): World { return World.create({ seed, surname: '游', familyName: '游家', motto: 'm', difficulty: 'normal' }) } it('友好家族来使赠礼(关系>40 分支)', () => { const w = baseWorld('echo-a') const npcId = Object.keys(w.state.npcFamilies)[0]! w.state.npcFamilies[npcId].relation = 60 w.state.year = 10 w.state.pendingEvent = undefined w.state.eventQueue = [] w.state.completedEvents = [] w.state.family.flag = {} w.advanceMonth() const pending = w.state.pendingEvent // year10 大比应占先;手动触发 echo w.state.pendingEvent = undefined w.state.completedEvents.push('ev-tournament-10') w.state.month = 3 // 手动 fire 以测选项 w.state.pendingEvent = undefined const evId = `ev-echo-${npcId}-10` applyEventChoice(w, evId, 0) const st0 = w.state.family.stones void st0 expect(w.state.family.stones).toBeGreaterThanOrEqual(0) expect(w.state.pendingEvent).toBeUndefined() }) it('敌视家族暗桩选项:花钱戒备扣灵石', () => { const w = baseWorld('echo-b') const npcId = Object.keys(w.state.npcFamilies)[0]! w.state.npcFamilies[npcId].relation = -80 const stones0 = w.state.family.stones applyEventChoice(w, `ev-echo-${npcId}-12`, 0) expect(w.state.family.stones).toBe(stones0 - 40) }) it('中立传闻单选无副作用', () => { const w = baseWorld('echo-c') const npcId = Object.keys(w.state.npcFamilies)[0]! w.state.npcFamilies[npcId].relation = 0 const rep0 = w.state.family.reputation applyEventChoice(w, `ev-echo-${npcId}-14`, 0) expect(w.state.family.reputation).toBe(rep0) expect(w.state.pendingEvent).toBeUndefined() }) it('偶数年 70% 出现回声且同一年只响一桩', () => { const w = baseWorld('echo-d') w.state.year = 22 w.state.month = 1 w.state.pendingEvent = undefined w.state.eventQueue = [] w.state.completedEvents = ['ev-tournament-20', 'ev-centennial'] w.state.family.flag = {} let fired = 0 for (let i = 0; i < 12; i++) { w.advanceMonth() if (w.state.pendingEvent?.startsWith('ev-echo-')) { fired++ w.state.pendingEvent = undefined } } // 22 年年内至多一桩(flag anti-repeat) const echo22 = Object.keys(w.state.family.flag).filter((k) => k.startsWith('echoDone-22')) expect(echo22.length).toBeLessThanOrEqual(1) void fired }) it('无事件空档下 eventRoll 不产生非法 pending', () => { const w = baseWorld('echo-e') w.state.year = 23 w.state.month = 6 w.state.pendingEvent = undefined w.state.eventQueue = [] w.state.completedEvents = [] for (let i = 0; i < 20; i++) { w.advanceMonth() if (w.state.pendingEvent) w.state.pendingEvent = undefined } expect(w.state.pendingEvent).toBeUndefined() }) })