From 593fc2927f13d43c1f8605325b118b2186164aa5 Mon Sep 17 00:00:00 2001 From: Ceikry Date: Sun, 21 Mar 2021 23:36:08 -0500 Subject: [PATCH] decant --- .../skill/herblore/MassDecantingPlugin.java | 56 ------------------- .../game/interaction/npc/DecantListener.kt | 55 ++++++++++++++++++ 2 files changed, 55 insertions(+), 56 deletions(-) delete mode 100644 Server/src/main/java/core/game/node/entity/skill/herblore/MassDecantingPlugin.java create mode 100644 Server/src/main/kotlin/rs09/game/interaction/npc/DecantListener.kt diff --git a/Server/src/main/java/core/game/node/entity/skill/herblore/MassDecantingPlugin.java b/Server/src/main/java/core/game/node/entity/skill/herblore/MassDecantingPlugin.java deleted file mode 100644 index 4a5060a6c..000000000 --- a/Server/src/main/java/core/game/node/entity/skill/herblore/MassDecantingPlugin.java +++ /dev/null @@ -1,56 +0,0 @@ - -package core.game.node.entity.skill.herblore; - -import core.cache.def.impl.NPCDefinition; -import core.game.interaction.OptionHandler; -import core.game.node.Node; -import core.game.node.entity.player.Player; -import core.game.node.item.Item; - -import core.plugin.Initializable; -import core.plugin.Plugin; -import core.game.content.consumable.Consumables; -import core.game.content.consumable.Potion; - -import java.util.HashMap; -import java.util.List; - -@Initializable -public class MassDecantingPlugin extends OptionHandler { - - @Override - public Plugin newInstance(Object arg) throws Throwable { - NPCDefinition.setOptionHandler("decant",this); - return this; - } - - @Override - public boolean handle(Player player, Node node, String option) { - decant(player); - return true; - } - - public void decant(Player p){ - HashMap potcounts = new HashMap<>(); - final List results; - for(int i = 0; i < 28; i++){ - Potion pot = (Potion) Consumables.getConsumableById(p.getInventory().getId(i)); - if(pot != null){ - int dosage = Integer.parseInt(p.getInventory().get(i).getName().replaceAll("[^\\d.]","")); - if(potcounts.get(pot) != null){ - potcounts.replace(pot,potcounts.get(pot) + dosage); - } else { - potcounts.putIfAbsent(pot,dosage); - } - p.getInventory().remove(new Item(p.getInventory().getId(i))); - } - } - potcounts.keySet().forEach(pot -> { - int full_count = (potcounts.get(pot) / pot.getIds().length); - int partial_dose_amt = (potcounts.get(pot) % pot.getIds().length); - p.getInventory().add(new Item(pot.getIds()[0],full_count)); - if(partial_dose_amt > 0) p.getInventory().add(new Item(pot.getIds()[pot.getIds().length - partial_dose_amt])); - }); - } -} - diff --git a/Server/src/main/kotlin/rs09/game/interaction/npc/DecantListener.kt b/Server/src/main/kotlin/rs09/game/interaction/npc/DecantListener.kt new file mode 100644 index 000000000..a633eccec --- /dev/null +++ b/Server/src/main/kotlin/rs09/game/interaction/npc/DecantListener.kt @@ -0,0 +1,55 @@ +package rs09.game.interaction.npc + +import core.game.content.consumable.Consumables +import core.game.content.consumable.Potion +import core.game.node.entity.player.Player +import core.game.node.item.Item +import rs09.game.content.dialogue.DialogueFile +import rs09.game.interaction.InteractionListener +import rs09.tools.END_DIALOGUE + +class DecantListener : InteractionListener() { + + override fun defineListeners() { + on(NPC,"decant"){player, node -> + decant(player) + player.dialogueInterpreter.open(DecantingDialogue(),node.asNpc()) + return@on true + } + } + + + fun decant(p: Player) { + val potcounts = HashMap() + val results: List + for (i in 0..27) { + val pot = (Consumables.getConsumableById(p.inventory.getId(i)) ?: continue) as Potion + if (pot != null) { + val dosage = p.inventory[i].name.replace("[^\\d.]".toRegex(), "").toInt() + if (potcounts[pot] != null) { + potcounts.replace(pot, potcounts[pot]!! + dosage) + } else { + potcounts.putIfAbsent(pot, dosage) + } + p.inventory.remove(Item(p.inventory.getId(i))) + } + } + potcounts.keys.forEach{ pot: Potion -> + val full_count = potcounts[pot]!! / pot.ids.size + val partial_dose_amt = potcounts[pot]!! % pot.ids.size + p.inventory.add(Item(pot.ids[0], full_count)) + if (partial_dose_amt > 0) p.inventory + .add(Item(pot.ids[pot.ids.size - partial_dose_amt])) + } + } + + internal class DecantingDialogue : DialogueFile(){ + override fun handle(componentID: Int, buttonID: Int) { + when(stage++){ + 0 -> npc("There you go!") + 1 -> player("Thanks!").also { stage = END_DIALOGUE } + } + } + } + +} \ No newline at end of file