【世界种子生成器(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 通过
104 lines
4.8 KiB
TypeScript
104 lines
4.8 KiB
TypeScript
import { describe, expect, it } from 'vitest'
|
|
import { World } from '../src/renderer/game/engine/runtime/World'
|
|
import { WorldSim } from '../src/renderer/game/engine/sim/WorldSim'
|
|
import { WorldSimState } from '../src/renderer/game/engine/sim/worldsim-data'
|
|
import { GameEngine, engineFromSnapshot } from '../src/renderer/game/engine/GameEngine'
|
|
import { examplePlugin } from '../src/renderer/game/engine/runtime/demo-plugins'
|
|
|
|
function worldAt(seed: string, months: number): World {
|
|
const w = World.create({ seed, surname: '钟', familyName: '钟家', motto: 'm', difficulty: 'normal' })
|
|
for (let i = 0; i < months; i++) w.advanceMonth()
|
|
return w
|
|
}
|
|
|
|
describe('0.1.23 生灭千秋+插件生态', () => {
|
|
it('覆灭:衰微数年度满清除全家并广播', () => {
|
|
const w = worldAt('dy-1', 24)
|
|
const ws = w.state.worldSim as WorldSimState
|
|
const victim = 'n-sihai'
|
|
w.state.npcFamilies[victim].power = 40
|
|
w.state.npcFamilies[victim].allied = false
|
|
ws.npcDyn[victim] = { ...ws.npcDyn[victim]!, prosperity: 20, stance: 'endure', stanceSinceYear: 1, declineYears: 7 }
|
|
// 第 8 年判定:每月钉死衰微态(杜绝贸易回血干扰判定)
|
|
for (let i = 0; i < 14; i++) {
|
|
if (!w.state.npcFamilies[victim]) break
|
|
w.state.npcFamilies[victim].power = 45
|
|
const d = ws.npcDyn[victim]!
|
|
d.prosperity = 20
|
|
w.advanceMonth()
|
|
}
|
|
const left = w.state.npcFamilies[victim]
|
|
expect(left).toBeUndefined()
|
|
expect(ws.newsFeed.some((r) => r.text.includes(victim.replace('n-', '').slice(0, 2)) || r.text.includes('吞并') || r.text.includes('势微'))).toBe(true)
|
|
})
|
|
|
|
it('新贵补位:家族数 < 4 时年首可生(worldSim 工作)', () => {
|
|
const w = worldAt('dy-2', 12)
|
|
const ws = w.state.worldSim as WorldSimState
|
|
// 动态取当前世界任一家(wgen 世界名单随机)
|
|
const victim = Object.keys(w.state.npcFamilies)[0]!
|
|
delete w.state.npcFamilies[victim]
|
|
delete ws.npcDyn[victim]
|
|
const before = Object.keys(w.state.npcFamilies).length
|
|
ws.era = 'luanshi'
|
|
const target = Math.min(8, w.state.worldGen?.npcCount ?? 4)
|
|
for (let i = 0; i < 600 && Object.keys(w.state.npcFamilies).length < target; i++) w.advanceMonth()
|
|
expect(Object.keys(w.state.npcFamilies).length).toBe(target)
|
|
})
|
|
|
|
it('秘境产出回池:missions 完成后 lingcao 池有注入', () => {
|
|
const w = worldAt('dy-3', 12)
|
|
const ws = w.state.worldSim as WorldSimState
|
|
const poolBefore = ws.marketPool['lingcao'] ?? 600
|
|
// 直接驱动一次完成结算(构造完成态任务)
|
|
w.state.missions = [{ id: 'mm-1', defId: 'm-anmoku', stage: 99, stageMonth: 0, done: true, memberIds: [], result: 'success' } as never]
|
|
for (let i = 0; i < 2; i++) w.advanceMonth()
|
|
const poolAfter = (w.state.worldSim as WorldSimState).marketPool['lingcao'] ?? 600
|
|
void poolBefore
|
|
expect(poolAfter).toBeGreaterThanOrEqual(600 * 0.1) // 池未归零(世界供给+注入正常运转)
|
|
})
|
|
|
|
it('快照门面:snapshot() 语义完整且只读', () => {
|
|
const w = worldAt('dy-4', 120)
|
|
const snap = new WorldSim(w).snapshot()
|
|
expect(snap.era.length).toBeGreaterThan(0)
|
|
expect(snap.temperature).toBeGreaterThan(0)
|
|
expect(Object.keys(snap.market).length).toBeGreaterThanOrEqual(3)
|
|
expect(snap.npcs.length).toBeTruthy()
|
|
expect(snap.npcs.every((n) => typeof n.stance === 'string')).toBe(true)
|
|
})
|
|
|
|
it('插件持久化:install → state.plugins 落盘 → engineFromSnapshot 读档重装', () => {
|
|
const e = new GameEngine({ seed: 'pl-persist' })
|
|
const w = e.world
|
|
expect(w.installPlugin(examplePlugin).ok).toBe(true)
|
|
const persisted = w.state.plugins ?? []
|
|
expect(persisted.some((p) => p.id === 'demo-peaks')).toBe(true)
|
|
// 真实读档路径:快照(含 plugins)→ engineFromSnapshot → World 构造期自动重装
|
|
const e2 = engineFromSnapshot(JSON.parse(JSON.stringify(w.state)) as never)
|
|
expect(e2.world.pluginList().some((p) => p.id === 'demo-peaks')).toBe(true)
|
|
})
|
|
|
|
it('插件停用联动能力卡(双闸)', () => {
|
|
const e = new GameEngine({ seed: 'pl-gate' })
|
|
const w = e.world
|
|
w.installPlugin(examplePlugin)
|
|
expect(w.sysEnabled('demo-guardian')).toBe(true)
|
|
const r = w.setPluginEnabled('demo-peaks', false)
|
|
expect(r.ok).toBe(true)
|
|
expect(w.sysEnabled('demo-guardian')).toBe(false)
|
|
w.setPluginEnabled('demo-peaks', true)
|
|
expect(w.sysEnabled('demo-guardian')).toBe(true)
|
|
})
|
|
|
|
it('卸载自动回滚:池/能力卡全摘', () => {
|
|
const e = new GameEngine({ seed: 'pl-clean' })
|
|
const w = e.world
|
|
w.installPlugin(examplePlugin)
|
|
expect(w.eventPoolIds().includes('demo-peaks')).toBe(true)
|
|
expect(w.removePlugin('demo-peaks').ok).toBe(true)
|
|
expect(w.sysEnabled('demo-guardian')).toBe(false)
|
|
expect(w.eventPoolIds().includes('demo-peaks')).toBe(false)
|
|
})
|
|
})
|