- WorldSim(engine/sim/WorldSim.ts + worldsim-data.ts): A 资源循环市场(库存池/再平衡/价格弹性——Market 行情联动 sim.mult) B NPC 聚合演化(宗主换代/境界成长/势力=境界+财力+兵员;换代计数) C 秘境灵气(探索消耗/恢复)+ 灵气潮汐(6年周期×修炼倍率) D 灾年签(旱涝蝗疫兽寒,联动市场池) E 天下快讯(节流 24 月滚动 120 条,世界动态 feed) - 相位:新增 worldsim(diplomacy 后 epilogue 前);capabilities 加「天下演序」卡可停用 - 时钟合一:World.clock = Kernel.clock(单一时钟驱动,消除双时钟漂移) - 发现并修复:worldsim 注册被文件搬迁覆盖丢失(修改纪律验证中招——已补回); WorldSim 内 Math.random 根除(改 w.rng) - fingerprint 纳入 worldSim 概要(市场/灵脉/潮汐/换代/快讯数) - 金钟罩三档重固化(0.1.14 正式基线,受控变更) - 验证:35 套件/967 测试全绿;typecheck 0 error
70 lines
2.9 KiB
TypeScript
70 lines
2.9 KiB
TypeScript
import { World } from '../src/renderer/game/engine/runtime/World'
|
|
import { GameState } from '../src/renderer/game/types/domain'
|
|
|
|
export function stateFingerprint(s: GameState): string {
|
|
const parts = [
|
|
s.year, s.month, s.seq, s.totalTicks,
|
|
s.family.stones,
|
|
s.family.reputation,
|
|
s.family.generation,
|
|
JSON.stringify(sortedInv(s.family.inventory)),
|
|
JSON.stringify(sortedBld(s.family.buildings)),
|
|
s.family.headId,
|
|
s.family.techniques.join(',')
|
|
]
|
|
const members = Object.values(s.members)
|
|
.map((c) => `${c.id}:${c.alive}:${c.realm.major}/${c.realm.minor}:${Math.floor(c.realmProgress * 10) / 10}:${Math.floor(c.health * 10) / 10}:${c.state}:${c.bornYear}:${c.techniqueRank ?? 0}:${Math.floor((c.techniqueProgress ?? 0) * 10) / 10}:${c.post ?? ''}:${c.aspiration ?? ''}:${c.spouseId ?? ''}:${c.children.join('-')}`)
|
|
.sort()
|
|
parts.push(members.join('|'))
|
|
parts.push(JSON.stringify(sortedNpc(s.npcFamilies)))
|
|
parts.push(s.missions.length + ':' + s.missions.map((m) => `${m.defId}:${m.stage}:${m.stageMonth}:${m.done}:${m.memberIds.join('+')}`).join(';'))
|
|
parts.push(s.chronicle.length + ':' + s.chronicle.slice(-5).map((e) => `${e.year}${e.month}${e.category}`).join(','))
|
|
parts.push(s.battles.length)
|
|
parts.push(Object.keys(s.completedEvents).length + ':' + s.completedEvents.slice(-3).join(','))
|
|
parts.push(JSON.stringify(sortedFlags(s.family.flag)))
|
|
parts.push(s.yearlyReports.length)
|
|
const ws = s.worldSim
|
|
if (ws) {
|
|
parts.push(`ws:${JSON.stringify(ws.marketPool ?? {})}:${JSON.stringify(ws.secretQi ?? {})}:${ws.tide ?? 0}:${ws.npcSuccessions ?? 0}:${(ws.newsFeed ?? []).length}`)
|
|
} else {
|
|
parts.push('ws:none')
|
|
}
|
|
return hash32(parts.join('\u0001'))
|
|
}
|
|
|
|
function sortedInv(inv: Record<string, number>): Array<[string, number]> {
|
|
return Object.entries(inv).sort((a, b) => (a[0] < b[0] ? -1 : 1))
|
|
}
|
|
function sortedBld(b: Record<string, number>): Array<[string, number]> {
|
|
return Object.entries(b).sort((a, b) => (a[0] < b[0] ? -1 : 1))
|
|
}
|
|
function sortedFlags(f: Record<string, number | boolean | string>): Array<[string, string]> {
|
|
return Object.entries(f)
|
|
.map(([k, v]) => [k, String(v)] as [string, string])
|
|
.sort((a, b) => (a[0] < b[0] ? -1 : 1))
|
|
}
|
|
function sortedNpc(n: GameState['npcFamilies']): Array<[string, string]> {
|
|
return Object.entries(n)
|
|
.map(([k, v]) => [k, `${v.relation}:${v.power}:${v.allied}`] as [string, string])
|
|
.sort((a, b) => (a[0] < b[0] ? -1 : 1))
|
|
}
|
|
|
|
function hash32(str: string): string {
|
|
let h = 2166136261
|
|
for (let i = 0; i < str.length; i++) {
|
|
h ^= str.charCodeAt(i)
|
|
h = Math.imul(h, 16777619)
|
|
h = (h << 13) | (h >>> 19)
|
|
}
|
|
return (h >>> 0).toString(16).padStart(8, '0')
|
|
}
|
|
|
|
export function longRun(seed: string, months = 560): World {
|
|
const w = World.create({ seed, surname: '钟', familyName: '钟家', motto: 'm', difficulty: 'normal' })
|
|
for (let i = 0; i < months; i++) {
|
|
if (w.state.gameOver) break
|
|
w.advanceMonth()
|
|
}
|
|
return w
|
|
}
|