From bc535130c5798299b5ecd56199de89f8a13c2d95 Mon Sep 17 00:00:00 2001 From: ASangarin Date: Fri, 16 Oct 2020 20:28:49 +0200 Subject: [PATCH] Added a Stamina Trigger --- .../mmocore/api/load/DefaultMMOLoader.java | 4 ++ .../api/quest/trigger/StaminaTrigger.java | 46 +++++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100644 src/main/java/net/Indyuce/mmocore/api/quest/trigger/StaminaTrigger.java diff --git a/src/main/java/net/Indyuce/mmocore/api/load/DefaultMMOLoader.java b/src/main/java/net/Indyuce/mmocore/api/load/DefaultMMOLoader.java index cfdb4957..4959e98c 100644 --- a/src/main/java/net/Indyuce/mmocore/api/load/DefaultMMOLoader.java +++ b/src/main/java/net/Indyuce/mmocore/api/load/DefaultMMOLoader.java @@ -37,6 +37,7 @@ import net.Indyuce.mmocore.api.quest.trigger.ItemTrigger; import net.Indyuce.mmocore.api.quest.trigger.ManaTrigger; import net.Indyuce.mmocore.api.quest.trigger.MessageTrigger; import net.Indyuce.mmocore.api.quest.trigger.SoundTrigger; +import net.Indyuce.mmocore.api.quest.trigger.StaminaTrigger; import net.Indyuce.mmocore.api.quest.trigger.StelliumTrigger; import net.Indyuce.mmocore.api.quest.trigger.Trigger; import net.mmogroup.mmolib.api.MMOLineConfig; @@ -54,6 +55,9 @@ public class DefaultMMOLoader extends MMOLoader { if (config.getKey().equals("mana")) return new ManaTrigger(config); + if (config.getKey().equals("stamina")) + return new StaminaTrigger(config); + if (config.getKey().equals("stellium")) return new StelliumTrigger(config); diff --git a/src/main/java/net/Indyuce/mmocore/api/quest/trigger/StaminaTrigger.java b/src/main/java/net/Indyuce/mmocore/api/quest/trigger/StaminaTrigger.java new file mode 100644 index 00000000..848c67ca --- /dev/null +++ b/src/main/java/net/Indyuce/mmocore/api/quest/trigger/StaminaTrigger.java @@ -0,0 +1,46 @@ +package net.Indyuce.mmocore.api.quest.trigger; + +import net.Indyuce.mmocore.api.player.PlayerData; +import net.Indyuce.mmocore.api.util.math.formula.RandomAmount; +import net.mmogroup.mmolib.api.MMOLineConfig; + +public class StaminaTrigger extends Trigger { + private final RandomAmount amount; + private final Operation operation; + + public StaminaTrigger(MMOLineConfig config) { + super(config); + + config.validate("amount"); + amount = new RandomAmount(config.getString("amount")); + operation = config.contains("operation") ? Operation.valueOf(config.getString("operation").toUpperCase()) : Operation.GIVE; + } + + @Override + public void apply(PlayerData player) { + + /* + * give mana + */ + if (operation == Operation.GIVE) + player.giveStamina(amount.calculate()); + + /* + * set mana + */ + else if (operation == Operation.SET) + player.setStamina(amount.calculate()); + + /* + * take mana + */ + else + player.giveStamina(-amount.calculate()); + } + + public enum Operation { + GIVE, + SET, + TAKE; + } +}