Create different action types for XpTracker plugin

Signed-off-by: Tomas Slusny <slusnucky@gmail.com>
This commit is contained in:
Tomas Slusny
2018-10-24 14:12:47 +02:00
parent 1f13c27a6a
commit 74a2313449
5 changed files with 110 additions and 19 deletions

View File

@@ -0,0 +1,36 @@
/*
* Copyright (c) 2018, Tomas Slusny <slusnucky@gmail.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 XpAction
{
private int actions = 0;
private boolean actionsHistoryInitialized = false;
private int[] actionExps = new int[10];
private int actionExpIndex = 0;
}

View File

@@ -0,0 +1,37 @@
/*
* Copyright (c) 2018, Tomas Slusny <slusnucky@gmail.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.AllArgsConstructor;
import lombok.Getter;
@Getter
@AllArgsConstructor
enum XpActionType
{
EXPERIENCE("Actions");
private final String label;
}

View File

@@ -59,8 +59,8 @@ class XpInfoBox extends JPanel
// Templates // Templates
private static final String HTML_TOOL_TIP_TEMPLATE = private static final String HTML_TOOL_TIP_TEMPLATE =
"<html>%s actions done<br/>" "<html>%s %s done<br/>"
+ "%s actions/hr<br/>" + "%s %s/hr<br/>"
+ "%s till goal lvl</html>"; + "%s till goal lvl</html>";
private static final String HTML_LABEL_TEMPLATE = private static final String HTML_LABEL_TEMPLATE =
"<html><body style='color:%s'>%s<span style='color:white'>%s</span></body></html>"; "<html><body style='color:%s'>%s<span style='color:white'>%s</span></body></html>";
@@ -197,7 +197,7 @@ class XpInfoBox extends JPanel
// Update information labels // Update information labels
expGained.setText(htmlLabel("XP Gained: ", xpSnapshotSingle.getXpGainedInSession())); expGained.setText(htmlLabel("XP Gained: ", xpSnapshotSingle.getXpGainedInSession()));
expLeft.setText(htmlLabel("XP Left: ", xpSnapshotSingle.getXpRemainingToGoal())); expLeft.setText(htmlLabel("XP Left: ", xpSnapshotSingle.getXpRemainingToGoal()));
actionsLeft.setText(htmlLabel("Actions: ", xpSnapshotSingle.getActionsRemainingToGoal())); actionsLeft.setText(htmlLabel(xpSnapshotSingle.getActionType().getLabel() + ": ", xpSnapshotSingle.getActionsRemainingToGoal()));
// Update progress bar // Update progress bar
progressBar.setValue((int) xpSnapshotSingle.getSkillProgressToGoal()); progressBar.setValue((int) xpSnapshotSingle.getSkillProgressToGoal());
@@ -210,7 +210,9 @@ class XpInfoBox extends JPanel
progressBar.setToolTipText(String.format( progressBar.setToolTipText(String.format(
HTML_TOOL_TIP_TEMPLATE, HTML_TOOL_TIP_TEMPLATE,
xpSnapshotSingle.getActionsInSession(), xpSnapshotSingle.getActionsInSession(),
xpSnapshotSingle.getActionType().getLabel(),
xpSnapshotSingle.getActionsPerHour(), xpSnapshotSingle.getActionsPerHour(),
xpSnapshotSingle.getActionType().getLabel(),
xpSnapshotSingle.getTimeTillGoal())); xpSnapshotSingle.getTimeTillGoal()));
progressBar.setDimmed(skillPaused); progressBar.setDimmed(skillPaused);

View File

@@ -31,6 +31,7 @@ import lombok.Value;
@Value @Value
class XpSnapshotSingle class XpSnapshotSingle
{ {
private XpActionType actionType;
private int startLevel; private int startLevel;
private int endLevel; private int endLevel;
private int startGoalXp; private int startGoalXp;

View File

@@ -25,8 +25,11 @@
*/ */
package net.runelite.client.plugins.xptracker; package net.runelite.client.plugins.xptracker;
import java.util.HashMap;
import java.util.Map;
import lombok.Getter; import lombok.Getter;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import net.runelite.api.Experience; import net.runelite.api.Experience;
import net.runelite.api.Skill; import net.runelite.api.Skill;
@@ -36,6 +39,7 @@ import net.runelite.api.Skill;
class XpStateSingle class XpStateSingle
{ {
private final Skill skill; private final Skill skill;
private final Map<XpActionType, XpAction> actions = new HashMap<>();
@Getter @Getter
private final int startXp; private final int startXp;
@@ -43,13 +47,18 @@ class XpStateSingle
@Getter @Getter
private int xpGained = 0; private int xpGained = 0;
@Setter
private XpActionType actionType = XpActionType.EXPERIENCE;
private long skillTime = 0; private long skillTime = 0;
private int actions = 0;
private int startLevelExp = 0; private int startLevelExp = 0;
private int endLevelExp = 0; private int endLevelExp = 0;
private boolean actionsHistoryInitialized = false;
private int[] actionExps = new int[10]; private XpAction getXpAction(final XpActionType type)
private int actionExpIndex = 0; {
actions.putIfAbsent(type, new XpAction());
return actions.get(type);
}
private int getCurrentXp() private int getCurrentXp()
{ {
@@ -58,7 +67,7 @@ class XpStateSingle
private int getActionsHr() private int getActionsHr()
{ {
return toHourly(actions); return toHourly(getXpAction(actionType).getActions());
} }
private int toHourly(int value) private int toHourly(int value)
@@ -92,12 +101,14 @@ class XpStateSingle
private int getActionsRemaining() private int getActionsRemaining()
{ {
if (actionsHistoryInitialized) final XpAction action = getXpAction(actionType);
if (action.isActionsHistoryInitialized())
{ {
long xpRemaining = getXpRemaining() * actionExps.length; long xpRemaining = getXpRemaining() * action.getActionExps().length;
long totalActionXp = 0; long totalActionXp = 0;
for (int actionXp : actionExps) for (int actionXp : action.getActionExps())
{ {
totalActionXp += actionXp; totalActionXp += actionXp;
} }
@@ -186,23 +197,26 @@ class XpStateSingle
return false; return false;
} }
if (actionsHistoryInitialized) // Update EXPERIENCE action
final XpAction action = getXpAction(XpActionType.EXPERIENCE);
if (action.isActionsHistoryInitialized())
{ {
actionExps[actionExpIndex] = actionExp; action.getActionExps()[action.getActionExpIndex()] = actionExp;
} }
else else
{ {
// So we have a decent average off the bat, lets populate all values with what we see. // So we have a decent average off the bat, lets populate all values with what we see.
for (int i = 0; i < actionExps.length; i++) for (int i = 0; i < action.getActionExps().length; i++)
{ {
actionExps[i] = actionExp; action.getActionExps()[i] = actionExp;
} }
actionsHistoryInitialized = true; action.setActionsHistoryInitialized(true);
} }
actionExpIndex = (actionExpIndex + 1) % actionExps.length; action.setActionExpIndex((action.getActionExpIndex() + 1) % action.getActionExps().length);
actions++; action.setActions(action.getActions() + 1);
// Calculate experience gained // Calculate experience gained
xpGained = currentXp - startXp; xpGained = currentXp - startXp;
@@ -251,7 +265,8 @@ class XpStateSingle
.xpRemainingToGoal(getXpRemaining()) .xpRemainingToGoal(getXpRemaining())
.xpPerHour(getXpHr()) .xpPerHour(getXpHr())
.skillProgressToGoal(getSkillProgress()) .skillProgressToGoal(getSkillProgress())
.actionsInSession(actions) .actionType(actionType)
.actionsInSession(getXpAction(actionType).getActions())
.actionsRemainingToGoal(getActionsRemaining()) .actionsRemainingToGoal(getActionsRemaining())
.actionsPerHour(getActionsHr()) .actionsPerHour(getActionsHr())
.timeTillGoal(getTimeTillLevel()) .timeTillGoal(getTimeTillLevel())