xptracker: use long for tracking overall xp

This commit is contained in:
Adam
2019-03-03 14:40:07 -05:00
parent 319ccb68e4
commit 188bb70417
7 changed files with 85 additions and 56 deletions

View File

@@ -49,7 +49,7 @@ class XpPauseState
return findPauseState(skill).isPaused();
}
void tickXp(Skill skill, int currentXp, int pauseAfterMinutes)
void tickXp(Skill skill, long currentXp, int pauseAfterMinutes)
{
final XpPauseStateSingle state = findPauseState(skill);

View File

@@ -39,7 +39,7 @@ class XpPauseStateSingle
@Getter
private long lastChangeMillis;
@Getter
private int xp;
private long xp;
boolean isPaused()
{
@@ -66,7 +66,7 @@ class XpPauseStateSingle
return pauseReasons.add(XpPauseReason.PAUSE_MANUAL);
}
boolean xpChanged(int xp)
boolean xpChanged(long xp)
{
this.xp = xp;
this.lastChangeMillis = System.currentTimeMillis();

View File

@@ -56,7 +56,7 @@ class XpState
* @param skill Skill to reset
* @param currentXp Current XP to set to, if unknown set to -1
*/
void resetSkill(Skill skill, int currentXp)
void resetSkill(Skill skill, long currentXp)
{
xpSkills.remove(skill);
xpSkills.put(skill, new XpStateSingle(skill, currentXp));
@@ -73,7 +73,7 @@ class XpState
* @param goalEndXp Possible XP end goal
* @return Whether or not the skill has been initialized, there was no change, or it has been updated
*/
XpUpdateResult updateSkill(Skill skill, int currentXp, int goalStartXp, int goalEndXp)
XpUpdateResult updateSkill(Skill skill, long currentXp, int goalStartXp, int goalEndXp)
{
XpStateSingle state = getSkill(skill);
@@ -91,7 +91,7 @@ class XpState
}
else
{
int startXp = state.getStartXp();
long startXp = state.getStartXp();
int gainedXp = state.getXpGained();
if (startXp + gainedXp > currentXp)
@@ -191,7 +191,7 @@ class XpState
* @param skill Skill to initialize
* @param currentXp Current known XP for the skill
*/
void initializeSkill(Skill skill, int currentXp)
void initializeSkill(Skill skill, long currentXp)
{
xpSkills.put(skill, new XpStateSingle(skill, currentXp));
}

View File

@@ -42,7 +42,7 @@ class XpStateSingle
private final Map<XpActionType, XpAction> actions = new HashMap<>();
@Getter
private final int startXp;
private final long startXp;
@Getter
private int xpGained = 0;
@@ -60,7 +60,7 @@ class XpStateSingle
return actions.get(type);
}
private int getCurrentXp()
private long getCurrentXp()
{
return startXp + xpGained;
}
@@ -86,7 +86,7 @@ class XpStateSingle
private int getXpRemaining()
{
return endLevelExp - getCurrentXp();
return endLevelExp - (int) getCurrentXp();
}
private int getActionsRemaining()
@@ -170,7 +170,7 @@ class XpStateSingle
return toHourly(xpGained);
}
boolean update(int currentXp, int goalStartXp, int goalEndXp)
boolean update(long currentXp, int goalStartXp, int goalEndXp)
{
if (startXp == -1)
{
@@ -178,8 +178,8 @@ class XpStateSingle
return false;
}
int originalXp = xpGained + startXp;
int actionExp = currentXp - originalXp;
long originalXp = xpGained + startXp;
int actionExp = (int) (currentXp - originalXp);
// No experience gained
if (actionExp == 0)
@@ -210,28 +210,31 @@ class XpStateSingle
action.setActions(action.getActions() + 1);
// Calculate experience gained
xpGained = currentXp - startXp;
xpGained = (int) (currentXp - startXp);
// Determine XP goals
if (goalStartXp <= 0 || currentXp > goalEndXp)
// Determine XP goals, overall has no goals
if (skill != Skill.OVERALL)
{
startLevelExp = Experience.getXpForLevel(Experience.getLevelForXp(currentXp));
}
else
{
startLevelExp = goalStartXp;
}
if (goalStartXp <= 0 || currentXp > goalEndXp)
{
startLevelExp = Experience.getXpForLevel(Experience.getLevelForXp((int) currentXp));
}
else
{
startLevelExp = goalStartXp;
}
if (goalEndXp <= 0 || currentXp > goalEndXp)
{
int currentLevel = Experience.getLevelForXp(currentXp);
endLevelExp = currentLevel + 1 <= Experience.MAX_VIRT_LEVEL
? Experience.getXpForLevel(currentLevel + 1)
: Experience.MAX_SKILL_XP;
}
else
{
endLevelExp = goalEndXp;
if (goalEndXp <= 0 || currentXp > goalEndXp)
{
int currentLevel = Experience.getLevelForXp((int) currentXp);
endLevelExp = currentLevel + 1 <= Experience.MAX_VIRT_LEVEL
? Experience.getXpForLevel(currentLevel + 1)
: Experience.MAX_SKILL_XP;
}
else
{
endLevelExp = goalEndXp;
}
}
return true;

View File

@@ -146,16 +146,6 @@ public class XpTrackerPlugin extends Plugin
clientToolbar.removeNavigation(navButton);
}
private long getTotalXp()
{
long total = 0;
for (Skill skill : Skill.values())
{
total += client.getSkillExperience(skill);
}
return total;
}
@Subscribe
public void onGameStateChanged(GameStateChanged event)
{
@@ -195,7 +185,7 @@ public class XpTrackerPlugin extends Plugin
return;
}
long totalXp = getTotalXp();
long totalXp = client.getOverallExperience();
// Don't submit xptrack unless xp threshold is reached
if (Math.abs(totalXp - lastXp) > XP_THRESHOLD)
{
@@ -229,7 +219,16 @@ public class XpTrackerPlugin extends Plugin
for (Skill skill : Skill.values())
{
int currentXp = client.getSkillExperience(skill);
long currentXp;
if (skill == Skill.OVERALL)
{
currentXp = client.getOverallExperience();
}
else
{
currentXp = client.getSkillExperience(skill);
}
xpState.initializeSkill(skill, currentXp);
}
}
@@ -306,11 +305,11 @@ public class XpTrackerPlugin extends Plugin
if (skill == Skill.CONSTRUCTION && updateResult == XpUpdateResult.INITIALIZED)
{
// Construction is the last skill initialized on login, now initialize the total experience
xpState.initializeSkill(Skill.OVERALL, client.getSkillExperience(Skill.OVERALL));
xpState.initializeSkill(Skill.OVERALL, client.getOverallExperience());
}
else if (xpState.isInitialized(Skill.OVERALL))
{
xpState.updateSkill(Skill.OVERALL, client.getSkillExperience(Skill.OVERALL), -1, -1);
xpState.updateSkill(Skill.OVERALL, client.getOverallExperience(), -1, -1);
xpPanel.updateTotal(xpState.getTotalSnapshot());
}
}
@@ -341,7 +340,7 @@ public class XpTrackerPlugin extends Plugin
rebuildSkills();
if (fetchXp)
{
lastXp = getTotalXp();
lastXp = client.getOverallExperience();
fetchXp = false;
}
}
@@ -470,7 +469,17 @@ public class XpTrackerPlugin extends Plugin
// Adjust unpause states
for (Skill skill : Skill.values())
{
xpPauseState.tickXp(skill, client.getSkillExperience(skill), xpTrackerConfig.pauseSkillAfter());
long skillExperience;
if (skill == Skill.OVERALL)
{
skillExperience = client.getOverallExperience();
}
else
{
skillExperience = client.getSkillExperience(skill);
}
xpPauseState.tickXp(skill, skillExperience, xpTrackerConfig.pauseSkillAfter());
}
xpPauseState.tickLogout(xpTrackerConfig.pauseOnLogout(), !GameState.LOGIN_SCREEN.equals(client.getGameState()));