This commit is contained in:
2026-05-05 21:09:38 +03:00
parent bedf25b6f6
commit 781a2b92de
2 changed files with 12 additions and 23 deletions

View File

@@ -17,28 +17,16 @@ function gatherState() {
const total_points = uw.Game?.player_points ?? 0; const total_points = uw.Game?.player_points ?? 0;
const world = uw.Game?.world_id || ''; const world = uw.Game?.world_id || '';
let battle_points = { available: 0, used: 0 }; // Battle points: att+def = total earned, used = spent, available = att+def-used
// Source: ModernBot.user.js line 1635: let available = killpoints.att + killpoints.def - killpoints.used;
let battle_points = { att: 0, def: 0, used: 0, available: 0 };
try { try {
const pkModels = uw.MM?.getModels?.()?.PlayerKillpoints; const pk = uw.MM?.getModelByNameAndPlayerId?.('PlayerKillpoints')?.attributes;
if (pkModels && pkModels[player_id]) { if (pk) {
const pk = pkModels[player_id]; battle_points.att = pk.att || 0;
battle_points.used = pk.attributes?.used || 0; battle_points.def = pk.def || 0;
if (typeof pk.getUnusedPoints === 'function') { battle_points.used = pk.used || 0;
battle_points.available = pk.getUnusedPoints(); battle_points.available = battle_points.att + battle_points.def - battle_points.used;
} else if (pk.attributes?.available !== undefined) {
battle_points.available = pk.attributes.available;
}
}
// Force sync with the exact UI number if available (e.g. 1986)
if (uw.$) {
const uiText = uw.$('.nui_battlepoints_container .points').text();
if (uiText) {
const parsed = parseInt(uiText.replace(/[^\d]/g, ''), 10);
if (!isNaN(parsed)) {
battle_points.available = parsed;
}
}
} }
} catch (e) { log(`Failed to extract battle_points: ${e}`); } } catch (e) { log(`Failed to extract battle_points: ${e}`); }

View File

@@ -178,8 +178,9 @@ window.renderTownDetails = function() {
allianceHtml = `<div>Συμμαχία: ID <strong style="color:#aaa">${t.alliance_id}</strong></div>`; allianceHtml = `<div>Συμμαχία: ID <strong style="color:#aaa">${t.alliance_id}</strong></div>`;
} }
let bp = t.battle_points || { available: 0, used: 0 }; let bp = t.battle_points || { att: 0, def: 0, used: 0, available: 0 };
let bpHtml = `<div>Πόντοι Μάχης: <strong style="color:#2ecc71">${bp.available}</strong> / <span style="color:#aaa">${bp.available + bp.used}</span></div>`; let bpTotal = (bp.att || 0) + (bp.def || 0);
let bpHtml = `<div>Πόντοι Μάχης: <strong style="color:#2ecc71">${bp.available}</strong><span style="color:#666;font-size:0.8rem"> / ${bpTotal} (⚔${bp.att||0} 🛡${bp.def||0})</span></div>`;
document.getElementById('td-general').innerHTML = ` document.getElementById('td-general').innerHTML = `
<div>Πόντοι: <strong>${t.points}</strong>${t.wonder_points ? ` / Θαύμα: <strong>${t.wonder_points}</strong>` : ''}</div> <div>Πόντοι: <strong>${t.points}</strong>${t.wonder_points ? ` / Θαύμα: <strong>${t.wonder_points}</strong>` : ''}</div>