【主线一:世界自演进深化《八方风雨》】 - NPC 战略姿态 stance:守成/扩张/隐忍/结盟四态,年首评估(era>景气>power>relation) 全行为调制:raid 概率×2/×0.4/×0、互攻阈值 -40/-70/不攻、贸量 ×1.3/×0.7、 赠礼收益 ally×1.3、结盟门槛 ally 放宽至30——NPC 从统计物理到行为战略 - 超卖潮(谷贱伤农):池>1.8×base 世界产能回调×0.7 + 年度播报(防玩家玩崩市场) - 盟约连坐:结盟令世仇(rel<-50)对玩家-20;盟者世仇 raid 概率×2 - 盟友求援:互攻失利盟友告急(distress 旗标)——WorldPanel 响应(出资200/见死不救) - 干预天下:调停(50灵石令世仇-60→-25、声望+2)/ 资助盟友;恩怨网情报视图(各家关系展开+调停钮) 【主线二:孤立系统归并引擎】 - P0 兜底修复:empty() 收敛 makeWorldSimState 单源 + normalize 补 tideTicks/calamityLeft/ era/eraStartYear/prosperity/distress/overfluxYear(旧档 NaN 级联防死) - FxGate 从 engine/kernel/fxqueue.ts 并入 ui/fx.ts(kernel 清纯引擎;deltas 顶层导出, 3 处引用 10 行改动);engine 侧零 UI 依赖再下一城 - 音效语义补充:onFx→blade/pulse/spark→sWar/sGong/sBell;onLog kind 兜底保留(不静音) - store.advance drift/season 段左移 fx.ts(fxSeason 复活接管 season 检测) - 死码清除:timesense.tideOf/tintLabel、tideDir 全链(类型/初始/写入/domain) - domain.ts worldSim 局部类型补全 0.1.18/0.1.19 全部新字段(断言类型安全) 【测试】1002 全绿(41 套件):stance-world 7 例(兜底/姿态/raid/超卖/连坐/调停/求援)
118 lines
4.4 KiB
TypeScript
118 lines
4.4 KiB
TypeScript
import { describe, expect, it } from 'vitest'
|
|
import { World } from '../src/renderer/game/engine/runtime/World'
|
|
import { GameFacade } from '../src/renderer/game/engine/runtime/ApiFacade'
|
|
import { installCoreSystems, buildClock } from '../src/renderer/game/engine/runtime/clocks'
|
|
import { emptyClock } from '../src/renderer/game/engine/runtime/clocks'
|
|
import { CORE_PLUGINS } from '../src/renderer/game/engine/runtime/plugin-bootstrap'
|
|
import { examplePlugin, brokenPlugin } from './helpers/examplePlugin'
|
|
import { stateFingerprint, longRun } from './fingerprint.helper'
|
|
import { findEvent } from '../src/renderer/game/engine/runtime/Systems/events'
|
|
import { resetSaveBus, attachLogSink } from './world.helpers'
|
|
|
|
function baseWorld(seed: string): World {
|
|
const w = World.create({ seed, surname: '夏', familyName: '夏家', motto: 'm', difficulty: 'normal' })
|
|
resetSaveBus()
|
|
attachLogSink(w)
|
|
return w
|
|
}
|
|
|
|
describe('PluginCore 插件协议', () => {
|
|
it('内置三插件常驻且受保护', () => {
|
|
const w = baseWorld('pl-a')
|
|
const list = w.pluginList()
|
|
expect(list.length).toBe(3)
|
|
for (const p of list) {
|
|
expect(p.installed).toBe(true)
|
|
expect(p.enabled).toBe(true)
|
|
expect(p.protected).toBe(true)
|
|
}
|
|
const ids = list.map((p) => p.id)
|
|
expect(ids).toContain('core-systems')
|
|
expect(ids).toContain('core-data')
|
|
expect(ids).toContain('core-events')
|
|
})
|
|
|
|
it('核心插件不可卸载(保护)', () => {
|
|
const w = baseWorld('pl-b')
|
|
const r = w.removePlugin('core-systems')
|
|
expect(r.ok).toBe(false)
|
|
})
|
|
|
|
it('依赖缺失拒绝安装;依赖满足则放行', () => {
|
|
const w = baseWorld('pl-c')
|
|
expect(w.installPlugin(brokenPlugin).ok).toBe(false)
|
|
expect(w.installPlugin(examplePlugin).ok).toBe(true)
|
|
expect(w.pluginList().length).toBe(4)
|
|
})
|
|
|
|
it('示例安装后:消息池注入生效 + 山神庇佑加值;卸载后两清', () => {
|
|
const w = baseWorld('pl-d')
|
|
w.installPlugin(examplePlugin)
|
|
expect(w.eventPoolIds()).toContain('demo-peaks')
|
|
const x5 = w.state.members['x5']
|
|
x5.realm = { major: 'qi', minor: 1 }
|
|
const p0 = x5.realmProgress
|
|
// 推进到跨年触发年首庇佑
|
|
for (let i = 0; i < 13; i++) w.advanceMonth()
|
|
expect(x5.realmProgress).toBeGreaterThan(p0)
|
|
// 事件注入可被解析(findEvent 命中 demo 池 = 注入生效;确定性校验不赌概率)
|
|
expect(findEvent('ev-demo-guardian', w)).toBeTruthy()
|
|
// 卸载
|
|
expect(w.removePlugin('demo-peaks').ok).toBe(true)
|
|
expect(w.eventPoolIds()).not.toContain('demo-peaks')
|
|
expect(w.pluginList().length).toBe(3)
|
|
})
|
|
|
|
it('remove 后时钟钩子计数恢复(真摘钩)', () => {
|
|
const w = baseWorld('pl-e')
|
|
const before = w.clock.subscriptionCount()
|
|
w.installPlugin(examplePlugin)
|
|
const mounted = w.clock.subscriptionCount()
|
|
expect(mounted).toBe(before + 1)
|
|
w.removePlugin('demo-peaks')
|
|
expect(w.clock.subscriptionCount()).toBe(before)
|
|
})
|
|
|
|
it('安装序确定性:同版本两次世界插件列表一致', () => {
|
|
const a = baseWorld('pl-f')
|
|
const b = baseWorld('pl-f')
|
|
expect(JSON.stringify(a.pluginList())).toBe(JSON.stringify(b.pluginList()))
|
|
})
|
|
|
|
it('默认管线金钟罩不受插件层影响', () => {
|
|
expect(stateFingerprint(longRun('bell-seed-1').state)).toBe('aeed3b65')
|
|
expect(stateFingerprint(longRun('bell-seed-2').state)).toBe('6bb6ff89')
|
|
expect(stateFingerprint(longRun('bell-seed-3').state)).toBe('39892725')
|
|
})
|
|
|
|
it('facade 插件查询与 about.plugins', () => {
|
|
const w = baseWorld('pl-g')
|
|
const f = new GameFacade(w, 1)
|
|
const pl = f.query('plugins') as { list: { id: string }[] }
|
|
expect(pl.list.length).toBe(3)
|
|
expect(f.about().plugins).toBe(3)
|
|
})
|
|
|
|
it('订阅可捕获 plugin 生命周期事件', () => {
|
|
const w = baseWorld('pl-h')
|
|
const f = new GameFacade(w, 1)
|
|
const events: string[] = []
|
|
const unsub = f.subscribe((e) => {
|
|
if (e.type === 'plugin') events.push((e as { action: string }).action)
|
|
})
|
|
w.installPlugin(examplePlugin)
|
|
w.removePlugin('demo-peaks')
|
|
expect(events).toContain('install')
|
|
expect(events).toContain('remove')
|
|
unsub()
|
|
})
|
|
|
|
it('buildClock 兼容路径仍完整注册(测试/工具用)', () => {
|
|
const clock = buildClock()
|
|
expect(clock.subscriptionCount()).toBeGreaterThanOrEqual(10)
|
|
const empty = emptyClock()
|
|
expect(empty.subscriptionCount()).toBe(0)
|
|
void installCoreSystems
|
|
})
|
|
})
|