xptracker: use long for tracking overall xp
This commit is contained in:
@@ -782,6 +782,13 @@ public interface Client extends GameEngine
|
|||||||
*/
|
*/
|
||||||
int getSkillExperience(Skill skill);
|
int getSkillExperience(Skill skill);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the total experience of the player
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
long getOverallExperience();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the game drawing mode.
|
* Gets the game drawing mode.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ class XpPauseState
|
|||||||
return findPauseState(skill).isPaused();
|
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);
|
final XpPauseStateSingle state = findPauseState(skill);
|
||||||
|
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ class XpPauseStateSingle
|
|||||||
@Getter
|
@Getter
|
||||||
private long lastChangeMillis;
|
private long lastChangeMillis;
|
||||||
@Getter
|
@Getter
|
||||||
private int xp;
|
private long xp;
|
||||||
|
|
||||||
boolean isPaused()
|
boolean isPaused()
|
||||||
{
|
{
|
||||||
@@ -66,7 +66,7 @@ class XpPauseStateSingle
|
|||||||
return pauseReasons.add(XpPauseReason.PAUSE_MANUAL);
|
return pauseReasons.add(XpPauseReason.PAUSE_MANUAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean xpChanged(int xp)
|
boolean xpChanged(long xp)
|
||||||
{
|
{
|
||||||
this.xp = xp;
|
this.xp = xp;
|
||||||
this.lastChangeMillis = System.currentTimeMillis();
|
this.lastChangeMillis = System.currentTimeMillis();
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ class XpState
|
|||||||
* @param skill Skill to reset
|
* @param skill Skill to reset
|
||||||
* @param currentXp Current XP to set to, if unknown set to -1
|
* @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.remove(skill);
|
||||||
xpSkills.put(skill, new XpStateSingle(skill, currentXp));
|
xpSkills.put(skill, new XpStateSingle(skill, currentXp));
|
||||||
@@ -73,7 +73,7 @@ class XpState
|
|||||||
* @param goalEndXp Possible XP end goal
|
* @param goalEndXp Possible XP end goal
|
||||||
* @return Whether or not the skill has been initialized, there was no change, or it has been updated
|
* @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);
|
XpStateSingle state = getSkill(skill);
|
||||||
|
|
||||||
@@ -91,7 +91,7 @@ class XpState
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
int startXp = state.getStartXp();
|
long startXp = state.getStartXp();
|
||||||
int gainedXp = state.getXpGained();
|
int gainedXp = state.getXpGained();
|
||||||
|
|
||||||
if (startXp + gainedXp > currentXp)
|
if (startXp + gainedXp > currentXp)
|
||||||
@@ -191,7 +191,7 @@ class XpState
|
|||||||
* @param skill Skill to initialize
|
* @param skill Skill to initialize
|
||||||
* @param currentXp Current known XP for the skill
|
* @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));
|
xpSkills.put(skill, new XpStateSingle(skill, currentXp));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ class XpStateSingle
|
|||||||
private final Map<XpActionType, XpAction> actions = new HashMap<>();
|
private final Map<XpActionType, XpAction> actions = new HashMap<>();
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
private final int startXp;
|
private final long startXp;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
private int xpGained = 0;
|
private int xpGained = 0;
|
||||||
@@ -60,7 +60,7 @@ class XpStateSingle
|
|||||||
return actions.get(type);
|
return actions.get(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
private int getCurrentXp()
|
private long getCurrentXp()
|
||||||
{
|
{
|
||||||
return startXp + xpGained;
|
return startXp + xpGained;
|
||||||
}
|
}
|
||||||
@@ -86,7 +86,7 @@ class XpStateSingle
|
|||||||
|
|
||||||
private int getXpRemaining()
|
private int getXpRemaining()
|
||||||
{
|
{
|
||||||
return endLevelExp - getCurrentXp();
|
return endLevelExp - (int) getCurrentXp();
|
||||||
}
|
}
|
||||||
|
|
||||||
private int getActionsRemaining()
|
private int getActionsRemaining()
|
||||||
@@ -170,7 +170,7 @@ class XpStateSingle
|
|||||||
return toHourly(xpGained);
|
return toHourly(xpGained);
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean update(int currentXp, int goalStartXp, int goalEndXp)
|
boolean update(long currentXp, int goalStartXp, int goalEndXp)
|
||||||
{
|
{
|
||||||
if (startXp == -1)
|
if (startXp == -1)
|
||||||
{
|
{
|
||||||
@@ -178,8 +178,8 @@ class XpStateSingle
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int originalXp = xpGained + startXp;
|
long originalXp = xpGained + startXp;
|
||||||
int actionExp = currentXp - originalXp;
|
int actionExp = (int) (currentXp - originalXp);
|
||||||
|
|
||||||
// No experience gained
|
// No experience gained
|
||||||
if (actionExp == 0)
|
if (actionExp == 0)
|
||||||
@@ -210,28 +210,31 @@ class XpStateSingle
|
|||||||
action.setActions(action.getActions() + 1);
|
action.setActions(action.getActions() + 1);
|
||||||
|
|
||||||
// Calculate experience gained
|
// Calculate experience gained
|
||||||
xpGained = currentXp - startXp;
|
xpGained = (int) (currentXp - startXp);
|
||||||
|
|
||||||
// Determine XP goals
|
// Determine XP goals, overall has no goals
|
||||||
if (goalStartXp <= 0 || currentXp > goalEndXp)
|
if (skill != Skill.OVERALL)
|
||||||
{
|
{
|
||||||
startLevelExp = Experience.getXpForLevel(Experience.getLevelForXp(currentXp));
|
if (goalStartXp <= 0 || currentXp > goalEndXp)
|
||||||
}
|
{
|
||||||
else
|
startLevelExp = Experience.getXpForLevel(Experience.getLevelForXp((int) currentXp));
|
||||||
{
|
}
|
||||||
startLevelExp = goalStartXp;
|
else
|
||||||
}
|
{
|
||||||
|
startLevelExp = goalStartXp;
|
||||||
|
}
|
||||||
|
|
||||||
if (goalEndXp <= 0 || currentXp > goalEndXp)
|
if (goalEndXp <= 0 || currentXp > goalEndXp)
|
||||||
{
|
{
|
||||||
int currentLevel = Experience.getLevelForXp(currentXp);
|
int currentLevel = Experience.getLevelForXp((int) currentXp);
|
||||||
endLevelExp = currentLevel + 1 <= Experience.MAX_VIRT_LEVEL
|
endLevelExp = currentLevel + 1 <= Experience.MAX_VIRT_LEVEL
|
||||||
? Experience.getXpForLevel(currentLevel + 1)
|
? Experience.getXpForLevel(currentLevel + 1)
|
||||||
: Experience.MAX_SKILL_XP;
|
: Experience.MAX_SKILL_XP;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
endLevelExp = goalEndXp;
|
endLevelExp = goalEndXp;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -146,16 +146,6 @@ public class XpTrackerPlugin extends Plugin
|
|||||||
clientToolbar.removeNavigation(navButton);
|
clientToolbar.removeNavigation(navButton);
|
||||||
}
|
}
|
||||||
|
|
||||||
private long getTotalXp()
|
|
||||||
{
|
|
||||||
long total = 0;
|
|
||||||
for (Skill skill : Skill.values())
|
|
||||||
{
|
|
||||||
total += client.getSkillExperience(skill);
|
|
||||||
}
|
|
||||||
return total;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void onGameStateChanged(GameStateChanged event)
|
public void onGameStateChanged(GameStateChanged event)
|
||||||
{
|
{
|
||||||
@@ -195,7 +185,7 @@ public class XpTrackerPlugin extends Plugin
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
long totalXp = getTotalXp();
|
long totalXp = client.getOverallExperience();
|
||||||
// Don't submit xptrack unless xp threshold is reached
|
// Don't submit xptrack unless xp threshold is reached
|
||||||
if (Math.abs(totalXp - lastXp) > XP_THRESHOLD)
|
if (Math.abs(totalXp - lastXp) > XP_THRESHOLD)
|
||||||
{
|
{
|
||||||
@@ -229,7 +219,16 @@ public class XpTrackerPlugin extends Plugin
|
|||||||
|
|
||||||
for (Skill skill : Skill.values())
|
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);
|
xpState.initializeSkill(skill, currentXp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -306,11 +305,11 @@ public class XpTrackerPlugin extends Plugin
|
|||||||
if (skill == Skill.CONSTRUCTION && updateResult == XpUpdateResult.INITIALIZED)
|
if (skill == Skill.CONSTRUCTION && updateResult == XpUpdateResult.INITIALIZED)
|
||||||
{
|
{
|
||||||
// Construction is the last skill initialized on login, now initialize the total experience
|
// 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))
|
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());
|
xpPanel.updateTotal(xpState.getTotalSnapshot());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -341,7 +340,7 @@ public class XpTrackerPlugin extends Plugin
|
|||||||
rebuildSkills();
|
rebuildSkills();
|
||||||
if (fetchXp)
|
if (fetchXp)
|
||||||
{
|
{
|
||||||
lastXp = getTotalXp();
|
lastXp = client.getOverallExperience();
|
||||||
fetchXp = false;
|
fetchXp = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -470,7 +469,17 @@ public class XpTrackerPlugin extends Plugin
|
|||||||
// Adjust unpause states
|
// Adjust unpause states
|
||||||
for (Skill skill : Skill.values())
|
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()));
|
xpPauseState.tickLogout(xpTrackerConfig.pauseOnLogout(), !GameState.LOGIN_SCREEN.equals(client.getGameState()));
|
||||||
|
|||||||
@@ -504,14 +504,8 @@ public abstract class RSClientMixin implements RSClient
|
|||||||
|
|
||||||
if (skill == Skill.OVERALL)
|
if (skill == Skill.OVERALL)
|
||||||
{
|
{
|
||||||
int totalExperience = 0;
|
logger.debug("getSkillExperience called for {}!", skill);
|
||||||
|
return (int) getOverallExperience();
|
||||||
for (int experience : experiences)
|
|
||||||
{
|
|
||||||
totalExperience += experience;
|
|
||||||
}
|
|
||||||
|
|
||||||
return totalExperience;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int idx = skill.ordinal();
|
int idx = skill.ordinal();
|
||||||
@@ -526,6 +520,22 @@ public abstract class RSClientMixin implements RSClient
|
|||||||
return experiences[idx];
|
return experiences[idx];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
@Override
|
||||||
|
public long getOverallExperience()
|
||||||
|
{
|
||||||
|
int[] experiences = getSkillExperiences();
|
||||||
|
|
||||||
|
long totalExperience = 0L;
|
||||||
|
|
||||||
|
for (int experience : experiences)
|
||||||
|
{
|
||||||
|
totalExperience += experience;
|
||||||
|
}
|
||||||
|
|
||||||
|
return totalExperience;
|
||||||
|
}
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
@Override
|
@Override
|
||||||
public void refreshChat()
|
public void refreshChat()
|
||||||
|
|||||||
Reference in New Issue
Block a user