// 公式层:由存档状态组装运行时乘区,供 UI / Canvas / 测试复用(纯函数,无副作用)。 // 与 GDD.md「数值表」逐条对应。署名:FmodeCode import * as C from './config.js'; const nowSec = () => Date.now() / 1000; /** 本轮起始层 F(种子的起点) */ export function F0(state) { return C.earlyLayer(state.maxLayerRound || 0, C.PLANE_RULES[state.currentPlane || 0]); } /** 推进基准(米魔卡点):前 15 层 ×1;之后每深入 1 层,单层推进时间 ×1.063(封顶 ×15) */ export const GM_GRACE = 15; export const GM_EPS = 0.01; export function marchBase(layer, start) { // 推进基准 gm(“米魔”卡点):D = L − F // gm = D^1.5(能量谷包络):推进时间 ∝ √D,即层数 ∝ 推进量的 2/3 次方——每突破一格都需要速度乘区跟上 // 跳关把推进量按时间乘区放大:层数对时间乘区的幂次 = 1.5(≈ 任务书“逃逸进度 ^1.5”) const D = Math.max(0, layer - (start || 0)); return Math.pow(Math.max(1, D), 1.5); } /** 兵种技能与“已解锁兵种数”(用于羁绊 / 炼化乘区)——供 stats 与 UI 复用 */ export function lifeSkill(state) { const lv = state.lives || {}; let prod = 1, speed = 1, skip = 0, crystal = 1; const byRace = { 生命: 0, 星穹: 0, 虚空: 0 }; let total = 0; for (const l of C.LIVES) { const n = lv[l.id] || 0; if (!n) continue; byRace[l.race]++; total += n; const strength = l.eff.per * n; if (l.eff.kind === 'prod') prod *= 1 + strength; else if (l.eff.kind === 'speed') speed *= 1 + strength; else if (l.eff.kind === 'skip') skip += strength; else if (l.eff.kind === 'crystal') crystal *= 1 + strength; } const stacks = {}; for (const r of Object.keys(C.RACES)) stacks[r] = C.raceStacks(r, byRace[r]); return { prod, speed, skip, crystal, byRace, total, stacks, bondProd: Math.pow(C.RACE_BOND_MULT, stacks.生命), bondCrystal: Math.pow(C.RACE_BOND_MULT, stacks.星穹), bondSkip: Math.min(2, C.RACE_SKIP_BONUS * stacks.虚空), }; } /** 跳关触发率(全部可加来源直接相加,封顶 60%) */ export function skipProbOf(state, sk) { const rule = C.PLANE_RULES[state.currentPlane || 0]; const l = sk || lifeSkill(state); const raw = C.canopySkip(state.upgrades?.canopy || 0) + l.skip + l.bondSkip + (rule.skipMult - 1); return Math.min(C.SKIP.cap, raw); } /** 炼化乘区 M(兵种技能 × 星穹羁绊 × 探索阶梯 × 跳关加成 × 自由轮回) */ export function rebirthMOf(state, sk) { const p = state.currentPlane ?? 0; const l = sk || lifeSkill(state); const tier = C.exploreTierOf(state.planes?.[p]?.explore || 0); const skipNote = 1 + Math.min(C.REBIRTH.skipNoteCap, skipProbOf(state, l) * 0.5); // 见闻:所有位面的探索度之和参与炼化乘区(可回头刷低阶位面补强主世界) const insight = 1 + (state.exploreSum || 0) / 100; return l.crystal * l.bondCrystal * tier.crystal * skipNote * insight * C.freedomMul(state) * C.resonanceMul(state); } /** 速度乘区 M_spd(不含危机、不含卡点) */ export function speedMulOf(state) { const p = state.currentPlane ?? 0; const l = lifeSkill(state); return C.treeSpeedMul(state.treeLv || 0) * C.rootSpeedMul(state.upgrades?.root || 0) * l.speed * C.PLANE_RULES[p].speedMult; } /** * 全部乘区与速率(GDD §6)。 * 本源产出/秒(本轮)= Σ_{k now; const crisisPenalty = (cr.penaltyUntil || 0) > now; const crisisMult = crisisBuff ? 1 + C.CRISIS.reward : crisisPenalty ? 1 - C.CRISIS.penalty : 1; const narrSig = state.magic?.sigUntil > now ? state.magic.sig || 0 : 0; const narrate = Math.pow(rule.narrateBoost || 1, Math.min(C.NARRATE_STACK_CAP, narrSig)); // ── 产出乘区(独立相乘) const mults = { tree: C.treeProdMul(state.treeLv || 0), blood: C.multRebirth(state.rebirths || 0), explore: C.multExploration(explore), creature: C.multCreature(sk.total), bond: sk.bondProd, relic: C.relicMul(state.relics?.length || 0), freedom: C.freedomMul(state), plane: rule.prodMult, crisis: crisisMult, narrate, }; const prodMul = Object.values(mults).reduce((a, b) => a * b, 1); const rootP = C.rootProdMul(state.upgrades?.root || 0); const rel = Math.max(0, layer - start); const base = rel > 0 ? (Math.pow(C.ESSENCE_GROWTH, rel) - 1) / Math.log(C.ESSENCE_GROWTH) : 0; const prodRaw = base * rootP * prodMul; // ── 推进速度 const gm = marchBase(layer, start); const speedMul = speedMulOf(state) * (crisisPenalty ? 1 - C.CRISIS.penalty : 1); const layerSec = (C.visitTime(layer) * gm) / speedMul; const layersPerSec = speedMul / (C.visitTime(layer) * gm); const skipP = skipProbOf(state, sk); const skipExp = C.skipExpectation(skipP); const timeMul = 1 + skipExp; const rebirthM = rebirthMOf(state, sk); const reward = rebirthEstimate(state, rebirthM); return { plane: p, rule, start, rel, base, rootP, prodMul, mults, frozen, prodRaw, prod: frozen ? 0 : prodRaw, creatureLv: sk.total, skills: sk, tier, explore, gm, speedMul, layerSec, layersPerSec, minutesPerLayer: (layerSec * timeMul) / 60, skipP, skipExp, timeMul, rebirthM, reward, rebirthCost: C.rebirthCost(state.maxLayerRound || 0), crisisBuff, crisisPenalty, crisisMult, narrate, narrSig, anchored: explore >= C.EXPLORE_FULL, }; } /** 单次炼化可得结晶(含衰减 / 自由轮回叠加)。state.rebirth() 使用同一函数:UI 预期 = 实得 */ export function rebirthEstimate(state, M) { const p = state.currentPlane ?? 0; const mm = M ?? rebirthMOf(state); const base = C.rebirthReward({ maxLayer: state.maxLayerRound || 0, exploreSum: state.exploreSum || 0, incomeMul: mm, ruleMod: C.PLANE_REBIRTH_MOD[p] || 1, }); if (state.planeRun && state.planeRun.state !== 'result') return 0; // 里世界中主世界冻结:不可回溯 return Math.max(1, base); } /** 本轮升级成本 / 批量成本 */ export function upgradeCost(state, kind) { const rule = C.PLANE_RULES[state.currentPlane || 0]; return Math.ceil(C.costOf(kind, state.upgrades?.[kind] || 0) * rule.costMult); } export function upgradeBatchCost(state, kind, n) { const rule = C.PLANE_RULES[state.currentPlane || 0]; return Math.ceil(C.batchCost(kind, state.upgrades?.[kind] || 0, n) * rule.costMult); } /** 兵种升级成本(下一级) */ export function lifeCost(state, lifeId, atLevel) { const def = C.LIVES.find((l) => l.id === lifeId); const n = atLevel ?? (state.lives?.[lifeId] || 0); const rule = C.PLANE_RULES[state.currentPlane || 0]; return Math.ceil(C.lifeCostOf(def.cost, n + 1) * rule.costMult); } export function lifeUnlocked(state, idx) { if (idx === 0) return true; return (state.lives?.[C.LIVES[idx - 1].id] || 0) >= 3; } /** 永久投资成本(时间结晶) */ export function permCost(state, kind) { if (kind === 'stem' || kind === 'tree') return C.treeCost(state.treeLv || 0); if (kind === 'relic') return C.relicCost(state.relics?.length || 0); return Infinity; } /** 转生后起始层 */ export function rebirthFloor(state) { return C.earlyLayer(Math.max(state.maxLayerRound || 0, state.layer || 0), C.PLANE_RULES[state.currentPlane || 0]); } /** 主线逃逸进度(0~1):连续空间里“抵达的层数 / 1000” */ export function escapeProgress(state) { return Math.min(1, (state.layer || 0) / C.TOTAL_LAYERS); }