From 039baed3d3c4e93efc130c8ede7a59631920d5fe Mon Sep 17 00:00:00 2001 From: Jules Date: Fri, 14 Apr 2023 17:32:02 +0200 Subject: [PATCH] New triggers for skill management --- .../mmocore/api/load/DefaultMMOLoader.java | 6 ++++ .../api/quest/trigger/BindSkillTrigger.java | 36 +++++++++++++++++++ .../quest/trigger/LevelUpSkillTrigger.java | 32 +++++++++++++++++ 3 files changed, 74 insertions(+) create mode 100644 MMOCore-API/src/main/java/net/Indyuce/mmocore/api/quest/trigger/BindSkillTrigger.java create mode 100644 MMOCore-API/src/main/java/net/Indyuce/mmocore/api/quest/trigger/LevelUpSkillTrigger.java diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/load/DefaultMMOLoader.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/load/DefaultMMOLoader.java index 820b85a1..53458d1b 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/load/DefaultMMOLoader.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/load/DefaultMMOLoader.java @@ -29,6 +29,12 @@ public class DefaultMMOLoader extends MMOLoader { if (config.getKey().equals("unlock_skill")) return new UnlockSkillTrigger(config); + if (config.getKey().equals("bind_skill")) + return new BindSkillTrigger(config); + + if (config.getKey().equals("levelup_skill")) + return new LevelUpSkillTrigger(config); + if (config.getKey().equals("skill_buff")) return new SkillModifierTrigger(config); diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/quest/trigger/BindSkillTrigger.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/quest/trigger/BindSkillTrigger.java new file mode 100644 index 00000000..22aecf55 --- /dev/null +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/quest/trigger/BindSkillTrigger.java @@ -0,0 +1,36 @@ +package net.Indyuce.mmocore.api.quest.trigger; + +import io.lumine.mythic.lib.api.MMOLineConfig; +import net.Indyuce.mmocore.MMOCore; +import net.Indyuce.mmocore.api.player.PlayerData; +import net.Indyuce.mmocore.api.quest.trigger.api.Removable; +import net.Indyuce.mmocore.skill.ClassSkill; +import net.Indyuce.mmocore.skill.RegisteredSkill; + +import javax.annotation.Nullable; +import java.util.Objects; + +public class BindSkillTrigger extends Trigger implements Removable { + private final RegisteredSkill skill; + private final int slot; + + public BindSkillTrigger(MMOLineConfig config) { + super(config); + + config.validateKeys("skill", "slot"); + slot = config.getInt("slot"); + skill = Objects.requireNonNull(MMOCore.plugin.skillManager.getSkill(config.getString("skill"))); + } + + @Override + public void apply(PlayerData playerData) { + final @Nullable ClassSkill found = playerData.getProfess().getSkill(skill); + if (found != null) + playerData.bindSkill(slot, found); + } + + @Override + public void remove(PlayerData playerData) { + playerData.unbindSkill(slot); + } +} diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/quest/trigger/LevelUpSkillTrigger.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/quest/trigger/LevelUpSkillTrigger.java new file mode 100644 index 00000000..db1ce9e9 --- /dev/null +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/quest/trigger/LevelUpSkillTrigger.java @@ -0,0 +1,32 @@ +package net.Indyuce.mmocore.api.quest.trigger; + +import io.lumine.mythic.lib.api.MMOLineConfig; +import net.Indyuce.mmocore.MMOCore; +import net.Indyuce.mmocore.api.player.PlayerData; +import net.Indyuce.mmocore.api.quest.trigger.api.Removable; +import net.Indyuce.mmocore.skill.RegisteredSkill; + +import java.util.Objects; + +public class LevelUpSkillTrigger extends Trigger implements Removable { + private final RegisteredSkill skill; + private final int amount; + + public LevelUpSkillTrigger(MMOLineConfig config) { + super(config); + + config.validateKeys("skill", "amount"); + amount = config.getInt("amount"); + skill = Objects.requireNonNull(MMOCore.plugin.skillManager.getSkill(config.getString("skill"))); + } + + @Override + public void apply(PlayerData playerData) { + playerData.setSkillLevel(skill, playerData.getSkillLevel(skill) + amount); + } + + @Override + public void remove(PlayerData playerData) { + playerData.setSkillLevel(skill, Math.max(0, playerData.getSkillLevel(skill) - amount)); + } +}