xptracker: use tracked overall xpstate to calculate total xp
This commit is contained in:
@@ -185,7 +185,7 @@ class XpPanel extends PluginPanel
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void updateTotal(XpSnapshotTotal xpSnapshotTotal)
|
void updateTotal(XpSnapshotSingle xpSnapshotTotal)
|
||||||
{
|
{
|
||||||
// if player has gained exp and hasn't switched displays yet, hide error panel and show overall info
|
// if player has gained exp and hasn't switched displays yet, hide error panel and show overall info
|
||||||
if (xpSnapshotTotal.getXpGainedInSession() > 0 && !overallPanel.isVisible())
|
if (xpSnapshotTotal.getXpGainedInSession() > 0 && !overallPanel.isVisible())
|
||||||
@@ -193,11 +193,16 @@ class XpPanel extends PluginPanel
|
|||||||
overallPanel.setVisible(true);
|
overallPanel.setVisible(true);
|
||||||
remove(errorPanel);
|
remove(errorPanel);
|
||||||
}
|
}
|
||||||
|
else if (xpSnapshotTotal.getXpGainedInSession() == 0 && overallPanel.isVisible())
|
||||||
|
{
|
||||||
|
overallPanel.setVisible(false);
|
||||||
|
add(errorPanel);
|
||||||
|
}
|
||||||
|
|
||||||
SwingUtilities.invokeLater(() -> rebuildAsync(xpSnapshotTotal));
|
SwingUtilities.invokeLater(() -> rebuildAsync(xpSnapshotTotal));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void rebuildAsync(XpSnapshotTotal xpSnapshotTotal)
|
private void rebuildAsync(XpSnapshotSingle xpSnapshotTotal)
|
||||||
{
|
{
|
||||||
overallExpGained.setText(XpInfoBox.htmlLabel("Gained: ", xpSnapshotTotal.getXpGainedInSession()));
|
overallExpGained.setText(XpInfoBox.htmlLabel("Gained: ", xpSnapshotTotal.getXpGainedInSession()));
|
||||||
overallExpHour.setText(XpInfoBox.htmlLabel("Per hour: ", xpSnapshotTotal.getXpPerHour()));
|
overallExpHour.setText(XpInfoBox.htmlLabel("Per hour: ", xpSnapshotTotal.getXpPerHour()));
|
||||||
|
|||||||
@@ -1,39 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2018, Levi <me@levischuck.com>
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
* Redistribution and use in source and binary forms, with or without
|
|
||||||
* modification, are permitted provided that the following conditions are met:
|
|
||||||
*
|
|
||||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
|
||||||
* list of conditions and the following disclaimer.
|
|
||||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
||||||
* this list of conditions and the following disclaimer in the documentation
|
|
||||||
* and/or other materials provided with the distribution.
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
||||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
||||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
||||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
|
||||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
||||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
||||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
|
||||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
||||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
||||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*/
|
|
||||||
package net.runelite.client.plugins.xptracker;
|
|
||||||
|
|
||||||
import lombok.Value;
|
|
||||||
|
|
||||||
@Value
|
|
||||||
class XpSnapshotTotal
|
|
||||||
{
|
|
||||||
private final int xpGainedInSession;
|
|
||||||
private final int xpPerHour;
|
|
||||||
|
|
||||||
static XpSnapshotTotal zero()
|
|
||||||
{
|
|
||||||
return new XpSnapshotTotal(0, 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -40,7 +40,6 @@ class XpState
|
|||||||
{
|
{
|
||||||
private static final double DEFAULT_XP_MODIFIER = 4.0;
|
private static final double DEFAULT_XP_MODIFIER = 4.0;
|
||||||
private static final double SHARED_XP_MODIFIER = DEFAULT_XP_MODIFIER / 3.0;
|
private static final double SHARED_XP_MODIFIER = DEFAULT_XP_MODIFIER / 3.0;
|
||||||
private final XpStateTotal xpTotal = new XpStateTotal();
|
|
||||||
private final Map<Skill, XpStateSingle> xpSkills = new EnumMap<>(Skill.class);
|
private final Map<Skill, XpStateSingle> xpSkills = new EnumMap<>(Skill.class);
|
||||||
private NPC interactedNPC;
|
private NPC interactedNPC;
|
||||||
|
|
||||||
@@ -49,7 +48,6 @@ class XpState
|
|||||||
*/
|
*/
|
||||||
void reset()
|
void reset()
|
||||||
{
|
{
|
||||||
xpTotal.reset();
|
|
||||||
xpSkills.clear();
|
xpSkills.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -62,21 +60,6 @@ class XpState
|
|||||||
{
|
{
|
||||||
xpSkills.remove(skill);
|
xpSkills.remove(skill);
|
||||||
xpSkills.put(skill, new XpStateSingle(skill, currentXp));
|
xpSkills.put(skill, new XpStateSingle(skill, currentXp));
|
||||||
recalculateTotal();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Calculates the total skill changes observed in this session or since the last reset
|
|
||||||
*/
|
|
||||||
void recalculateTotal()
|
|
||||||
{
|
|
||||||
xpTotal.reset();
|
|
||||||
|
|
||||||
for (XpStateSingle state : xpSkills.values())
|
|
||||||
{
|
|
||||||
xpTotal.addXpGainedInSession(state.getXpGained());
|
|
||||||
xpTotal.addXpPerHour(state.getXpHr());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -213,6 +196,11 @@ class XpState
|
|||||||
xpSkills.put(skill, new XpStateSingle(skill, currentXp));
|
xpSkills.put(skill, new XpStateSingle(skill, currentXp));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
boolean isInitialized(Skill skill)
|
||||||
|
{
|
||||||
|
return xpSkills.containsKey(skill);
|
||||||
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
XpStateSingle getSkill(Skill skill)
|
XpStateSingle getSkill(Skill skill)
|
||||||
{
|
{
|
||||||
@@ -237,8 +225,8 @@ class XpState
|
|||||||
* @return An immutable snapshot of total information for this session since first login or last reset
|
* @return An immutable snapshot of total information for this session since first login or last reset
|
||||||
*/
|
*/
|
||||||
@NonNull
|
@NonNull
|
||||||
XpSnapshotTotal getTotalSnapshot()
|
XpSnapshotSingle getTotalSnapshot()
|
||||||
{
|
{
|
||||||
return xpTotal.snapshot();
|
return getSkill(Skill.OVERALL).snapshot();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,55 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2018, Levi <me@levischuck.com>
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
* Redistribution and use in source and binary forms, with or without
|
|
||||||
* modification, are permitted provided that the following conditions are met:
|
|
||||||
*
|
|
||||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
|
||||||
* list of conditions and the following disclaimer.
|
|
||||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
||||||
* this list of conditions and the following disclaimer in the documentation
|
|
||||||
* and/or other materials provided with the distribution.
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
||||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
||||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
||||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
|
||||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
||||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
||||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
|
||||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
||||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
||||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*/
|
|
||||||
package net.runelite.client.plugins.xptracker;
|
|
||||||
|
|
||||||
import lombok.Data;
|
|
||||||
|
|
||||||
@Data
|
|
||||||
class XpStateTotal
|
|
||||||
{
|
|
||||||
private int xpGainedInSession = 0;
|
|
||||||
private int xpPerHour = 0;
|
|
||||||
|
|
||||||
void reset()
|
|
||||||
{
|
|
||||||
xpGainedInSession = 0;
|
|
||||||
xpPerHour = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void addXpGainedInSession(int skillXpGainedInSession)
|
|
||||||
{
|
|
||||||
xpGainedInSession += skillXpGainedInSession;
|
|
||||||
}
|
|
||||||
|
|
||||||
void addXpPerHour(int skillXpGainedPerHour)
|
|
||||||
{
|
|
||||||
xpPerHour += skillXpGainedPerHour;
|
|
||||||
}
|
|
||||||
|
|
||||||
XpSnapshotTotal snapshot()
|
|
||||||
{
|
|
||||||
return new XpSnapshotTotal(xpGainedInSession, xpPerHour);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -242,7 +242,7 @@ public class XpTrackerPlugin extends Plugin
|
|||||||
{
|
{
|
||||||
xpState.reset();
|
xpState.reset();
|
||||||
xpPanel.resetAllInfoBoxes();
|
xpPanel.resetAllInfoBoxes();
|
||||||
xpPanel.updateTotal(XpSnapshotTotal.zero());
|
xpPanel.updateTotal(new XpSnapshotSingle.XpSnapshotSingleBuilder().build());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -254,7 +254,6 @@ public class XpTrackerPlugin extends Plugin
|
|||||||
{
|
{
|
||||||
int currentXp = client.getSkillExperience(skill);
|
int currentXp = client.getSkillExperience(skill);
|
||||||
xpState.resetSkill(skill, currentXp);
|
xpState.resetSkill(skill, currentXp);
|
||||||
xpState.recalculateTotal();
|
|
||||||
xpPanel.resetSkill(skill);
|
xpPanel.resetSkill(skill);
|
||||||
xpPanel.updateTotal(xpState.getTotalSnapshot());
|
xpPanel.updateTotal(xpState.getTotalSnapshot());
|
||||||
}
|
}
|
||||||
@@ -302,10 +301,18 @@ public class XpTrackerPlugin extends Plugin
|
|||||||
}
|
}
|
||||||
|
|
||||||
final XpUpdateResult updateResult = xpState.updateSkill(skill, currentXp, startGoalXp, endGoalXp);
|
final XpUpdateResult updateResult = xpState.updateSkill(skill, currentXp, startGoalXp, endGoalXp);
|
||||||
final boolean updated = XpUpdateResult.UPDATED.equals(updateResult);
|
xpPanel.updateSkillExperience(updateResult == XpUpdateResult.UPDATED, xpPauseState.isPaused(skill), skill, xpState.getSkillSnapshot(skill));
|
||||||
xpPanel.updateSkillExperience(updated, xpPauseState.isPaused(skill), skill, xpState.getSkillSnapshot(skill));
|
|
||||||
xpState.recalculateTotal();
|
if (skill == Skill.CONSTRUCTION && updateResult == XpUpdateResult.INITIALIZED)
|
||||||
xpPanel.updateTotal(xpState.getTotalSnapshot());
|
{
|
||||||
|
// Construction is the last skill initialized on login, now initialize the total experience
|
||||||
|
xpState.initializeSkill(Skill.OVERALL, client.getSkillExperience(Skill.OVERALL));
|
||||||
|
}
|
||||||
|
else if (xpState.isInitialized(Skill.OVERALL))
|
||||||
|
{
|
||||||
|
xpState.updateSkill(Skill.OVERALL, client.getSkillExperience(Skill.OVERALL), -1, -1);
|
||||||
|
xpPanel.updateTotal(xpState.getTotalSnapshot());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
@@ -325,7 +332,6 @@ public class XpTrackerPlugin extends Plugin
|
|||||||
xpPanel.updateSkillExperience(updated, xpPauseState.isPaused(skill), skill, xpState.getSkillSnapshot(skill));
|
xpPanel.updateSkillExperience(updated, xpPauseState.isPaused(skill), skill, xpState.getSkillSnapshot(skill));
|
||||||
}
|
}
|
||||||
|
|
||||||
xpState.recalculateTotal();
|
|
||||||
xpPanel.updateTotal(xpState.getTotalSnapshot());
|
xpPanel.updateTotal(xpState.getTotalSnapshot());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -498,7 +504,6 @@ public class XpTrackerPlugin extends Plugin
|
|||||||
xpPanel.updateSkillExperience(false, xpPauseState.isPaused(skill), skill, xpState.getSkillSnapshot(skill));
|
xpPanel.updateSkillExperience(false, xpPauseState.isPaused(skill), skill, xpState.getSkillSnapshot(skill));
|
||||||
}
|
}
|
||||||
|
|
||||||
xpState.recalculateTotal();
|
|
||||||
xpPanel.updateTotal(xpState.getTotalSnapshot());
|
xpPanel.updateTotal(xpState.getTotalSnapshot());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user