diff options
Diffstat (limited to 'src/localplayer.cpp')
-rw-r--r-- | src/localplayer.cpp | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/src/localplayer.cpp b/src/localplayer.cpp index 78395438..494bbb5a 100644 --- a/src/localplayer.cpp +++ b/src/localplayer.cpp @@ -1031,10 +1031,27 @@ void LocalPlayer::event(Event::Channel channel, const Event &event) { if (event.getInt("id") == EXP) { - int change = event.getInt("newValue") - - event.getInt("oldValue"); + int change = 0; + int oldXp = event.getInt("oldValue"); + int newXp = event.getInt("newValue"); + + // When the new XP is lower than the old one, + // it means that a new level has been reached. + // Thus, the xp difference can only be obtained + // with the exp needed for the next level. + // The new XP value is then the XP obtained for the new level. + if (newXp < oldXp) + { + change = PlayerInfo::getAttribute(EXP_NEEDED) + - oldXp + newXp; + } + else + { + change = newXp - oldXp; + } - addMessageToQueue(toString(change) + " xp"); + if (change > 0) + addMessageToQueue(toString(change) + " xp"); } } } |