Average actions left between last 10 XP drops (#1323)
To remove jumping between actions left because of partial XP drops, average the actions left between last 10 experience drops.
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
/*
|
||||
* Copyright (c) 2017, Cameron <moberg@tuta.io>
|
||||
* Copyright (c) 2018, Levi <me@levischuck.com>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -41,10 +42,12 @@ class SkillXPInfo
|
||||
private int startXp = -1;
|
||||
private int xpGained = 0;
|
||||
private int actions = 0;
|
||||
private int actionExp = 0;
|
||||
private int nextLevelExp = 0;
|
||||
private int startLevelExp = 0;
|
||||
private int level = 0;
|
||||
private boolean initialized = false;
|
||||
private int[] actionExps = new int[10];
|
||||
private int actionExpIndex = 0;
|
||||
|
||||
int getXpHr()
|
||||
{
|
||||
@@ -79,7 +82,20 @@ class SkillXPInfo
|
||||
|
||||
int getActionsRemaining()
|
||||
{
|
||||
return (int) Math.ceil(getXpRemaining() / (float) actionExp);
|
||||
if (initialized)
|
||||
{
|
||||
long xpRemaining = getXpRemaining() * actionExps.length;
|
||||
long actionExp = 0;
|
||||
|
||||
for (int i = 0; i < actionExps.length; i++)
|
||||
{
|
||||
actionExp += actionExps[i];
|
||||
}
|
||||
|
||||
return Math.toIntExact(xpRemaining / actionExp);
|
||||
}
|
||||
|
||||
return Integer.MAX_VALUE;
|
||||
}
|
||||
|
||||
int getSkillProgress()
|
||||
@@ -126,7 +142,25 @@ class SkillXPInfo
|
||||
return false;
|
||||
}
|
||||
|
||||
actionExp = currentXp - originalXp;
|
||||
int actionExp = currentXp - originalXp;
|
||||
|
||||
if (initialized)
|
||||
{
|
||||
actionExps[actionExpIndex] = 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++)
|
||||
{
|
||||
actionExps[i] = actionExp;
|
||||
}
|
||||
|
||||
initialized = true;
|
||||
}
|
||||
|
||||
actionExpIndex = (actionExpIndex + 1) % actionExps.length;
|
||||
|
||||
actions++;
|
||||
xpGained = currentXp - startXp;
|
||||
startLevelExp = Experience.getXpForLevel(Experience.getLevelForXp(currentXp));
|
||||
|
||||
@@ -194,7 +194,7 @@ public class XpTrackerPlugin extends Plugin
|
||||
|
||||
public SkillXPInfo getSkillXpInfo(Skill skill)
|
||||
{
|
||||
return xpInfos.computeIfAbsent(skill, s -> new SkillXPInfo(s));
|
||||
return xpInfos.computeIfAbsent(skill, SkillXPInfo::new);
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
|
||||
Reference in New Issue
Block a user