Skills now always have mana and stamina

This commit is contained in:
Jules 2021-07-25 16:17:26 +02:00
parent 9cbc951fad
commit 7496b2d2b9
2 changed files with 263 additions and 235 deletions

View File

@ -1,23 +1,16 @@
package net.Indyuce.mmocore.api.skill; package net.Indyuce.mmocore.api.skill;
import java.util.ArrayList; import net.Indyuce.mmocore.api.player.PlayerData;
import java.util.Arrays; import net.Indyuce.mmocore.api.util.MMOCoreUtils;
import java.util.HashMap; import net.Indyuce.mmocore.api.util.math.formula.IntegerLinearValue;
import java.util.List; import net.Indyuce.mmocore.api.util.math.formula.LinearValue;
import java.util.Map;
import java.util.Random;
import java.util.Set;
import org.apache.commons.lang.Validate; import org.apache.commons.lang.Validate;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import net.Indyuce.mmocore.api.player.PlayerData; import java.util.*;
import net.Indyuce.mmocore.api.util.MMOCoreUtils;
import net.Indyuce.mmocore.api.util.math.formula.IntegerLinearValue;
import net.Indyuce.mmocore.api.util.math.formula.LinearValue;
public abstract class Skill { public abstract class Skill {
private final String id; private final String id;
@ -38,6 +31,10 @@ public abstract class Skill {
Validate.notNull(id, "ID cannot be null"); Validate.notNull(id, "ID cannot be null");
Validate.notNull(id, "Name cannot be null"); Validate.notNull(id, "Name cannot be null");
// Default modifiers
addModifierIfNone("mana", LinearValue.ZERO);
addModifierIfNone("stamina", LinearValue.ZERO);
} }
public Skill(String id) { public Skill(String id) {
@ -88,8 +85,10 @@ public abstract class Skill {
return icon.clone(); return icon.clone();
} }
/* /**
* passive skills do not display any message * Passive skills do not display any message when trying to cast them
*
* @return If the skill is passive
*/ */
public boolean isPassive() { public boolean isPassive() {
return passive; return passive;
@ -103,6 +102,11 @@ public abstract class Skill {
modifiers.put(modifier, linear); modifiers.put(modifier, linear);
} }
public void addModifierIfNone(String mod, LinearValue defaultValue) {
if (!hasModifier(mod))
addModifier(mod, defaultValue);
}
public LinearValue getModifierInfo(String modifier) { public LinearValue getModifierInfo(String modifier) {
return modifiers.get(modifier); return modifiers.get(modifier);
} }

View File

@ -7,11 +7,15 @@ public class LinearValue {
private final double base, perLevel, min, max; private final double base, perLevel, min, max;
private final boolean hasmin, hasmax; private final boolean hasmin, hasmax;
public static final LinearValue ZERO = new LinearValue(0, 0, 0, 0);
/* /**
* a number which depends on the player level. it can be used as a skill * A number formula which depends on the player level. It can be used
* modifier to make the ability better depending on the player level or as * to handle skill modifiers so that the ability gets better with the
* an attrribute value to make attributes increase with the player level * skill level, or as an attribute value to make them scale with the class level.
*
* @param base Base value
* @param perLevel Every level, final value is increased by X
*/ */
public LinearValue(double base, double perLevel) { public LinearValue(double base, double perLevel) {
this.base = base; this.base = base;
@ -22,6 +26,16 @@ public class LinearValue {
max = 0; max = 0;
} }
/**
* A number formula which depends on the player level. It can be used
* to handle skill modifiers so that the ability gets better with the
* skill level, or as an attribute value to make them scale with the class level.
*
* @param base Base value
* @param perLevel Every level, final value is increased by X
* @param min Minimum final value
* @param max Maximum final value
*/
public LinearValue(double base, double perLevel, double min, double max) { public LinearValue(double base, double perLevel, double min, double max) {
this.base = base; this.base = base;
this.perLevel = perLevel; this.perLevel = perLevel;
@ -31,6 +45,11 @@ public class LinearValue {
this.max = max; this.max = max;
} }
/**
* Copies a linear formula
*
* @param value Formula to copy
*/
public LinearValue(LinearValue value) { public LinearValue(LinearValue value) {
base = value.base; base = value.base;
perLevel = value.perLevel; perLevel = value.perLevel;
@ -40,6 +59,11 @@ public class LinearValue {
max = value.max; max = value.max;
} }
/**
* Loads a linear formula from a config section
*
* @param config Config to load the formula from
*/
public LinearValue(ConfigurationSection config) { public LinearValue(ConfigurationSection config) {
base = config.getDouble("base"); base = config.getDouble("base");
perLevel = config.getDouble("per-level"); perLevel = config.getDouble("per-level");