【世界种子生成器(NPC 数量不再定死)】 - sim/worldgen.ts:generateWorld(seed) 确定性塑造天下——NPC 4~8 家随机 (老牌世家模板 + 词库组合新贵,名字去重)、初始关系网(1-2世仇+1盟友)、 开局 era 三态、区域风味、市场偏移 ±15% - 独立派生 rng(seed::worldgen)——World.rng 主序列零消耗:同 seed 世界可重放、 玩法随机序列不受生成器移动(金钟罩玩法序保护) - state.worldGen 落档(normalize 旧档按 seed 重放=同世界,存档兼容) - creation 初始化 npcFamilies/initSim 关系网/era/池偏置全走 worldgen——开局即恩怨 - 局内补位目标 = 开局家数(4~8),生灭闭环持续 【插件深化(0.1.24 第二组钩子)】 - PluginContext.beforePhase/afterPhase(时轮锚点:phase 前后挂勾,卸载全摘) - PluginContext.addNpcTemplate(世界模板注入——词库插件化) - plugin-public 文档同步;示例 Plugin 契约升级 【测试适配(世界名单随机化)】 - 静态 npc id 假设全面改动态取家(anyNpc helper 共享); - 难度梯度用例改「同 seed 不同难度」比较;worldgen 确定性/范围/去重/关系对称 7 例 【测试】1034 全绿(45 套件);金钟罩 0.1.24 基线固化(worldgen 随机世界)+ worldAnnals 等; build 通过
122 lines
5.0 KiB
TypeScript
122 lines
5.0 KiB
TypeScript
import { describe, expect, it } from 'vitest'
|
|
import { World, normalizeGameState } from '../src/renderer/game/engine/runtime/World'
|
|
import {
|
|
marryNpcFamily,
|
|
makePeace
|
|
} from '../src/renderer/game/engine/runtime/Systems/diplomacy'
|
|
import { sendMission, recallAll } from '../src/renderer/game/engine/runtime/Systems/missions'
|
|
import { applyEventChoice } from '../src/renderer/game/engine/runtime/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 npcId = Object.keys(w.state.npcFamilies)[0]!
|
|
const npc = w.state.npcFamilies[npcId]
|
|
npc.relation = 60
|
|
// 姑且让长子成年(18岁可婚)
|
|
w.state.members['x3'].bornYear = 1 - 18
|
|
expect(marryNpcFamily(w, npcId)).toBe(true)
|
|
expect(npc.allied).toBe(true)
|
|
expect(marryNpcFamily(w, npcId)).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 npcId2 = Object.keys(w.state.npcFamilies)[0]!
|
|
const npc = w.state.npcFamilies[npcId2]
|
|
npc.relation = -80
|
|
w.state.family.stones = 900
|
|
expect(makePeace(w, npcId2)).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' })
|
|
const npcId2 = Object.keys(w.state.npcFamilies)[0]!
|
|
w.state.family.stones = 30
|
|
applyEventChoice(w, `ev-raid-${npcId2}`, 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)
|
|
}
|
|
})
|
|
})
|