diff --git a/Server/src/main/java/core/game/node/entity/skill/cooking/CookingRewrite.kt b/Server/src/main/java/core/game/node/entity/skill/cooking/CookingRewrite.kt index e7cec5cd2..356da297c 100644 --- a/Server/src/main/java/core/game/node/entity/skill/cooking/CookingRewrite.kt +++ b/Server/src/main/java/core/game/node/entity/skill/cooking/CookingRewrite.kt @@ -3,16 +3,15 @@ package core.game.node.entity.skill.cooking import core.game.node.`object`.GameObject import core.game.node.entity.player.Player import core.game.node.item.Item -import core.plugin.Initializable import org.rs09.consts.Items import org.rs09.consts.Items.BREAD_DOUGH_2307 import org.rs09.consts.Items.RAW_BEEF_2132 import org.rs09.consts.Items.SEAWEED_401 import org.rs09.consts.Items.UNCOOKED_CAKE_1889 import rs09.game.interaction.InteractionListener +import rs09.game.node.entity.skill.cooking.CookingDialogue //author: Ceik -@Initializable class CookingRewrite : InteractionListener() { val RAW_FOODS: IntArray @@ -31,11 +30,11 @@ class CookingRewrite : InteractionListener() { val range = obj.name.toLowerCase().contains("range") when (item.id) { RAW_BEEF_2132 -> if (range) { - player.dialogueInterpreter.open(FoodCookingDialogue.DialogueID, item, 9436, true, obj) + player.dialogueInterpreter.open(CookingDialogue(item,9436,true,obj)) return@onUseWith true } SEAWEED_401 -> if (range) { - player.dialogueInterpreter.open(FoodCookingDialogue.DialogueID, item, 1781, false, obj) + player.dialogueInterpreter.open(CookingDialogue(item,1781,false,obj)) return@onUseWith true } BREAD_DOUGH_2307, UNCOOKED_CAKE_1889 -> if (!range) { @@ -45,7 +44,7 @@ class CookingRewrite : InteractionListener() { } //cook a standard item - player.dialogueInterpreter.open(FoodCookingDialogue.DialogueID, item.id, obj) + player.dialogueInterpreter.open(CookingDialogue(item.id,obj)) return@onUseWith true } diff --git a/Server/src/main/java/core/game/node/entity/skill/cooking/FoodCookingDialogue.java b/Server/src/main/java/core/game/node/entity/skill/cooking/FoodCookingDialogue.java deleted file mode 100644 index 2d644e655..000000000 --- a/Server/src/main/java/core/game/node/entity/skill/cooking/FoodCookingDialogue.java +++ /dev/null @@ -1,125 +0,0 @@ -package core.game.node.entity.skill.cooking; - -import core.cache.def.impl.ItemDefinition; -import core.game.content.dialogue.DialoguePlugin; -import core.game.node.entity.player.Player; -import core.game.node.entity.player.link.RunScript; -import core.game.node.object.GameObject; -import core.net.packet.PacketRepository; -import core.net.packet.context.ChildPositionContext; -import core.net.packet.out.RepositionChild; - -public class FoodCookingDialogue extends DialoguePlugin { - public static final int DialogueID = 1238503; - private int initial,product; - private boolean sinew = false; - private GameObject object; - - public FoodCookingDialogue(){ - /** - * Empty - */ - } - public FoodCookingDialogue(Player player){super(player);} - - @Override - public DialoguePlugin newInstance(Player player) { - return new FoodCookingDialogue(player); - } - - @Override - public boolean open(Object... args) { - stage = 0; - switch(args.length){ - case 2: - initial = (int) args[0]; - if(CookableItems.intentionalBurn(initial)){ // checks intentional burning - product = CookableItems.getIntentionalBurn(initial).getId(); - } else { - product = CookableItems.forId(initial).cooked; - - } - object = (GameObject) args[1]; - break; - case 4: - initial = (int) args[0]; - product = (int) args[1]; - sinew = (boolean) args[2]; - object = (GameObject) args[3]; - if(sinew){ - player.getDialogueInterpreter().sendOptions("Select one","Dry the meat into sinew","Cook the meat"); - stage = 100; - return true; - } - break; - } - display(); - return true; - } - - @Override - public boolean handle(int interfaceId, int buttonId) { - switch(stage){ - case 0: - end(); - int amount = getAmount(buttonId); - switch(amount){ - case -1: - player.setAttribute("runscript", new RunScript() { - @Override - public boolean handle() { - int amount = (int) value; - CookingRewrite.cook(player, object, initial, product, amount); - return false; - } - }); - player.getDialogueInterpreter().sendInput(false,"Enter an amount:"); - break; - default: - end(); - CookingRewrite.cook(player,object,initial,product,amount); - break; - } - break; - case 100: - switch(buttonId){ - case 1: - CookingRewrite.cook(player,object,initial,product,1); - break; - case 2: - product = CookableItems.forId(initial).cooked; - display(); - break; - } - } - return true; - } - - private final int getAmount(final int buttonId) { - switch (buttonId) { - case 5: - return 1; - case 4: - return 5; - case 3: - return -1; - case 2: - return player.getInventory().getAmount(initial); - } - return -1; - } - - public void display() { - player.getInterfaceManager().openChatbox(307); - PacketRepository.send(RepositionChild.class, new ChildPositionContext(player, 307, 3, 60, 90)); - PacketRepository.send(RepositionChild.class, new ChildPositionContext(player,307,2,208,20)); - player.getPacketDispatch().sendItemZoomOnInterface(product, 160, 307, 2); - player.getPacketDispatch().sendString(ItemDefinition.forId(product).getName(), 307, 3); - stage = 0; - } - - @Override - public int[] getIds() { - return new int[] {DialogueID}; - } -} diff --git a/Server/src/main/kotlin/rs09/game/node/entity/skill/cooking/CookingDialogue.kt b/Server/src/main/kotlin/rs09/game/node/entity/skill/cooking/CookingDialogue.kt new file mode 100644 index 000000000..12b1432b8 --- /dev/null +++ b/Server/src/main/kotlin/rs09/game/node/entity/skill/cooking/CookingDialogue.kt @@ -0,0 +1,103 @@ +package rs09.game.node.entity.skill.cooking + +import core.cache.def.impl.ItemDefinition +import core.game.node.`object`.GameObject +import core.game.node.entity.player.link.RunScript +import core.game.node.entity.skill.cooking.CookableItems +import core.game.node.entity.skill.cooking.CookingRewrite.Companion.cook +import core.net.packet.PacketRepository +import core.net.packet.context.ChildPositionContext +import core.net.packet.out.RepositionChild +import rs09.game.content.dialogue.DialogueFile +import rs09.tools.START_DIALOGUE + +class CookingDialogue(vararg val args: Any) : DialogueFile(){ + var initial = 0 + var product = 0 + var `object`: GameObject? = null + var sinew = false + override fun handle(componentID: Int, buttonID: Int) { + when(stage){ + START_DIALOGUE -> { + when (args.size) { + 2 -> { + initial = args.get(0) as Int + if (CookableItems.intentionalBurn(initial)) { // checks intentional burning + product = CookableItems.getIntentionalBurn(initial).id + } else { + product = CookableItems.forId(initial).cooked + } + `object` = args.get(1) as GameObject + } + 4 -> { + initial = args.get(0) as Int + product = args.get(1) as Int + sinew = args.get(2) as Boolean + `object` = args.get(3) as GameObject + if (sinew) { + player!!.dialogueInterpreter.sendOptions( + "Select one", + "Dry the meat into sinew", + "Cook the meat" + ) + stage = 100 + return + } + } + } + display() + } + + 1 -> { + end() + val amount = getAmount(buttonID) + when (amount) { + -1 -> { + player!!.setAttribute("runscript", object : RunScript() { + override fun handle(): Boolean { + val amount = value as Int + cook(player, `object`, initial, product, amount) + return false + } + }) + player!!.dialogueInterpreter.sendInput(false, "Enter an amount:") + } + else -> { + end() + cook(player!!, `object`, initial, product, amount) + } + } + } + + 100 -> { + when (buttonID) { + 1 -> cook(player!!, `object`, initial, product, 1) + 2 -> { + product = CookableItems.forId(initial).cooked + display() + } + } + } + } + } + + private fun getAmount(buttonId: Int): Int { + when (buttonId) { + 5 -> return 1 + 4 -> return 5 + 3 -> return -1 + 2 -> return player!!.inventory.getAmount(initial) + } + return -1 + } + + fun display() { + player!!.interfaceManager.openChatbox(307) + PacketRepository.send(RepositionChild::class.java, ChildPositionContext(player, 307, 3, 60, 90)) + PacketRepository.send(RepositionChild::class.java, ChildPositionContext(player, 307, 2, 208, 20)) + player!!.packetDispatch.sendItemZoomOnInterface(product, 160, 307, 2) + player!!.packetDispatch.sendString(ItemDefinition.forId(product).name, 307, 3) + stage = 1 + } + +} \ No newline at end of file