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.EnumMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import javax.inject.Inject;
|
||||||
import lombok.NonNull;
|
import lombok.NonNull;
|
||||||
import net.runelite.api.NPC;
|
import net.runelite.api.NPC;
|
||||||
import net.runelite.api.Skill;
|
import net.runelite.api.Skill;
|
||||||
@@ -43,6 +44,9 @@ class XpState
|
|||||||
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;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private XpTrackerConfig xpTrackerConfig;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Destroys all internal state, however any XpSnapshotSingle or XpSnapshotTotal remain unaffected.
|
* Destroys all internal state, however any XpSnapshotSingle or XpSnapshotTotal remain unaffected.
|
||||||
*/
|
*/
|
||||||
@@ -196,7 +200,22 @@ class XpState
|
|||||||
|
|
||||||
void tick(Skill skill, long delta)
|
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
|
@Setter
|
||||||
private long skillTime = 0;
|
private long skillTime = 0;
|
||||||
|
@Getter
|
||||||
|
private long lastChangeMillis;
|
||||||
|
|
||||||
private int startLevelExp = 0;
|
private int startLevelExp = 0;
|
||||||
private int endLevelExp = 0;
|
private int endLevelExp = 0;
|
||||||
@@ -75,6 +77,12 @@ class XpStateSingle
|
|||||||
return startXp + getTotalXpGained();
|
return startXp + getTotalXpGained();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void setXpGainedSinceReset(int xpGainedSinceReset)
|
||||||
|
{
|
||||||
|
this.xpGainedSinceReset = xpGainedSinceReset;
|
||||||
|
lastChangeMillis = System.currentTimeMillis();
|
||||||
|
}
|
||||||
|
|
||||||
int getTotalXpGained()
|
int getTotalXpGained()
|
||||||
{
|
{
|
||||||
return xpGainedBeforeReset + xpGainedSinceReset;
|
return xpGainedBeforeReset + xpGainedSinceReset;
|
||||||
@@ -220,7 +228,7 @@ class XpStateSingle
|
|||||||
|
|
||||||
//reset xp per hour
|
//reset xp per hour
|
||||||
xpGainedBeforeReset += xpGainedSinceReset;
|
xpGainedBeforeReset += xpGainedSinceReset;
|
||||||
xpGainedSinceReset = 0;
|
setXpGainedSinceReset(0);
|
||||||
setSkillTime(0);
|
setSkillTime(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -264,7 +272,7 @@ class XpStateSingle
|
|||||||
action.setActionsSinceReset(action.getActionsSinceReset() + 1);
|
action.setActionsSinceReset(action.getActionsSinceReset() + 1);
|
||||||
|
|
||||||
// Calculate experience gained
|
// Calculate experience gained
|
||||||
xpGainedSinceReset = (int) (currentXp - (startXp + xpGainedBeforeReset));
|
setXpGainedSinceReset((int) (currentXp - (startXp + xpGainedBeforeReset)));
|
||||||
|
|
||||||
// Determine XP goals, overall has no goals
|
// Determine XP goals, overall has no goals
|
||||||
if (skill != Skill.OVERALL)
|
if (skill != Skill.OVERALL)
|
||||||
|
|||||||
@@ -88,6 +88,18 @@ public interface XpTrackerConfig extends Config
|
|||||||
|
|
||||||
@ConfigItem(
|
@ConfigItem(
|
||||||
position = 4,
|
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",
|
keyName = "skillTabOverlayMenuOptions",
|
||||||
name = "Add skill tab canvas menu option",
|
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",
|
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(
|
@ConfigItem(
|
||||||
position = 5,
|
position = 6,
|
||||||
keyName = "onScreenDisplayMode",
|
keyName = "onScreenDisplayMode",
|
||||||
name = "On-screen tracker display mode (top)",
|
name = "On-screen tracker display mode (top)",
|
||||||
description = "Configures the information displayed in the first line of on-screen XP overlays",
|
description = "Configures the information displayed in the first line of on-screen XP overlays",
|
||||||
@@ -111,7 +123,7 @@ public interface XpTrackerConfig extends Config
|
|||||||
}
|
}
|
||||||
|
|
||||||
@ConfigItem(
|
@ConfigItem(
|
||||||
position = 6,
|
position = 7,
|
||||||
keyName = "onScreenDisplayModeBottom",
|
keyName = "onScreenDisplayModeBottom",
|
||||||
name = "On-screen tracker display mode (bottom)",
|
name = "On-screen tracker display mode (bottom)",
|
||||||
description = "Configures the information displayed in the second line of on-screen XP overlays",
|
description = "Configures the information displayed in the second line of on-screen XP overlays",
|
||||||
@@ -123,7 +135,7 @@ public interface XpTrackerConfig extends Config
|
|||||||
}
|
}
|
||||||
|
|
||||||
@ConfigItem(
|
@ConfigItem(
|
||||||
position = 7,
|
position = 8,
|
||||||
keyName = "xpPanelLabel1",
|
keyName = "xpPanelLabel1",
|
||||||
name = "Top-left XP info label",
|
name = "Top-left XP info label",
|
||||||
description = "Configures the information displayed in the top-left of XP info box"
|
description = "Configures the information displayed in the top-left of XP info box"
|
||||||
@@ -134,7 +146,7 @@ public interface XpTrackerConfig extends Config
|
|||||||
}
|
}
|
||||||
|
|
||||||
@ConfigItem(
|
@ConfigItem(
|
||||||
position = 8,
|
position = 9,
|
||||||
keyName = "xpPanelLabel2",
|
keyName = "xpPanelLabel2",
|
||||||
name = "Top-right XP info label",
|
name = "Top-right XP info label",
|
||||||
description = "Configures the information displayed in the top-right of XP info box"
|
description = "Configures the information displayed in the top-right of XP info box"
|
||||||
@@ -146,7 +158,7 @@ public interface XpTrackerConfig extends Config
|
|||||||
}
|
}
|
||||||
|
|
||||||
@ConfigItem(
|
@ConfigItem(
|
||||||
position = 9,
|
position = 10,
|
||||||
keyName = "xpPanelLabel3",
|
keyName = "xpPanelLabel3",
|
||||||
name = "Bottom-left XP info label",
|
name = "Bottom-left XP info label",
|
||||||
description = "Configures the information displayed in the bottom-left of XP info box"
|
description = "Configures the information displayed in the bottom-left of XP info box"
|
||||||
@@ -157,7 +169,7 @@ public interface XpTrackerConfig extends Config
|
|||||||
}
|
}
|
||||||
|
|
||||||
@ConfigItem(
|
@ConfigItem(
|
||||||
position = 10,
|
position = 11,
|
||||||
keyName = "xpPanelLabel4",
|
keyName = "xpPanelLabel4",
|
||||||
name = "Bottom-right XP info label",
|
name = "Bottom-right XP info label",
|
||||||
description = "Configures the information displayed in the bottom-right of XP info box"
|
description = "Configures the information displayed in the bottom-right of XP info box"
|
||||||
@@ -168,7 +180,7 @@ public interface XpTrackerConfig extends Config
|
|||||||
}
|
}
|
||||||
|
|
||||||
@ConfigItem(
|
@ConfigItem(
|
||||||
position = 11,
|
position = 12,
|
||||||
keyName = "progressBarLabel",
|
keyName = "progressBarLabel",
|
||||||
name = "Progress bar label",
|
name = "Progress bar label",
|
||||||
description = "Configures the info box progress bar to show Time to goal or percentage complete"
|
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(
|
@ConfigItem(
|
||||||
position = 12,
|
position = 13,
|
||||||
keyName = "progressBarTooltipLabel",
|
keyName = "progressBarTooltipLabel",
|
||||||
name = "Tooltip label",
|
name = "Tooltip label",
|
||||||
description = "Configures the info box progress bar tooltip to show Time to goal or percentage complete"
|
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(
|
@ConfigItem(
|
||||||
position = 13,
|
position = 14,
|
||||||
keyName = "prioritizeRecentXpSkills",
|
keyName = "prioritizeRecentXpSkills",
|
||||||
name = "Move recently trained skills to top",
|
name = "Move recently trained skills to top",
|
||||||
description = "Configures whether skills should be organized by most recently gained xp"
|
description = "Configures whether skills should be organized by most recently gained xp"
|
||||||
|
|||||||
@@ -120,6 +120,9 @@ public class XpTrackerPlugin extends Plugin
|
|||||||
@Inject
|
@Inject
|
||||||
private XpClient xpClient;
|
private XpClient xpClient;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private XpState xpState;
|
||||||
|
|
||||||
private NavigationButton navButton;
|
private NavigationButton navButton;
|
||||||
@Setter(AccessLevel.PACKAGE)
|
@Setter(AccessLevel.PACKAGE)
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
@@ -131,7 +134,6 @@ public class XpTrackerPlugin extends Plugin
|
|||||||
private long lastXp = 0;
|
private long lastXp = 0;
|
||||||
private boolean initializeTracker;
|
private boolean initializeTracker;
|
||||||
|
|
||||||
private final XpState xpState = new XpState();
|
|
||||||
private final XpPauseState xpPauseState = new XpPauseState();
|
private final XpPauseState xpPauseState = new XpPauseState();
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
|
|||||||
Reference in New Issue
Block a user