mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-25 14:46:46 +01:00
Validate, and nicer loading.
This commit is contained in:
parent
223649ec28
commit
8282d84b16
@ -1,5 +1,8 @@
|
|||||||
package com.gmail.nossr50.config.experience;
|
package com.gmail.nossr50.config.experience;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import com.gmail.nossr50.config.AutoUpdateConfigLoader;
|
import com.gmail.nossr50.config.AutoUpdateConfigLoader;
|
||||||
import com.gmail.nossr50.datatypes.experience.FormulaType;
|
import com.gmail.nossr50.datatypes.experience.FormulaType;
|
||||||
import com.gmail.nossr50.datatypes.skills.SkillType;
|
import com.gmail.nossr50.datatypes.skills.SkillType;
|
||||||
@ -10,6 +13,7 @@ public class ExperienceConfig extends AutoUpdateConfigLoader {
|
|||||||
|
|
||||||
private ExperienceConfig() {
|
private ExperienceConfig() {
|
||||||
super("experienceFormula.yml");
|
super("experienceFormula.yml");
|
||||||
|
validate();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ExperienceConfig getInstance() {
|
public static ExperienceConfig getInstance() {
|
||||||
@ -23,18 +27,37 @@ public class ExperienceConfig extends AutoUpdateConfigLoader {
|
|||||||
@Override
|
@Override
|
||||||
protected void loadKeys() {}
|
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 */
|
/* XP Formula Multiplier */
|
||||||
public FormulaType getFormulaType() { return FormulaType.getFormulaType(config.getString("Experience_Formula.Curve")); }
|
public FormulaType getFormulaType() { return FormulaType.getFormulaType(config.getString("Experience_Formula.Curve")); }
|
||||||
public boolean getCumulativeCurveEnabled() { return config.getBoolean("Experience_Formula.Cumulative_Curve", false); }
|
public boolean getCumulativeCurveEnabled() { return config.getBoolean("Experience_Formula.Cumulative_Curve", false); }
|
||||||
|
|
||||||
/* Linear curve values */
|
/* Curve values */
|
||||||
public int getLinearBase() { return config.getInt("Experience_Formula.Linear_Values.base", 1020); }
|
public double getMultiplier(FormulaType type) { return config.getDouble("Experience_Formula." + StringUtils.getCapitalized(type.toString()) + "_Values.multiplier"); }
|
||||||
public double getLinearMultiplier() { return config.getDouble("Experience_Formula.Linear_Values.multiplier", 20); }
|
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"); }
|
||||||
/* 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); }
|
|
||||||
|
|
||||||
/* Skill modifiers */
|
/* Skill modifiers */
|
||||||
public double getFormulaSkillModifier(SkillType skill) { return config.getDouble("Experience_Formula.Modifier." + StringUtils.getCapitalized(skill.toString())); }
|
public double getFormulaSkillModifier(SkillType skill) { return config.getDouble("Experience_Formula.Modifier." + StringUtils.getCapitalized(skill.toString())); }
|
||||||
|
@ -9,6 +9,7 @@ import com.gmail.nossr50.mcMMO;
|
|||||||
import com.gmail.nossr50.config.Config;
|
import com.gmail.nossr50.config.Config;
|
||||||
import com.gmail.nossr50.config.HiddenConfig;
|
import com.gmail.nossr50.config.HiddenConfig;
|
||||||
import com.gmail.nossr50.config.experience.ExperienceConfig;
|
import com.gmail.nossr50.config.experience.ExperienceConfig;
|
||||||
|
import com.gmail.nossr50.datatypes.experience.FormulaType;
|
||||||
import com.gmail.nossr50.locale.LocaleLoader;
|
import com.gmail.nossr50.locale.LocaleLoader;
|
||||||
import com.turt2live.metrics.EMetrics;
|
import com.turt2live.metrics.EMetrics;
|
||||||
import com.turt2live.metrics.Metrics;
|
import com.turt2live.metrics.Metrics;
|
||||||
@ -200,7 +201,7 @@ public class MetricsManager {
|
|||||||
// GlobalCurveModifier Graph
|
// GlobalCurveModifier Graph
|
||||||
Graph globalCurveModifierGraph = metrics.createGraph("Global Curve Modifier 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
|
@Override
|
||||||
public int getValue() {
|
public int getValue() {
|
||||||
return 1;
|
return 1;
|
||||||
@ -238,7 +239,7 @@ public class MetricsManager {
|
|||||||
// GlobalCurveModifier Fuzzy Logic Numbers
|
// GlobalCurveModifier Fuzzy Logic Numbers
|
||||||
Graph globalCurveMultiplierGraphFuzzy = metrics.createGraph("Global Curve Multiplier Fuzz");
|
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") {
|
globalCurveMultiplierGraphFuzzy.addPlotter(new Metrics.Plotter("Higher") {
|
||||||
@Override
|
@Override
|
||||||
public int getValue() {
|
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") {
|
globalCurveMultiplierGraphFuzzy.addPlotter(new Metrics.Plotter("Lower") {
|
||||||
@Override
|
@Override
|
||||||
public int getValue() {
|
public int getValue() {
|
||||||
|
@ -33,7 +33,7 @@ public class FormulaConversionTask extends BukkitRunnable {
|
|||||||
profile = mcMMO.getDatabaseManager().loadPlayerProfile(playerName, false);
|
profile = mcMMO.getDatabaseManager().loadPlayerProfile(playerName, false);
|
||||||
|
|
||||||
if (!profile.isLoaded()) {
|
if (!profile.isLoaded()) {
|
||||||
mcMMO.p.debug("Profile not loaded");
|
mcMMO.p.debug("Profile not loaded.");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -62,15 +62,7 @@ public class FormulaConversionTask extends BukkitRunnable {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
double modifier = ExperienceConfig.getInstance().getExpModifier();
|
int[] newExperienceValues = mcMMO.getFormulaManager().calculateNewLevel(skillType, (int) Math.floor(totalOldXP / ExperienceConfig.getInstance().getExpModifier()), formulaType);
|
||||||
|
|
||||||
//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 newLevel = newExperienceValues[0];
|
int newLevel = newExperienceValues[0];
|
||||||
int newXPlevel = newExperienceValues[1];
|
int newXPlevel = newExperienceValues[1];
|
||||||
|
|
||||||
|
@ -105,20 +105,20 @@ public class FormulaManager {
|
|||||||
*/
|
*/
|
||||||
public int getCachedXpToLevel(int level, FormulaType formulaType) {
|
public int getCachedXpToLevel(int level, FormulaType formulaType) {
|
||||||
int experience;
|
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) {
|
switch (formulaType) {
|
||||||
case UNKNOWN:
|
case UNKNOWN:
|
||||||
case LINEAR:
|
case LINEAR:
|
||||||
if (!experienceNeededLinear.containsKey(level)) {
|
if (!experienceNeededLinear.containsKey(level)) {
|
||||||
multiplier = ExperienceConfig.getInstance().getLinearMultiplier();
|
experience = (int) Math.floor(base + level * multiplier);
|
||||||
|
|
||||||
//TODO: Validate at load?
|
|
||||||
if (multiplier <= 0) {
|
|
||||||
multiplier = 20;
|
|
||||||
}
|
|
||||||
|
|
||||||
experience = (int) Math.floor(ExperienceConfig.getInstance().getLinearBase() + level * multiplier);
|
|
||||||
experienceNeededLinear.put(level, experience);
|
experienceNeededLinear.put(level, experience);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -126,20 +126,6 @@ public class FormulaManager {
|
|||||||
|
|
||||||
case EXPONENTIAL:
|
case EXPONENTIAL:
|
||||||
if (!experienceNeededExponential.containsKey(level)) {
|
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);
|
experience = (int) Math.floor(multiplier * Math.pow(level, exponent) + base);
|
||||||
experienceNeededExponential.put(level, experience);
|
experienceNeededExponential.put(level, experience);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user