import { describe, expect, it } from 'vitest' import { World } from '../src/renderer/game/engine/runtime/World' import { ITEMS, ARTIFACT_POWER } from '../src/renderer/game/data/items' import { resolveEncounter } from '../src/renderer/game/engine/runtime/Systems/combat' import { productionTick } from '../src/renderer/game/engine/runtime/Systems/production' function mk(seed: string): World { return World.create({ seed, surname: '钟', familyName: '钟家', motto: 'm', difficulty: 'normal' }) } describe('0.1.33 物品闭环:符箓生效/幽灵物归位/灾年生效', () => { it('幽灵物品归位:丹方/铸器产出物均可命中物品表且可炼成', () => { const w = mk('c33-ghost') w.state.family.stones = 100000 w.state.family.inventory['lingcao'] = 1000 w.state.family.inventory['beastcore'] = 100 w.state.family.inventory['lingkuang'] = 500 w.state.family.buildings['danfang'] = 5 let ok = false for (let i = 0; i < 30 && !ok; i++) ok = w.craftPill('heling') || w.craftPill('xudan') || w.forgeArtifact('weapon-yu') expect(ok).toBe(true) expect(ITEMS['pill-heling']).toBeTruthy() expect(ITEMS['pill-xudan']).toBeTruthy() expect(ITEMS['weapon-yu']).toBeTruthy() expect(ARTIFACT_POWER['weapon-yu']).toBe(0.4) expect((w.state.family.inventory['pill-heling'] ?? 0) + (w.state.family.inventory['pill-xudan'] ?? 0) + (w.state.family.inventory['weapon-yu'] ?? 0) >= 1).toBe(true) }) it('符箓开战生效:消耗 1 张且战报记武备先声', () => { const w = mk('c33-fu') w.state.family.inventory['talisman-feng'] = 2 const crew = w.aliveMembers().slice(0, 3) const res = resolveEncounter(w, { title: '试锋', enemy: { id: 'z', name: '妖兽', realm: 'qi', strength: 0.4, desc: '野怪' }, risk: 0.2, team: crew, kind: 'war', year: w.state.year, month: w.state.month }) expect(w.state.family.inventory['talisman-feng']).toBe(1) expect(res.lines.some((l) => l.includes('武备先声'))).toBe(true) }) it('灾年生效:同一世界无灾×0.7 减产(旱灾)实际作用', () => { const w = mk('c33-cal-a') w.state.family.buildings['lingtian'] = 2 w.state.family.inventory['lingcao'] = 0 w.advanceMonth() if (w.state.worldSim) w.state.worldSim.calamity = '旱灾' const before = w.state.family.inventory['lingcao'] ?? 0 productionTick(w) const gain = (w.state.family.inventory['lingcao'] ?? 0) - before expect(gain).toBeGreaterThan(0) if (w.state.worldSim) w.state.worldSim.calamity = undefined const before2 = w.state.family.inventory['lingcao'] ?? 0 productionTick(w) const gain2 = (w.state.family.inventory['lingcao'] ?? 0) - before2 expect(gain).toBeLessThan(gain2) expect(Math.abs(gain - gain2 * 0.7)).toBeLessThanOrEqual(1) }) })