Files
ChronicleOfTheImmortalClan/tests/plugin.test.ts
T
thzxx ea9f5c9c5d v0.1.17: 天下为市——世界真炉膛(市场实体化+NPC博弈+灾年持续)
【A 市场实体化(真库存循环)】
- 世界呼吸:池月供给 × 潮汐span - 常驻需求(worldSupplyRate 2% vs worldDemandRate 1.5%)
- NPC 上桌:def.sells/buys 逐月入池出池——池浅采不到→power-15%,池深抛货→市场暖意
- 玩家交易回写:buy 浅池价涨/sell 盈池价跌(tradeSettle 0.35 份额粒度);池深<35% 断供拒单(12% 是枯井)
- marketPrice 统一走 marketMultFor;本地 POOL_BASE/TECH 复刻清除(worldsim-data 单源)

【B 世界格局博弈】
- 战争伤骨:劫掠胜负回写 power(败-18%/胜+6%)+ dead 字段 raidCount/warCooldownYear 启用
- 社交回响:赠礼回礼(30% 灵石/30% 灵草)+ power 微涨;联姻/和约/结盟皆涨 power
- NPC 关系网:relationsWithOthers 填实(同风格亲30~55/异风格隙-35~15)+ 年首±5 漂移;世仇<-50 年首互攻(败方-18%)
- 灾年共苦:灾年 NPC 贸易 ×0.7;tide 对供给 ±0.3 弹性
- 灾年持续 6 月渐退;灾起/灾散快讯(kind 标记)

【UI】
- 天下面板:池深百分比(含断供阈值 tooltip)/本族天下排位/灾年余月
- 快讯响应化:行情见顶抛售5/见底吃进5/灾年救济(50灵石→关系8)
- MarketPanel 法帖价格改 techniquePrice()(硬编码清除)

【测试】994 全绿(38 套件,新增世界炉膛 8 例);金钟罩 0.1.17 基线固化
2026-08-23 14:24:23 +08:00

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('c923fdd1')
expect(stateFingerprint(longRun('bell-seed-2').state)).toBe('e98eb9fa')
expect(stateFingerprint(longRun('bell-seed-3').state)).toBe('5edde2cd')
})
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
})
})