fix: XP bar renders full and the tooltip reads "-5500 percent to go" (#1797)

Bug Fixes:
- Improved experience and level progress accuracy when handling level-change updates.
- Prevented analyser updates when no local player is available.
- Normalized level percentages for newer protocols, ensuring progress bars and tooltips display correct values.
This commit is contained in:
mimus-assa 2026-08-05 08:28:56 -06:00 committed by GitHub
parent e6bcb1f2f6
commit 478522f36c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 12 additions and 2 deletions

View file

@ -544,7 +544,13 @@ function checkNumber(self, text)
end
function onLevelChange(localPlayer, value, percent)
XPAnalyser:setupLevel(value, percent)
-- See game_skills/skills.lua onLevelChange: the callback passes the level percent raw
-- (centipercent with GameLevelPercentU16, protocol >= 1520). Normalize it with
-- getLevelPercent() or the analyser bar renders full.
if not localPlayer then
return
end
XPAnalyser:setupLevel(value, localPlayer:getLevelPercent())
end
function managerDropTracker(itemId, checked)

View file

@ -1105,7 +1105,11 @@ function onLevelChange(localPlayer, value, percent)
if not localPlayer then
return
end
percent = percent or localPlayer:getLevelPercent()
-- The C++ onLevelChange callback passes m_levelPercent raw, which is centipercent
-- (0-10000) once GameLevelPercentU16 is enabled (protocol >= 1520), not the 0-100 the
-- UI expects. getLevelPercent() normalizes it, so always use the getter: otherwise the
-- bar renders full and the tooltip reads "-5500 percent to go" at high levels.
percent = localPlayer:getLevelPercent()
setSkillValue('level', comma_value(value))
local text = tr('You have %s percent to go', 100 - percent)
setSkillPercent('level', percent, text)