diff --git a/bot_modules/02_state.js b/bot_modules/02_state.js index a868dfb..80ab196 100644 --- a/bot_modules/02_state.js +++ b/bot_modules/02_state.js @@ -17,28 +17,16 @@ function gatherState() { const total_points = uw.Game?.player_points ?? 0; 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 { - const pkModels = uw.MM?.getModels?.()?.PlayerKillpoints; - if (pkModels && pkModels[player_id]) { - const pk = pkModels[player_id]; - battle_points.used = pk.attributes?.used || 0; - if (typeof pk.getUnusedPoints === 'function') { - battle_points.available = pk.getUnusedPoints(); - } 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; - } - } + const pk = uw.MM?.getModelByNameAndPlayerId?.('PlayerKillpoints')?.attributes; + if (pk) { + battle_points.att = pk.att || 0; + battle_points.def = pk.def || 0; + battle_points.used = pk.used || 0; + battle_points.available = battle_points.att + battle_points.def - battle_points.used; } } catch (e) { log(`Failed to extract battle_points: ${e}`); } diff --git a/static/js/components/townViewer.js b/static/js/components/townViewer.js index 5e2d6db..2dda0ba 100644 --- a/static/js/components/townViewer.js +++ b/static/js/components/townViewer.js @@ -178,8 +178,9 @@ window.renderTownDetails = function() { allianceHtml = `