Refactored MMOCore skill modifiers to call them skill parameters as in MythicLib, Fixed issue #834.

This commit is contained in:
Ka0rX 2023-05-29 10:25:04 +01:00
parent 1282d18934
commit b093d325dd
9 changed files with 93 additions and 51 deletions

View File

@ -72,13 +72,13 @@ public class RPGPlaceholders extends PlaceholderExpansion {
String id = identifier.substring(12); String id = identifier.substring(12);
RegisteredSkill skill = Objects.requireNonNull(MMOCore.plugin.skillManager.getSkill(id), "Could not find skill with ID '" + id + "'"); RegisteredSkill skill = Objects.requireNonNull(MMOCore.plugin.skillManager.getSkill(id), "Could not find skill with ID '" + id + "'");
return String.valueOf(playerData.getSkillLevel(skill)); return String.valueOf(playerData.getSkillLevel(skill));
} else if (identifier.startsWith("skill_modifier_")) { } else if (identifier.startsWith("skill_modifier_")||identifier.startsWith("skill_parameter_")) {
String[] ids = identifier.substring(15).split(":"); String[] ids= (identifier.startsWith("skill_modifier_")?identifier.substring(16):identifier.substring(17)).split(":");
String modifierId = ids[0]; String parameterId = ids[0];
String skillId = ids[1]; String skillId = ids[1];
RegisteredSkill skill = Objects.requireNonNull(MMOCore.plugin.skillManager.getSkill(skillId), "Could not find skill with ID '" + skillId + "'"); RegisteredSkill skill = Objects.requireNonNull(MMOCore.plugin.skillManager.getSkill(skillId), "Could not find skill with ID '" + skillId + "'");
ClassSkill classSkill = playerData.getProfess().getSkill(skill); ClassSkill classSkill = playerData.getProfess().getSkill(skill);
double value = classSkill.toCastable(playerData).getModifier(modifierId); double value = classSkill.toCastable(playerData).getParameter(parameterId);
return MythicLib.plugin.getMMOConfig().decimal.format(value); return MythicLib.plugin.getMMOConfig().decimal.format(value);
} else if (identifier.startsWith("attribute_points_spent_")) { } else if (identifier.startsWith("attribute_points_spent_")) {
String attributeId = identifier.substring(31); String attributeId = identifier.substring(31);

View File

@ -74,11 +74,11 @@ public class SkillManager implements MMOCoreManager {
config.getConfig().set("name", MMOCoreUtils.caseOnWords(handler.getId().replace("_", " ").replace("-", " ").toLowerCase())); config.getConfig().set("name", MMOCoreUtils.caseOnWords(handler.getId().replace("_", " ").replace("-", " ").toLowerCase()));
config.getConfig().set("lore", Arrays.asList("This is the default skill description", "", "&e{cooldown}s Cooldown", "&9Costs {mana} {mana_name}")); config.getConfig().set("lore", Arrays.asList("This is the default skill description", "", "&e{cooldown}s Cooldown", "&9Costs {mana} {mana_name}"));
config.getConfig().set("material", "BOOK"); config.getConfig().set("material", "BOOK");
for (Object mod : handler.getModifiers()) { for (Object param : handler.getParameters()) {
config.getConfig().set(mod + ".base", 0); config.getConfig().set(param + ".base", 0);
config.getConfig().set(mod + ".per-level", 0); config.getConfig().set(param + ".per-level", 0);
config.getConfig().set(mod + ".min", 0); config.getConfig().set(param + ".min", 0);
config.getConfig().set(mod + ".max", 0); config.getConfig().set(param + ".max", 0);
} }
config.save(); config.save();
} }

View File

@ -7,6 +7,7 @@ import io.lumine.mythic.lib.skill.Skill;
import io.lumine.mythic.lib.skill.SkillMetadata; import io.lumine.mythic.lib.skill.SkillMetadata;
import io.lumine.mythic.lib.skill.handler.SkillHandler; import io.lumine.mythic.lib.skill.handler.SkillHandler;
import net.Indyuce.mmocore.MMOCore; import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.api.ConfigMessage;
import net.Indyuce.mmocore.api.player.PlayerActivity; import net.Indyuce.mmocore.api.player.PlayerActivity;
import net.Indyuce.mmocore.api.player.PlayerData; import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.api.event.PlayerResourceUpdateEvent; import net.Indyuce.mmocore.api.event.PlayerResourceUpdateEvent;
@ -64,15 +65,16 @@ public class CastableSkill extends Skill {
} }
// Mana cost // Mana cost
if (playerData.getMana() < getModifier("mana")) { if (playerData.getMana() < getParameter("mana")) {
if (loud) MMOCore.plugin.configManager.getSimpleMessage("casting.no-mana", if (loud) new ConfigMessage("casting.no-mana").addPlaceholders(
"mana-required", MythicLib.plugin.getMMOConfig().decimal.format((getModifier("mana") - playerData.getMana())), "mana-required", MythicLib.plugin.getMMOConfig().decimal.format((getParameter("mana") - playerData.getMana())),
"mana", playerData.getProfess().getManaDisplay().getName()).send(playerData.getPlayer()); "mana", playerData.getProfess().getManaDisplay().getName()).send(playerData.getPlayer());
return false; return false;
} }
// Stamina cost // Stamina cost
if (playerData.getStamina() < getModifier("stamina")) { if (playerData.getStamina() < getParameter("stamina")) {
if (loud) MMOCore.plugin.configManager.getSimpleMessage("casting.no-stamina").send(playerData.getPlayer()); if (loud) MMOCore.plugin.configManager.getSimpleMessage("casting.no-stamina").send(playerData.getPlayer());
return false; return false;
} }
@ -93,11 +95,11 @@ public class CastableSkill extends Skill {
// Cooldown // Cooldown
double flatCooldownReduction = Math.max(0, Math.min(1, skillMeta.getCaster().getStat("COOLDOWN_REDUCTION") / 100)); double flatCooldownReduction = Math.max(0, Math.min(1, skillMeta.getCaster().getStat("COOLDOWN_REDUCTION") / 100));
CooldownInfo cooldownHandler = skillMeta.getCaster().getData().getCooldownMap().applyCooldown(this, getModifier("cooldown")); CooldownInfo cooldownHandler = skillMeta.getCaster().getData().getCooldownMap().applyCooldown(this, getParameter("cooldown"));
cooldownHandler.reduceInitialCooldown(flatCooldownReduction); cooldownHandler.reduceInitialCooldown(flatCooldownReduction);
casterData.giveMana(-getModifier("mana"), PlayerResourceUpdateEvent.UpdateReason.SKILL_COST); casterData.giveMana(-getParameter("mana"), PlayerResourceUpdateEvent.UpdateReason.SKILL_COST);
casterData.giveStamina(-getModifier("stamina"), PlayerResourceUpdateEvent.UpdateReason.SKILL_COST); casterData.giveStamina(-getParameter("stamina"), PlayerResourceUpdateEvent.UpdateReason.SKILL_COST);
} }
if (!getTrigger().isPassive()) if (!getTrigger().isPassive())
@ -110,7 +112,7 @@ public class CastableSkill extends Skill {
} }
@Override @Override
public double getModifier(String mod) { public double getParameter(String mod) {
return skill.getModifier(mod, skillLevel.get()); return skill.getParameter(mod, skillLevel.get());
} }
} }

View File

@ -5,7 +5,6 @@ import io.lumine.mythic.lib.api.player.EquipmentSlot;
import io.lumine.mythic.lib.player.cooldown.CooldownObject; import io.lumine.mythic.lib.player.cooldown.CooldownObject;
import io.lumine.mythic.lib.player.modifier.ModifierSource; import io.lumine.mythic.lib.player.modifier.ModifierSource;
import io.lumine.mythic.lib.player.skill.PassiveSkill; import io.lumine.mythic.lib.player.skill.PassiveSkill;
import io.lumine.mythic.lib.script.condition.Condition;
import net.Indyuce.mmocore.MMOCore; import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.api.player.PlayerData; import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.api.util.math.formula.IntegerLinearValue; import net.Indyuce.mmocore.api.util.math.formula.IntegerLinearValue;
@ -22,7 +21,7 @@ public class ClassSkill implements CooldownObject, Unlockable {
private final RegisteredSkill skill; private final RegisteredSkill skill;
private final int unlockLevel, maxSkillLevel; private final int unlockLevel, maxSkillLevel;
private final boolean unlockedByDefault; private final boolean unlockedByDefault;
private final Map<String, LinearValue> modifiers = new HashMap<>(); private final Map<String, LinearValue> parameters = new HashMap<>();
/** /**
* Class used to save information about skills IN A CLASS CONTEXT * Class used to save information about skills IN A CLASS CONTEXT
@ -42,8 +41,8 @@ public class ClassSkill implements CooldownObject, Unlockable {
this.unlockLevel = unlockLevel; this.unlockLevel = unlockLevel;
this.maxSkillLevel = maxSkillLevel; this.maxSkillLevel = maxSkillLevel;
this.unlockedByDefault = unlockedByDefault; this.unlockedByDefault = unlockedByDefault;
for (String mod : skill.getHandler().getModifiers()) for (String param : skill.getHandler().getParameters())
this.modifiers.put(mod, skill.getModifierInfo(mod)); this.parameters.put(param, skill.getParameterInfo(param));
} }
public ClassSkill(RegisteredSkill skill, ConfigurationSection config) { public ClassSkill(RegisteredSkill skill, ConfigurationSection config) {
@ -51,9 +50,9 @@ public class ClassSkill implements CooldownObject, Unlockable {
unlockLevel = config.getInt("level"); unlockLevel = config.getInt("level");
maxSkillLevel = config.getInt("max-level"); maxSkillLevel = config.getInt("max-level");
unlockedByDefault = config.getBoolean("unlocked-by-default", true); unlockedByDefault = config.getBoolean("unlocked-by-default", true);
for (String mod : skill.getHandler().getModifiers()) { for (String param : skill.getHandler().getParameters()) {
LinearValue defaultValue = skill.getModifierInfo(mod); LinearValue defaultValue = skill.getParameterInfo(param);
this.modifiers.put(mod, config.isConfigurationSection(mod) ? readLinearValue(defaultValue, config.getConfigurationSection(mod)) : defaultValue); this.parameters.put(param, config.isConfigurationSection(param) ? readLinearValue(defaultValue, config.getConfigurationSection(param)) : defaultValue);
} }
} }
@ -101,17 +100,35 @@ public class ClassSkill implements CooldownObject, Unlockable {
playerData.getStats().updateStats(); playerData.getStats().updateStats();
} }
/** /**
* This method can only override default modifiers and * Skill modifiers are now called parameters.
*/
@Deprecated
public void addModifier(String modifier, LinearValue linear) {
addParameter(modifier, linear);
}
/**
* This method can only override default parameters and
* will throw an error when trying to define non existing modifiers * will throw an error when trying to define non existing modifiers
*/ */
public void addModifier(String modifier, LinearValue linear) { public void addParameter(String parameter, LinearValue linear) {
Validate.isTrue(modifiers.containsKey(modifier), "Could not find modifier '" + modifier + "'"); Validate.isTrue(parameters.containsKey(parameter), "Could not find parameter '" + parameter + "'");
modifiers.put(modifier, linear); parameters.put(parameter, linear);
} }
/**
* Skill modifiers are now called parameters.
*/
@Deprecated
public double getModifier(String modifier, int level) { public double getModifier(String modifier, int level) {
return Objects.requireNonNull(modifiers.get(modifier), "Could not find modifier '" + modifier + "'").calculate(level); return getParameter(modifier, level);
}
public double getParameter(String parameter, int level) {
return Objects.requireNonNull(parameters.get(parameter), "Could not find parameter '" + parameter + "'").calculate(level);
} }
public List<String> calculateLore(PlayerData data) { public List<String> calculateLore(PlayerData data) {
@ -122,7 +139,7 @@ public class ClassSkill implements CooldownObject, Unlockable {
// Calculate placeholders // Calculate placeholders
Placeholders placeholders = new Placeholders(); Placeholders placeholders = new Placeholders();
modifiers.keySet().forEach(modifier -> placeholders.register(modifier, MythicLib.plugin.getMMOConfig().decimal.format(data.getMMOPlayerData().getSkillModifierMap().getInstance(skill.getHandler(), modifier).getTotal(modifiers.get(modifier).calculate(x))))); parameters.keySet().forEach(modifier -> placeholders.register(modifier, MythicLib.plugin.getMMOConfig().decimal.format(data.getMMOPlayerData().getSkillModifierMap().getInstance(skill.getHandler(), modifier).getTotal(parameters.get(modifier).calculate(x)))));
placeholders.register("mana_name", data.getProfess().getManaDisplay().getName()); placeholders.register("mana_name", data.getProfess().getManaDisplay().getName());
placeholders.register("mana_color", data.getProfess().getManaDisplay().getFull().toString()); placeholders.register("mana_color", data.getProfess().getManaDisplay().getFull().toString());

View File

@ -18,11 +18,10 @@ import java.util.*;
public class RegisteredSkill { public class RegisteredSkill {
private final SkillHandler<?> handler; private final SkillHandler<?> handler;
private final String name; private final String name;
private final Map<String, LinearValue> defaultModifiers = new HashMap<>(); private final Map<String, LinearValue> defaultParameters = new HashMap<>();
private final ItemStack icon; private final ItemStack icon;
private final List<String> lore; private final List<String> lore;
private final List<String> categories; private final List<String> categories;
@NotNull
private final TriggerType triggerType; private final TriggerType triggerType;
public RegisteredSkill(SkillHandler<?> handler, ConfigurationSection config) { public RegisteredSkill(SkillHandler<?> handler, ConfigurationSection config) {
@ -44,14 +43,14 @@ public class RegisteredSkill {
categories.add("ACTIVE"); categories.add("ACTIVE");
// Load default modifier formulas // Load default modifier formulas
for (String mod : handler.getModifiers()) for (String param : handler.getParameters())
defaultModifiers.put(mod, config.contains(mod) ? new LinearValue(config.getConfigurationSection(mod)) : LinearValue.ZERO); defaultParameters.put(param, config.contains(param) ? new LinearValue(config.getConfigurationSection(param)) : LinearValue.ZERO);
/* /*
* This is so that SkillAPI skill level matches the MMOCore skill level * This is so that SkillAPI skill level matches the MMOCore skill level
* https://gitlab.com/phoenix-dvpmt/mmocore/-/issues/531 * https://gitlab.com/phoenix-dvpmt/mmocore/-/issues/531
*/ */
defaultModifiers.put("level", new IntegerLinearValue(0, 1)); defaultParameters.put("level", new IntegerLinearValue(0, 1));
} }
public RegisteredSkill(SkillHandler<?> handler, String name, ItemStack icon, List<String> lore, @Nullable TriggerType triggerType) { public RegisteredSkill(SkillHandler<?> handler, String name, ItemStack icon, List<String> lore, @Nullable TriggerType triggerType) {
@ -83,8 +82,16 @@ public class RegisteredSkill {
return icon.clone(); return icon.clone();
} }
public boolean hasParameter(String parameter) {
return defaultParameters.containsKey(parameter);
}
/**
* Skills modifiers are now called parameters.
*/
@Deprecated
public boolean hasModifier(String modifier) { public boolean hasModifier(String modifier) {
return defaultModifiers.containsKey(modifier); return defaultParameters.containsKey(modifier);
} }
@NotNull @NotNull
@ -92,27 +99,45 @@ public class RegisteredSkill {
return Objects.requireNonNull(triggerType, "Skill has no trigger"); return Objects.requireNonNull(triggerType, "Skill has no trigger");
} }
/**
* Skill modifiers are now called parameters.
*/
@Deprecated
public void addModifier(String modifier, LinearValue linear) { public void addModifier(String modifier, LinearValue linear) {
defaultModifiers.put(modifier, linear); defaultParameters.put(modifier, linear);
} }
public void addParameter(String parameter, LinearValue linear) {
defaultParameters.put(parameter, linear);
}
@Deprecated @Deprecated
public void addModifierIfNone(String mod, LinearValue defaultValue) { public void addModifierIfNone(String mod, LinearValue defaultValue) {
if (!hasModifier(mod)) if (!hasParameter(mod))
addModifier(mod, defaultValue); addParameter(mod, defaultValue);
}
/**
* Skill modifiers are now called parameters.
*/
@Deprecated
public LinearValue getModifierInfo(String modifier) {
return defaultParameters.get(modifier);
} }
/** /**
* @return Modifier formula. * @return Modifier formula.
* Not null as long as the modifier is well defined * Not null as long as the modifier is well defined
*/ */
@NotNull @NotNull
public LinearValue getModifierInfo(String modifier) { public LinearValue getParameterInfo(String parameter) {
return defaultModifiers.get(modifier); return defaultParameters.get(parameter);
} }
public double getModifier(String modifier, int level) { public double getModifier(String modifier, int level) {
return defaultModifiers.get(modifier).calculate(level); return defaultParameters.get(modifier).calculate(level);
} }
public boolean matchesFormula(String formula) { public boolean matchesFormula(String formula) {

View File

@ -17,7 +17,6 @@ import org.bukkit.GameMode;
import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerItemHeldEvent; import org.bukkit.event.player.PlayerItemHeldEvent;
import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scheduler.BukkitRunnable;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@ -151,11 +150,11 @@ public class SkillBar implements SkillCastingListener {
} }
private boolean noMana(PlayerData data, ClassSkill skill) { private boolean noMana(PlayerData data, ClassSkill skill) {
return skill.getSkill().hasModifier("mana") && skill.getModifier("mana", data.getSkillLevel(skill.getSkill())) > data.getMana(); return skill.getSkill().hasParameter("mana") && skill.getParameter("mana", data.getSkillLevel(skill.getSkill())) > data.getMana();
} }
private boolean noStamina(PlayerData data, ClassSkill skill) { private boolean noStamina(PlayerData data, ClassSkill skill) {
return skill.getSkill().hasModifier("stamina") && skill.getModifier("stamina", data.getSkillLevel(skill.getSkill())) > data.getStamina(); return skill.getSkill().hasParameter("stamina") && skill.getParameter("stamina", data.getSkillLevel(skill.getSkill())) > data.getStamina();
} }
@Override @Override

View File

@ -40,7 +40,7 @@ public class Ambers extends SkillHandler<SimpleSkillResult> implements Listener
Location loc = target.getLocation(); Location loc = target.getLocation();
double a = random.nextDouble() * 2 * Math.PI; double a = random.nextDouble() * 2 * Math.PI;
new Amber(skillMeta.getCaster().getData(), EntityLocationType.BODY.getLocation(target), loc.clone().add(4 * Math.cos(a), 0, 4 * Math.sin(a)), skillMeta.getModifier("percent")); new Amber(skillMeta.getCaster().getData(), EntityLocationType.BODY.getLocation(target), loc.clone().add(4 * Math.cos(a), 0, 4 * Math.sin(a)), skillMeta.getParameter("percent"));
} }
@EventHandler @EventHandler

View File

@ -5,7 +5,6 @@ import io.lumine.mythic.lib.skill.SkillMetadata;
import io.lumine.mythic.lib.skill.handler.SkillHandler; import io.lumine.mythic.lib.skill.handler.SkillHandler;
import io.lumine.mythic.lib.skill.result.def.SimpleSkillResult; import io.lumine.mythic.lib.skill.result.def.SimpleSkillResult;
import net.Indyuce.mmocore.api.event.PlayerResourceUpdateEvent; import net.Indyuce.mmocore.api.event.PlayerResourceUpdateEvent;
import net.Indyuce.mmocore.api.player.PlayerData;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
@ -34,7 +33,7 @@ public class Neptune_Gift extends SkillHandler<SimpleSkillResult> implements Lis
if (skill == null) if (skill == null)
return; return;
event.setAmount(event.getAmount() * (1 + skill.getTriggeredSkill().getModifier("extra") / 100)); event.setAmount(event.getAmount() * (1 + skill.getTriggeredSkill().getParameter("extra") / 100));
} }
} }
} }

View File

@ -30,7 +30,7 @@ public class Sneaky_Picky extends SkillHandler<SimpleSkillResult> implements Lis
@Override @Override
public void whenCast(SimpleSkillResult result, SkillMetadata skillMeta) { public void whenCast(SimpleSkillResult result, SkillMetadata skillMeta) {
LivingEntity target = (LivingEntity) skillMeta.getTargetEntity(); LivingEntity target = (LivingEntity) skillMeta.getTargetEntity();
skillMeta.getAttack().getDamage().multiplicativeModifier(1 + skillMeta.getModifier("extra") / 100, DamageType.WEAPON); skillMeta.getAttack().getDamage().multiplicativeModifier(1 + skillMeta.getParameter("extra") / 100, DamageType.WEAPON);
target.getWorld().spawnParticle(Particle.SMOKE_NORMAL, target.getLocation().add(0, target.getHeight() / 2, 0), 64, 0, 0, 0, .05); target.getWorld().spawnParticle(Particle.SMOKE_NORMAL, target.getLocation().add(0, target.getHeight() / 2, 0), 64, 0, 0, 0, .05);
target.getWorld().playSound(target.getLocation(), Sound.ENTITY_ZOMBIE_ATTACK_IRON_DOOR, 1, 2); target.getWorld().playSound(target.getLocation(), Sound.ENTITY_ZOMBIE_ATTACK_IRON_DOOR, 1, 2);
} }