|
|
@@ -0,0 +1,925 @@
|
|
|
+// 表现层:DOM 渲染、弹窗、Toast、里世界交互、存档 UI。只读 state,所有写入都经 state.js 的 action。
|
|
|
+// 署名:FmodeCode
|
|
|
+import * as C from './config.js';
|
|
|
+import * as F from './formulas.js';
|
|
|
+import * as S from './state.js';
|
|
|
+import * as R from './rift.js';
|
|
|
+import { CIV_EVENTS, CRISIS_EVENTS } from './events-data.js';
|
|
|
+import { fmt, fmtPct, fmtTime, esc } from './util.js';
|
|
|
+import { I, lifeIcon, relicIcon } from './icons.js';
|
|
|
+import { MarchScene } from './march.js';
|
|
|
+
|
|
|
+const $ = (s, r = document) => r.querySelector(s);
|
|
|
+const $$ = (s, r = document) => Array.from(r.querySelectorAll(s));
|
|
|
+const BATCH = 12;
|
|
|
+
|
|
|
+export class App {
|
|
|
+ constructor(state, rift) {
|
|
|
+ this.s = state;
|
|
|
+ this.riftRun = rift && rift.run ? rift.run : null;
|
|
|
+ this.cache = new Map();
|
|
|
+ this.scene = new MarchScene($('#march'));
|
|
|
+ this.toasts = [];
|
|
|
+ this.modalOpen = false;
|
|
|
+ this.dialog = null; // 当前弹窗类型
|
|
|
+ this.dialogQueue = [];
|
|
|
+ this.lastFrame = performance.now();
|
|
|
+ this.lastSave = 0;
|
|
|
+ this.lastRender = 0;
|
|
|
+ this.fps = { n: 0, t: 0, v: 60 };
|
|
|
+ this.bindEvents();
|
|
|
+ this.bindKeys();
|
|
|
+ this.startLoop();
|
|
|
+ }
|
|
|
+
|
|
|
+ // ───────────── 循环 ─────────────
|
|
|
+ startLoop() {
|
|
|
+ let acc = 0;
|
|
|
+ const STEP = 0.2;
|
|
|
+ const loop = (ts) => {
|
|
|
+ const dt = Math.min(0.5, (ts - this.lastFrame) / 1000);
|
|
|
+ this.lastFrame = ts;
|
|
|
+ acc += dt;
|
|
|
+ let guard = 0;
|
|
|
+ while (acc >= STEP && guard++ < 10) { acc -= STEP; this.step(STEP); }
|
|
|
+ if (ts - this.lastRender > 100) { this.lastRender = ts; this.renderDynamic(); }
|
|
|
+ this.fps.n++; this.fps.t += dt;
|
|
|
+ if (this.fps.t >= 1) { this.fps.v = Math.round(this.fps.n / this.fps.t); this.fps.n = 0; this.fps.t = 0; }
|
|
|
+ requestAnimationFrame(loop);
|
|
|
+ };
|
|
|
+ requestAnimationFrame(loop);
|
|
|
+ }
|
|
|
+
|
|
|
+ step(dt) {
|
|
|
+ const s = this.s;
|
|
|
+ const out = S.tick(s, this.riftRun ? { run: this.riftRun } : null, dt);
|
|
|
+ this.riftRun = s.planeRun;
|
|
|
+ // 表现:跳关
|
|
|
+ if (out.skip) { this.scene.burst(1); this.floatLayer(`跃迁 +${out.skip.k}`); }
|
|
|
+ for (const e of out.events) {
|
|
|
+ if (e.quiet) continue;
|
|
|
+ if (e.type === 'civ') this.pushDialog({ kind: 'civ', civIdx: e.civIdx });
|
|
|
+ else if (e.type === 'milestone') this.pushDialog({ kind: 'milestone', data: e });
|
|
|
+ else if (e.type === 'info') this.log(e.title + ':' + e.text, 'info');
|
|
|
+ }
|
|
|
+ if (out.crisis) this.pushDialog({ kind: 'crisis' });
|
|
|
+ if (out.crisisExpire) { const t = S.crisisExpire(s); if (t) this.log(t, 'crisis'); this.toast(t, 'warn'); }
|
|
|
+ if (out.anchors) this.log(`锚定位面后台采集:${out.anchors.count} 个位面 +${fmt(out.anchors.gain)} 本源`, 'anchor');
|
|
|
+ if (out.auto) this.autoHarvest();
|
|
|
+ if (out.floor) this.floatLayer(`${out.floor} 层`);
|
|
|
+ // 存档
|
|
|
+ if (performance.now() - this.lastSave > 30000) { this.lastSave = performance.now(); this.saveNow(); }
|
|
|
+ }
|
|
|
+
|
|
|
+ autoHarvest() {
|
|
|
+ const s = this.s;
|
|
|
+ if (s.planeRun) return;
|
|
|
+ const st = F.computeStats(s);
|
|
|
+ if ((s.maxLayerRound || 0) < 3) return;
|
|
|
+ const r = S.rebirth(s);
|
|
|
+ if (r.event) this.pushDialog({ kind: 'milestone', data: r.event });
|
|
|
+ this.log(`禅定回溯 #${s.rebirths} · +${fmt(r.gain)} 结晶(本轮深度 ${fmt(r.T, { int: true })})`, 'mile');
|
|
|
+ this.toast(`禅定回溯:+${fmt(r.gain)} 时间结晶`, 'good');
|
|
|
+ this.renderStatic();
|
|
|
+ }
|
|
|
+
|
|
|
+ floatLayer(text) {
|
|
|
+ const el = document.createElement('div');
|
|
|
+ el.className = 'skip-float';
|
|
|
+ el.textContent = text;
|
|
|
+ el.style.left = (18 + Math.random() * 30) + '%';
|
|
|
+ el.style.top = (28 + Math.random() * 20) + '%';
|
|
|
+ $('#float-layer').appendChild(el);
|
|
|
+ setTimeout(() => el.remove(), 1200);
|
|
|
+ }
|
|
|
+
|
|
|
+ // ───────────── 渲染 ─────────────
|
|
|
+ renderStatic() { this.renderTop(); this.renderLeft(); this.renderRight(); this.renderRiftPanel(); this.renderDynamic(); }
|
|
|
+
|
|
|
+ renderDynamic() {
|
|
|
+ const s = this.s;
|
|
|
+ const st = F.computeStats(s);
|
|
|
+ this.stats = st;
|
|
|
+ this.renderTop(st);
|
|
|
+ this.renderHud(st);
|
|
|
+ // 资源块
|
|
|
+ this.setText('#res-essence', fmt(s.essence));
|
|
|
+ this.setText('#res-essence-rate', `${fmt(st.prod)} / 秒${st.frozen ? '(冻结)' : ''}`);
|
|
|
+ this.setText('#res-crystal', fmt(s.crystals));
|
|
|
+ this.setText('#res-crystal-rate', s.planes.filter((p) => p.explore >= 100).length ? `锚定采集 ${s.planes.filter((p) => p.explore >= 100).length} 处运行中` : '转生结算,永久');
|
|
|
+ // HUD
|
|
|
+ const lf = s.layer;
|
|
|
+
|
|
|
+ this.html('#hud-r', `<b>${fmt(s.maxLayerRound || 0, { int: true })}</b> 本轮最深<br>时间乘区 <b>×${st.timeMul.toFixed(2)}</b>`);
|
|
|
+ const magic = $('#magic-badge');
|
|
|
+ if (st.narrSig > 0) {
|
|
|
+ this.html('#magic-badge', `叙事共鸣 ×${Math.pow(1.3, Math.min(10, st.narrSig)).toFixed(2)}(${st.narrSig} 层)`);
|
|
|
+ $('#magic-badge').hidden = false;
|
|
|
+ } else $('#magic-badge').hidden = true;
|
|
|
+ // 行动条
|
|
|
+ this.refreshActions();
|
|
|
+ this.refreshAutoButtons();
|
|
|
+ // 转生面板
|
|
|
+ this.refreshRebirth();
|
|
|
+ // 升级按钮状态(价格变化)
|
|
|
+ this.refreshUpgradeButtons();
|
|
|
+ this.refreshLives();
|
|
|
+ // 主世界 canvas
|
|
|
+ const chF = C.chapterOf(lf);
|
|
|
+ this.scene.update({ chapter: chF, layerFloat: lf, layersPerSec: st.layersPerSec, layerSec: st.layerSec });
|
|
|
+ this.setText('#hud-layer', fmt(Math.floor(lf), { int: true }));
|
|
|
+ this.setText('#hud-sub', `第 ${fmt(Math.floor(lf) + 1, { int: true })} 层 · 距下一层 ${fmtPct(lf - Math.floor(lf), 0)}`);
|
|
|
+ this.html('#hud-meta', `${fmt(st.prod)} 本源/秒 · 约 ${st.minutesPerLayer < 0.01 ? '<0.01' : st.minutesPerLayer.toFixed(2)} 分/层(含跳关) · 跳关 ${fmtPct(st.skipP, 0)}`);
|
|
|
+ document.documentElement.style.setProperty('--plane-c', C.PLANES[s.currentPlane].color);
|
|
|
+ $('.topbar').style.borderTopColor = C.PLANES[s.currentPlane].color;
|
|
|
+ // 里世界
|
|
|
+ if (this.riftRun) this.renderRiftLive();
|
|
|
+ // 引导
|
|
|
+ this.refreshGuide(st);
|
|
|
+ }
|
|
|
+
|
|
|
+ renderHud(st) {
|
|
|
+ const lf = this.s.layer;
|
|
|
+ this.setText('#hud-layer', fmt(Math.floor(lf), { int: true }));
|
|
|
+ this.setText('#hud-sub', `第 ${fmt(Math.floor(lf) + 1, { int: true })} 层 · 距下一层 ${fmtPct(Math.min(0.99, lf - Math.floor(lf)), 0)}`);
|
|
|
+ this.html('#hud-meta', `${fmt(st.prod)} 本源/秒 · 约 ${st.minutesPerLayer < 0.01 ? '<0.01' : st.minutesPerLayer.toFixed(2)} 分/层(含跳关) · 跳关触发率 ${fmtPct(st.skipP, 0)}`);
|
|
|
+ }
|
|
|
+
|
|
|
+ setText(sel, v) { const e = $(sel); if (e && e.textContent !== v) e.textContent = v; }
|
|
|
+ html(sel, v) { const e = $(sel); if (e && this.cache.get(sel) !== v) { e.innerHTML = v; this.cache.set(sel, v); } }
|
|
|
+
|
|
|
+ renderTop(st) {
|
|
|
+ if (!st) st = this.stats || F.computeStats(this.s);
|
|
|
+ const s = this.s;
|
|
|
+ const ch = C.chapterOf(s.layer);
|
|
|
+ const t = s.escaped ? (s.escapedT || 0) : null;
|
|
|
+ this.html('#topstats', `
|
|
|
+ <div class="tstat"><span class="k">世界树等级</span><span class="v num">D${s.treeLv}</span></div>
|
|
|
+ <div class="tstat optional"><span class="k">回归</span><span class="v num">${s.rebirths}</span></div>
|
|
|
+ <div class="tstat optional"><span class="k">位面</span><span class="v">${C.PLANES[s.currentPlane].tier} · ${C.PLANES[s.currentPlane].name}</span></div>
|
|
|
+ <div class="tstat"><span class="k">当前章节</span><span class="v">${s.escaped ? '已冲出空洞' : C.CHAPTERS[ch].title}</span></div>`);
|
|
|
+ }
|
|
|
+
|
|
|
+ renderLeft() {
|
|
|
+ const s = this.s;
|
|
|
+ this.html('#resources', `
|
|
|
+ <div class="panel-title">资源 · ${C.PLANES[s.currentPlane].essence}</div>
|
|
|
+ <div class="res-row">
|
|
|
+ <div class="res"><div class="k"><span class="dot"></span>本源 <span style="font-size:10px;color:var(--muted-2)">· 本轮</span></div>
|
|
|
+ <div class="v num" id="res-essence">0</div><div class="d" id="res-essence-rate">0 / 秒</div></div>
|
|
|
+ <div class="res"><div class="k"><span class="dot gold"></span>时间结晶 <span style="font-size:10px;color:var(--muted-2)">· 永久</span></div>
|
|
|
+ <div class="v num" id="res-crystal">0</div><div class="d" id="res-crystal-rate">转生结算,永久</div></div>
|
|
|
+ </div>`);
|
|
|
+ this.renderMainline();
|
|
|
+ this.renderUpgrades();
|
|
|
+ }
|
|
|
+
|
|
|
+ renderMainline() {
|
|
|
+ const s = this.s;
|
|
|
+ const ch = s.escaped ? 5 : C.chapterOf(s.layer);
|
|
|
+ const info = C.CHAPTERS[ch];
|
|
|
+ const prog = Math.min(1, s.layer / C.TOTAL_LAYERS);
|
|
|
+ const marks = C.CHAPTERS.slice(1).map((c) => {
|
|
|
+ const pct = (c.at / C.TOTAL_LAYERS) * 100;
|
|
|
+ return `<div class="mark ${s.layer >= c.at ? 'done' : ''}" style="left:${pct}%"><span>${c.short}</span></div>`;
|
|
|
+ }).join('');
|
|
|
+ let guide = '';
|
|
|
+ if (!s.flags.guideDone) {
|
|
|
+ const step = this.guideStep();
|
|
|
+ if (step) guide = `<div class="guide" style="margin-bottom:10px"><div class="g">${step}</div><button class="x" data-act="guide-x" title="我知道了">×</button></div>`;
|
|
|
+ }
|
|
|
+ this.html('#mainline', `
|
|
|
+ ${guide}
|
|
|
+ <div class="panel-title">主线 · 逃逸进度 <span class="tag">${fmtPct(prog, 2)}</span></div>
|
|
|
+ <div class="chapter">
|
|
|
+ <div class="ch-title"><span class="idx">CH.${ch + 1} / 6</span>${s.escaped ? '冲出空洞 · 自由轮回' : info.title}</div>
|
|
|
+ <div class="ch-desc">${s.escaped ? `空洞已被甩在身后。你已完成 ${s.escapeCount || 1} 次逃逸;禅定循环将继续为你累积自由轮回加成(×${C.freedomMul(s).toFixed(2)})。` : info.desc}</div>
|
|
|
+ </div>
|
|
|
+ <div class="esc-track">
|
|
|
+ <div class="esc-bar"><div class="fill" style="width:${(prog * 100).toFixed(2)}%"></div>${marks}</div>
|
|
|
+ <span>第 ${fmt(Math.floor(s.layer), { int: true })} / 1000 层</span><span>${s.escaped ? '已抵达' : '目标:冲出空洞'}</span>
|
|
|
+ </div>`);
|
|
|
+ }
|
|
|
+
|
|
|
+ guideStep() {
|
|
|
+ const s = this.s;
|
|
|
+ if (s.playSec < 12) return '世界树正在沿连续空间行军。<b>本源</b>在持续生长,先点「升级根须」让它长得更快。';
|
|
|
+ if (s.rebirths === 0 && s.layer < 10) return '推进速度在加深后放缓。<b>本源</b>够了就买「根须」:产出 ×1.10、推进 ×5%。';
|
|
|
+ if (s.rebirths === 0 && s.layer >= 10) return '本节快到顶了——点右侧 <b>「回溯」</b>炼化时间结晶,下一次轮回会更快。';
|
|
|
+ if (s.planes[0].explore < 100 && !s.flags.riftDone2) return '时空裂缝已开启:去 <b>里世界</b> 打一局(约 1~5 分钟),用探索度锚定位面。';
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ refreshGuide(st) {
|
|
|
+ // 小步骤完成标记后自动消失
|
|
|
+ if (this.s.flags.guideDone) return;
|
|
|
+ const step = this.guideStep();
|
|
|
+ const g = $('#mainline .guide .g');
|
|
|
+ if (!step) { const el = $('#mainline .guide'); if (el) el.remove(); return; }
|
|
|
+ if (!g) { this.renderMainline(); return; }
|
|
|
+ if (g.innerHTML !== step) g.innerHTML = step;
|
|
|
+ }
|
|
|
+
|
|
|
+ renderUpgrades() {
|
|
|
+ const s = this.s;
|
|
|
+ const rows = C.UPGRADE_KINDS.map((k) => {
|
|
|
+ const c = C.COST[k];
|
|
|
+ const lv = s.upgrades[k] || 0;
|
|
|
+ const ic = k === 'root' ? I.tree() : I.canopy();
|
|
|
+ return `<div class="upg">
|
|
|
+ <div class="ic">${ic}</div>
|
|
|
+ <div class="info"><div class="n"><span>${c.name}</span><span class="lv">Lv ${lv}</span></div><div class="d" data-desc="${k}">${this.upgradeDesc(k, lv)}</div></div>
|
|
|
+ <button class="buy" data-act="upg" data-k="${k}" id="buy-${k}"><span class="c" id="cost-${k}">—</span><span class="n2">点击购买</span></button>
|
|
|
+ </div>`;
|
|
|
+ }).join('');
|
|
|
+ this.html('#upgrades', `<div class="panel-title">本轮升级</div>${rows}`);
|
|
|
+ }
|
|
|
+
|
|
|
+ upgradeDesc(k, lv) {
|
|
|
+ if (k === 'root') return `产出 <b>×${C.rootProdMul(lv + BATCH / 2).toFixed(2)}</b> · 推进速度 <b>×${C.rootSpeedMul(lv).toFixed(2)}</b>`;
|
|
|
+ return `跳关触发率 <b>${fmtPct(C.canopySkip(lv), 1)}</b>(每级 +1.2%,封顶 60%)`;
|
|
|
+ }
|
|
|
+
|
|
|
+ refreshUpgradeButtons() {
|
|
|
+ const s = this.s;
|
|
|
+ for (const k of C.UPGRADE_KINDS) {
|
|
|
+ const btn = $('#buy-' + k);
|
|
|
+ if (!btn) continue;
|
|
|
+ const lv = s.upgrades[k] || 0;
|
|
|
+ const n = C.maxAffordable(k, lv, s.essence * 0.9);
|
|
|
+ const cost = C.batchCost(k, lv, n);
|
|
|
+ const can = n > 0;
|
|
|
+ btn.disabled = !can;
|
|
|
+ btn.classList.toggle('ok', can);
|
|
|
+ btn.classList.toggle('pulse', can && lv === 0);
|
|
|
+ this.setText('#cost-' + k, can ? `${n} 级 · ${fmt(cost)}` : `${fmt(C.costOf(k, lv))}`);
|
|
|
+ const d = $(`#upgrades [data-desc="${k}"]`);
|
|
|
+ if (d) { const v = this.upgradeDesc(k, lv); if (d.innerHTML !== v) d.innerHTML = v; }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ refreshLives() {
|
|
|
+ const s = this.s;
|
|
|
+ if (!this.lifeEls) {
|
|
|
+ const raceHead = (r) => `<div class="race-head"><span class="chip" style="background:${C.RACES[r].color}">${r}</span><span style="font-weight:500;letter-spacing:0;text-transform:none">${C.RACES[r].bond.split(':')[0]}</span><span class="bond" id="bond-${r}"></span></div>`;
|
|
|
+ const lifeRow = (l) => `<div class="life" data-life="${l.id}" id="life-${l.id}"><div class="ic">${lifeIcon(l.icon)}</div><div class="info"><div class="n"><span>${l.name}</span><span class="lv" id="life-desc-${l.id}"></span></div><div class="s">${l.skill}</div></div><button class="buy" data-act="life" data-id="${l.id}" id="life-buy-${l.id}"><span class="c"></span></button></div>`;
|
|
|
+ const block = (r) => `<div class="race-block">${raceHead(r)}${C.LIVES.filter((l) => l.race === r).map(lifeRow).join('')}</div>`;
|
|
|
+ this.html('#lives', `<div class="panel-title">兵种 · 常驻跑道</div>${block('生命')}${block('星穹')}${block('虚空')}`);
|
|
|
+ this.lifeEls = true;
|
|
|
+ this.lifeEls = true;
|
|
|
+ }
|
|
|
+ const sk = F.lifeSkill(s);
|
|
|
+ const bondN = sk.stacks;
|
|
|
+ for (const r of Object.keys(C.RACES)) {
|
|
|
+ const el = $('#bond-' + r);
|
|
|
+ if (el) {
|
|
|
+ const txt = r === '虚空' ? `跳关 +${(bondN[r] * C.RACE_SKIP_BONUS * 100).toFixed(0)}%` : `×${Math.pow(1.3, bondN[r]).toFixed(2)}`;
|
|
|
+ if (el.textContent !== txt) el.textContent = txt;
|
|
|
+ el.classList.toggle('on', bondN[r] > 0);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ C.LIVES.forEach((l, i) => {
|
|
|
+ const row = $('#life-' + l.id);
|
|
|
+ if (!row) return;
|
|
|
+ const unlocked = F.lifeUnlocked(s, i);
|
|
|
+ const lv = s.lives[l.id] || 0;
|
|
|
+ row.classList.toggle('locked', !unlocked);
|
|
|
+ this.setText('#life-desc-' + l.id, unlocked ? `Lv ${lv}` : '未解锁');
|
|
|
+ const btn = $('#life-buy-' + l.id);
|
|
|
+ const cost = F.lifeCost(s, l.id);
|
|
|
+ const can = unlocked && s.essence >= cost;
|
|
|
+ btn.disabled = !can;
|
|
|
+ btn.classList.toggle('ok', can);
|
|
|
+ btn.innerHTML = unlocked ? `<span class="c">${fmt(cost)}</span><span style="font-size:10px;color:var(--muted)">本源</span>` : `<span class="c" style="color:var(--muted)">锁定</span>`;
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ renderRight() {
|
|
|
+ this.renderRebirthStatic();
|
|
|
+ this.renderPerm();
|
|
|
+ this.renderPlanes();
|
|
|
+ }
|
|
|
+
|
|
|
+ renderRebirthStatic() {
|
|
|
+ this.html('#rebirth', `
|
|
|
+ <div class="panel-title">时间回溯</div>
|
|
|
+ <div class="reb-card">
|
|
|
+ <div class="k">预计炼化</div>
|
|
|
+ <div class="v"><span id="reb-gain">0</span><small>结晶</small></div>
|
|
|
+ <div class="line"><span>本轮深度 <b id="reb-depth">0</b></span><span>回溯代价 <b id="reb-cost">1</b></span><span>收益效率 <b id="reb-eff">—</b></span></div>
|
|
|
+ </div>
|
|
|
+ <div class="actions" style="grid-template-columns:1fr 1fr;margin-top:9px">
|
|
|
+ <button class="act primary" data-act="rebirth" id="btn-rebirth"><span class="t">回溯 ${'<span class="kbd">R</span>'}</span><span class="s" id="reb-sub">炼化时间结晶</span></button>
|
|
|
+ <button class="act" data-act="auto" id="btn-auto"><span class="t">禅定</span><span class="s" id="auto-sub">挂机自动回溯</span></button>
|
|
|
+ </div>
|
|
|
+ <div class="sub-line" style="margin-top:8px"><span>自由轮回加成 <b id="reb-freedom">×1.00</b></span><span>转生衰减 <b id="reb-decay">×1</b></span></div>`);
|
|
|
+ }
|
|
|
+
|
|
|
+ refreshRebirth() {
|
|
|
+ const s = this.s;
|
|
|
+ const st = this.stats || F.computeStats(s);
|
|
|
+ const T = s.maxLayerRound || 0;
|
|
|
+ const gain = st.reward;
|
|
|
+ const cost = C.rebirthCost(T);
|
|
|
+ this.setText('#reb-gain', fmt(gain));
|
|
|
+ this.setText('#reb-depth', fmt(Math.max(T, s.layer || 0), { int: true }));
|
|
|
+ this.setText('#reb-cost', fmt(cost, { int: true }));
|
|
|
+ this.setText('#reb-eff', `×${(gain / Math.max(1, cost)).toFixed(2)}`);
|
|
|
+ const btn = $('#btn-rebirth');
|
|
|
+ btn.classList.toggle('can', gain / Math.max(1, cost) >= 1);
|
|
|
+ const r = F.rebirthFloor(s);
|
|
|
+ const btnS = $('#reb-sub');
|
|
|
+ const sub = s.escaped ? '逃逸完成 · 可自由轮回' : `下一轮回从第 ${fmt(r, { int: true })} 层起飞`;
|
|
|
+ if (btnS.textContent !== sub) btnS.textContent = sub;
|
|
|
+ btn.disabled = (T < 3) || !!s.planeRun;
|
|
|
+ this.setText('#reb-freedom', '×' + C.freedomMul(s).toFixed(2));
|
|
|
+ this.setText('#reb-decay', '×' + Math.pow(0.5, 0).toFixed(0));
|
|
|
+ }
|
|
|
+
|
|
|
+ renderPerm() {
|
|
|
+ const s = this.s;
|
|
|
+ const nextCost = C.treeCost(s.treeLv);
|
|
|
+ const nextProd = C.treeProdMul(s.treeLv + 1) / C.treeProdMul(s.treeLv);
|
|
|
+ const nextSpd = C.treeSpeedMul(s.treeLv + 1) / C.treeSpeedMul(s.treeLv);
|
|
|
+ const relicCost = s.relics.length < 8 ? C.relicCost(s.relics.length) : null;
|
|
|
+ const relics = C.RELICS.map((r, i) => `<div class="relic ${i < s.relics.length ? '' : 'off'}" title="${r.name}:${r.desc}">${relicIcon(r.icon)}</div>`).join('');
|
|
|
+ this.html('#perm', `
|
|
|
+ <div class="panel-title">永久投资 · 时间结晶</div>
|
|
|
+ <div class="perm">
|
|
|
+ <div class="info"><div class="n"><span>世界树等级 <span style="font-size:11px;color:var(--muted);font-weight:500">D${s.treeLv}</span></span></div>
|
|
|
+ <div class="d">产出 ×${nextProd.toFixed(2)} · 速度 ×${nextSpd.toFixed(2)}(永久)</div></div>
|
|
|
+ <button class="buy" data-act="buy-tree" id="buy-tree"><span class="c" id="tree-cost">${fmt(nextCost, { int: true })}</span><span style="font-size:10px;color:var(--muted)">结晶</span></button>
|
|
|
+ </div>
|
|
|
+ <div class="perm">
|
|
|
+ <div class="info"><div class="n"><span>遗物 ${s.relics.length}/8</span></div><div class="d">每件 本源产出 ×1.25(独立乘区)</div>
|
|
|
+ <div class="relics">${relics}</div></div>
|
|
|
+ <button class="buy" data-act="buy-relic" id="buy-relic" ${relicCost == null ? 'disabled' : ''}><span class="c" id="relic-cost">${relicCost == null ? '已收集' : fmt(relicCost, { int: true })}</span><span style="font-size:10px;color:var(--muted)">结晶</span></button>
|
|
|
+ </div>`);
|
|
|
+ }
|
|
|
+
|
|
|
+ refreshPermButtons() {
|
|
|
+ const s = this.s;
|
|
|
+ const tb = $('#buy-tree');
|
|
|
+ if (tb) { const can = s.crystals >= C.treeCost(s.treeLv); tb.disabled = !can; tb.classList.toggle('ok', can); }
|
|
|
+ const rb = $('#buy-relic');
|
|
|
+ if (rb && s.relics.length < 8) { const can = s.crystals >= C.relicCost(s.relics.length); rb.disabled = !can; rb.classList.toggle('ok', can); }
|
|
|
+ }
|
|
|
+
|
|
|
+ renderPlanes() {
|
|
|
+ const s = this.s;
|
|
|
+ const cards = C.PLANES.map((p, i) => {
|
|
|
+ const ex = s.planes[i].explore;
|
|
|
+ const unlocked = C.planeUnlocked(s, i);
|
|
|
+ const tier = C.exploreTierOf(ex);
|
|
|
+ const lock = i > 0 ? C.PLANE_UNLOCK_AT.find((u) => u.plane === i) : null;
|
|
|
+ return `<button class="plane-card ${s.currentPlane === i ? 'cur' : ''} ${unlocked ? '' : 'locked'}" data-act="plane" data-p="${i}" ${unlocked ? '' : 'disabled'}>
|
|
|
+ <span class="tier" style="background:${p.color}">${p.tier}</span>
|
|
|
+ <div class="nm">${p.name}</div>
|
|
|
+ <div class="met">${p.metric} · ${p.essence}</div>
|
|
|
+ <div class="bar"><i style="width:${ex}%;background:${p.color}"></i></div>
|
|
|
+ <div class="ex"><span>探索 ${ex.toFixed(0)}/100 · ${tier.at ? tier.label.split(',')[0] : '未勘探'}</span>${ex >= 100 ? '<span class="an">已锚定</span>' : ''}</div>
|
|
|
+ ${unlocked ? '' : `<div class="ex"><span>需 ${C.PLANES[lock.from].name} 锚定</span></div>`}
|
|
|
+ </button>`;
|
|
|
+ }).join('');
|
|
|
+ const p = C.PLANES[s.currentPlane];
|
|
|
+ this.html('#planes', `<div class="panel-title">位面 · 规则模板</div>
|
|
|
+ <div class="plane-list">${cards}</div>
|
|
|
+ <div class="plane-note"><b>${p.name}规则</b>:${p.rule}<br><b>加成</b>:${p.bonus}</div>`);
|
|
|
+ }
|
|
|
+
|
|
|
+ renderActions() {
|
|
|
+ if (this.actionsKey === 'built') return;
|
|
|
+ this.actionsKey = 'built';
|
|
|
+ const s = this.s;
|
|
|
+ const riftCd = s.riftCdSec || 0;
|
|
|
+ this.html('#actions', `
|
|
|
+ <button class="act primary" data-act="rebirth"><span class="t">回溯 <span class="kbd">R</span></span><span class="s">炼化时间结晶 · 重置本轮</span></button>
|
|
|
+ <button class="act" data-act="rift" id="btn-rift"><span class="t">里世界 <span class="kbd">T</span></span><span class="s" id="rift-sub">${riftCd > 0 ? `冷却 ${Math.ceil(riftCd)} 秒` : '时空裂缝 · 探索位面'}</span></button>
|
|
|
+ <button class="act" data-act="auto" id="btn-auto2"><span class="t">禅定 <span class="kbd">A</span></span><span class="s">${s.autoOn ? `开启 · 每 ${S.autoRebirthEvery(s)} 秒` : '挂机自动回溯'}</span></button>
|
|
|
+ <button class="act" data-act="save"><span class="t">存档</span><span class="s">导出 / 导入 / 重置</span></button>`);
|
|
|
+ }
|
|
|
+
|
|
|
+ refreshAutoButtons() {
|
|
|
+ const s = this.s;
|
|
|
+ for (const id of ['btn-auto', 'btn-auto2']) {
|
|
|
+ const b = $('#' + id);
|
|
|
+ if (!b) continue;
|
|
|
+ b.classList.toggle('primary', !!s.autoOn);
|
|
|
+ b.classList.toggle('can', !s.autoOn && s.rebirths === 0 && s.playSec > 20);
|
|
|
+ }
|
|
|
+ if ($('#auto-sub')) this.setText('#auto-sub', s.autoOn ? `每 ${S.autoRebirthEvery(s)} 秒 · 已开启(点击关闭)` : '挂机时自动回溯');
|
|
|
+ }
|
|
|
+
|
|
|
+ refreshActions() {
|
|
|
+ const s = this.s;
|
|
|
+ const sub = $('#rift-sub');
|
|
|
+ if (sub) { const v = (s.riftCdSec || 0) > 0 ? `冷却 ${Math.ceil(s.riftCdSec)} 秒` : '时空裂缝 · 探索位面'; if (sub.textContent !== v) sub.textContent = v; }
|
|
|
+ const b = $('#btn-rift'); if (b) b.disabled = (s.riftCdSec || 0) > 0;
|
|
|
+ const sub2 = $('#btn-auto2 .s'); if (sub2) { const v = s.autoOn ? `开启 · 每 ${S.autoRebirthEvery(s)} 秒` : '挂机自动回溯'; if (sub2.textContent !== v) sub2.textContent = v; }
|
|
|
+ const a2 = $('#btn-auto2'); if (a2) { a2.classList.toggle('can', !s.autoOn && s.rebirths === 0 && s.playSec > 20); }
|
|
|
+ const cd = $('#plane-cd'); if (cd) { const v = s.planes.filter((p) => p.explore >= 100).length ? `锚定 ${s.planes.filter((p) => p.explore >= 100).length} 处采集中` : '未锚定'; if (cd.textContent !== v) cd.textContent = v; }
|
|
|
+ this.refreshPermButtons();
|
|
|
+ }
|
|
|
+
|
|
|
+ // ───────────── 日志 ─────────────
|
|
|
+ log(text, kind = 'info') {
|
|
|
+ const feed = $('#feed');
|
|
|
+ if (!feed) return;
|
|
|
+ const row = document.createElement('div');
|
|
|
+ row.className = 'row ' + kind;
|
|
|
+ const t = new Date();
|
|
|
+ row.innerHTML = `<time>${String(t.getHours()).padStart(2, '0')}:${String(t.getMinutes()).padStart(2, '0')}:${String(t.getSeconds()).padStart(2, '0')}</time><span>${esc(text)}</span>`;
|
|
|
+ feed.prepend(row);
|
|
|
+ while (feed.children.length > 40) feed.lastChild.remove();
|
|
|
+ }
|
|
|
+
|
|
|
+ toast(text, kind = '') {
|
|
|
+ const el = document.createElement('div');
|
|
|
+ el.className = 'toast ' + kind;
|
|
|
+ el.textContent = text;
|
|
|
+ $('#toasts').appendChild(el);
|
|
|
+ setTimeout(() => { el.style.opacity = '0'; el.style.transition = 'opacity .3s'; setTimeout(() => el.remove(), 320); }, 2400);
|
|
|
+ while ($('#toasts').children.length > 3) $('#toasts').firstChild.remove();
|
|
|
+ }
|
|
|
+
|
|
|
+ // ───────────── 弹窗队列 ─────────────
|
|
|
+ pushDialog(d) {
|
|
|
+ if (d.kind === 'civ' && this.dialog && this.dialog.kind === 'civ') return;
|
|
|
+ this.dialogQueue.push(d);
|
|
|
+ if (!this.modalOpen) this.nextDialog();
|
|
|
+ }
|
|
|
+
|
|
|
+ nextDialog() {
|
|
|
+ const d = this.dialogQueue.shift();
|
|
|
+ if (!d) { this.closeModal(); return; }
|
|
|
+ this.dialog = d;
|
|
|
+ this.openModal(d);
|
|
|
+ }
|
|
|
+
|
|
|
+ beginModal() { this.modalOpen = true; $('#modal-mask').hidden = false; }
|
|
|
+
|
|
|
+ closeModal() {
|
|
|
+ this.modalOpen = false;
|
|
|
+ this.dialog = null;
|
|
|
+ $('#modal-mask').hidden = true;
|
|
|
+ }
|
|
|
+
|
|
|
+ setModal(tag, tagCls, title, bodyHtml, footHtml) {
|
|
|
+ $('#modal-tag').className = 'mtag ' + tagCls;
|
|
|
+ $('#modal-tag').textContent = tag;
|
|
|
+ $('#modal-title').textContent = title;
|
|
|
+ $('#modal-body').innerHTML = bodyHtml;
|
|
|
+ $('#modal-foot').innerHTML = footHtml || '';
|
|
|
+ }
|
|
|
+
|
|
|
+ closeDialog() {
|
|
|
+ this.dialog = null;
|
|
|
+ if (this.dialogQueue.length) this.nextDialog();
|
|
|
+ else this.closeModal();
|
|
|
+ }
|
|
|
+
|
|
|
+ // ───────────── 交互 ─────────────
|
|
|
+ bindKeys() {
|
|
|
+ document.addEventListener('keydown', (e) => {
|
|
|
+ if (e.target && /INPUT|TEXTAREA/.test(e.target.tagName)) return;
|
|
|
+ if (this.riftRun && this.riftRun.state === 'fight' && /^[0-9]$/.test(e.key)) { this.rollRift(+e.key); return; }
|
|
|
+ if (this.riftRun && this.riftRun.state === 'fight' && e.key === 'ArrowRight') { this.rollRift(5); return; }
|
|
|
+ if (this.modalOpen) {
|
|
|
+ if (e.key === 'Escape' && this.dialog && this.dialog.kind !== 'crisis') this.closeDialog();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ const k = e.key.toLowerCase();
|
|
|
+ if (k === 'r') this.doRebirth();
|
|
|
+ else if (k === 't') this.startRift();
|
|
|
+ else if (k === 'a') this.toggleAuto();
|
|
|
+ else if (k === '1') this.buy('root');
|
|
|
+ else if (k === '2') this.buy('canopy');
|
|
|
+ else if (k === 'q' && this.riftRun) this.rollRift(5);
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ bindEvents() {
|
|
|
+ $('#main').addEventListener('click', (e) => {
|
|
|
+ const rb = e.target.closest('[data-r]');
|
|
|
+ if (rb) { this.riftAction(rb.dataset.r, rb.dataset.k, rb.dataset.i); return; }
|
|
|
+ const b = e.target.closest('[data-act]');
|
|
|
+ if (!b) return;
|
|
|
+ const act = b.dataset.act;
|
|
|
+ if (act === 'upg') this.buy(b.dataset.k);
|
|
|
+ else if (act === 'life') this.buyLife(b.dataset.id);
|
|
|
+ else if (act === 'rebirth') this.doRebirth();
|
|
|
+ else if (act === 'auto') this.toggleAuto();
|
|
|
+ else if (act === 'rift') this.startRift();
|
|
|
+ else if (act === 'save') this.openSave();
|
|
|
+ else if (act === 'buy-tree') { if (S.buyTree(this.s)) { this.toast(`世界树升至 D${this.s.treeLv}`, 'good'); this.renderPerm(); } }
|
|
|
+ else if (act === 'buy-relic') { if (S.buyRelic(this.s)) { this.toast('获得遗物:' + C.RELICS[this.s.relics.length - 1].name, 'good'); this.renderPerm(); } this.log(`遗物入手:${C.RELICS[this.s.relics.length - 1] ? C.RELICS[this.s.relics.length - 1].name : ''}`, 'mile'); }
|
|
|
+ else if (act === 'plane') this.switchPlane(+b.dataset.p);
|
|
|
+ else if (act === 'guide-x') { this.s.flags.guideDone = true; this.renderMainline(); this.toast('提示已收起。'); }
|
|
|
+
|
|
|
+ this.saveNow();
|
|
|
+ });
|
|
|
+ $('#modal').addEventListener('click', (e) => {
|
|
|
+ const b = e.target.closest('[data-mact]');
|
|
|
+ if (!b) return;
|
|
|
+ const m = b.dataset.mact;
|
|
|
+ if (m === 'close') this.closeDialog();
|
|
|
+ else if (m === 'crisis') this.answerCrisis(b.dataset.i);
|
|
|
+ else if (m === 'civ') this.answerCiv(+b.dataset.i);
|
|
|
+ else if (m === 'save') this.saveActions(b.dataset.sub);
|
|
|
+ });
|
|
|
+ $('#modal-x').addEventListener('click', () => {
|
|
|
+ if (this.dialog && this.dialog.kind === 'crisis') return;
|
|
|
+ this.closeDialog();
|
|
|
+ });
|
|
|
+ const ts = $('.top-save'); if (ts) ts.addEventListener('click', () => this.openSave());
|
|
|
+ $$('.vp-btn').forEach((b) => b.addEventListener('click', () => {
|
|
|
+ $$('.vp-btn').forEach((x) => x.classList.toggle('on', x === b));
|
|
|
+ document.body.classList.toggle('vp-phone', b.dataset.vp === 'phone');
|
|
|
+ this.scene._resize();
|
|
|
+ }));
|
|
|
+ $$('#tabbar button').forEach((b) => b.addEventListener('click', () => {
|
|
|
+ $$('#tabbar button').forEach((x) => x.classList.toggle('on', x === b));
|
|
|
+ const tab = b.dataset.tab;
|
|
|
+ if (tab === 'rift') { this.startRift(); return; }
|
|
|
+ $$('.main > .col').forEach((c) => c.classList.toggle('active', c.id === 'col-' + tab));
|
|
|
+ $('#main').classList.remove('show-right');
|
|
|
+ this.scene._resize();
|
|
|
+ }));
|
|
|
+ window.addEventListener('beforeunload', () => this.saveNow());
|
|
|
+ document.addEventListener('visibilitychange', () => {
|
|
|
+ if (document.hidden) this.saveNow();
|
|
|
+ else this.checkOffline();
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ buy(kind) {
|
|
|
+ const r = S.buyUpgrade(this.s, kind);
|
|
|
+ if (r) {
|
|
|
+ const el = $('#buy-' + kind);
|
|
|
+ if (el) { el.style.transform = 'scale(.96)'; setTimeout(() => (el.style.transform = ''), 120); }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ buyLife(id) { if (S.buyLife(this.s, id)) this.saveNow(); }
|
|
|
+
|
|
|
+ doRebirth() {
|
|
|
+ const s = this.s;
|
|
|
+ if (s.planeRun) { this.toast('里世界中主世界时间冻结,无法回溯。', 'warn'); return; }
|
|
|
+ if ((s.maxLayerRound || 0) < 3) { this.toast('先让世界树长到第 3 层以上。'); return; }
|
|
|
+ const est = F.rebirthEstimate(s);
|
|
|
+ const r = S.rebirth(s);
|
|
|
+ this.log(`回溯 #${s.rebirths} · 炼化 ${fmt(r.gain)} 结晶 · 种子落在第 ${fmt(r.floor, { int: true })} 层`, 'mile');
|
|
|
+ this.toast(`回溯完成:+${fmt(r.gain)} 时间结晶`, 'good');
|
|
|
+ if (r.event) this.pushDialog({ kind: 'milestone', data: r.event });
|
|
|
+ this.renderLeft(); this.renderRight(); this.renderDynamic();
|
|
|
+ this.saveNow();
|
|
|
+ }
|
|
|
+
|
|
|
+ toggleAuto() {
|
|
|
+ const s = this.s;
|
|
|
+ s.autoOn = !s.autoOn;
|
|
|
+ this.toast(s.autoOn ? `禅定开启:每 ${S.autoRebirthEvery(s)} 秒自动回溯` : '禅定关闭:手动决定回溯时机', s.autoOn ? 'good' : '');
|
|
|
+ this.renderActions(); this.renderDynamic();
|
|
|
+ this.saveNow();
|
|
|
+ }
|
|
|
+
|
|
|
+ switchPlane(p) {
|
|
|
+ if (p === this.s.currentPlane) return;
|
|
|
+ if (S.switchPlane(this.s, p)) {
|
|
|
+ this.log(`切换位面:${C.PLANES[p].name} —— ${C.PLANES[p].rule}`, 'mile');
|
|
|
+ this.toast(`进入${C.PLANES[p].name}:${C.PLANES[p].bonus}`);
|
|
|
+ this.renderLeft(); this.renderRight(); this.renderDynamic();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // ───────────── 事件弹窗 ─────────────
|
|
|
+ showCrisis() {
|
|
|
+ const s = this.s;
|
|
|
+ const ev = CRISIS_EVENTS[(s.escapeCount || 0 + s.rebirths) % CRISIS_EVENTS.length];
|
|
|
+ const left = Math.max(0, Math.ceil((s.crisis.popUntil || 0)));
|
|
|
+ this.setModal('危机事件', 'crisis', ev.title,
|
|
|
+ `<p>${esc(ev.text)}</p><p class="cd">侵蚀前沿正在逼近:<b id="crisis-cd">${left}</b> 秒内不响应,前沿将吞没 3 层根系并压低产出。</p>
|
|
|
+ <div class="opts">${ev.options.map((o, i) => `<button class="opt" data-mact="crisis" data-i="${o.effect}"><div class="l">${esc(o.label)}</div><div class="h">${esc(o.hint)}</div></button>`).join('')}</div>`);
|
|
|
+ this.crisisTimer = setInterval(() => {
|
|
|
+ const e = $('#crisis-cd');
|
|
|
+ const l = Math.max(0, Math.ceil((this.s.crisis.popUntil || 0)));
|
|
|
+ if (e) e.textContent = l;
|
|
|
+ if (l <= 0 || !this.s.crisis.active) { clearInterval(this.crisisTimer); if (this.dialog && this.dialog.kind === 'crisis') this.closeDialog(); }
|
|
|
+ }, 1000);
|
|
|
+ }
|
|
|
+
|
|
|
+ answerCrisis(effect) {
|
|
|
+ const t = S.crisisRespond(this.s, effect);
|
|
|
+ clearInterval(this.crisisTimer);
|
|
|
+ if (t) { this.log('危机响应:' + t, 'crisis'); this.toast(t, 'warn'); }
|
|
|
+ this.closeDialog();
|
|
|
+ }
|
|
|
+
|
|
|
+ showCiv(idx) {
|
|
|
+ const ev = CIV_EVENTS[idx];
|
|
|
+ const stage = C.CHAPTERS[C.chapterOf(this.s.layer)].short;
|
|
|
+ this.setModal(`文明事件 · ${stage}`, 'civ', ev.title,
|
|
|
+ `<p>${esc(ev.text)}</p><div class="opts">${ev.opts.map((o, i) => `<button class="opt" data-mact="civ" data-i="${i}"><div class="l">${esc(o.label)}</div><div class="h">${esc(o.hint)}</div></button>`).join('')}</div>`);
|
|
|
+ }
|
|
|
+
|
|
|
+ answerCiv(i) {
|
|
|
+ const t = S.civChoose(this.s, this.dialog.civIdx, i);
|
|
|
+ if (t) { this.log(`文明事件:${CIV_EVENTS[this.dialog.civIdx].title} —— ${t}`, 'mile'); this.toast(t, 'good'); }
|
|
|
+ this.closeDialog();
|
|
|
+ this.renderRight();
|
|
|
+ }
|
|
|
+
|
|
|
+ showMilestone(d) {
|
|
|
+ this.setModal('里程碑', 'mile', d.title || '里程碑', `<p>${esc(d.text || '')}</p>`,
|
|
|
+ `<button class="btn" data-mact="close">继续前行</button>`);
|
|
|
+ this.log(`【${d.title || '里程碑'}】${d.text || ''}`, 'mile');
|
|
|
+ }
|
|
|
+
|
|
|
+ openModal(d) {
|
|
|
+ this.beginModal();
|
|
|
+ if (d.kind === 'crisis') this.showCrisis();
|
|
|
+ else if (d.kind === 'civ') this.showCiv(d.civIdx);
|
|
|
+ else if (d.kind === 'milestone') this.showMilestone(d.data);
|
|
|
+ else if (d.kind === 'save') this.showSave(this._saveSub);
|
|
|
+ else if (d.kind === 'offline') this.showOffline(d.data);
|
|
|
+ else if (d.kind === 'riftResult') this.showRiftResult(d.data);
|
|
|
+ }
|
|
|
+
|
|
|
+ // ───────────── 存档 ─────────────
|
|
|
+ saveNow() { S.save.write(localStorage, this.s, this.riftRun ? { run: this.riftRun } : null); }
|
|
|
+
|
|
|
+ openSave() { this._saveSub = null; this.dialogQueue.push({ kind: 'save' }); if (!this.modalOpen) this.nextDialog(); }
|
|
|
+
|
|
|
+ showSave(sub) {
|
|
|
+ this._saveSub = sub || null;
|
|
|
+ const s = this.s;
|
|
|
+ if (sub === 'export') {
|
|
|
+ const txt = S.save.serialize(s, this.riftRun ? { run: this.riftRun } : null);
|
|
|
+ this.setModal('存档', '', '导出存档', `<p style="margin-top:0">复制下面的 JSON 字符串保存。导入时粘贴即可恢复(含本轮进度与里世界局内状态)。</p><textarea id="save-text" readonly>${esc(txt)}</textarea>`,
|
|
|
+ `<button class="btn ghost" data-mact="save" data-sub="">返回</button><button class="btn" id="copy-save">复制</button>`);
|
|
|
+ setTimeout(() => {
|
|
|
+ const ta = $('#save-text');
|
|
|
+ const btn = $('#copy-save');
|
|
|
+ const done = () => { btn.textContent = '已复制 ✓'; this.toast('存档已复制到剪贴板', 'good'); };
|
|
|
+ btn.onclick = () => {
|
|
|
+ ta.select();
|
|
|
+ if (navigator.clipboard && navigator.clipboard.writeText) navigator.clipboard.writeText(txt).then(done, () => { document.execCommand('copy'); done(); });
|
|
|
+ else { document.execCommand('copy'); done(); }
|
|
|
+ };
|
|
|
+ }, 0);
|
|
|
+ } else if (sub === 'import') {
|
|
|
+ this.setModal('存档', '', '导入存档', `<p style="margin-top:0">粘贴之前导出的 JSON。非法存档会被拒绝,不会覆盖当前进度。</p><textarea id="save-in" placeholder='{"v":1,"state":{...}}'></textarea><div id="save-msg" style="font-size:12px;color:var(--muted);margin-top:6px"></div>`,
|
|
|
+ `<button class="btn ghost" data-mact="save" data-sub="">返回</button><button class="btn" id="do-import">导入并覆盖</button>`);
|
|
|
+ setTimeout(() => {
|
|
|
+ $('#do-import').onclick = () => {
|
|
|
+ const r = S.save.parse($('#save-in').value);
|
|
|
+ const msg = $('#save-msg');
|
|
|
+ if (!r.ok) { msg.style.color = 'var(--danger)'; msg.textContent = '导入失败:' + r.error; return; }
|
|
|
+ S.save.write(localStorage, r.data.state, r.data.rift);
|
|
|
+ if (window.__wt && window.__wt !== this) { location.reload(); return; }
|
|
|
+ msg.style.color = 'var(--life)'; msg.textContent = '导入成功,正在恢复…';
|
|
|
+ setTimeout(() => location.reload(), 120);
|
|
|
+ };
|
|
|
+ }, 0);
|
|
|
+ } else if (sub === 'reset') {
|
|
|
+ this.setModal('存档', '', '硬重置', `<p style="margin-top:0">将清空本地存档并重新开始,<b>不可撤销</b>。确定要这样做吗?</p>`,
|
|
|
+ `<button class="btn ghost" data-mact="save" data-sub="">取消</button><button class="btn" id="do-reset" style="background:#c0492e;border-color:#c0492e">确认清空</button>`);
|
|
|
+ setTimeout(() => { $('#do-reset').onclick = () => { S.save.clear(localStorage); location.reload(); }; }, 0);
|
|
|
+ } else {
|
|
|
+ const info = S.save.load(localStorage);
|
|
|
+ let when = '尚未存档';
|
|
|
+ try { const raw = JSON.parse(localStorage.getItem(C.SAVE_KEY) || '{}'); when = raw.t ? new Date(raw.t).toLocaleString() : when; } catch (e) { /* ignore */ }
|
|
|
+ this.setModal('存档', '', '存档管理',
|
|
|
+ `<p style="margin-top:0">自动存档:关键操作后 + 每 30 秒 + 关闭页面前。上次保存:<b>${esc(when)}</b>。</p>
|
|
|
+ <div class="opts">
|
|
|
+ <button class="opt" data-mact="save" data-sub="export"><div class="l">导出存档</div><div class="h">生成 JSON 字符串供复制备份</div></button>
|
|
|
+ <button class="opt" data-mact="save" data-sub="import"><div class="l">导入存档</div><div class="h">粘贴 JSON 恢复进度(校验非法输入)</div></button>
|
|
|
+ <button class="opt" data-mact="save" data-sub="reset"><div class="l" style="color:var(--danger)">硬重置</div><div class="h">清空存档,二次确认</div></button>
|
|
|
+ </div>`, `<button class="btn ghost" data-mact="close">关闭</button>`);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ saveActions(sub) {
|
|
|
+ if (sub) { this.showSave(sub); return; }
|
|
|
+ this.showSave(null);
|
|
|
+ }
|
|
|
+
|
|
|
+ showOffline(o) {
|
|
|
+ this.setModal('离线收益', '', '你不在的这段时间', `<p style="margin-top:0">离线 <b>${esc(fmtTime(o.sec))}</b>(上限 8 小时,效率 60%)。世界树自己长了一段:</p>
|
|
|
+ <div class="res-row"><div class="res"><div class="k">本源</div><div class="v num">+${fmt(o.essence)}</div></div><div class="res"><div class="k">层数</div><div class="v num">${fmt(o.fromLayer, { int: true })} → ${fmt(o.toLayer, { int: true })}</div></div></div>`,
|
|
|
+ `<button class="btn" data-mact="close">收下</button>`);
|
|
|
+ }
|
|
|
+
|
|
|
+ checkOffline() {
|
|
|
+ // 页面重新可见时按真实时间补算(离线只结算主世界)
|
|
|
+ const now = Date.now();
|
|
|
+ if (!this._lastTickAt) { this._lastTickAt = now; return; }
|
|
|
+ const gap = (now - this._lastTickAt) / 1000;
|
|
|
+ this._lastTickAt = now;
|
|
|
+ if (gap > 60 && !this.s.escaped) {
|
|
|
+ const o = S.applyOffline(this.s, gap, this.riftRun ? { run: this.riftRun } : null);
|
|
|
+ if (o && !o.skipped) { this.lastFrame = performance.now(); this.pushDialog({ kind: 'offline', data: o }); this.renderAll(); }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // ───────────── 里世界 ─────────────
|
|
|
+ startRift() {
|
|
|
+ const s = this.s;
|
|
|
+ if (this.riftRun && this.riftRun.state !== 'result') { this.showTab('center'); this.toast('里世界进行中:主世界已冻结。'); return; }
|
|
|
+ const run = S.startRift(s);
|
|
|
+ if (!run) { this.toast(`时空裂缝冷却中:${Math.ceil(s.riftCdSec)} 秒`, 'warn'); return; }
|
|
|
+ this.riftRun = run;
|
|
|
+ this.log(`进入里世界(${C.PLANES[s.currentPlane].name} · ${C.PLANES[s.currentPlane].tier})`, 'rift');
|
|
|
+ this.showTab('center');
|
|
|
+ this.renderRiftPanel();
|
|
|
+ this.saveNow();
|
|
|
+ }
|
|
|
+
|
|
|
+ showTab(tab) {
|
|
|
+ $$('#tabbar button').forEach((x) => x.classList.toggle('on', x.dataset.tab === tab));
|
|
|
+ $$('.main > .col').forEach((c) => c.classList.toggle('active', c.id === 'col-' + tab));
|
|
|
+ if (window.innerWidth > 760) { $$('.main > .col').forEach((c) => c.classList.add('active')); }
|
|
|
+ requestAnimationFrame(() => this.scene._resize());
|
|
|
+ }
|
|
|
+
|
|
|
+ renderRiftPanel() {
|
|
|
+ const r = this.riftRun;
|
|
|
+ const slot = $('#rift-slot');
|
|
|
+ const wrap = $('#canvas-wrap');
|
|
|
+ if (!r || r.state === 'result') { slot.hidden = true; slot.innerHTML = ''; wrap.hidden = false; $('.actions').hidden = false; this.riftPanelKey = null; return; }
|
|
|
+ slot.hidden = false; wrap.hidden = true; $('.actions').hidden = true;
|
|
|
+ if (!slot.querySelector('#rift-live')) slot.innerHTML = '<div class="panel rift-panel" id="rift-live"></div>';
|
|
|
+ const panel = slot.querySelector('#rift-live');
|
|
|
+ const key = r.state + ':' + r.step + ':' + (r.buildDone ? 1 : 0);
|
|
|
+ if (this.riftPanelKey === key) return;
|
|
|
+ this.riftPanelKey = key;
|
|
|
+ const env = C.RIFT_ENVS[r.plane];
|
|
|
+ if (r.state === 'build') {
|
|
|
+ const left = R.pointsLeft(r);
|
|
|
+ const slots = R.RULES.map((k) => {
|
|
|
+ const v = r.attrs[k]; const cap = r.available[k];
|
|
|
+ return `<div class="slot"><div class="h"><span style="color:${C.RULE_COLORS[k]}">${R.RULE_NAME[k]}</span><span style="color:var(--muted)">${v}/${cap}</span></div>
|
|
|
+ <div class="v">${v}</div>
|
|
|
+ <div class="stepper"><button data-r="and" data-k="${k}">+</button><button data-r="sub" data-k="${k}">−</button></div></div>`;
|
|
|
+ }).join('');
|
|
|
+ panel.innerHTML = `<div class="rift-head"><span class="elite-tag" style="background:${env.color}">里世界 · ${C.PLANES[r.plane].tier}</span><span class="nm">${env.name}</span><span class="kb">规则浓度 ×${r.density.toFixed(2)}</span></div>
|
|
|
+ <div style="font-size:12px;color:var(--muted)">${env.desc}</div>
|
|
|
+ <div class="build-hint">开局分配规则(本源点):剩余 <b>${left}</b> / ${r.budget}——规则总和越高,你可以调动的战力越多,同时敌人的威胁 = 你的规则总和。</div>
|
|
|
+ <div class="slot-bar">${slots}</div>
|
|
|
+ <div style="font-size:11px;color:var(--muted);margin-top:10px;line-height:1.6">知识 → 攻击 +1.5 誓约 → 生命 +4(最大项时首击豁免)<br>信念 → 生命 +1.5(最大项时每次受击回 0.5×信念) 裁决 → 攻击 +2(并额外削敌)</div>
|
|
|
+ <div style="display:grid;grid-template-columns:1fr 96px;gap:8px;margin-top:10px">
|
|
|
+ <button class="btn" data-r="build">进入 ${env.name}</button><button class="btn danger" data-r="abandon">放弃本局</button>
|
|
|
+ </div>`;
|
|
|
+ } else if (r.state === 'event') {
|
|
|
+ const m = r.mouth;
|
|
|
+ panel.innerHTML = `<div class="rift-head"><span class="elite-tag" style="background:${env.color}">奇遇 · 第 ${r.step + 1}/6 幕</span><span class="nm">${esc(m.title)}</span></div>
|
|
|
+ <div class="step-dots">${Array.from({ length: R.ENCOUNTERS }, (_, i) => `<i class="${i < r.step ? 'past' : i === r.step ? 'now' : ''}"></i>`).join('')}</div>
|
|
|
+ <div class="taunt">${esc(m.text)}</div>
|
|
|
+ <div class="card-opts">${m.opts.map((o) => `<button class="opt" data-r="opt" data-i="${o.j}"><div class="l">${esc(o.label)}</div><div class="h">${esc(o.hint)}</div></button>`).join('')}</div>
|
|
|
+ <div class="kv">${this.riftKv(r)}</div>`;
|
|
|
+ } else if (r.state === 'fight' || r.state === 'run') {
|
|
|
+ const m = r.mouth;
|
|
|
+ const hp = R.hpMaxOf(r), hpm = Math.max(0, r.hp);
|
|
|
+ const atk = R.atkOf(r);
|
|
|
+ const kindTag = m.type === 'boss' ? '<span class="elite-tag boss">终局</span>' : m.type === 'elite' ? '<span class="elite-tag">精英</span>' : '<span class="elite-tag" style="background:var(--muted)">战斗</span>';
|
|
|
+ const hints = [0, 1, 2, 3, 4, 5].map((k) => {
|
|
|
+ const v = Math.round(atk + k);
|
|
|
+ const cls = v >= m.threat * 1.75 ? 'crit-hint' : v > m.threat ? 'hint' : '';
|
|
|
+ return `<button class="roll-btn ${cls}" data-r="roll" data-k="${k}">${v}<div style="font-size:9px;font-weight:500;color:var(--muted)">+${k}</div></button>`;
|
|
|
+ }).join('');
|
|
|
+ const last = m.lastLog;
|
|
|
+ panel.innerHTML = `<div class="rift-head"><span class="elite-tag" style="background:${env.color}">${env.name} · 第 ${r.step + 1}/6 幕</span><span class="nm">${esc(m.name)}</span>${kindTag}</div>
|
|
|
+ <div class="taunt">“${esc(m.taunt)}”</div>
|
|
|
+ <div class="hpbar enemy"><i style="width:${(m.hp / m.hpMax * 100).toFixed(1)}%"></i><div class="txt">${fmt(m.hp, { int: true })} / ${fmt(m.hpMax, { int: true })}</div></div>
|
|
|
+ <div class="fight-grid">
|
|
|
+ <div class="box"><div class="k">敌人威胁 pK(拼招需 > pK,超杀 ≥ ×1.75)</div><div class="v">${m.threat}</div></div>
|
|
|
+ <div class="box enemy"><div class="k">你的生命 / 攻击</div><div class="v">${fmt(hpm, { int: true })}<span style="font-size:13px;color:var(--muted)"> / ${fmt(atk, { int: true })}</span></div></div>
|
|
|
+ </div>
|
|
|
+ <div class="roll-bar">${hints}</div>
|
|
|
+ <div style="font-size:10.5px;color:var(--muted-2);margin-top:4px">点击数字 = 挥剑(结果 = 攻击 + 临时战意 0..5;方向键/数字键也可)· <b>Q</b> 全力 5</div>
|
|
|
+ ${last ? `<div class="log3">上一剑:<b>${({ block: '阻断', win: '拼招', crit: '超杀' })[last.res]}</b> ${last.value} vs ${last.threat} 敌人 −${last.dmg},自己 −${last.back}</div>` : `<div class="log3">选择你的战意:拼招(> pK)削敌、超杀(≥1.75×pK)重创并自伤更少,阻断(≤ pK)会被格挡。</div>`}
|
|
|
+ <div class="kv">${this.riftKv(r)}</div>
|
|
|
+ <div style="display:flex;gap:8px;margin-top:8px"><button class="btn ghost" style="flex:1" data-r="abandon">撤退(结算本局)</button></div>`;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ riftKv(r) {
|
|
|
+ const stepDots = Array.from({ length: R.ENCOUNTERS }, (_, i) => `<i class="${i < r.step ? 'past' : i === r.step ? 'now' : ''}"></i>`).join('');
|
|
|
+ return `<div>连击/分<b>${r.score}</b></div><div>生命<b>${Math.max(0, Math.round(r.hp))}/${R.hpMaxOf(r)}</b></div><div>攻击<b>${Math.round(R.atkOf(r))}</b></div><div>能量<b>${Math.round(r.energy)}</b></div><div>步数<b>${r.step + 1}/6</b></div>`;
|
|
|
+ }
|
|
|
+
|
|
|
+ renderRiftLive() {
|
|
|
+ const r = this.riftRun;
|
|
|
+ if (!r) return;
|
|
|
+ this.renderRiftPanel();
|
|
|
+ const panel = $('#rift-live');
|
|
|
+ if (!panel || panel.hidden) return;
|
|
|
+ // 战斗中动态部分
|
|
|
+ if ((r.state === 'fight' || r.state === 'run') && r.mouth) {
|
|
|
+ const bar = panel.querySelector('.hpbar.enemy');
|
|
|
+ if (bar) { bar.querySelector('i').style.width = (r.mouth.hp / r.mouth.hpMax * 100).toFixed(1) + '%'; bar.querySelector('.txt').textContent = `${fmt(r.mouth.hp, { int: true })} / ${fmt(r.mouth.hpMax, { int: true })}`; }
|
|
|
+ const kv = panel.querySelector('.kv');
|
|
|
+ if (kv) kv.innerHTML = this.riftKv(r);
|
|
|
+ }
|
|
|
+ if (r.state === 'event' && r.mouth) {
|
|
|
+ const dots = panel.querySelector('.step-dots');
|
|
|
+ if (dots) dots.innerHTML = Array.from({ length: R.ENCOUNTERS }, (_, i) => `<i class="${i < r.step ? 'past' : i === r.step ? 'now' : ''}"></i>`).join('');
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ riftAction(act, k, i) {
|
|
|
+ if (act === 'and') this.stepRiftInput(k, 1);
|
|
|
+ else if (act === 'sub') this.stepRiftInput(k, -1);
|
|
|
+ else if (act === 'build') this.riftBuild();
|
|
|
+ else if (act === 'abandon') this.confirmAbandon();
|
|
|
+ else if (act === 'opt') this.riftOption(+i);
|
|
|
+ else if (act === 'roll') this.rollRift(+k);
|
|
|
+ }
|
|
|
+
|
|
|
+ confirmAbandon() {
|
|
|
+ const r = this.riftRun;
|
|
|
+ if (!r) return;
|
|
|
+ if (r.state === 'build') { this.abandonRift(); return; }
|
|
|
+ this.setModal('里世界', 'rift', '撤退确认', `<p style="margin-top:0">提前离开本局:按当前进度结算探索碎片(失败也有价值),主世界时间随即恢复。</p>`, `<button class="btn ghost" data-mact="close">继续探索</button><button class="btn" data-mact="save" data-sub="__abandon" id="btn-abandon-ok">确认撤退</button>`);
|
|
|
+ setTimeout(() => { const b = $('#btn-abandon-ok'); if (b) b.onclick = () => { this.closeModal(); this.abandonRift(); }; }, 0);
|
|
|
+ }
|
|
|
+
|
|
|
+ stepRiftInput(k, dir) {
|
|
|
+ const r = this.riftRun;
|
|
|
+ if (!r || r.state !== 'build') return;
|
|
|
+ const cap = r.available[k];
|
|
|
+ if (dir > 0) { if (r.attrs[k] < cap && R.pointsLeft(r) > 0) r.attrs[k]++; }
|
|
|
+ else { if (r.attrs[k] > 1) r.attrs[k]--; }
|
|
|
+ this.riftPanelKey = null;
|
|
|
+ this.renderRiftPanel();
|
|
|
+ }
|
|
|
+
|
|
|
+ riftBuild() {
|
|
|
+ const r = this.riftRun;
|
|
|
+ if (!R.buildDone(r, 0)) { this.toast(`还剩 ${R.pointsLeft(r)} 点规则未分配(每项至少 1).`, 'warn'); return; }
|
|
|
+ this.riftPanelKey = null; this.renderRiftPanel(); this.saveNow();
|
|
|
+ }
|
|
|
+
|
|
|
+ riftOption(j) {
|
|
|
+ const r = this.riftRun;
|
|
|
+ const res = R.applyOption(r, j);
|
|
|
+ if (!res) return;
|
|
|
+ this.toast(res.msg || '');
|
|
|
+ if (res.cleared) this.finishRift();
|
|
|
+ this.riftPanelKey = null; this.renderRiftPanel(); this.saveNow();
|
|
|
+ }
|
|
|
+
|
|
|
+ rollRift(k) {
|
|
|
+ const r = this.riftRun;
|
|
|
+ if (!r || r.state !== 'fight') return;
|
|
|
+ const res = R.slash(r, k);
|
|
|
+ if (!res) return;
|
|
|
+ const a = R.afterSlash(r, res);
|
|
|
+ const label = { block: '阻断 — 被封挡', win: '拼招 — 命中', crit: '超杀 — 重创' }[res.res];
|
|
|
+ this.log(`里世界:${label}(${res.value} vs ${res.threat})`, 'rift');
|
|
|
+ if (a.cleared) this.finishRift();
|
|
|
+ this.riftPanelKey = null; this.renderRiftPanel(); this.saveNow();
|
|
|
+ }
|
|
|
+
|
|
|
+ abandonRift() {
|
|
|
+ const r = this.riftRun;
|
|
|
+ if (!r) return;
|
|
|
+ if (r.state !== 'result') { r.state = 'result'; r.cleared = false; r.dead = true; }
|
|
|
+ this.finishRift();
|
|
|
+ }
|
|
|
+
|
|
|
+ finishRift() {
|
|
|
+ const r = this.riftRun;
|
|
|
+ if (!r) return;
|
|
|
+ const res0 = R.riftResult(r, F.computeStats(Object.assign({}, this.s, { planeRun: null })).prodRaw, this.s.planes[r.plane].explore >= 100);
|
|
|
+ const out = S.endRift(this.s);
|
|
|
+ this.riftRun = null;
|
|
|
+ this.riftPanelKey = null;
|
|
|
+ this.renderRiftPanel();
|
|
|
+ if (!out) return;
|
|
|
+ const { res, events } = out;
|
|
|
+ this.log(`里世界结算:探索度 +${res.explore},本源 +${fmt(res.essence)}${res.shard ? ',徽记 +1' : ''}`, 'rift');
|
|
|
+ this.lastFrame = performance.now();
|
|
|
+ this.pushDialog({ kind: 'riftResult', data: res });
|
|
|
+ events.forEach((e) => this.pushDialog({ kind: 'milestone', data: e }));
|
|
|
+ this.renderLeft(); this.renderRight(); this.renderAll(); this.saveNow();
|
|
|
+ }
|
|
|
+
|
|
|
+ showRiftResult(res) {
|
|
|
+ const anchoredNote = res.anchoredNow ? '<p style="color:#1c7a48"><b>位面已锚定!</b>此后该位面将在后台自动采集本源(每 60 秒按本源秒产 2% 结算),并已解锁下一阶时空裂缝。</p>' : '';
|
|
|
+ this.setModal('里世界结算', 'rift', res.cleared ? '通关 · 位面回声' : '撤离 · 碎片回响',
|
|
|
+ `<p style="margin-top:0">${res.cleared ? '你走完了全部 6 幕,带着这个位面的规则碎片归来。' : '本局未能走完,但失败也有价值:碎片会带回到世界树。'}</p>
|
|
|
+ <div class="res-row">
|
|
|
+ <div class="res"><div class="k">探索度 +</div><div class="v num">${res.explore}</div><div class="d">${res.planeName}</div></div>
|
|
|
+ <div class="res"><div class="k">本源 +</div><div class="v num">${fmt(res.essence)}</div><div class="d">带回主世界</div></div>
|
|
|
+ </div>
|
|
|
+ <div class="sub-line" style="margin-top:10px"><span>得分 <b>${res.score}</b></span><span>徽记 <b>${res.shard ? '+1' : '0'}</b></span><span>步数 <b>${res.steps}/6</b></span><span>当前探索 <b>${res.anchored ? '100(已锚定)' : res.explore + ' 点增量'}</b></span></div>
|
|
|
+ ${anchoredNote}`,
|
|
|
+ `<button class="btn" data-mact="close">回到世界树</button>`);
|
|
|
+ }
|
|
|
+
|
|
|
+ renderAll() { this.renderStatic(); this.renderDynamic(); }
|
|
|
+}
|
|
|
+
|
|
|
+// 小工具:模板里表示空的占位
|
|
|
+function d() { return ''; }
|