// 里世界肉鸽:规则引擎(纯数据,不碰 DOM)。隔离局内,不继承主世界永久资源。 // 一局 = 6 场遭遇(战斗/精英/奇遇/圣所),约 1~5 分钟。署名:FmodeCode import * as C from './config.js'; import { mulberry32, clamp } from './util.js'; export const RULES = ['knowledge', 'oath', 'belief', 'judge']; export const RULE_NAME = { knowledge: '知识', oath: '誓约', belief: '信念', judge: '裁决' }; export const RULE_DESC = { knowledge: '知识 → 攻击:每点攻击 +1.5', oath: '誓约 → 生命:每点最大生命 +9', belief: '信念 → 生命:每点最大生命 +9', judge: '裁决 → 攻击:每点攻击 +2', }; export const ENCOUNTERS = 6; // 一局推进 6 步,第 6 步为终局 export const CAP = { knowledge: 30, oath: 30, belief: 30, judge: 30 }; export const STARTER = 1; // 每项规则起步 1 点 const MONSTERS = ['灰烬守卫', '蚀影猎犬', '残响歌者', '残影巡游者', '无人电梯', '空洞低语', '镜像拷问者']; const ELITES = ['蚀壳巨像', '规则提灯人', '终末回声', '零点行者']; const BOSSES = ['灰烬王座', '演算核心', '镜之城主人', '天劫化身']; export const TAUNTS = [ '你不该记得上一次。', '规则站在我这边。', '树根不会再长出来了。', '你的誓约很轻。', '这一次也一样的。', '尘埃也想逃出去吗?', ]; const EVENTS = [ { id: 'pool', title: '断桥下的光池', text: '桥塌了一半,水面倒映出不是你的脸。光池里漂着一枚还在跳动的规则碎片。', opts: [ { label: '伸手打捞', hint: '获得 2 点随机属性,损失 15% 生命', apply: { rules: 2, dmg: 0.15 } }, { label: '绕路前行', hint: '恢复 25% 生命,能量 +2', apply: { heal: 0.25, energy: 2 } }, ] }, { id: 'altar', title: '无名的祭坛', text: '祭坛上刻着:献上你的一部分,换取它曾经的名字。', opts: [ { label: '献上记忆', hint: '最高属性 +3,受到 20% 伤害', apply: { topRule: 3, dmg: 0.2 } }, { label: '拿走供品', hint: '能量 +4', apply: { energy: 4 } }, ] }, { id: 'wanderer', title: '迷路的观测者', text: '穿旧外套的观测者正在记录星光。他说记得你轮回之前的样子。', opts: [ { label: '交换情报', hint: '知识 +3、裁决 +1', apply: { add: { knowledge: 3, judge: 1 } } }, { label: '请他疗伤', hint: '恢复 40% 生命', apply: { heal: 0.4 } }, { label: '离开', hint: '能量 +1', apply: { energy: 1 } }, ] }, { id: 'mirror', title: '会说话的镜子', text: '镜子里是另一个你,它说:“你每次都死在同一个地方。”它没有说错。', opts: [ { label: '击碎镜子', hint: '全部属性 +2,同时受到 15% 伤害', apply: { addAll: 2, dmg: 0.15 } }, { label: '对它微笑', hint: '能量 +3', apply: { energy: 3 } }, ] }, { id: 'door', title: '三扇门', text: '三扇门后传来不同的声音:翻页声、祷词声、心跳声。', opts: [ { label: '推开翻页的那扇', hint: '知识 +3', apply: { add: { knowledge: 3 } } }, { label: '推开祷词的那扇', hint: '誓约 +3', apply: { add: { oath: 3 } } }, { label: '推开心跳的那扇', hint: '信念 +3', apply: { add: { belief: 3 } } }, ] }, { id: 'forge', title: '灰烬铁匠铺', text: '炉火还温着。铁匠不在,桌上有一柄未完工的誓约之剑。', opts: [ { label: '锻成剑刃', hint: '裁决 +3', apply: { add: { judge: 3 } } }, { label: '带走防具', hint: '信念 +2、誓约 +1', apply: { add: { belief: 2, oath: 1 } } }, ] }, ]; const OATHS = [ { id: 'battle', name: '破阵之愿', desc: '攻击 +3', add: { knowledge: 1, judge: 1 }, atkBonus: 1 }, { id: 'warden', name: '守望之愿', desc: '最大生命 +40%,誓约、信念各 +1', hp: 0.4, add: { oath: 1, belief: 1 } }, { id: 'seer', name: '先知之愿', desc: '事件强化 ×2(随机属性翻倍、治疗翻倍)', eventMul: 2 }, ]; const rnd = (r, n) => Math.floor(r() * n); const pick = (r, arr) => arr[rnd(r, arr.length)]; export function atkOf(s) { return 10 + 1.5 * (s.attrs.knowledge + bonusOf(s, 'knowledge')) + 2 * (s.attrs.judge + bonusOf(s, 'judge')) + ((s.oathObj && s.oathObj.atkBonus) || 0); } export function hpMaxOf(s) { return Math.round((40 + 4 * (s.attrs.oath + bonusOf(s, 'oath')) + 1.5 * (s.attrs.belief + bonusOf(s, 'belief'))) * (1 + (s.oathObj?.hp || 0))); } /** 敌人威胁 pK:随步数与位面递增,与玩家属性无关(属性只放大你的攻击/生命) */ export function threatOf(s, step, kind) { const a = s.attrs; const sum = a.knowledge + a.oath + a.belief + a.judge; const p = s.plane || 0, i = step ?? s.step ?? 0; // 敌方威胁 = 你的规则总和 ×(1+10%×步)×1.15^位面——敌人始终比你“多带一点规则”,位面越深越硬(与你的预算密度同序) const base = sum * (1 + 0.1 * i) * Math.pow(1.15, p); return Math.max(1, Math.round(base * (kind === 'boss' ? 1.1 : kind === 'elite' ? 1.05 : 1))); } export function clampAttr(v, k) { return clamp(+v.toFixed(2), 0, CAP[k]); } // 本位面在里世界的“规则浓度”:一阶 ×1.00 → 四阶 ×1.30;浓度越高,开局预算点越多(世界树等级的心智加成) export function planeDensity(plane) { return Math.pow(1.3, plane || 0); } export function riftNewRun(plane, budgetOverride) { const r = mulberry32((Math.random() * 1e9) >>> 0); return { seed: rnd(r, 1e9), plane, step: 0, state: 'build', cleared: false, dead: false, budget: budgetOverride != null ? budgetOverride : Math.round(20 * planeDensity(plane)), // 开局“本源点”(预算点):一阶 20、二阶 26、三阶 34、四阶 44 density: planeDensity(plane), available: (() => { let k = 3 + rnd(r, 3), o = 3 + rnd(r, 3), b = 3 + rnd(r, 3), j = 3 + rnd(r, 3); const T = Math.round(20 * planeDensity(plane)); while (k + o + b + j < T) { const pick = [k, o, b, j]; let m = 0; for (let q = 1; q < 4; q++) if (pick[q] < pick[m]) m = q; if (m === 0) k++; else if (m === 1) o++; else if (m === 2) b++; else j++; } return { knowledge: k, oath: o, belief: b, judge: j }; })(), // 每类可分配格(总和 ≥ 预算点) hp: 100, hpMul: 1, dmgMul: 1, energy: C.RIFT.energy + 8, maxEnergy: C.RIFT.energy + 8, attrs: { knowledge: 0, oath: 0, belief: 0, judge: 0 }, // 由玩家分配 mouth: null, oathObj: null, immune: false, log: [], score: 0, turns: 0, }; } /** 开局自由分配规则:总点数 = budget,每类不超过 available[k] */ export function pointsSpent(s) { return RULES.reduce((a, k) => a + s.attrs[k], 0); } /** 自动分配:把剩余本源点按列表顺序填入(不超过 available) */ export function autoSpend(s) { const order = ['judge', 'knowledge', 'oath', 'belief']; let left = pointsLeft(s); let guard = 0; while (left > 0 && guard++ < 200) { for (const k of order) { if (left > 0 && s.attrs[k] < s.available[k]) { s.attrs[k]++; left--; } } } return left === 0; } export function pointsLeft(s) { return s.budget - pointsSpent(s); } export function isBuildValid(s) { return (pointsLeft(s) === 0 || (s.autoBuild && pointsLeft(s) <= 0)) && RULES.every((k) => s.attrs[k] >= 1); } /** 事件加成(不计入威胁):存于 s.bonus,战斗生效 */ export function bonusOf(s, k) { return (s.bonus && s.bonus[k]) || 0; } export function buildDone(s, oathIdx) { if (pointsLeft(s) > 0) return false; // 必须把本源点分完 if (!RULES.every((k) => s.attrs[k] >= 1)) return false; s.buildDone = true; const o = OATHS[clamp(oathIdx, 0, OATHS.length - 1)]; s.oathObj = o; s.hp = hpMaxOf(s); s.state = 'run'; riftPrepare(s, 0); return true; } function constDone(s) { return !!s.oathObj; } export function encounterKind(i) { if (i === ENCOUNTERS - 1) return 'boss'; return ['normal', 'event', 'elite', 'normal', 'event'][i] || 'normal'; } export function riftPrepare(s, i) { s.step = i; const r = mulberry32((s.seed + i * 7919) >>> 0); const kind = encounterKind(i); if (kind === 'event') { const ev = pick(r, EVENTS); s.state = 'event'; s.mouth = { type: 'event', title: ev.title, text: ev.text, opts: ev.opts.map((o, j) => ({ label: o.label, hint: o.hint, j })), ev }; return s; } s.state = 'fight'; const scale = Math.pow(1.08, s.plane) * Math.pow(1.06, i); // 终局血量按终局威胁校准:恰好需要 3 次左右超杀(能赢,但有压力) const atk0 = atkOf(s); // 敌人血量/攻击 ∝ 你的攻击力(按全局强度计算,不吃本局临时加点):数值不脱钩,打起来始终“几到十几剑” const basis = (s.baseAtk || 10 + 1.5 * 1 + 2 * 1) * Math.pow(s.density || planeDensity(s.plane), 2.2); const gAtk = basis; const kHp = (kind === 'elite' ? 1.5 : 1.0) * Math.pow(1.06, i + s.plane); let hp = gAtk * kHp * 2.6; let dmg = gAtk * 0.04 * (kind === 'boss' ? 1.15 : 1); let name = pick(r, MONSTERS); if (kind === 'elite') name = pick(r, ELITES); if (kind === 'boss') { hp = Math.max(hp, threatOf(s, i, 'boss') * 4.0); name = pick(r, BOSSES); } s.mouth = { type: kind, name, hp: Math.round(hp), hpMax: Math.round(hp), dmg: Math.round(dmg * 10) / 10, threat: threatOf(s, i, kind), taunt: pick(r, TAUNTS), nextImmunity: !!s.immune, hp0: Math.round(hp), }; return s; } export function kindName(k) { return { normal: '战斗', elite: '精英', boss: '终局', event: '奇遇' }[k] || k; } /** * 挥剑:结果 = 攻击 + 骰面(0..5);pK = 敌人威胁。 * 拼招 结果 > pK 且 < pK×1.75 → 敌人 −结果,自己 −3 * 超杀 结果 ≥ pK×1.75 → 敌人 −⌊结果×1.75⌋,自己 −1 * 阻断 结果 ≤ pK → 敌人格挡,自己 −5,能量 +1 * 誓约最大时,每场第一次受击豁免。 */ export function slash(s, rollVal) { const m = s.mouth; if (s.state !== 'fight' || !m) return null; const roll = clamp(Math.floor(rollVal), 0, 5); // 基础战力 = 攻击(含知识/裁决),每次挥剑再叠一个 0..5 的“临时战意” const value = Math.round(atkOf(s) + roll); const threat = m.threat; let res, dmg = 0, back = 0; const a = s.attrs; const maxK = RULES.reduce((x, y) => (a[y] > a[x] ? y : x), RULES[0]); if (value > threat) { const need = threat * 1.75; if (value >= need) { res = 'crit'; dmg = Math.floor(value * 1.75); back = 1; } else { res = 'win'; dmg = value; back = 3; } // 裁决(攻击属性):拼招/超杀时额外削减 = 裁决 × 1 if (maxK === 'judge' || maxK === 'knowledge') dmg += Math.floor((maxK === 'judge' ? a.judge + bonusOf(s, 'judge') : a.knowledge + bonusOf(s, 'knowledge')) * 1); } else { res = 'block'; back = 5; s.energy = Math.min(s.maxEnergy, s.energy + 1); } if (back > 0 && maxK === 'oath' && !s.immune) { back = 0; s.immune = true; } m.hp = Math.max(0, m.hp - dmg); s.hp = Math.min(hpMaxOf(s), s.hp - back); if (maxK === 'belief' && back > 0) s.hp = Math.min(hpMaxOf(s), s.hp + a.belief * 0.5); s.turns++; s.score += res === 'crit' ? 25 : res === 'win' ? 12 : 0; m.lastLog = { res, roll, value, threat, dmg, back }; const killed = m.hp <= 0, dead = s.hp <= 0; if (killed) s.score += m.type === 'boss' ? 120 : m.type === 'elite' ? 60 : 30; if (dead) s.dead = true; return { res, roll, value, threat, dmg, back, killed, dead, maxK, mHp: m.hp, mHpMax: m.hpMax, heroHp: s.hp, heroMax: hpMaxOf(s) }; } /** 挥剑后的流程:死亡 → 结算;击杀 → 下一步 / 通关 */ export function afterSlash(s, r) { if (r.dead) { s.state = 'result'; return { dead: true }; } if (r.killed) { if (s.step + 1 >= ENCOUNTERS) { s.state = 'result'; s.cleared = true; return { cleared: true }; } riftPrepare(s, s.step + 1); return { next: true }; } return {}; } /** 奇遇选择 */ export function applyOption(s, j) { const m = s.mouth; if (s.state !== 'event' || !m || !m.ev) return null; const opt = m.ev.opts[j]; if (!opt) return null; const r = mulberry32((s.seed + s.step * 53 + j) >>> 0); const mul = (s.oathObj && s.oathObj.eventMul) || 1; const a = opt.apply; const msgs = []; s.bonus = s.bonus || {}; const addA = (k, n) => { s.bonus[k] = (s.bonus[k] || 0) + n * mul; msgs.push(`${RULE_NAME[k]} +${n * mul}`); }; if (a.add) for (const k of Object.keys(a.add)) addA(k, a.add[k]); if (a.addAll) for (const k of RULES) addA(k, a.addAll); if (a.rules) for (let i = 0; i < a.rules; i++) addA(pick(r, RULES), 1); if (a.topRule) { const tot = (k) => s.attrs[k] + (s.bonus[k] || 0); const k = RULES.slice().sort((x, y) => tot(y) - tot(x))[0]; addA(k, a.topRule); } if (a.heal) { const v = Math.round(hpMaxOf(s) * a.heal * mul); s.hp = Math.min(hpMaxOf(s), s.hp + v); msgs.push(`生命 +${v}`); } if (a.energy) { s.energy = Math.min(s.maxEnergy, s.energy + a.energy); msgs.push(`能量 +${a.energy}`); } if (a.dmg) { const v = Math.round(hpMaxOf(s) * a.dmg); s.hp = Math.max(1, s.hp - v); msgs.push(`生命 −${v}`); } s.score += 8; if (s.step + 1 >= ENCOUNTERS) { s.state = 'result'; s.cleared = true; return { cleared: true, msg: msgs.join(',') }; } riftPrepare(s, s.step + 1); return { next: true, msg: msgs.join(',') }; } /** * 结算:探索度增量 = ⌊√(步数+1 + 分/20)⌋,通关 ×1.5(与 config.riftExploreDelta 同源) * 本源碎片 = max(本源秒产, 10) × 8 × 探索增量/4 * 徽记:通关 1 枚;失败但分 ≥ 100 也 1 枚(失败也有价值);已锚定位面不再产出徽记 */ export function riftResult(s, prodPerSec, alreadyAnchored) { const steps = s.step + (s.cleared ? 1 : 0) + 1; // 失败也有价值:探索碎片至少 25% 的固定产出 const delta = Math.max(3, C.riftExploreDelta(steps, s.score, s.cleared)); const essence = Math.max(prodPerSec * 8, 10) * Math.max(1, delta / 16); const shard = alreadyAnchored ? 0 : (s.cleared ? 1 : s.score >= 100 ? 1 : 0); return { explore: delta, essence, score: s.score, shard, cleared: s.cleared, steps }; } export { OATHS };