forked from Upstream/mmocore
Skills now always have mana and stamina
This commit is contained in:
parent
9cbc951fad
commit
7496b2d2b9
@ -1,225 +1,229 @@
|
|||||||
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;
|
||||||
|
|
||||||
private String name;
|
private String name;
|
||||||
private ItemStack icon = new ItemStack(Material.BOOK);
|
private ItemStack icon = new ItemStack(Material.BOOK);
|
||||||
private List<String> lore;
|
private List<String> lore;
|
||||||
private boolean passive;
|
private boolean passive;
|
||||||
|
|
||||||
private final Map<String, LinearValue> modifiers = new HashMap<>();
|
private final Map<String, LinearValue> modifiers = new HashMap<>();
|
||||||
private final Skill skill = this;
|
private final Skill skill = this;
|
||||||
|
|
||||||
protected static final Random random = new Random();
|
protected static final Random random = new Random();
|
||||||
|
|
||||||
public Skill() {
|
public Skill() {
|
||||||
id = getClass().getSimpleName().toUpperCase();
|
id = getClass().getSimpleName().toUpperCase();
|
||||||
name = getClass().getSimpleName().replace("_", " ");
|
name = getClass().getSimpleName().replace("_", " ");
|
||||||
|
|
||||||
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");
|
||||||
}
|
|
||||||
|
|
||||||
public Skill(String id) {
|
// Default modifiers
|
||||||
this.id = id.toUpperCase().replace(" ", "_").replace("-", "_");
|
addModifierIfNone("mana", LinearValue.ZERO);
|
||||||
}
|
addModifierIfNone("stamina", LinearValue.ZERO);
|
||||||
|
}
|
||||||
|
|
||||||
public void setName(String name) {
|
public Skill(String id) {
|
||||||
this.name = name;
|
this.id = id.toUpperCase().replace(" ", "_").replace("-", "_");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setMaterial(Material material) {
|
public void setName(String name) {
|
||||||
setIcon(new ItemStack(material));
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setIcon(ItemStack item) {
|
public void setMaterial(Material material) {
|
||||||
this.icon = item;
|
setIcon(new ItemStack(material));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setLore(String... lore) {
|
public void setIcon(ItemStack item) {
|
||||||
setLore(Arrays.asList(lore));
|
this.icon = item;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setLore(List<String> lore) {
|
public void setLore(String... lore) {
|
||||||
this.lore = lore;
|
setLore(Arrays.asList(lore));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPassive() {
|
public void setLore(List<String> lore) {
|
||||||
passive = true;
|
this.lore = lore;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getName() {
|
public void setPassive() {
|
||||||
return name;
|
passive = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getId() {
|
public String getName() {
|
||||||
return id;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getLowerCaseId() {
|
public String getId() {
|
||||||
return id.replace("_", "-").toLowerCase();
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<String> getLore() {
|
public String getLowerCaseId() {
|
||||||
return lore;
|
return id.replace("_", "-").toLowerCase();
|
||||||
}
|
}
|
||||||
|
|
||||||
public ItemStack getIcon() {
|
public List<String> getLore() {
|
||||||
return icon.clone();
|
return lore;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
public ItemStack getIcon() {
|
||||||
* passive skills do not display any message
|
return icon.clone();
|
||||||
*/
|
}
|
||||||
public boolean isPassive() {
|
|
||||||
return passive;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean hasModifier(String modifier) {
|
/**
|
||||||
return modifiers.containsKey(modifier);
|
* Passive skills do not display any message when trying to cast them
|
||||||
}
|
*
|
||||||
|
* @return If the skill is passive
|
||||||
|
*/
|
||||||
|
public boolean isPassive() {
|
||||||
|
return passive;
|
||||||
|
}
|
||||||
|
|
||||||
public void addModifier(String modifier, LinearValue linear) {
|
public boolean hasModifier(String modifier) {
|
||||||
modifiers.put(modifier, linear);
|
return modifiers.containsKey(modifier);
|
||||||
}
|
}
|
||||||
|
|
||||||
public LinearValue getModifierInfo(String modifier) {
|
public void addModifier(String modifier, LinearValue linear) {
|
||||||
return modifiers.get(modifier);
|
modifiers.put(modifier, linear);
|
||||||
}
|
}
|
||||||
|
|
||||||
public double getModifier(String modifier, int level) {
|
public void addModifierIfNone(String mod, LinearValue defaultValue) {
|
||||||
return modifiers.get(modifier).calculate(level);
|
if (!hasModifier(mod))
|
||||||
}
|
addModifier(mod, defaultValue);
|
||||||
|
}
|
||||||
|
|
||||||
public Set<String> getModifiers() {
|
public LinearValue getModifierInfo(String modifier) {
|
||||||
return modifiers.keySet();
|
return modifiers.get(modifier);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void update(FileConfiguration config) {
|
public double getModifier(String modifier, int level) {
|
||||||
name = config.getString("name", "INVALID NAME");
|
return modifiers.get(modifier).calculate(level);
|
||||||
lore = config.getStringList("lore");
|
}
|
||||||
icon = MMOCoreUtils.readIcon(config.getString("material", "DIRT"));
|
|
||||||
|
|
||||||
for (String modifier : modifiers.keySet())
|
public Set<String> getModifiers() {
|
||||||
if (config.contains(modifier))
|
return modifiers.keySet();
|
||||||
modifiers.put(modifier, readLinearValue(modifiers.get(modifier), config.getConfigurationSection(modifier)));
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private LinearValue readLinearValue(LinearValue current, ConfigurationSection config) {
|
public void update(FileConfiguration config) {
|
||||||
return current instanceof IntegerLinearValue ? new IntegerLinearValue(config) : new LinearValue(config);
|
name = config.getString("name", "INVALID NAME");
|
||||||
}
|
lore = config.getStringList("lore");
|
||||||
|
icon = MMOCoreUtils.readIcon(config.getString("material", "DIRT"));
|
||||||
|
|
||||||
/*
|
for (String modifier : modifiers.keySet())
|
||||||
* not overriden for passive skills therefore not abstract.
|
if (config.contains(modifier))
|
||||||
*/
|
modifiers.put(modifier, readLinearValue(modifiers.get(modifier), config.getConfigurationSection(modifier)));
|
||||||
public SkillResult whenCast(PlayerData data, SkillInfo skill) {
|
}
|
||||||
return new SkillResult(data, skill);
|
|
||||||
}
|
|
||||||
|
|
||||||
public SkillInfo newSkillInfo(ConfigurationSection config) {
|
private LinearValue readLinearValue(LinearValue current, ConfigurationSection config) {
|
||||||
return new SkillInfo(config);
|
return current instanceof IntegerLinearValue ? new IntegerLinearValue(config) : new LinearValue(config);
|
||||||
}
|
}
|
||||||
|
|
||||||
public SkillInfo newSkillInfo(int level) {
|
/*
|
||||||
return new SkillInfo(level);
|
* not overriden for passive skills therefore not abstract.
|
||||||
}
|
*/
|
||||||
|
public SkillResult whenCast(PlayerData data, SkillInfo skill) {
|
||||||
|
return new SkillResult(data, skill);
|
||||||
|
}
|
||||||
|
|
||||||
public class SkillInfo {
|
public SkillInfo newSkillInfo(ConfigurationSection config) {
|
||||||
private final int level, max;
|
return new SkillInfo(config);
|
||||||
private final Map<String, LinearValue> modifiers = new HashMap<>(skill.modifiers);
|
}
|
||||||
|
|
||||||
/*
|
public SkillInfo newSkillInfo(int level) {
|
||||||
* class used to save information about skills IN A CLASS CONTEXT i.e at
|
return new SkillInfo(level);
|
||||||
* which level the skill can be unlocked, etc.
|
}
|
||||||
*/
|
|
||||||
public SkillInfo(int level) {
|
|
||||||
this.level = level;
|
|
||||||
this.max = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public SkillInfo(ConfigurationSection config) {
|
public class SkillInfo {
|
||||||
level = config.getInt("level");
|
private final int level, max;
|
||||||
max = config.getInt("max-level");
|
private final Map<String, LinearValue> modifiers = new HashMap<>(skill.modifiers);
|
||||||
|
|
||||||
for (String key : config.getKeys(false))
|
/*
|
||||||
if (config.get(key) instanceof ConfigurationSection && modifiers.containsKey(key))
|
* class used to save information about skills IN A CLASS CONTEXT i.e at
|
||||||
modifiers.put(key, readLinearValue(modifiers.get(key), config.getConfigurationSection(key)));
|
* which level the skill can be unlocked, etc.
|
||||||
}
|
*/
|
||||||
|
public SkillInfo(int level) {
|
||||||
|
this.level = level;
|
||||||
|
this.max = 0;
|
||||||
|
}
|
||||||
|
|
||||||
public Skill getSkill() {
|
public SkillInfo(ConfigurationSection config) {
|
||||||
return skill;
|
level = config.getInt("level");
|
||||||
}
|
max = config.getInt("max-level");
|
||||||
|
|
||||||
public int getUnlockLevel() {
|
for (String key : config.getKeys(false))
|
||||||
return level;
|
if (config.get(key) instanceof ConfigurationSection && modifiers.containsKey(key))
|
||||||
}
|
modifiers.put(key, readLinearValue(modifiers.get(key), config.getConfigurationSection(key)));
|
||||||
|
}
|
||||||
|
|
||||||
public boolean hasMaxLevel() {
|
public Skill getSkill() {
|
||||||
return max > 0;
|
return skill;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getMaxLevel() {
|
public int getUnlockLevel() {
|
||||||
return max;
|
return level;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
public boolean hasMaxLevel() {
|
||||||
* this method can only OVERRIDE default modifiers
|
return max > 0;
|
||||||
*/
|
}
|
||||||
public void addModifier(String modifier, LinearValue linear) {
|
|
||||||
if (modifiers.containsKey(modifier))
|
|
||||||
modifiers.put(modifier, linear);
|
|
||||||
}
|
|
||||||
|
|
||||||
public double getModifier(String modifier, int level) {
|
public int getMaxLevel() {
|
||||||
return modifiers.get(modifier).calculate(level);
|
return max;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<String> calculateLore(PlayerData data) {
|
/*
|
||||||
return calculateLore(data, data.getSkillLevel(skill));
|
* this method can only OVERRIDE default modifiers
|
||||||
}
|
*/
|
||||||
|
public void addModifier(String modifier, LinearValue linear) {
|
||||||
|
if (modifiers.containsKey(modifier))
|
||||||
|
modifiers.put(modifier, linear);
|
||||||
|
}
|
||||||
|
|
||||||
public List<String> calculateLore(PlayerData data, int x) {
|
public double getModifier(String modifier, int level) {
|
||||||
List<String> list = new ArrayList<>();
|
return modifiers.get(modifier).calculate(level);
|
||||||
|
}
|
||||||
|
|
||||||
Map<String, String> placeholders = calculateModifiers(x);
|
public List<String> calculateLore(PlayerData data) {
|
||||||
placeholders.put("mana_name", data.getProfess().getManaDisplay().getName());
|
return calculateLore(data, data.getSkillLevel(skill));
|
||||||
lore.forEach(str -> list.add(applyPlaceholders(placeholders, str)));
|
}
|
||||||
|
|
||||||
return list;
|
public List<String> calculateLore(PlayerData data, int x) {
|
||||||
}
|
List<String> list = new ArrayList<>();
|
||||||
|
|
||||||
private String applyPlaceholders(Map<String, String> placeholders, String str) {
|
Map<String, String> placeholders = calculateModifiers(x);
|
||||||
while (str.contains("{") && str.substring(str.indexOf("{")).contains("}")) {
|
placeholders.put("mana_name", data.getProfess().getManaDisplay().getName());
|
||||||
String holder = str.substring(str.indexOf("{") + 1, str.indexOf("}"));
|
lore.forEach(str -> list.add(applyPlaceholders(placeholders, str)));
|
||||||
str = str.replace("{" + holder + "}", placeholders.getOrDefault(holder, "PHE"));
|
|
||||||
}
|
|
||||||
return str;
|
|
||||||
}
|
|
||||||
|
|
||||||
private Map<String, String> calculateModifiers(int x) {
|
return list;
|
||||||
Map<String, String> map = new HashMap<>();
|
}
|
||||||
modifiers.keySet().forEach(modifier -> map.put(modifier, modifiers.get(modifier).getDisplay(x)));
|
|
||||||
return map;
|
private String applyPlaceholders(Map<String, String> placeholders, String str) {
|
||||||
}
|
while (str.contains("{") && str.substring(str.indexOf("{")).contains("}")) {
|
||||||
}
|
String holder = str.substring(str.indexOf("{") + 1, str.indexOf("}"));
|
||||||
|
str = str.replace("{" + holder + "}", placeholders.getOrDefault(holder, "PHE"));
|
||||||
|
}
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Map<String, String> calculateModifiers(int x) {
|
||||||
|
Map<String, String> map = new HashMap<>();
|
||||||
|
modifiers.keySet().forEach(modifier -> map.put(modifier, modifiers.get(modifier).getDisplay(x)));
|
||||||
|
return map;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,86 +4,110 @@ import io.lumine.mythic.lib.MythicLib;
|
|||||||
import org.bukkit.configuration.ConfigurationSection;
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
|
|
||||||
public class LinearValue {
|
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.
|
||||||
*/
|
*
|
||||||
public LinearValue(double base, double perLevel) {
|
* @param base Base value
|
||||||
this.base = base;
|
* @param perLevel Every level, final value is increased by X
|
||||||
this.perLevel = perLevel;
|
*/
|
||||||
hasmin = false;
|
public LinearValue(double base, double perLevel) {
|
||||||
hasmax = false;
|
this.base = base;
|
||||||
min = 0;
|
this.perLevel = perLevel;
|
||||||
max = 0;
|
hasmin = false;
|
||||||
}
|
hasmax = false;
|
||||||
|
min = 0;
|
||||||
|
max = 0;
|
||||||
|
}
|
||||||
|
|
||||||
public LinearValue(double base, double perLevel, double min, double max) {
|
/**
|
||||||
this.base = base;
|
* A number formula which depends on the player level. It can be used
|
||||||
this.perLevel = perLevel;
|
* to handle skill modifiers so that the ability gets better with the
|
||||||
hasmin = true;
|
* skill level, or as an attribute value to make them scale with the class level.
|
||||||
hasmax = true;
|
*
|
||||||
this.min = min;
|
* @param base Base value
|
||||||
this.max = max;
|
* @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) {
|
||||||
|
this.base = base;
|
||||||
|
this.perLevel = perLevel;
|
||||||
|
hasmin = true;
|
||||||
|
hasmax = true;
|
||||||
|
this.min = min;
|
||||||
|
this.max = max;
|
||||||
|
}
|
||||||
|
|
||||||
public LinearValue(LinearValue value) {
|
/**
|
||||||
base = value.base;
|
* Copies a linear formula
|
||||||
perLevel = value.perLevel;
|
*
|
||||||
hasmin = value.hasmin;
|
* @param value Formula to copy
|
||||||
hasmax = value.hasmax;
|
*/
|
||||||
min = value.min;
|
public LinearValue(LinearValue value) {
|
||||||
max = value.max;
|
base = value.base;
|
||||||
}
|
perLevel = value.perLevel;
|
||||||
|
hasmin = value.hasmin;
|
||||||
|
hasmax = value.hasmax;
|
||||||
|
min = value.min;
|
||||||
|
max = value.max;
|
||||||
|
}
|
||||||
|
|
||||||
public LinearValue(ConfigurationSection config) {
|
/**
|
||||||
base = config.getDouble("base");
|
* Loads a linear formula from a config section
|
||||||
perLevel = config.getDouble("per-level");
|
*
|
||||||
hasmin = config.contains("min");
|
* @param config Config to load the formula from
|
||||||
hasmax = config.contains("max");
|
*/
|
||||||
min = hasmin ? config.getDouble("min") : 0;
|
public LinearValue(ConfigurationSection config) {
|
||||||
max = hasmax ? config.getDouble("max") : 0;
|
base = config.getDouble("base");
|
||||||
}
|
perLevel = config.getDouble("per-level");
|
||||||
|
hasmin = config.contains("min");
|
||||||
|
hasmax = config.contains("max");
|
||||||
|
min = hasmin ? config.getDouble("min") : 0;
|
||||||
|
max = hasmax ? config.getDouble("max") : 0;
|
||||||
|
}
|
||||||
|
|
||||||
public double getBaseValue() {
|
public double getBaseValue() {
|
||||||
return base;
|
return base;
|
||||||
}
|
}
|
||||||
|
|
||||||
public double getPerLevel() {
|
public double getPerLevel() {
|
||||||
return perLevel;
|
return perLevel;
|
||||||
}
|
}
|
||||||
|
|
||||||
public double getMax() {
|
public double getMax() {
|
||||||
return max;
|
return max;
|
||||||
}
|
}
|
||||||
|
|
||||||
public double getMin() {
|
public double getMin() {
|
||||||
return min;
|
return min;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasMax() {
|
public boolean hasMax() {
|
||||||
return hasmax;
|
return hasmax;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasMin() {
|
public boolean hasMin() {
|
||||||
return hasmin;
|
return hasmin;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getDisplay(int level) {
|
public String getDisplay(int level) {
|
||||||
return MythicLib.plugin.getMMOConfig().decimals.format(calculate(level));
|
return MythicLib.plugin.getMMOConfig().decimals.format(calculate(level));
|
||||||
}
|
}
|
||||||
|
|
||||||
public double calculate(int level) {
|
public double calculate(int level) {
|
||||||
double value = base + perLevel * (level - 1);
|
double value = base + perLevel * (level - 1);
|
||||||
|
|
||||||
if (hasmin) value = Math.max(min, value);
|
if (hasmin) value = Math.max(min, value);
|
||||||
|
|
||||||
if (hasmax) value = Math.min(max, value);
|
if (hasmax) value = Math.min(max, value);
|
||||||
|
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user