xptracker: add auto reset per hour rates after set time
This commit is contained in:
@@ -26,6 +26,7 @@ package net.runelite.client.plugins.xptracker;
|
||||
|
||||
import java.util.EnumMap;
|
||||
import java.util.Map;
|
||||
import javax.inject.Inject;
|
||||
import lombok.NonNull;
|
||||
import net.runelite.api.NPC;
|
||||
import net.runelite.api.Skill;
|
||||
@@ -43,6 +44,9 @@ class XpState
|
||||
private final Map<Skill, XpStateSingle> xpSkills = new EnumMap<>(Skill.class);
|
||||
private NPC interactedNPC;
|
||||
|
||||
@Inject
|
||||
private XpTrackerConfig xpTrackerConfig;
|
||||
|
||||
/**
|
||||
* Destroys all internal state, however any XpSnapshotSingle or XpSnapshotTotal remain unaffected.
|
||||
*/
|
||||
@@ -196,7 +200,22 @@ class XpState
|
||||
|
||||
void tick(Skill skill, long delta)
|
||||
{
|
||||
getSkill(skill).tick(delta);
|
||||
final XpStateSingle state = getSkill(skill);
|
||||
|
||||
state.tick(delta);
|
||||
|
||||
int resetAfterMinutes = xpTrackerConfig.resetSkillRateAfter();
|
||||
if (resetAfterMinutes > 0)
|
||||
{
|
||||
final long now = System.currentTimeMillis();
|
||||
final int resetAfterMillis = resetAfterMinutes * 60 * 1000;
|
||||
final long lastChangeMillis = state.getLastChangeMillis();
|
||||
// When pauseSkillAfter is 0, it is effectively disabled
|
||||
if (lastChangeMillis != 0 && (now - lastChangeMillis) >= resetAfterMillis)
|
||||
{
|
||||
state.resetPerHour();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -54,6 +54,8 @@ class XpStateSingle
|
||||
|
||||
@Setter
|
||||
private long skillTime = 0;
|
||||
@Getter
|
||||
private long lastChangeMillis;
|
||||
|
||||
private int startLevelExp = 0;
|
||||
private int endLevelExp = 0;
|
||||
@@ -75,6 +77,12 @@ class XpStateSingle
|
||||
return startXp + getTotalXpGained();
|
||||
}
|
||||
|
||||
void setXpGainedSinceReset(int xpGainedSinceReset)
|
||||
{
|
||||
this.xpGainedSinceReset = xpGainedSinceReset;
|
||||
lastChangeMillis = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
int getTotalXpGained()
|
||||
{
|
||||
return xpGainedBeforeReset + xpGainedSinceReset;
|
||||
@@ -220,7 +228,7 @@ class XpStateSingle
|
||||
|
||||
//reset xp per hour
|
||||
xpGainedBeforeReset += xpGainedSinceReset;
|
||||
xpGainedSinceReset = 0;
|
||||
setXpGainedSinceReset(0);
|
||||
setSkillTime(0);
|
||||
}
|
||||
|
||||
@@ -264,7 +272,7 @@ class XpStateSingle
|
||||
action.setActionsSinceReset(action.getActionsSinceReset() + 1);
|
||||
|
||||
// Calculate experience gained
|
||||
xpGainedSinceReset = (int) (currentXp - (startXp + xpGainedBeforeReset));
|
||||
setXpGainedSinceReset((int) (currentXp - (startXp + xpGainedBeforeReset)));
|
||||
|
||||
// Determine XP goals, overall has no goals
|
||||
if (skill != Skill.OVERALL)
|
||||
|
||||
@@ -88,6 +88,18 @@ public interface XpTrackerConfig extends Config
|
||||
|
||||
@ConfigItem(
|
||||
position = 4,
|
||||
keyName = "resetSkillRateAfter",
|
||||
name = "Auto reset after",
|
||||
description = "Configures how many minutes passes before resetting a skill's per hour rates while in game and there's no XP, 0 means disabled"
|
||||
)
|
||||
@Units(Units.MINUTES)
|
||||
default int resetSkillRateAfter()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ConfigItem(
|
||||
position = 5,
|
||||
keyName = "skillTabOverlayMenuOptions",
|
||||
name = "Add skill tab canvas menu option",
|
||||
description = "Configures whether a menu option to show/hide canvas XP trackers will be added to skills on the skill tab",
|
||||
@@ -99,7 +111,7 @@ public interface XpTrackerConfig extends Config
|
||||
}
|
||||
|
||||
@ConfigItem(
|
||||
position = 5,
|
||||
position = 6,
|
||||
keyName = "onScreenDisplayMode",
|
||||
name = "On-screen tracker display mode (top)",
|
||||
description = "Configures the information displayed in the first line of on-screen XP overlays",
|
||||
@@ -111,7 +123,7 @@ public interface XpTrackerConfig extends Config
|
||||
}
|
||||
|
||||
@ConfigItem(
|
||||
position = 6,
|
||||
position = 7,
|
||||
keyName = "onScreenDisplayModeBottom",
|
||||
name = "On-screen tracker display mode (bottom)",
|
||||
description = "Configures the information displayed in the second line of on-screen XP overlays",
|
||||
@@ -123,7 +135,7 @@ public interface XpTrackerConfig extends Config
|
||||
}
|
||||
|
||||
@ConfigItem(
|
||||
position = 7,
|
||||
position = 8,
|
||||
keyName = "xpPanelLabel1",
|
||||
name = "Top-left XP info label",
|
||||
description = "Configures the information displayed in the top-left of XP info box"
|
||||
@@ -134,7 +146,7 @@ public interface XpTrackerConfig extends Config
|
||||
}
|
||||
|
||||
@ConfigItem(
|
||||
position = 8,
|
||||
position = 9,
|
||||
keyName = "xpPanelLabel2",
|
||||
name = "Top-right XP info label",
|
||||
description = "Configures the information displayed in the top-right of XP info box"
|
||||
@@ -146,7 +158,7 @@ public interface XpTrackerConfig extends Config
|
||||
}
|
||||
|
||||
@ConfigItem(
|
||||
position = 9,
|
||||
position = 10,
|
||||
keyName = "xpPanelLabel3",
|
||||
name = "Bottom-left XP info label",
|
||||
description = "Configures the information displayed in the bottom-left of XP info box"
|
||||
@@ -157,7 +169,7 @@ public interface XpTrackerConfig extends Config
|
||||
}
|
||||
|
||||
@ConfigItem(
|
||||
position = 10,
|
||||
position = 11,
|
||||
keyName = "xpPanelLabel4",
|
||||
name = "Bottom-right XP info label",
|
||||
description = "Configures the information displayed in the bottom-right of XP info box"
|
||||
@@ -168,7 +180,7 @@ public interface XpTrackerConfig extends Config
|
||||
}
|
||||
|
||||
@ConfigItem(
|
||||
position = 11,
|
||||
position = 12,
|
||||
keyName = "progressBarLabel",
|
||||
name = "Progress bar label",
|
||||
description = "Configures the info box progress bar to show Time to goal or percentage complete"
|
||||
@@ -179,7 +191,7 @@ public interface XpTrackerConfig extends Config
|
||||
}
|
||||
|
||||
@ConfigItem(
|
||||
position = 12,
|
||||
position = 13,
|
||||
keyName = "progressBarTooltipLabel",
|
||||
name = "Tooltip label",
|
||||
description = "Configures the info box progress bar tooltip to show Time to goal or percentage complete"
|
||||
@@ -190,7 +202,7 @@ public interface XpTrackerConfig extends Config
|
||||
}
|
||||
|
||||
@ConfigItem(
|
||||
position = 13,
|
||||
position = 14,
|
||||
keyName = "prioritizeRecentXpSkills",
|
||||
name = "Move recently trained skills to top",
|
||||
description = "Configures whether skills should be organized by most recently gained xp"
|
||||
|
||||
@@ -120,6 +120,9 @@ public class XpTrackerPlugin extends Plugin
|
||||
@Inject
|
||||
private XpClient xpClient;
|
||||
|
||||
@Inject
|
||||
private XpState xpState;
|
||||
|
||||
private NavigationButton navButton;
|
||||
@Setter(AccessLevel.PACKAGE)
|
||||
@VisibleForTesting
|
||||
@@ -131,7 +134,6 @@ public class XpTrackerPlugin extends Plugin
|
||||
private long lastXp = 0;
|
||||
private boolean initializeTracker;
|
||||
|
||||
private final XpState xpState = new XpState();
|
||||
private final XpPauseState xpPauseState = new XpPauseState();
|
||||
|
||||
@Provides
|
||||
|
||||
Reference in New Issue
Block a user