forked from Upstream/mmocore
Refactored MMOCore skill modifiers to call them skill parameters as in MythicLib, Fixed issue #834.
This commit is contained in:
parent
1282d18934
commit
b093d325dd
@ -72,13 +72,13 @@ public class RPGPlaceholders extends PlaceholderExpansion {
|
||||
String id = identifier.substring(12);
|
||||
RegisteredSkill skill = Objects.requireNonNull(MMOCore.plugin.skillManager.getSkill(id), "Could not find skill with ID '" + id + "'");
|
||||
return String.valueOf(playerData.getSkillLevel(skill));
|
||||
} else if (identifier.startsWith("skill_modifier_")) {
|
||||
String[] ids = identifier.substring(15).split(":");
|
||||
String modifierId = ids[0];
|
||||
} else if (identifier.startsWith("skill_modifier_")||identifier.startsWith("skill_parameter_")) {
|
||||
String[] ids= (identifier.startsWith("skill_modifier_")?identifier.substring(16):identifier.substring(17)).split(":");
|
||||
String parameterId = ids[0];
|
||||
String skillId = ids[1];
|
||||
RegisteredSkill skill = Objects.requireNonNull(MMOCore.plugin.skillManager.getSkill(skillId), "Could not find skill with ID '" + skillId + "'");
|
||||
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);
|
||||
} else if (identifier.startsWith("attribute_points_spent_")) {
|
||||
String attributeId = identifier.substring(31);
|
||||
|
@ -74,11 +74,11 @@ public class SkillManager implements MMOCoreManager {
|
||||
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("material", "BOOK");
|
||||
for (Object mod : handler.getModifiers()) {
|
||||
config.getConfig().set(mod + ".base", 0);
|
||||
config.getConfig().set(mod + ".per-level", 0);
|
||||
config.getConfig().set(mod + ".min", 0);
|
||||
config.getConfig().set(mod + ".max", 0);
|
||||
for (Object param : handler.getParameters()) {
|
||||
config.getConfig().set(param + ".base", 0);
|
||||
config.getConfig().set(param + ".per-level", 0);
|
||||
config.getConfig().set(param + ".min", 0);
|
||||
config.getConfig().set(param + ".max", 0);
|
||||
}
|
||||
config.save();
|
||||
}
|
||||
|
@ -7,6 +7,7 @@ import io.lumine.mythic.lib.skill.Skill;
|
||||
import io.lumine.mythic.lib.skill.SkillMetadata;
|
||||
import io.lumine.mythic.lib.skill.handler.SkillHandler;
|
||||
import net.Indyuce.mmocore.MMOCore;
|
||||
import net.Indyuce.mmocore.api.ConfigMessage;
|
||||
import net.Indyuce.mmocore.api.player.PlayerActivity;
|
||||
import net.Indyuce.mmocore.api.player.PlayerData;
|
||||
import net.Indyuce.mmocore.api.event.PlayerResourceUpdateEvent;
|
||||
@ -64,15 +65,16 @@ public class CastableSkill extends Skill {
|
||||
}
|
||||
|
||||
// Mana cost
|
||||
if (playerData.getMana() < getModifier("mana")) {
|
||||
if (loud) MMOCore.plugin.configManager.getSimpleMessage("casting.no-mana",
|
||||
"mana-required", MythicLib.plugin.getMMOConfig().decimal.format((getModifier("mana") - playerData.getMana())),
|
||||
if (playerData.getMana() < getParameter("mana")) {
|
||||
if (loud) new ConfigMessage("casting.no-mana").addPlaceholders(
|
||||
"mana-required", MythicLib.plugin.getMMOConfig().decimal.format((getParameter("mana") - playerData.getMana())),
|
||||
"mana", playerData.getProfess().getManaDisplay().getName()).send(playerData.getPlayer());
|
||||
return false;
|
||||
}
|
||||
|
||||
// Stamina cost
|
||||
if (playerData.getStamina() < getModifier("stamina")) {
|
||||
if (playerData.getStamina() < getParameter("stamina")) {
|
||||
|
||||
if (loud) MMOCore.plugin.configManager.getSimpleMessage("casting.no-stamina").send(playerData.getPlayer());
|
||||
return false;
|
||||
}
|
||||
@ -93,11 +95,11 @@ public class CastableSkill extends Skill {
|
||||
|
||||
// Cooldown
|
||||
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);
|
||||
|
||||
casterData.giveMana(-getModifier("mana"), PlayerResourceUpdateEvent.UpdateReason.SKILL_COST);
|
||||
casterData.giveStamina(-getModifier("stamina"), PlayerResourceUpdateEvent.UpdateReason.SKILL_COST);
|
||||
casterData.giveMana(-getParameter("mana"), PlayerResourceUpdateEvent.UpdateReason.SKILL_COST);
|
||||
casterData.giveStamina(-getParameter("stamina"), PlayerResourceUpdateEvent.UpdateReason.SKILL_COST);
|
||||
}
|
||||
|
||||
if (!getTrigger().isPassive())
|
||||
@ -110,7 +112,7 @@ public class CastableSkill extends Skill {
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getModifier(String mod) {
|
||||
return skill.getModifier(mod, skillLevel.get());
|
||||
public double getParameter(String mod) {
|
||||
return skill.getParameter(mod, skillLevel.get());
|
||||
}
|
||||
}
|
||||
|
@ -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.modifier.ModifierSource;
|
||||
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.api.player.PlayerData;
|
||||
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 int unlockLevel, maxSkillLevel;
|
||||
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
|
||||
@ -42,8 +41,8 @@ public class ClassSkill implements CooldownObject, Unlockable {
|
||||
this.unlockLevel = unlockLevel;
|
||||
this.maxSkillLevel = maxSkillLevel;
|
||||
this.unlockedByDefault = unlockedByDefault;
|
||||
for (String mod : skill.getHandler().getModifiers())
|
||||
this.modifiers.put(mod, skill.getModifierInfo(mod));
|
||||
for (String param : skill.getHandler().getParameters())
|
||||
this.parameters.put(param, skill.getParameterInfo(param));
|
||||
}
|
||||
|
||||
public ClassSkill(RegisteredSkill skill, ConfigurationSection config) {
|
||||
@ -51,9 +50,9 @@ public class ClassSkill implements CooldownObject, Unlockable {
|
||||
unlockLevel = config.getInt("level");
|
||||
maxSkillLevel = config.getInt("max-level");
|
||||
unlockedByDefault = config.getBoolean("unlocked-by-default", true);
|
||||
for (String mod : skill.getHandler().getModifiers()) {
|
||||
LinearValue defaultValue = skill.getModifierInfo(mod);
|
||||
this.modifiers.put(mod, config.isConfigurationSection(mod) ? readLinearValue(defaultValue, config.getConfigurationSection(mod)) : defaultValue);
|
||||
for (String param : skill.getHandler().getParameters()) {
|
||||
LinearValue defaultValue = skill.getParameterInfo(param);
|
||||
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();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
public void addModifier(String modifier, LinearValue linear) {
|
||||
Validate.isTrue(modifiers.containsKey(modifier), "Could not find modifier '" + modifier + "'");
|
||||
modifiers.put(modifier, linear);
|
||||
public void addParameter(String parameter, LinearValue linear) {
|
||||
Validate.isTrue(parameters.containsKey(parameter), "Could not find parameter '" + parameter + "'");
|
||||
parameters.put(parameter, linear);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Skill modifiers are now called parameters.
|
||||
*/
|
||||
@Deprecated
|
||||
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) {
|
||||
@ -122,7 +139,7 @@ public class ClassSkill implements CooldownObject, Unlockable {
|
||||
|
||||
// Calculate 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_color", data.getProfess().getManaDisplay().getFull().toString());
|
||||
|
||||
|
@ -18,11 +18,10 @@ import java.util.*;
|
||||
public class RegisteredSkill {
|
||||
private final SkillHandler<?> handler;
|
||||
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 List<String> lore;
|
||||
private final List<String> categories;
|
||||
@NotNull
|
||||
private final TriggerType triggerType;
|
||||
|
||||
public RegisteredSkill(SkillHandler<?> handler, ConfigurationSection config) {
|
||||
@ -44,14 +43,14 @@ public class RegisteredSkill {
|
||||
categories.add("ACTIVE");
|
||||
|
||||
// Load default modifier formulas
|
||||
for (String mod : handler.getModifiers())
|
||||
defaultModifiers.put(mod, config.contains(mod) ? new LinearValue(config.getConfigurationSection(mod)) : LinearValue.ZERO);
|
||||
for (String param : handler.getParameters())
|
||||
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
|
||||
* 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) {
|
||||
@ -83,8 +82,16 @@ public class RegisteredSkill {
|
||||
return icon.clone();
|
||||
}
|
||||
|
||||
public boolean hasParameter(String parameter) {
|
||||
return defaultParameters.containsKey(parameter);
|
||||
}
|
||||
|
||||
/**
|
||||
* Skills modifiers are now called parameters.
|
||||
*/
|
||||
@Deprecated
|
||||
public boolean hasModifier(String modifier) {
|
||||
return defaultModifiers.containsKey(modifier);
|
||||
return defaultParameters.containsKey(modifier);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@ -92,27 +99,45 @@ public class RegisteredSkill {
|
||||
return Objects.requireNonNull(triggerType, "Skill has no trigger");
|
||||
}
|
||||
|
||||
/**
|
||||
* Skill modifiers are now called parameters.
|
||||
*/
|
||||
@Deprecated
|
||||
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
|
||||
public void addModifierIfNone(String mod, LinearValue defaultValue) {
|
||||
if (!hasModifier(mod))
|
||||
addModifier(mod, defaultValue);
|
||||
if (!hasParameter(mod))
|
||||
addParameter(mod, defaultValue);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Skill modifiers are now called parameters.
|
||||
*/
|
||||
@Deprecated
|
||||
public LinearValue getModifierInfo(String modifier) {
|
||||
return defaultParameters.get(modifier);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Modifier formula.
|
||||
* Not null as long as the modifier is well defined
|
||||
* Not null as long as the modifier is well defined
|
||||
*/
|
||||
@NotNull
|
||||
public LinearValue getModifierInfo(String modifier) {
|
||||
return defaultModifiers.get(modifier);
|
||||
public LinearValue getParameterInfo(String parameter) {
|
||||
return defaultParameters.get(parameter);
|
||||
}
|
||||
|
||||
public double getModifier(String modifier, int level) {
|
||||
return defaultModifiers.get(modifier).calculate(level);
|
||||
return defaultParameters.get(modifier).calculate(level);
|
||||
}
|
||||
|
||||
public boolean matchesFormula(String formula) {
|
||||
|
@ -17,7 +17,6 @@ import org.bukkit.GameMode;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerItemHeldEvent;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@ -151,11 +150,11 @@ public class SkillBar implements SkillCastingListener {
|
||||
}
|
||||
|
||||
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) {
|
||||
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
|
||||
|
@ -40,7 +40,7 @@ public class Ambers extends SkillHandler<SimpleSkillResult> implements Listener
|
||||
Location loc = target.getLocation();
|
||||
|
||||
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
|
||||
|
@ -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.result.def.SimpleSkillResult;
|
||||
import net.Indyuce.mmocore.api.event.PlayerResourceUpdateEvent;
|
||||
import net.Indyuce.mmocore.api.player.PlayerData;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
@ -34,7 +33,7 @@ public class Neptune_Gift extends SkillHandler<SimpleSkillResult> implements Lis
|
||||
if (skill == null)
|
||||
return;
|
||||
|
||||
event.setAmount(event.getAmount() * (1 + skill.getTriggeredSkill().getModifier("extra") / 100));
|
||||
event.setAmount(event.getAmount() * (1 + skill.getTriggeredSkill().getParameter("extra") / 100));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -30,7 +30,7 @@ public class Sneaky_Picky extends SkillHandler<SimpleSkillResult> implements Lis
|
||||
@Override
|
||||
public void whenCast(SimpleSkillResult result, SkillMetadata skillMeta) {
|
||||
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().playSound(target.getLocation(), Sound.ENTITY_ZOMBIE_ATTACK_IRON_DOOR, 1, 2);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user