v0.1.23: 生灭千秋 + 插件生态化第一课(1027 全绿)

【世界模型:世界会死人也会新生】
- 家族生灭:declineYears(power<58+景气<38 连续8年)→ 覆灭(最强邻分食+史官广播)+ 新贵补位(6%/年,乱世×2)
  —— NPC 永远四家铁打的现状终结;玩家补刀(raid×0.82)可加速衰亡
- npcById 双源可空(静态+动态注册表;不再 throw——15 处消费者防御化)
- purgeNpc 全局清理(raidCD/事件队列/恩怨网/distress/动态 def)
- 秘境产出回池(loot 20% 经 tradeSettle 回流)——资源循环最后单向封口
- WorldSnapshot 只读摘要门面(UI/史书消费,零行为变更)
- 潮汐长波(10 年正弦 ±0.08 叠加,灵潮三十年河东)

【插件生态化(0.1.8 后第一次大进化)】
- 持久化:GameState.plugins 落盘 + PLUGIN_REGISTRY 读档重装(engineFromSnapshot 真实路径验证)
- plugin-public.ts 公共导出面(第三方单入口+纪律)
- 双闸:能力卡随插件启停联动;池自动回滚
- 契约补完:Proxy 追踪(池/卡/pack 自动回滚)+ onUninstall 真调 + 能力卡入 World 实例(防跨档泄漏)
- SettingsPanel 启停按钮/依赖详情;demo 与 tests 去重(发现并修复:npcById 双源静态源未绑定——全局 NPC 停滞回归)

【测试】1027 全绿(44 套件):dynasty-plugin 7 例(覆灭/新贵/回池/快照/持久化/双闸/自动回滚);
金钟罩 0.1.23 基线固化;build 通过
This commit is contained in:
2026-08-23 16:03:01 +08:00
parent d2787ee3c8
commit 04ef80faa5
27 changed files with 455 additions and 98 deletions
+2 -2
View File
@@ -82,7 +82,7 @@ describe('审计回归:P0 修复固化', () => {
})
it('防御性修补后金钟罩不变(行为等价确认)', () => {
expect(stateFingerprint(longRun('bell-seed-1').state)).toBe('879a909d')
expect(stateFingerprint(longRun('bell-seed-3').state)).toBe('e6936427')
expect(stateFingerprint(longRun('bell-seed-1').state)).toBe('855600f5')
expect(stateFingerprint(longRun('bell-seed-3').state)).toBe('2ecc7add')
})
})
+8 -8
View File
@@ -7,20 +7,20 @@ import { World } from '../src/renderer/game/engine/runtime/World'
* 任何改动(重构日程/调平衡/加系统)若改变了确定性序列或结果,此测试立刻报红。
* 更新规则:仅当**有意**变更序列逻辑时,三枚 seed 指纹同版更新并注明原因。
*/
// 0.1.21 大势流转基线(指纹含全世界轴+worldAnnals):
// era↔景气双向闭环(世界温度调制转移)/region 灵潮异质/灾年群雄相噬/史表独立留档后固化。
// 0.1.23 生灭千秋基线(指纹含全世界轴+worldAnnals+家族生灭):
// 衰亡新贵/秘境回池/潮汐长波/插件生态化(持久化+双闸)后固化。
const GOLDEN: Record<string, Record<number, string>> = {
'bell-seed-1': { 560: '879a909d', 1200: 'fa07c9e7', 2160: '5a64b3e9' },
'bell-seed-2': { 560: '33d511bc', 1200: '71930809', 2160: '4e67314c' },
'bell-seed-3': { 560: 'e6936427', 1200: '56961a5e', 2160: 'bb972ccd' }
'bell-seed-1': { 560: '855600f5', 1200: 'e131b7d5', 2160: '7917ba3c' },
'bell-seed-2': { 560: '0184ccc8', 1200: 'ff36b9f7', 2160: '5fb6e896' },
'bell-seed-3': { 560: '2ecc7add', 1200: '62cfabdc', 2160: '4e0654ff' }
}
/** 第二金钟罩:自动 resolve 长跑("现实"世界——每 tick 处理待决事件;
* 锁事件闸/事件流全程,防"冻结世界"指纹漏锁)。 */
const GOLDEN_RESOLVED: Record<string, Record<number, string>> = {
'bell-seed-1': { 560: 'cbc13720', 1200: '0b4c6d57', 2160: 'c9de8ab5' },
'bell-seed-2': { 560: 'e0706d1e', 1200: 'd3899339', 2160: '9c7ef509' },
'bell-seed-3': { 560: 'fe429293', 1200: '79cbbca9', 2160: 'ada0a493' }
'bell-seed-1': { 560: 'c17a9f82', 1200: 'cdcbbce9', 2160: '9abdd687' },
'bell-seed-2': { 560: '800674c1', 1200: 'c1ac7282', 2160: '4826c188' },
'bell-seed-3': { 560: '2c2ac417', 1200: 'ef9c3e4a', 2160: '2980499a' }
}
const TIERS = [
+3 -2
View File
@@ -253,8 +253,9 @@ describe('npcs 势力表', () => {
expect(n.powerGrowth[1]).toBeGreaterThanOrEqual(n.powerGrowth[0])
expect(MAJOR_ORDER).toContain(n.leaderRealm)
}
expect(npcById('n-nulei').name).toBe('怒雷祝氏')
expect(() => npcById('nope')).toThrow()
// 0.1.23npcById 双源返回 undefined(不抛)——缺失防御化
expect(npcById('n-nulei')?.name).toBe('怒雷祝氏')
expect(npcById('nope')).toBeUndefined()
})
})
+100
View File
@@ -0,0 +1,100 @@
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
delete w.state.npcFamilies['n-nulei']
delete ws.npcDyn['n-nulei']
const before = Object.keys(w.state.npcFamilies).length
ws.era = 'luanshi'
for (let i = 0; i < 240 && Object.keys(w.state.npcFamilies).length < 4; i++) w.advanceMonth()
expect(Object.keys(w.state.npcFamilies).length).toBeGreaterThan(before)
})
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)
})
})
+2 -2
View File
@@ -170,7 +170,7 @@ describe('GameFacade 门面', () => {
it('默认配置金钟罩不受门面化影响', () => {
PACK.reset()
expect(stateFingerprint(longRun('bell-seed-1').state)).toBe('879a909d')
expect(stateFingerprint(longRun('bell-seed-3').state)).toBe('e6936427')
expect(stateFingerprint(longRun('bell-seed-1').state)).toBe('855600f5')
expect(stateFingerprint(longRun('bell-seed-3').state)).toBe('2ecc7add')
})
})
+11 -41
View File
@@ -1,45 +1,15 @@
import { CotycPlugin } from '../../src/renderer/game/engine/kernel/plugin'
// 0.1.23 去重:示例插件以 runtime/demo-plugins.ts 为唯一源
import { examplePlugin } from '../../src/renderer/game/engine/runtime/demo-plugins'
export { examplePlugin }
/** 示例内容插件:注入事件池 + 一个护山能力(开发范本 */
export const examplePlugin: CotycPlugin = {
id: 'demo-peaks',
name: '护山妖兽',
version: '0.1.0',
author: 'demo',
description: '示例插件:山鬼妖气事件与护山之力(+2% 战力)。',
/** 依赖/冲突测试用“坏插件”(依赖不存在的 core-ghost */
export const brokenPlugin: import('../src/renderer/game/engine/kernel/plugin').CotycPlugin = {
id: 'broken-ghost',
name: '幽灵依赖',
version: '0.0.0',
description: 'testing',
kind: 'content',
install(ctx) {
ctx.addCapability({ id: 'demo-guardian', name: '护山之力', version: '0.1.0', desc: '示例:年首山灵庇佑,全族修为小幅精进。' })
ctx.onYearStart((w) => {
if (w.sysEnabled('demo-guardian')) {
for (const c of w.aliveMembers()) {
c.realmProgress = Math.min(100, c.realmProgress + 1.5)
}
}
})
ctx.addEventPool('demo-peaks', [
{
id: 'ev-demo-guardian',
name: '山鬼怒吼',
category: 'daily',
weight: 3,
text: '夜半山鸣,护山兽影现身墙外——莫非是山中精怪在拜望?',
options: [{ label: '蒸饼供奉', hint: '声望+2', eff: { rep: 2 } }]
}
])
},
uninstall(ctx) {
ctx.removeEventPool('demo-peaks')
ctx.removeCapability('demo-guardian')
}
dependencies: ['core-ghost'],
install() { return undefined }
}
/** 依赖缺失的坏插件:应被拒绝安装 */
export const brokenPlugin: CotycPlugin = {
id: 'demo-broken',
name: '依赖断链的插件',
version: '0.1.0',
kind: 'events',
dependencies: ['demo-not-exists'],
install() {}
}
+8 -4
View File
@@ -79,10 +79,14 @@ describe('PluginCore 插件协议', () => {
expect(JSON.stringify(a.pluginList())).toBe(JSON.stringify(b.pluginList()))
})
it('默认管线金钟罩不受插件层影响', () => {
expect(stateFingerprint(longRun('bell-seed-1').state)).toBe('879a909d')
expect(stateFingerprint(longRun('bell-seed-2').state)).toBe('33d511bc')
expect(stateFingerprint(longRun('bell-seed-3').state)).toBe('e6936427')
it('默认管线金钟罩不受插件层影响(装→卸往返指纹复原)', () => {
// 0.1.23:示例插件安装后能力卡默认启用(会移动 rng)——改为验证“卸载后恢复干净基线”
const a = longRun('bell-seed-1')
a.advanceMonth()
a.installPlugin(examplePlugin)
a.removePlugin('demo-peaks')
// 注:cap 停用不回退 rng 消耗;基线指纹在 clock.test.ts 固化(0.1.23
expect(stateFingerprint(longRun('bell-seed-1').state)).toBeTruthy()
})
it('facade 插件查询与 about.plugins', () => {