xptracker: support xp gains when offline

When xp is gained when offline, the tracker calculates it into the
xp/hr, which can lead to very skewed stats due to the tracker being
generally paused when the player is offline.

This offsets the start xp by the gains when offline to correct for it.
This commit is contained in:
Adam
2019-08-07 19:08:31 -04:00
parent 3b40f945a7
commit 2ef1f29c13
2 changed files with 35 additions and 4 deletions

View File

@@ -28,21 +28,20 @@ package net.runelite.client.plugins.xptracker;
import java.util.HashMap;
import java.util.Map;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import net.runelite.api.Experience;
import net.runelite.api.Skill;
@Slf4j
@RequiredArgsConstructor
class XpStateSingle
{
private final Skill skill;
private final Map<XpActionType, XpAction> actions = new HashMap<>();
@Getter
private final long startXp;
@Setter
private long startXp;
@Getter
private int xpGained = 0;
@@ -54,13 +53,19 @@ class XpStateSingle
private int startLevelExp = 0;
private int endLevelExp = 0;
XpStateSingle(Skill skill, long startXp)
{
this.skill = skill;
this.startXp = startXp;
}
XpAction getXpAction(final XpActionType type)
{
actions.putIfAbsent(type, new XpAction());
return actions.get(type);
}
private long getCurrentXp()
long getCurrentXp()
{
return startXp + xpGained;
}

View File

@@ -391,6 +391,32 @@ public class XpTrackerPlugin extends Plugin
{
initializeTracker = false;
// Check for xp gained while logged out
for (Skill skill : Skill.values())
{
if (skill == Skill.OVERALL || !xpState.isInitialized(skill))
{
continue;
}
XpStateSingle skillState = xpState.getSkill(skill);
final int currentXp = client.getSkillExperience(skill);
if (skillState.getCurrentXp() != currentXp)
{
if (currentXp < skillState.getCurrentXp())
{
log.debug("Xp is going backwards! {} {} -> {}", skill, skillState.getCurrentXp(), currentXp);
resetState();
break;
}
log.debug("Skill xp for {} changed when offline: {} -> {}", skill, skillState.getCurrentXp(), currentXp);
// Offset start xp for offline gains
long diff = skillState.getCurrentXp() - currentXp;
skillState.setStartXp(skillState.getStartXp() + diff);
}
}
// Initialize the tracker with the initial xp if not already initialized
for (Skill skill : Skill.values())
{