Create different action types for XpTracker plugin
Signed-off-by: Tomas Slusny <slusnucky@gmail.com>
This commit is contained in:
@@ -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;
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
@@ -59,8 +59,8 @@ class XpInfoBox extends JPanel
|
||||
|
||||
// Templates
|
||||
private static final String HTML_TOOL_TIP_TEMPLATE =
|
||||
"<html>%s actions done<br/>"
|
||||
+ "%s actions/hr<br/>"
|
||||
"<html>%s %s done<br/>"
|
||||
+ "%s %s/hr<br/>"
|
||||
+ "%s till goal lvl</html>";
|
||||
private static final String HTML_LABEL_TEMPLATE =
|
||||
"<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
|
||||
expGained.setText(htmlLabel("XP Gained: ", xpSnapshotSingle.getXpGainedInSession()));
|
||||
expLeft.setText(htmlLabel("XP Left: ", xpSnapshotSingle.getXpRemainingToGoal()));
|
||||
actionsLeft.setText(htmlLabel("Actions: ", xpSnapshotSingle.getActionsRemainingToGoal()));
|
||||
actionsLeft.setText(htmlLabel(xpSnapshotSingle.getActionType().getLabel() + ": ", xpSnapshotSingle.getActionsRemainingToGoal()));
|
||||
|
||||
// Update progress bar
|
||||
progressBar.setValue((int) xpSnapshotSingle.getSkillProgressToGoal());
|
||||
@@ -210,7 +210,9 @@ class XpInfoBox extends JPanel
|
||||
progressBar.setToolTipText(String.format(
|
||||
HTML_TOOL_TIP_TEMPLATE,
|
||||
xpSnapshotSingle.getActionsInSession(),
|
||||
xpSnapshotSingle.getActionType().getLabel(),
|
||||
xpSnapshotSingle.getActionsPerHour(),
|
||||
xpSnapshotSingle.getActionType().getLabel(),
|
||||
xpSnapshotSingle.getTimeTillGoal()));
|
||||
|
||||
progressBar.setDimmed(skillPaused);
|
||||
|
||||
@@ -31,6 +31,7 @@ import lombok.Value;
|
||||
@Value
|
||||
class XpSnapshotSingle
|
||||
{
|
||||
private XpActionType actionType;
|
||||
private int startLevel;
|
||||
private int endLevel;
|
||||
private int startGoalXp;
|
||||
|
||||
@@ -25,8 +25,11 @@
|
||||
*/
|
||||
package net.runelite.client.plugins.xptracker;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.runelite.api.Experience;
|
||||
import net.runelite.api.Skill;
|
||||
@@ -36,6 +39,7 @@ import net.runelite.api.Skill;
|
||||
class XpStateSingle
|
||||
{
|
||||
private final Skill skill;
|
||||
private final Map<XpActionType, XpAction> actions = new HashMap<>();
|
||||
|
||||
@Getter
|
||||
private final int startXp;
|
||||
@@ -43,13 +47,18 @@ class XpStateSingle
|
||||
@Getter
|
||||
private int xpGained = 0;
|
||||
|
||||
@Setter
|
||||
private XpActionType actionType = XpActionType.EXPERIENCE;
|
||||
|
||||
private long skillTime = 0;
|
||||
private int actions = 0;
|
||||
private int startLevelExp = 0;
|
||||
private int endLevelExp = 0;
|
||||
private boolean actionsHistoryInitialized = false;
|
||||
private int[] actionExps = new int[10];
|
||||
private int actionExpIndex = 0;
|
||||
|
||||
private XpAction getXpAction(final XpActionType type)
|
||||
{
|
||||
actions.putIfAbsent(type, new XpAction());
|
||||
return actions.get(type);
|
||||
}
|
||||
|
||||
private int getCurrentXp()
|
||||
{
|
||||
@@ -58,7 +67,7 @@ class XpStateSingle
|
||||
|
||||
private int getActionsHr()
|
||||
{
|
||||
return toHourly(actions);
|
||||
return toHourly(getXpAction(actionType).getActions());
|
||||
}
|
||||
|
||||
private int toHourly(int value)
|
||||
@@ -92,12 +101,14 @@ class XpStateSingle
|
||||
|
||||
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;
|
||||
|
||||
for (int actionXp : actionExps)
|
||||
for (int actionXp : action.getActionExps())
|
||||
{
|
||||
totalActionXp += actionXp;
|
||||
}
|
||||
@@ -186,23 +197,26 @@ class XpStateSingle
|
||||
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
|
||||
{
|
||||
// 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;
|
||||
actions++;
|
||||
action.setActionExpIndex((action.getActionExpIndex() + 1) % action.getActionExps().length);
|
||||
action.setActions(action.getActions() + 1);
|
||||
|
||||
// Calculate experience gained
|
||||
xpGained = currentXp - startXp;
|
||||
@@ -251,7 +265,8 @@ class XpStateSingle
|
||||
.xpRemainingToGoal(getXpRemaining())
|
||||
.xpPerHour(getXpHr())
|
||||
.skillProgressToGoal(getSkillProgress())
|
||||
.actionsInSession(actions)
|
||||
.actionType(actionType)
|
||||
.actionsInSession(getXpAction(actionType).getActions())
|
||||
.actionsRemainingToGoal(getActionsRemaining())
|
||||
.actionsPerHour(getActionsHr())
|
||||
.timeTillGoal(getTimeTillLevel())
|
||||
|
||||
Reference in New Issue
Block a user