Removing the clunky previous formula file design

This commit is contained in:
nossr50 2019-05-30 15:33:57 -07:00
parent b27d46f0cc
commit 8d10f8053f
4 changed files with 29 additions and 74 deletions

View File

@ -2,14 +2,5 @@ package com.gmail.nossr50.datatypes.experience;
public enum FormulaType { public enum FormulaType {
LINEAR, LINEAR,
EXPONENTIAL, EXPONENTIAL
UNKNOWN;
public static FormulaType getFormulaType(String string) {
try {
return valueOf(string);
} catch (IllegalArgumentException ex) {
return UNKNOWN;
}
}
} }

View File

@ -14,6 +14,7 @@ import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import sun.security.krb5.Config;
import java.text.DecimalFormat; import java.text.DecimalFormat;
import java.util.ArrayList; import java.util.ArrayList;
@ -193,12 +194,7 @@ public class Party {
} }
public int getXpToLevel() { public int getXpToLevel() {
<<<<<<< HEAD return mcMMO.getFormulaManager().getXPtoNextLevel(level);
return mcMMO.getFormulaManager().getPartyCachedXpToLevel(level);
=======
FormulaType formulaType = ExperienceConfig.getInstance().getFormulaType();
return (mcMMO.getFormulaManager().getXPtoNextLevel(level, formulaType)) * (getOnlineMembers().size() + Config.getInstance().getPartyXpCurveMultiplier());
>>>>>>> ff1bb0deed61cda7daa75a374da3942de9e2e172
} }
public String getXpToLevelPercentage() { public String getXpToLevelPercentage() {

View File

@ -390,7 +390,6 @@ public class PlayerProfile {
*/ */
public int getXpToLevel(PrimarySkillType primarySkillType) { public int getXpToLevel(PrimarySkillType primarySkillType) {
int level = (mcMMO.getConfigManager().getConfigLeveling().getConfigExperienceFormula().isCumulativeCurveEnabled()) ? UserManager.getPlayer(playerName).getPowerLevel() : skills.get(primarySkillType); int level = (mcMMO.getConfigManager().getConfigLeveling().getConfigExperienceFormula().isCumulativeCurveEnabled()) ? UserManager.getPlayer(playerName).getPowerLevel() : skills.get(primarySkillType);
FormulaType formulaType = mcMMO.getConfigManager().getConfigLeveling().getFormulaType();
return mcMMO.getFormulaManager().getXPtoNextLevel(level, formulaType); return mcMMO.getFormulaManager().getXPtoNextLevel(level, formulaType);
} }

View File

@ -3,6 +3,7 @@ package com.gmail.nossr50.util.experience;
import com.gmail.nossr50.datatypes.experience.FormulaType; import com.gmail.nossr50.datatypes.experience.FormulaType;
import com.gmail.nossr50.datatypes.skills.PrimarySkillType; import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.mcMMO;
import com.sk89q.worldedit.internal.expression.runtime.For;
import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.configuration.file.YamlConfiguration;
import java.io.File; import java.io.File;
@ -12,18 +13,17 @@ import java.util.Map;
public class FormulaManager { public class FormulaManager {
private static File formulaFile = new File(mcMMO.getFlatFileDirectory() + "formula.yml"); private static File formulaFile = new File(mcMMO.getFlatFileDirectory() + "formula.yml");
// Experience needed to reach a level, cached values to improve conversion speed // Experience needed to reach a level, cached values for speed
private Map<Integer, Integer> experienceNeededRetroLinear; private Map<Integer, Integer> experienceNeededRetroLinear;
private Map<Integer, Integer> experienceNeededStandardLinear; private Map<Integer, Integer> experienceNeededStandardLinear;
private Map<Integer, Integer> experienceNeededRetroExponential; private Map<Integer, Integer> experienceNeededRetroExponential;
private Map<Integer, Integer> experienceNeededStandardExponential; private Map<Integer, Integer> experienceNeededStandardExponential;
private FormulaType previousFormula; private FormulaType currentFormula;
public FormulaManager() { public FormulaManager() {
/* Setting for Classic Mode (Scales a lot of stuff up by * 10) */ currentFormula = mcMMO.getConfigManager().getConfigLeveling().getFormulaType();
initExperienceNeededMaps(); initExperienceNeededMaps();
loadFormula();
} }
/** /**
@ -36,24 +36,6 @@ public class FormulaManager {
experienceNeededStandardExponential = new HashMap<>(); experienceNeededStandardExponential = new HashMap<>();
} }
/**
* Get the formula type that was used before converting
*
* @return previously used formula type
*/
public FormulaType getPreviousFormulaType() {
return previousFormula;
}
/**
* Set the formula type that was used before converting
*
* @param previousFormulaType The {@link FormulaType} previously used
*/
public void setPreviousFormulaType(FormulaType previousFormulaType) {
this.previousFormula = previousFormulaType;
}
/** /**
* Calculate the total amount of experience earned based on * Calculate the total amount of experience earned based on
* the amount of levels and experience, using the previously * the amount of levels and experience, using the previously
@ -61,13 +43,14 @@ public class FormulaManager {
* *
* @param skillLevel Amount of levels * @param skillLevel Amount of levels
* @param skillXPLevel Amount of experience * @param skillXPLevel Amount of experience
* @param formulaType Formula to calculate XP for
* @return The total amount of experience * @return The total amount of experience
*/ */
public int calculateTotalExperience(int skillLevel, int skillXPLevel) { public int calculateTotalExperience(int skillLevel, int skillXPLevel, FormulaType formulaType) {
int totalXP = 0; int totalXP = 0;
for (int level = 0; level < skillLevel; level++) { for (int level = 0; level < skillLevel; level++) {
totalXP += getXPtoNextLevel(level, previousFormula); totalXP += getXPtoNextLevel(level, formulaType);
} }
totalXP += skillXPLevel; totalXP += skillXPLevel;
@ -119,12 +102,26 @@ public class FormulaManager {
* Standard mode XP requirements are multiplied by a factor of 10 * Standard mode XP requirements are multiplied by a factor of 10
*/ */
//TODO: When the heck is Unknown used? return processXPToNextLevel(level, formulaType);
if (formulaType == FormulaType.UNKNOWN) {
formulaType = FormulaType.LINEAR;
} }
return processXPToNextLevel(level, formulaType); /**
* Get the cached amount of experience needed to reach the next level,
* if cache doesn't contain the given value it is calculated and added
* to the cached data.
*
* Uses the formula specified in the user configuration file
*
* @param level level to check
* @return amount of experience needed to reach next level
*/
public int getXPtoNextLevel(int level) {
/**
* Retro mode XP requirements are the default requirements
* Standard mode XP requirements are multiplied by a factor of 10
*/
return processXPToNextLevel(level, currentFormula);
} }
/** /**
@ -206,32 +203,4 @@ public class FormulaManager {
return calculateXPNeeded(level, FormulaType.LINEAR); return calculateXPNeeded(level, FormulaType.LINEAR);
} }
} }
/**
* Load formula file.
*/
public void loadFormula() {
if (!formulaFile.exists()) {
previousFormula = FormulaType.UNKNOWN;
return;
}
previousFormula = FormulaType.getFormulaType(YamlConfiguration.loadConfiguration(formulaFile).getString("Previous_Formula", "UNKNOWN"));
}
/**
* Save formula file.
*/
public void saveFormula() {
mcMMO.p.debug("Saving previous XP formula type...");
YamlConfiguration formulasFile = new YamlConfiguration();
formulasFile.set("Previous_Formula", previousFormula.toString());
try {
formulasFile.save(formulaFile);
}
catch (Exception e) {
e.printStackTrace();
}
}
} }