- 23 source files in src/ (build via scripts/build.sh) - Forum-sourced player knowledge in references/ - DESIGN.md with architecture and corrections - References to existing scripts (Monsterbation, jpx, HV Utils)
108 lines
3.7 KiB
JavaScript
108 lines
3.7 KiB
JavaScript
// ═══════════════════════════════════════════════════════════════════════
|
|
// BATTLE LOGGER — saves raw battle log lines to localStorage in real time
|
|
// ═══════════════════════════════════════════════════════════════════════
|
|
|
|
let _lastLogCount = 0;
|
|
const LOG_KEY = SP + 'battleLog';
|
|
|
|
function initBattleLog() {
|
|
_lastLogCount = 0;
|
|
// Clear previous log
|
|
try { localStorage.removeItem(LOG_KEY); } catch (e) {}
|
|
}
|
|
|
|
function logRound() {
|
|
const log = document.getElementById('textlog');
|
|
if (!log) return;
|
|
|
|
const allRows = log.querySelectorAll('tr');
|
|
if (allRows.length <= _lastLogCount) return;
|
|
|
|
// Get only the NEW rows since last capture
|
|
const newLines = [];
|
|
for (let i = _lastLogCount; i < allRows.length; i++) {
|
|
const text = (allRows[i].textContent || '').trim();
|
|
if (text) newLines.push(text);
|
|
}
|
|
_lastLogCount = allRows.length;
|
|
|
|
if (newLines.length === 0) return;
|
|
|
|
// Read existing log from localStorage, append new lines, save back
|
|
let existing = [];
|
|
try {
|
|
const saved = localStorage.getItem(LOG_KEY);
|
|
if (saved) existing = JSON.parse(saved);
|
|
} catch (e) {}
|
|
|
|
existing.push(...newLines);
|
|
|
|
try {
|
|
localStorage.setItem(LOG_KEY, JSON.stringify(existing));
|
|
} catch (e) {
|
|
// localStorage full — keep only last 500 lines
|
|
try {
|
|
const trimmed = existing.slice(-500);
|
|
localStorage.setItem(LOG_KEY, JSON.stringify(trimmed));
|
|
} catch (e2) {}
|
|
}
|
|
}
|
|
|
|
function getBattleLog() {
|
|
try {
|
|
const saved = localStorage.getItem(LOG_KEY);
|
|
return saved ? JSON.parse(saved) : null;
|
|
} catch (e) {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
function getBattleSummary() {
|
|
const lines = getBattleLog();
|
|
if (!lines || lines.length === 0) return null;
|
|
|
|
let kills = 0, dmgDealt = 0, dmgTaken = 0, healed = 0;
|
|
const spells = {}, skills = {}, items = {};
|
|
|
|
for (const line of lines) {
|
|
const mKill = line.match(/(.+) has been defeated\./);
|
|
if (mKill && !line.includes('gains the effect')) kills++;
|
|
|
|
const mDmg = line.match(/causing (\d+) points/);
|
|
if (mDmg) dmgDealt += parseInt(mDmg[1]);
|
|
|
|
const mTaken = line.match(/take (\d+) (\w+)/);
|
|
if (mTaken) dmgTaken += parseInt(mTaken[1]);
|
|
|
|
const mRegen = line.match(/Regen restores (\d+)/);
|
|
if (mRegen) healed += parseInt(mRegen[1]);
|
|
const mPot = line.match(/Regeneration restores (\d+)/);
|
|
if (mPot) healed += parseInt(mPot[1]);
|
|
const mCure = line.match(/healed for (\d+)/);
|
|
if (mCure) healed += parseInt(mCure[1]);
|
|
|
|
const mSpell = line.match(/You cast (\w[\w\s-]+)\./);
|
|
if (mSpell) spells[mSpell[1]] = (spells[mSpell[1]] || 0) + 1;
|
|
|
|
const mSkill = line.match(/You use (\w[\w\s-]+)\./);
|
|
if (mSkill && !mSkill[1].includes('Draught') && !mSkill[1].includes('Potion') && !mSkill[1].includes('Elixir') && !mSkill[1].includes('Gem')) {
|
|
skills[mSkill[1]] = (skills[mSkill[1]] || 0) + 1;
|
|
}
|
|
|
|
const mItem = line.match(/You use (.+?)\.$/);
|
|
if (mItem && (mItem[1].includes('Draught') || mItem[1].includes('Potion') || mItem[1].includes('Elixir') || mItem[1].includes('Gem'))) {
|
|
items[mItem[1]] = (items[mItem[1]] || 0) + 1;
|
|
}
|
|
}
|
|
|
|
return {
|
|
totalLines: lines.length,
|
|
kills,
|
|
dmgDealt,
|
|
dmgTaken,
|
|
healed,
|
|
spells,
|
|
skills,
|
|
items,
|
|
};
|
|
}
|