From d48f585a282ac2420f39097fdde8ced19abf4f60 Mon Sep 17 00:00:00 2001 From: Ryan <2804894-ryannathans@users.noreply.gitlab.com> Date: Fri, 31 Dec 2021 15:45:22 +0000 Subject: [PATCH] Smelting Cannonballs Now Authentic, fixed Container.containsAtLeastOneItem(item) --- .../java/core/game/container/Container.java | 6 +- .../members/dwarfcannon/CannonBallPlugin.java | 138 ------------------ .../members/dwarfcannon/DwarfCannon.java | 1 - .../item/withobject/AmmoMouldOnFurnace.kt | 87 +++++++++++ 4 files changed, 90 insertions(+), 142 deletions(-) delete mode 100644 Server/src/main/java/core/game/content/quest/members/dwarfcannon/CannonBallPlugin.java create mode 100644 Server/src/main/kotlin/rs09/game/interaction/item/withobject/AmmoMouldOnFurnace.kt diff --git a/Server/src/main/java/core/game/container/Container.java b/Server/src/main/java/core/game/container/Container.java index d21244289..a350db758 100644 --- a/Server/src/main/java/core/game/container/Container.java +++ b/Server/src/main/java/core/game/container/Container.java @@ -659,14 +659,14 @@ public class Container { } /** - * Checks if the containers contains ONE item. + * Checks if the containers contains at least ONE item. * * @param itemId * @return */ public boolean containsAtLeastOneItem(int itemId) { for (Item item : items) { - if (item != null && item.getId() == itemId && item.getAmount() == 1) { + if (item != null && item.getId() == itemId && item.getAmount() > 0) { return true; } } @@ -680,7 +680,7 @@ public class Container { */ public boolean containsAtLeastOneItem(int[] itemIds) { for (int id : itemIds) { - if (getAmount(id) >= 1) + if (getAmount(id) > 0) return true; } return false; diff --git a/Server/src/main/java/core/game/content/quest/members/dwarfcannon/CannonBallPlugin.java b/Server/src/main/java/core/game/content/quest/members/dwarfcannon/CannonBallPlugin.java deleted file mode 100644 index 96282a133..000000000 --- a/Server/src/main/java/core/game/content/quest/members/dwarfcannon/CannonBallPlugin.java +++ /dev/null @@ -1,138 +0,0 @@ -package core.game.content.quest.members.dwarfcannon; - -import org.rs09.consts.Items; -import rs09.game.content.dialogue.SkillDialogueHandler; -import rs09.game.content.dialogue.SkillDialogueHandler.SkillDialogue; -import core.game.node.entity.skill.SkillPulse; -import core.game.node.entity.skill.Skills; -import core.game.interaction.NodeUsageEvent; -import core.game.interaction.UseWithHandler; -import core.game.node.entity.player.Player; -import core.game.node.item.Item; -import core.game.world.update.flag.context.Animation; -import core.plugin.Plugin; - -/** - * Handles the cannon ball making. - * @author Vexia - */ -public class CannonBallPlugin extends UseWithHandler { - - /** - * The furnaces. - */ - private static final int[] FURNACES = new int[] { 4304, 6189, 11010, 11666, 12100, 12809, 18497, 26814, 30021, 30510, 36956, 37651 }; - - /** - * Constructs a new {@Code CannonBallPlugin} {@Code Object} - */ - public CannonBallPlugin() { - super(Items.STEEL_BAR_2353); - } - - @Override - public Plugin newInstance(Object arg) throws Throwable { - for (int id : FURNACES) { - addHandler(id, OBJECT_TYPE, this); - } - return this; - } - - @Override - public boolean handle(final NodeUsageEvent event) { - final Player player = event.getPlayer(); - if (!player.getQuestRepository().isComplete(DwarfCannon.NAME)) { - player.getDialogueInterpreter().sendDialogue("You need to complete the Dwarf Cannon quest in order to do this."); - return true; - } - SkillDialogueHandler dialogue = new SkillDialogueHandler(player, SkillDialogue.ONE_OPTION, event.getUsedItem()) { - - @Override - public void create(final int amount, int index) { - player.getPulseManager().run(new CannonBallPulse(player, event.getUsedItem(), amount)); - } - - @Override - public int getAll(int index) { - return player.getInventory().getAmount(event.getUsedItem()); - } - - }; - dialogue.open(); - return true; - } - - /** - * Handles the pulse used to create a cannon ball. - * @author Vexia - */ - public class CannonBallPulse extends SkillPulse { - - /** - * The amount to make. - */ - private int amount; - - /** - * The ticks. - */ - private int ticks; - - /** - * Constructs a new {@Code CannonBallPulse} {@Code Object} - * @param player the player. - * @param node the node. - * @param amount the amount. - */ - public CannonBallPulse(Player player, Item node, int amount) { - super(player, node); - this.amount = amount; - } - - @Override - public boolean checkRequirements() { - if (player.getSkills().getLevel(Skills.SMITHING) < 35) { - player.getDialogueInterpreter().sendDialogue("You need a Smithing level of at least 35 in order to do this."); - return false; - } - if (!player.getInventory().contains(Items.AMMO_MOULD_4, 1)) { - player.getDialogueInterpreter().sendDialogue("You need an ammo mould in order to make a cannon ball."); - return false; - } - if (!player.getInventory().containsItem(node)) { - stop(); - return false; - } - return true; - } - - @Override - public void animate() { - if (ticks == 0 || ticks % 6 == 0) { - player.sendMessage("You heat the steel bar into a liquid state."); - player.animate(Animation.create(827)); //Bone burying animation (2009 used the same animation as burying bones) - } else if (ticks % 3 == 0) { - player.sendMessage("You pour the molten metal into your cannonball mould."); - } - } - - @Override - public boolean reward() { - if (++ticks % 6 != 0) { - return false; - } - amount--; - if (player.getInventory().remove(node)) { - player.getInventory().add(new Item(Items.CANNONBALL_2, 4)); - player.getSkills().addExperience(Skills.SMITHING, 25.6, true); - player.sendMessage("The molten metal cools slowly to form 4 cannonballs."); - } - return amount <= 0; - } - - @Override - public void message(int type) { - } - } - -} diff --git a/Server/src/main/java/core/game/content/quest/members/dwarfcannon/DwarfCannon.java b/Server/src/main/java/core/game/content/quest/members/dwarfcannon/DwarfCannon.java index 20da23932..86998a7dc 100644 --- a/Server/src/main/java/core/game/content/quest/members/dwarfcannon/DwarfCannon.java +++ b/Server/src/main/java/core/game/content/quest/members/dwarfcannon/DwarfCannon.java @@ -51,7 +51,6 @@ public class DwarfCannon extends Quest { PluginManager.definePlugin(new LollkDialogue()); PluginManager.definePlugin(new NulodionDialogue()); PluginManager.definePlugin(new CaptainLawgofNPC()); - PluginManager.definePlugin(new CannonBallPlugin()); PluginManager.definePlugin(new CaptainLawgofDialogue()); PluginManager.definePlugin(new DwarfCannonPlugin()); return this; diff --git a/Server/src/main/kotlin/rs09/game/interaction/item/withobject/AmmoMouldOnFurnace.kt b/Server/src/main/kotlin/rs09/game/interaction/item/withobject/AmmoMouldOnFurnace.kt new file mode 100644 index 000000000..fb0c20d72 --- /dev/null +++ b/Server/src/main/kotlin/rs09/game/interaction/item/withobject/AmmoMouldOnFurnace.kt @@ -0,0 +1,87 @@ +package rs09.game.interaction.item.withobject + +import core.game.content.quest.members.dwarfcannon.DwarfCannon +import core.game.node.Node +import core.game.node.entity.player.Player +import core.game.node.entity.skill.Skills +import core.game.node.item.Item +import core.game.system.task.Pulse +import core.game.world.update.flag.context.Animation +import org.rs09.consts.Items +import rs09.game.content.dialogue.SkillDialogueHandler +import rs09.game.interaction.InteractionListener + +class AmmoMouldOnFurnace : InteractionListener(){ + private val furnaces = intArrayOf(4304, 6189, 11010, 11666, 12100, 12809, 18497, 26814, 30021, 30510, 36956, 37651) // abstract when smelting converted to kotlin + val levelRequirement = 35 + + private fun cannonBallOnUseWithHandler(player: Player, used: Node, with: Node): Boolean { + player.faceLocation(with.centerLocation) + if(!player.questRepository.isComplete(DwarfCannon.NAME)) { + player.dialogueInterpreter.sendDialogue("You need to complete the ${DwarfCannon.NAME} quest in order to do this.") + return true + } + if (player.getSkills().getLevel(Skills.SMITHING) < levelRequirement) { + player.dialogueInterpreter.sendDialogue("You need a Smithing level of at least $levelRequirement in order to do this.") + return true + } + if (!player.inventory.contains(Items.AMMO_MOULD_4, 1)) { + player.dialogueInterpreter.sendDialogue("You need an ammo mould in order to make a cannon ball.") + return true + } + + val cannonBallPulse = object : Pulse() { + private var tick = 0 + var amount = 0 + override fun pulse(): Boolean { + when(tick++){ + 0 -> { + player.sendMessage("You heat the steel bar into a liquid state.") + player.animator.animate(Animation(3243)) // 899 would be preferable but the arms spaz out + } + 3 -> { + player.sendMessage("You pour the molten metal into your cannonball mould.") + player.animator.animate(Animation(827)) + } + 4 -> { + player.sendMessage("The molten metal cools slowly to form 4 cannonballs.") + } + 7 -> { + if (player.inventory.remove(used.asItem())) { + player.inventory.add(Item(Items.CANNONBALL_2, 4)) + player.getSkills().addExperience(Skills.SMITHING, 25.6, true) + } + player.animator.animate(Animation(827)) + } + 10 -> { + if (--amount == 0 || !player.inventory.containsAtLeastOneItem(Items.STEEL_BAR_2353)) { + return true + } + tick = 0 + } + } + return false + } + } + + val itemUsed = used.asItem() + + val dialogue: SkillDialogueHandler = object : SkillDialogueHandler(player, SkillDialogue.ONE_OPTION, itemUsed) { + override fun create(amount: Int, index: Int) { + cannonBallPulse.amount = amount + player.pulseManager.run(cannonBallPulse) + } + + override fun getAll(index: Int): Int { + return player.inventory.getAmount(itemUsed) + } + } + dialogue.open() + + return true + } + + override fun defineListeners() { + onUseWith(SCENERY, Items.STEEL_BAR_2353, *furnaces, handler = ::cannonBallOnUseWithHandler) + } +} \ No newline at end of file