【A+I】migrate.ts 迁移链(CURRENT_SCHEMA/MIGRATIONS/migrateIfNeeded/MigrationError)整链铲除→validateLoadedState 结构校验(seed/family/members 断言);信封统一 payload 单格式(去双格式兜底);APP_ID 保留 【F】schemaVersion 字段全删(domain/creation/save 8 处);SaveMeta.version 记游戏版本字符串 【C】chronicle 死表+saveChronicle 死方法(首行 return+unreachable legacy 僵尸)全删 【D/E】GameEngine __state globalThis 泄漏口+seed 三元(恒不可达)删除;engineFromSnapshot/noAutoCreate 保留(测试便利——非兼容机器) 【B/H】normalizeGameState 兼容批删:老档字段补(28行)/worldGen 重放(18行)/P0-2 占位 def(9行)/worldSim 字段批删;保留 npcs 重注册/headId 修复/d distress 防护;initSim 补 0.1.34 四键(唯一初始源) 【G】domain 收紧 5 兼容 optional(techniqueRank/Progress/tribBoost/worldGen 必填)+pcgen 必写 【测试】删 9 个兼容验证体(audit 0.1.0-era/全残缺矩阵/空 worldSim 兜底);5989 全绿——金钟罩零漂(新档结构全字段,删除不涉世界数值)
103 lines
5.0 KiB
TypeScript
103 lines
5.0 KiB
TypeScript
import { describe, expect, it } from 'vitest'
|
||
import { World } from '../src/renderer/game/engine/runtime/World'
|
||
import { normalizeGameState } from '../src/renderer/game/engine/runtime/World'
|
||
import { WorldSimState } from '../src/renderer/game/engine/sim/worldsim-data'
|
||
|
||
describe('0.1.19 八方风雨', () => {
|
||
it('stance:四姿态值域 + 年首(约8年)可再评估', () => {
|
||
const w = World.create({ seed: 'st-1', surname: '冀', familyName: '冀家', motto: 'm', difficulty: 'normal' })
|
||
const seen = new Set<string>()
|
||
for (let i = 0; i < 1600; i++) {
|
||
if (w.state.gameOver) break
|
||
w.advanceMonth()
|
||
const dyns = (w.state.worldSim as WorldSimState).npcDyn
|
||
for (const d of Object.values(dyns)) {
|
||
expect(['guardian', 'expand', 'endure', 'ally']).toContain(d.stance ?? 'guardian')
|
||
if (d.stance) seen.add(d.stance)
|
||
}
|
||
}
|
||
expect(seen.size).toBeGreaterThanOrEqual(2)
|
||
})
|
||
|
||
it('姿态影响 raid 概率标尺(expand 双倍、endure 打折)', () => {
|
||
const w = World.create({ seed: 'st-2', surname: '邱', familyName: '邱家', motto: 'm', difficulty: 'normal' })
|
||
w.advanceMonth()
|
||
const dyns = w.state.worldSim as WorldSimState
|
||
const npcKey = Object.keys(w.state.npcFamilies).find((k) => k === 'n-nulei') ?? Object.keys(w.state.npcFamilies)[0]!
|
||
dyns.npcDyn[npcKey] = { ...dyns.npcDyn[npcKey]!, stance: 'expand', stanceSinceYear: 1 }
|
||
// 关系拉到仇深 + 伪造 raidCD 前一年,跑 240 月计数
|
||
const npc = w.state.npcFamilies[npcKey]
|
||
npc.relation = -70
|
||
npc.allied = false
|
||
let evcount = 0
|
||
for (let i = 0; i < 600; i++) {
|
||
npc.relation = -70 // 钉死(diplomacy drift 会拉回)
|
||
dyns.npcDyn[npcKey] = { ...dyns.npcDyn[npcKey], stance: 'expand', stanceSinceYear: w.state.year }
|
||
w.advanceMonth()
|
||
// 任何 pending 顶住事件闸则先清场(否则后续 raid 无法 fire)
|
||
while (w.state.pendingEvent) {
|
||
if (w.state.pendingEvent.startsWith('ev-raid-')) evcount++
|
||
w.applyEventChoice(w.state.pendingEvent, 0)
|
||
}
|
||
}
|
||
// 0.06×12月×10年 ≈ 7 次期待,≥1 稳
|
||
expect(evcount).toBeGreaterThanOrEqual(1)
|
||
})
|
||
|
||
it('超卖潮:库存过剩时世界产能乘0.7回调且播报一次/年', () => {
|
||
const w = World.create({ seed: 'st-3', surname: '盛', familyName: '盛家', motto: 'm', difficulty: 'normal' })
|
||
w.advanceMonth()
|
||
const ws = w.state.worldSim as WorldSimState
|
||
ws.marketPool['lingcao'] = 2000 // 远超 600*1.8
|
||
const before = ws.marketPool['lingcao']
|
||
w.advanceMonth()
|
||
const after = ws.marketPool['lingcao']
|
||
expect(after).toBeLessThan(before)
|
||
expect(ws.newsFeed.some((r) => r.text.includes('谷贱伤农'))).toBe(true)
|
||
})
|
||
|
||
it('结盟连坐:世仇得闻而暗恨(玩家关系-20)', () => {
|
||
const w = World.create({ seed: 'st-4', surname: '方', familyName: '方家', motto: 'm', difficulty: 'normal' })
|
||
w.advanceMonth()
|
||
const dyns = w.state.worldSim as WorldSimState
|
||
const allyKey = Object.keys(w.state.npcFamilies).find((k) => k === 'n-xuanying') ?? Object.keys(w.state.npcFamilies)[0]!
|
||
const foeKey = Object.keys(w.state.npcFamilies).find((k) => k === 'n-nulei') ?? Object.keys(w.state.npcFamilies)[1]!
|
||
dyns.npcDyn[allyKey]!.relationsWithOthers[foeKey] = -70
|
||
w.state.npcFamilies[allyKey].relation = 60
|
||
const before = w.state.npcFamilies[foeKey].relation
|
||
expect(w.setAlliance(allyKey, true)).toBe(true)
|
||
expect(w.state.npcFamilies[foeKey].relation).toBeLessThan(before)
|
||
})
|
||
|
||
it('调停:花50灵石令世仇回暖、声望+2', () => {
|
||
const w = World.create({ seed: 'st-5', surname: '凌', familyName: '凌家', motto: 'm', difficulty: 'normal' })
|
||
w.advanceMonth()
|
||
const dyns = w.state.worldSim as WorldSimState
|
||
const aKey = Object.keys(w.state.npcFamilies)[0]!
|
||
const bKey = Object.keys(w.state.npcFamilies)[1]!
|
||
dyns.npcDyn[aKey]!.relationsWithOthers[bKey] = -60
|
||
w.state.family.stones = 500
|
||
const r0 = dyns.npcDyn[aKey]!.relationsWithOthers[bKey]
|
||
expect(w.mediateNpcs(aKey, bKey)).toBe(true)
|
||
const r1 = dyns.npcDyn[aKey]!.relationsWithOthers[bKey]
|
||
expect(r1).toBeGreaterThan(r0)
|
||
expect(w.state.family.reputation).toBeGreaterThanOrEqual(2)
|
||
})
|
||
|
||
it('盟友求援:互攻失利盟友告急 → assistAlly 可应', () => {
|
||
const w = World.create({ seed: 'st-6', surname: '古', familyName: '古家', motto: 'm', difficulty: 'normal' })
|
||
w.advanceMonth()
|
||
const ws = w.state.worldSim as WorldSimState
|
||
ws.npcDyn['n-xuanying']!.relationsWithOthers['n-nulei'] = -80
|
||
ws.npcDyn['n-nulei']!.relationsWithOthers['n-xuanying'] = -80
|
||
w.state.npcFamilies['n-xuanying'].allied = true
|
||
w.state.family.stones = 1000
|
||
// 手动挂求援(互攻触发具随机性,此处测响应链)
|
||
ws.distress = { id: 'n-xuanying', year: w.state.year, month: w.state.month }
|
||
const p0 = w.state.npcFamilies['n-xuanying'].power
|
||
expect(w.assistAlly('n-xuanying')).toBe(true)
|
||
expect(w.state.npcFamilies['n-xuanying'].power).toBeGreaterThan(p0)
|
||
expect(ws.distress).toBeUndefined()
|
||
})
|
||
})
|