|
@@ -1,7 +1,10 @@
|
|
|
package com.gmail.nossr50.datatypes.player;
|
|
|
|
|
|
import java.util.HashMap;
|
|
|
+import java.util.Iterator;
|
|
|
+import java.util.LinkedList;
|
|
|
import java.util.Map;
|
|
|
+import java.util.Map.Entry;
|
|
|
import java.util.Set;
|
|
|
import java.util.UUID;
|
|
|
|
|
@@ -12,6 +15,7 @@ import com.gmail.nossr50.datatypes.MobHealthbarType;
|
|
|
import com.gmail.nossr50.datatypes.experience.FormulaType;
|
|
|
import com.gmail.nossr50.datatypes.skills.AbilityType;
|
|
|
import com.gmail.nossr50.datatypes.skills.SkillType;
|
|
|
+import com.gmail.nossr50.datatypes.skills.SkillXpGain;
|
|
|
import com.gmail.nossr50.runnables.player.PlayerProfileSaveTask;
|
|
|
import com.gmail.nossr50.skills.child.FamilyTree;
|
|
|
import com.gmail.nossr50.util.player.UserManager;
|
|
@@ -33,7 +37,8 @@ public class PlayerProfile {
|
|
|
private final Map<AbilityType, Integer> abilityDATS = new HashMap<AbilityType, Integer>(); // Ability & Cooldown
|
|
|
|
|
|
// Store previous XP gains for diminished returns
|
|
|
- private Map<SkillType, Float> gainedSkillsXp = new HashMap<SkillType, Float>();
|
|
|
+ private HashMap<SkillType, LinkedList<SkillXpGain>> gainedSkillsXp = new HashMap<SkillType, LinkedList<SkillXpGain>>();
|
|
|
+ private HashMap<SkillType, Float> rollingSkillsXp = new HashMap<SkillType, Float>();
|
|
|
|
|
|
@Deprecated
|
|
|
public PlayerProfile(String playerName) {
|
|
@@ -283,38 +288,63 @@ public class PlayerProfile {
|
|
|
* @return xp Experience amount registered
|
|
|
*/
|
|
|
public float getRegisteredXpGain(SkillType skillType) {
|
|
|
- float xp;
|
|
|
-
|
|
|
- if (gainedSkillsXp.get(skillType) == null) {
|
|
|
- xp = 0F;
|
|
|
- }
|
|
|
- else {
|
|
|
- xp = gainedSkillsXp.get(skillType);
|
|
|
+ float xp = 0F;
|
|
|
+
|
|
|
+ if (rollingSkillsXp.get(skillType) != null) {
|
|
|
+ xp = rollingSkillsXp.get(skillType);
|
|
|
}
|
|
|
|
|
|
return xp;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Set registered experience gains
|
|
|
+ * Register an experience gain
|
|
|
* This is used for diminished XP returns
|
|
|
*
|
|
|
* @param skillType Skill being used
|
|
|
- * @param xp Experience amount to set
|
|
|
+ * @param xp Experience amount to add
|
|
|
*/
|
|
|
- public void setRegisteredXpGain(SkillType skillType, float xp) {
|
|
|
- gainedSkillsXp.put(skillType, xp);
|
|
|
+ public void registeredXpGain(SkillType skillType, float xp) {
|
|
|
+ LinkedList<SkillXpGain> gains = gainedSkillsXp.get(skillType);
|
|
|
+
|
|
|
+ if (gains == null) {
|
|
|
+ gains = new LinkedList<SkillXpGain>(); // Maybe add an initial capacity?
|
|
|
+ }
|
|
|
+ gains.addLast(new SkillXpGain(System.currentTimeMillis(), xp));
|
|
|
+
|
|
|
+ gainedSkillsXp.put(skillType, gains);
|
|
|
+ rollingSkillsXp.put(skillType, getRegisteredXpGain(skillType) + xp);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Register an experience gain
|
|
|
+ * Remove experience gains older than a given time
|
|
|
* This is used for diminished XP returns
|
|
|
*
|
|
|
- * @param skillType Skill being used
|
|
|
- * @param xp Experience amount to add
|
|
|
+ * @param age Age in milliseconds that gains older than should be removed
|
|
|
*/
|
|
|
- public void registeredXpGain(SkillType skillType, float xp) {
|
|
|
- gainedSkillsXp.put(skillType, getRegisteredXpGain(skillType) + xp);
|
|
|
+ public void removeXpGainsOlderThan(long age) {
|
|
|
+ long now = System.currentTimeMillis();
|
|
|
+
|
|
|
+ Iterator<Entry<SkillType, LinkedList<SkillXpGain>>> iterator = gainedSkillsXp.entrySet().iterator();
|
|
|
+ while (iterator.hasNext()) {
|
|
|
+ Entry<SkillType, LinkedList<SkillXpGain>> skillGains = iterator.next();
|
|
|
+
|
|
|
+ float xp = 0;
|
|
|
+ // Because we are using a LinkedList and addLast ordering is guaranteed, so we loop through and remove things that are too old, and stop immediately once we find a young'n
|
|
|
+ Iterator<SkillXpGain> gainsIterator = skillGains.getValue().iterator();
|
|
|
+ while (gainsIterator.hasNext()) {
|
|
|
+ SkillXpGain gain = gainsIterator.next();
|
|
|
+
|
|
|
+ if (now - gain.getTime() >= age) {
|
|
|
+ gainsIterator.remove();
|
|
|
+ xp += gain.getXp();
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ rollingSkillsXp.put(skillGains.getKey(), rollingSkillsXp.get(skillGains.getKey()) - xp);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|