0.1.39 P4: purgeNpc 清理 worldGen.npcs/relations 僵尸定义 + 金钟罩重算 + 4例测试
This commit is contained in:
@@ -743,7 +743,10 @@ function evolveNpc(w: World, s: WorldSimState, noise: number): void {
|
||||
}
|
||||
}
|
||||
|
||||
/** 覆灭清理:npcFamilies/npcDyn/关系网/raidCD/排队事件/distress/dynamic def 全摘 */
|
||||
/** 覆灭清理:npcFamilies/npcDyn/关系网/raidCD/排队事件/distress/dynamic def/worldGen.npcs 全摘
|
||||
* 0.1.39 根治:补全 worldGen.npcs + worldGen.relations 中已灭亡 NPC 的定义清理——
|
||||
* 旧版 purgeNpc 遗漏了存档层数据,长跑 180 年后 worldGen.npcs 堆积 20+ 条僵尸定义,
|
||||
* 直接膨胀存档体积且读档时重注册已灭亡 NPC 的 def(虽然无运行时副作用但不洁)。 */
|
||||
function purgeNpc(w: World, s: WorldSimState, id: string): void {
|
||||
delete w.state.npcFamilies[id]
|
||||
delete s.npcDyn[id]
|
||||
@@ -755,6 +758,18 @@ function purgeNpc(w: World, s: WorldSimState, id: string): void {
|
||||
w.state.eventQueue = (w.state.eventQueue ?? []).filter((e) => !e.startsWith('ev-raid-') || !e.endsWith(id))
|
||||
if (s.distress?.id === id) s.distress = undefined
|
||||
unregisterNpcDef(id)
|
||||
// 0.1.39:从 worldGen.npcs 移除已灭亡 NPC 的定义(存档体积精简——僵尸 def 不再落盘)
|
||||
if (w.state.worldGen?.npcs) {
|
||||
const idx = w.state.worldGen.npcs.findIndex((n) => n.id === id)
|
||||
if (idx >= 0) w.state.worldGen.npcs.splice(idx, 1)
|
||||
}
|
||||
// 0.1.39:从 worldGen.relations 清理已灭亡 NPC 的关系条目(存档体积精简)
|
||||
if (w.state.worldGen?.relations) {
|
||||
delete w.state.worldGen.relations[id]
|
||||
for (const rid of Object.keys(w.state.worldGen.relations)) {
|
||||
delete w.state.worldGen.relations[rid]?.[id]
|
||||
}
|
||||
}
|
||||
w.emitFx('ripple', `purge:${id}`)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user