v0.1.24: 寰宇初构——世界种子生成器 + 插件时轮锚点(1034 全绿)

【世界种子生成器(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 通过
This commit is contained in:
2026-08-23 16:15:22 +08:00
parent 04ef80faa5
commit ec25bf92fc
28 changed files with 382 additions and 72 deletions
+17 -12
View File
@@ -35,15 +35,16 @@ describe('0.1.19 八方风雨', () => {
const w = World.create({ seed: 'st-2', surname: '邱', familyName: '邱家', motto: 'm', difficulty: 'normal' })
w.advanceMonth()
const dyns = w.state.worldSim as WorldSimState
dyns.npcDyn['n-nulei'] = { ...dyns.npcDyn['n-nulei']!, stance: 'expand', stanceSinceYear: 1 }
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['n-nulei']
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['n-nulei'] = { ...dyns.npcDyn['n-nulei'], stance: 'expand', stanceSinceYear: w.state.year }
dyns.npcDyn[npcKey] = { ...dyns.npcDyn[npcKey], stance: 'expand', stanceSinceYear: w.state.year }
w.advanceMonth()
// 任何 pending 顶住事件闸则先清场(否则后续 raid 无法 fire)
while (w.state.pendingEvent) {
@@ -71,22 +72,26 @@ describe('0.1.19 八方风雨', () => {
const w = World.create({ seed: 'st-4', surname: '方', familyName: '方家', motto: 'm', difficulty: 'normal' })
w.advanceMonth()
const dyns = w.state.worldSim as WorldSimState
dyns.npcDyn['n-xuanying']!.relationsWithOthers['n-nulei'] = -70
w.state.npcFamilies['n-xuanying'].relation = 60
const before = w.state.npcFamilies['n-nulei'].relation
expect(w.setAlliance('n-xuanying', true)).toBe(true)
expect(w.state.npcFamilies['n-nulei'].relation).toBeLessThan(before)
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
dyns.npcDyn['n-danxin']!.relationsWithOthers['n-sihai'] = -60
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['n-danxin']!.relationsWithOthers['n-sihai']
expect(w.mediateNpcs('n-danxin', 'n-sihai')).toBe(true)
const r1 = dyns.npcDyn['n-danxin']!.relationsWithOthers['n-sihai']
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)
})