v0.1.3: 深度审计修复(兼容/血缘/联姻/远征/数值)
- 旧档兼容:<0.1.1 存档缺 finance/yearStats/yearlyReports 字段加载归一化(防运行期崩溃) - 血缘防护:同母异父兄妹也禁止婚配(指婚/媒人/联姻三路齐封) - 联姻修正:一家一姻亲(allied 锁),再娶再嫁不再无限刷;男儿娶亲也子孙来归 - 和约语义:议和强推关系至 +30(真停战),不再打完一场还是仇雠 - 远征收队:任务完成/召回自动释放队员闲居;重伤者当月离队疗伤、不足定员提前撤队(修复人员永久困远征/卡状态) - 数值:婴儿夭折率 2%→0.8%;劫掠队强度 0.9→0.78;事件负资源钳制不为负灵石 - UI:丹药按钮显示持有并禁点;点将模式支持取消重选;设置页移除摆设项 - 新增 audit 套件:8 项(含 600 月长跑耐力)总测试 38→46 全绿
This commit is contained in:
@@ -0,0 +1,118 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { World, normalizeGameState } from '../src/renderer/game/engine/world'
|
||||
import {
|
||||
marryNpcFamily,
|
||||
makePeace
|
||||
} from '../src/renderer/game/engine/systems/diplomacy'
|
||||
import { sendMission, recallAll } from '../src/renderer/game/engine/systems/missions'
|
||||
import { applyEventChoice } from '../src/renderer/game/engine/systems/events'
|
||||
import { GameState } from '../src/renderer/game/types/domain'
|
||||
import { resetSaveBus, attachLogSink } from './world.helpers'
|
||||
|
||||
describe('0.1.3 audit regression', () => {
|
||||
it('loads a 0.1.0-era save (missing finance/yearStats fields)', () => {
|
||||
const w = World.create({ seed: 'legacy', surname: '崔', familyName: '崔家', motto: 'm', difficulty: 'normal' })
|
||||
const legacy = JSON.parse(JSON.stringify(w.state)) as GameState
|
||||
delete (legacy as Record<string, unknown>)['finance']
|
||||
delete (legacy as Record<string, unknown>)['yearStats']
|
||||
delete (legacy as Record<string, unknown>)['yearlyReports']
|
||||
const w2 = new World(legacy)
|
||||
for (let i = 0; i < 40; i++) w2.advanceMonth()
|
||||
expect(w2.state.yearlyReports.length).toBeGreaterThan(0)
|
||||
expect(Number.isNaN(w2.state.family.stones)).toBe(false)
|
||||
})
|
||||
|
||||
it('marries a npc family once only (allied lock)', () => {
|
||||
const w = World.create({ seed: 'hy', surname: '卫', familyName: '卫家', motto: 'm', difficulty: 'normal' })
|
||||
const npc = w.state.npcFamilies['n-danxin']
|
||||
npc.relation = 60
|
||||
// 姑且让长子成年(18岁可婚)
|
||||
w.state.members['x3'].bornYear = 1 - 18
|
||||
expect(marryNpcFamily(w, 'n-danxin')).toBe(true)
|
||||
expect(npc.allied).toBe(true)
|
||||
expect(marryNpcFamily(w, 'n-danxin')).toBe(false)
|
||||
})
|
||||
|
||||
it('or same-mother siblings cannot marry (candidates + direct)', () => {
|
||||
const w = World.create({ seed: 'kin', surname: '陆', familyName: '陆家', motto: 'm', difficulty: 'normal' })
|
||||
const a = w.state.members['x3']
|
||||
const b = w.state.members['x5']
|
||||
// 人为制造同母异父关系
|
||||
a.motherId = 'x2'
|
||||
b.motherId = 'x2'
|
||||
a.fatherId = undefined
|
||||
b.fatherId = undefined
|
||||
expect(w.marriageCandidatesOf(a.id).map((c) => c.id)).not.toContain(b.id)
|
||||
expect(w.marryTo(a.id, b.id)).toBe(false)
|
||||
})
|
||||
|
||||
it('peace cements relation to a floor above zero', () => {
|
||||
const w = World.create({ seed: 'peace', surname: '华', familyName: '华家', motto: 'm', difficulty: 'normal' })
|
||||
const npc = w.state.npcFamilies['n-nulei']
|
||||
npc.relation = -80
|
||||
w.state.family.stones = 900
|
||||
expect(makePeace(w, 'n-nulei')).toBe(true)
|
||||
expect(npc.relation).toBeGreaterThanOrEqual(30)
|
||||
})
|
||||
|
||||
it('event negative resource cannot sink stones below zero', () => {
|
||||
const w = World.create({ seed: 'clamp', surname: '曾', familyName: '曾家', motto: 'm', difficulty: 'normal' })
|
||||
w.state.family.stones = 30
|
||||
applyEventChoice(w, 'ev-raid-n-nulei', 1) // 割地求和 -250
|
||||
expect(w.state.family.stones).toBe(0)
|
||||
})
|
||||
|
||||
it('expedition squad releases members and drops wounded', () => {
|
||||
const w = World.create({ seed: 'exp', surname: '纪', familyName: '纪家', motto: 'm', difficulty: 'normal' })
|
||||
resetSaveBus()
|
||||
attachLogSink(w)
|
||||
const ok = sendMission(w, 'm-anmoku', ['x1', 'x3'])
|
||||
expect(ok).toBe(true)
|
||||
const m = w.state.missions[0]
|
||||
expect(m.memberIds.length).toBe(2)
|
||||
// 制造重伤:让一人带伤退出
|
||||
const c = w.state.members['x3']
|
||||
c.health = 10
|
||||
c.state = 'wounded'
|
||||
w.advanceMonth()
|
||||
expect(m.memberIds).not.toContain('x3')
|
||||
expect(w.state.members['x3'].state).toBe('wounded')
|
||||
// 剩余的 x1 一人 ≥ minMembers=1 可以继续;test recall releases
|
||||
recallAll(w, m.id)
|
||||
expect(w.state.members['x1'].state).toBe('idle')
|
||||
})
|
||||
|
||||
it('squad disband when members run short', () => {
|
||||
const w = World.create({ seed: 'exp2', surname: '窦', familyName: '窦家', motto: 'm', difficulty: 'normal' })
|
||||
resetSaveBus()
|
||||
attachLogSink(w)
|
||||
const ok = sendMission(w, 'm-xuangu', ['x1', 'x3']) // minMembers 1
|
||||
expect(ok).toBe(true)
|
||||
const m = w.state.missions[0]
|
||||
// 两人同时重伤离队
|
||||
w.state.members['x1'].health = 10
|
||||
w.state.members['x1'].state = 'wounded'
|
||||
w.state.members['x3'].health = 10
|
||||
w.state.members['x3'].state = 'wounded'
|
||||
w.advanceMonth()
|
||||
expect(m.done).toBe(true)
|
||||
expect(m.result).toBe('disband')
|
||||
})
|
||||
|
||||
it('long run 600 months stays sane', () => {
|
||||
const w = World.create({ seed: 'long', surname: '丁', familyName: '丁家', motto: 'm', difficulty: 'normal' })
|
||||
resetSaveBus()
|
||||
attachLogSink(w)
|
||||
for (let i = 0; i < 600; i++) {
|
||||
if (w.state.gameOver) break
|
||||
w.advanceMonth()
|
||||
}
|
||||
const s = w.state
|
||||
expect(Number.isNaN(s.family.stones)).toBe(false)
|
||||
expect(s.year).toBeGreaterThan(30)
|
||||
for (const c of Object.values(s.members)) {
|
||||
expect(Number.isNaN(c.realmProgress)).toBe(false)
|
||||
expect(Number.isNaN(c.health)).toBe(false)
|
||||
}
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user