Validate, and nicer loading.

This commit is contained in:
GJ 2013-08-21 15:52:51 -04:00 committed by TfT_02
parent 223649ec28
commit 8282d84b16
4 changed files with 46 additions and 44 deletions

View File

@ -1,5 +1,8 @@
package com.gmail.nossr50.config.experience;
import java.util.ArrayList;
import java.util.List;
import com.gmail.nossr50.config.AutoUpdateConfigLoader;
import com.gmail.nossr50.datatypes.experience.FormulaType;
import com.gmail.nossr50.datatypes.skills.SkillType;
@ -10,6 +13,7 @@ public class ExperienceConfig extends AutoUpdateConfigLoader {
private ExperienceConfig() {
super("experienceFormula.yml");
validate();
}
public static ExperienceConfig getInstance() {
@ -23,18 +27,37 @@ public class ExperienceConfig extends AutoUpdateConfigLoader {
@Override
protected void loadKeys() {}
@Override
protected boolean validateKeys() {
List<String> reason = new ArrayList<String>();
if (getExpModifier() <= 0) {
reason.add("Conversion.Exp_Modifier should be greater than 0!");
}
if (getMultiplier(FormulaType.EXPONENTIAL) <= 0) {
reason.add("Experience_Formula.Exponential_Values.multiplier should be greater than 0!");
}
if (getMultiplier(FormulaType.LINEAR) <= 0) {
reason.add("Experience_Formula.Linear_Values.multiplier should be greater than 0!");
}
if (getExponent(FormulaType.EXPONENTIAL) <= 0) {
reason.add("Experience_Formula.Exponential_Values.exponent should be greater than 0!");
}
return noErrorsInConfig(reason);
}
/* XP Formula Multiplier */
public FormulaType getFormulaType() { return FormulaType.getFormulaType(config.getString("Experience_Formula.Curve")); }
public boolean getCumulativeCurveEnabled() { return config.getBoolean("Experience_Formula.Cumulative_Curve", false); }
/* Linear curve values */
public int getLinearBase() { return config.getInt("Experience_Formula.Linear_Values.base", 1020); }
public double getLinearMultiplier() { return config.getDouble("Experience_Formula.Linear_Values.multiplier", 20); }
/* Exponential curve values */
public double getExponentialMultiplier() { return config.getDouble("Experience_Formula.Exponential_Values.multiplier", 0.1); }
public double getExponentialExponent() { return config.getDouble("Experience_Formula.Exponential_Values.exponent", 1.80); }
public int getExponentialBase() { return config.getInt("Experience_Formula.Exponential_Values.base", 2000); }
/* Curve values */
public double getMultiplier(FormulaType type) { return config.getDouble("Experience_Formula." + StringUtils.getCapitalized(type.toString()) + "_Values.multiplier"); }
public int getBase(FormulaType type) { return config.getInt("Experience_Formula." + StringUtils.getCapitalized(type.toString()) + "_Values.base"); }
public double getExponent(FormulaType type) { return config.getDouble("Experience_Formula." + StringUtils.getCapitalized(type.toString()) +"_Values.exponent"); }
/* Skill modifiers */
public double getFormulaSkillModifier(SkillType skill) { return config.getDouble("Experience_Formula.Modifier." + StringUtils.getCapitalized(skill.toString())); }

View File

@ -9,6 +9,7 @@ import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.config.HiddenConfig;
import com.gmail.nossr50.config.experience.ExperienceConfig;
import com.gmail.nossr50.datatypes.experience.FormulaType;
import com.gmail.nossr50.locale.LocaleLoader;
import com.turt2live.metrics.EMetrics;
import com.turt2live.metrics.Metrics;
@ -200,7 +201,7 @@ public class MetricsManager {
// GlobalCurveModifier Graph
Graph globalCurveModifierGraph = metrics.createGraph("Global Curve Modifier Graph");
globalCurveModifierGraph.addPlotter(new Metrics.Plotter(ExperienceConfig.getInstance().getLinearMultiplier() + "") {
globalCurveModifierGraph.addPlotter(new Metrics.Plotter(ExperienceConfig.getInstance().getMultiplier(FormulaType.LINEAR) + "") {
@Override
public int getValue() {
return 1;
@ -238,7 +239,7 @@ public class MetricsManager {
// GlobalCurveModifier Fuzzy Logic Numbers
Graph globalCurveMultiplierGraphFuzzy = metrics.createGraph("Global Curve Multiplier Fuzz");
if (ExperienceConfig.getInstance().getLinearMultiplier() > 20.0) {
if (ExperienceConfig.getInstance().getMultiplier(FormulaType.LINEAR) > 20.0) {
globalCurveMultiplierGraphFuzzy.addPlotter(new Metrics.Plotter("Higher") {
@Override
public int getValue() {
@ -246,7 +247,7 @@ public class MetricsManager {
}
});
}
else if (ExperienceConfig.getInstance().getLinearMultiplier() < 20.0) {
else if (ExperienceConfig.getInstance().getMultiplier(FormulaType.LINEAR) < 20.0) {
globalCurveMultiplierGraphFuzzy.addPlotter(new Metrics.Plotter("Lower") {
@Override
public int getValue() {

View File

@ -33,7 +33,7 @@ public class FormulaConversionTask extends BukkitRunnable {
profile = mcMMO.getDatabaseManager().loadPlayerProfile(playerName, false);
if (!profile.isLoaded()) {
mcMMO.p.debug("Profile not loaded");
mcMMO.p.debug("Profile not loaded.");
continue;
}
@ -62,15 +62,7 @@ public class FormulaConversionTask extends BukkitRunnable {
continue;
}
double modifier = ExperienceConfig.getInstance().getExpModifier();
//TODO: Why not validate like the other configs?
if (modifier <= 0) {
modifier = 1;
mcMMO.p.getLogger().warning("Invalid value found for Conversion.Exp_Modifier! Skipping using the modifier...");
}
int[] newExperienceValues = mcMMO.getFormulaManager().calculateNewLevel(skillType, (int) Math.floor(totalOldXP / modifier), formulaType);
int[] newExperienceValues = mcMMO.getFormulaManager().calculateNewLevel(skillType, (int) Math.floor(totalOldXP / ExperienceConfig.getInstance().getExpModifier()), formulaType);
int newLevel = newExperienceValues[0];
int newXPlevel = newExperienceValues[1];

View File

@ -105,20 +105,20 @@ public class FormulaManager {
*/
public int getCachedXpToLevel(int level, FormulaType formulaType) {
int experience;
double multiplier;
if (formulaType == FormulaType.UNKNOWN) {
formulaType = FormulaType.LINEAR;
}
int base = ExperienceConfig.getInstance().getBase(formulaType);
double multiplier = ExperienceConfig.getInstance().getMultiplier(formulaType);
double exponent = ExperienceConfig.getInstance().getExponent(formulaType);
switch (formulaType) {
case UNKNOWN:
case LINEAR:
if (!experienceNeededLinear.containsKey(level)) {
multiplier = ExperienceConfig.getInstance().getLinearMultiplier();
//TODO: Validate at load?
if (multiplier <= 0) {
multiplier = 20;
}
experience = (int) Math.floor(ExperienceConfig.getInstance().getLinearBase() + level * multiplier);
experience = (int) Math.floor(base + level * multiplier);
experienceNeededLinear.put(level, experience);
}
@ -126,20 +126,6 @@ public class FormulaManager {
case EXPONENTIAL:
if (!experienceNeededExponential.containsKey(level)) {
multiplier = ExperienceConfig.getInstance().getExponentialMultiplier();
double exponent = ExperienceConfig.getInstance().getExponentialExponent();
int base = ExperienceConfig.getInstance().getExponentialBase();
//TODO: Validate at load?
if (multiplier <= 0) {
multiplier = 0.1;
}
//TODO: Validate at load?
if (exponent <= 0) {
exponent = 1.80;
}
experience = (int) Math.floor(multiplier * Math.pow(level, exponent) + base);
experienceNeededExponential.put(level, experience);
}