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
+20
View File
@@ -39,6 +39,8 @@ export const PHASE_ORDER: PhaseId[] = [
export class GameClock {
private monthly = new Map<PhaseId, SystemHook[]>()
private yearly: SystemHook[] = []
private anchorsBefore: Array<{ phase: PhaseId; fn: SystemHook }> = []
private anchorsAfter: Array<{ phase: PhaseId; fn: SystemHook }> = []
register(phase: PhaseId, fn: SystemHook): () => void {
const list = this.monthly.get(phase) ?? []
@@ -58,6 +60,22 @@ export class GameClock {
}
}
/** 时轮锚点(0.1.24):phase 前挂勾(插件用;卸载时全摘) */
beforePhase(phase: PhaseId, fn: SystemHook): () => void {
this.anchorsBefore.push({ phase, fn })
return () => {
this.anchorsBefore = this.anchorsBefore.filter((a) => !(a.phase === phase && a.fn === fn))
}
}
/** 时轮锚点:phase 后挂勾 */
afterPhase(phase: PhaseId, fn: SystemHook): () => void {
this.anchorsAfter.push({ phase, fn })
return () => {
this.anchorsAfter = this.anchorsAfter.filter((a) => !(a.phase === phase && a.fn === fn))
}
}
fireYearStart(w: World): void {
for (const fn of this.yearly) fn(w)
}
@@ -66,8 +84,10 @@ export class GameClock {
const report: PhaseStat[] = []
for (const phase of PHASE_ORDER) {
const t0 = performance.now()
for (const a of this.anchorsBefore) if (a.phase === phase) a.fn(w)
const fns = [...(this.monthly.get(phase) ?? [])]
for (const fn of fns) fn(w)
for (const a of this.anchorsAfter) if (a.phase === phase) a.fn(w)
const ms = performance.now() - t0
report.push({ phase, ms, count: fns.length })
}
@@ -32,6 +32,11 @@ export interface PluginContext {
clock: GameClock
register: (phase: Parameters<GameClock['register']>[0], fn: SystemHook) => () => void
onYearStart: (fn: SystemHook) => () => void
/** 时轮 anchorphase 前/后挂勾(0.1.24;卸载时全摘) */
beforePhase: (phase: Parameters<GameClock['register']>[0], fn: SystemHook) => () => void
afterPhase: (phase: Parameters<GameClock['register']>[0], fn: SystemHook) => () => void
/** 世界生成钩子:插件可注入 NPC 模板(worldgen 词库插件化) */
addNpcTemplate: (def: import('../../data/npcs').NpcFamilyDef) => void
addCapability: (cap: { id: string; name: string; version: string; desc: string }) => void
removeCapability: (id: string) => void
enableCapability: (id: string, enabled: boolean) => void