From ee5bc78b6202629078f874d4a9723a4a7851ac2a Mon Sep 17 00:00:00 2001 From: vddcore <573729-vddcore@users.noreply.gitlab.com> Date: Mon, 27 Jun 2022 14:06:47 +0000 Subject: [PATCH] Refactored item note/unnote on bank booth handling QoL - only applies to bank booth, not banker NPCs Added server config world.bank_booth_note_enabled (enabled by default) to toggle the QoL globally Added server config world.bank_booth_note_uim (enabled by default) to toggle the QoL on ultimate ironmen only --- .../item/withobject/BankUnnotePlugin.java | 114 ------------------ .../core/net/packet/in/ItemActionPacket.java | 6 +- .../src/main/kotlin/rs09/ServerConstants.kt | 6 + .../rs09/game/interaction/ItemOnBankBooth.kt | 54 --------- .../interaction/object/BankBoothHandler.kt | 45 ++++++- .../game/system/config/ServerConfigParser.kt | 2 + 6 files changed, 53 insertions(+), 174 deletions(-) delete mode 100644 Server/src/main/java/core/game/interaction/item/withobject/BankUnnotePlugin.java delete mode 100644 Server/src/main/kotlin/rs09/game/interaction/ItemOnBankBooth.kt diff --git a/Server/src/main/java/core/game/interaction/item/withobject/BankUnnotePlugin.java b/Server/src/main/java/core/game/interaction/item/withobject/BankUnnotePlugin.java deleted file mode 100644 index 53032b7ca..000000000 --- a/Server/src/main/java/core/game/interaction/item/withobject/BankUnnotePlugin.java +++ /dev/null @@ -1,114 +0,0 @@ -package core.game.interaction.item.withobject; - -import core.game.interaction.NodeUsageEvent; -import core.game.interaction.UseWithHandler; -import core.game.node.Node; -import core.game.node.entity.npc.NPC; -import core.game.node.entity.player.Player; -import core.game.node.entity.player.link.IronmanMode; -import core.game.node.item.Item; -import core.game.world.map.Direction; -import core.game.world.map.Location; -import core.plugin.Initializable; -import core.plugin.Plugin; - -/** - * Handles the unnoting of noted items when used on a bank booth. - * @author Vexia - * @author Splinter - */ -@Initializable -public class BankUnnotePlugin extends UseWithHandler { - - /** - * The bank booth ids. - */ - private static final int[] BOOTHS = new int[] { 2213, 3194, 5276, 6084, 10517, 11338, 11402, 11758, 12309, 12798, 14367, 16700, 18491, 19230, 20325, 20391, 22819, 24914, 25808, 26972, 27663, 28514, 29085, 30016, 34752, 35647, 36786 }; - - /** - * The banker ids, - */ - private static final int[] BANKERS = new int[] { 44, 45, 494, 495, 496, 497, 498, 499, 953, 1036, 1360, 2163, 2164, 2354, 2355, 2568, 2569, 2570, 3198, 3199, 3824, 5258, 5260, 5776, 5777, 5912, 5913, 6200, 6532, 6533, 6534, 6535, 6538, 7445, 7446, 7605 }; - - /** - * Constructs a new {@Code BankUnnotePlugin} {@Code Object} - */ - public BankUnnotePlugin() { - super(); - } - - @Override - public Plugin newInstance(Object arg) throws Throwable { - for (int id : BOOTHS) { - addHandler(id, OBJECT_TYPE, this); - } - for (int id : BANKERS) { - addHandler(id, NPC_TYPE, this); - } - return this; - } - - @Override - public boolean handle(NodeUsageEvent event) { - final Player player = event.getPlayer(); - final Item item = event.getUsedItem(); - if (!player.isAdmin() && (player.getIronmanManager().getMode() == IronmanMode.NONE || item.getDefinition().isUnnoted())) { - return false; - } - if (item.getDefinition().isStackable() && item.getDefinition().isUnnoted()) { - player.getPacketDispatch().sendMessage("You can't note stackable items."); - return true; - } - int amount = item.getAmount(); - if (amount > player.getInventory().freeSlots()) { - amount = 28 - player.getInventory().freeSlots(); - } - if (amount < 1 || player.getInventory().freeSlots() <= 0) { - player.sendMessage("Not enough inventory space."); - return true; - } - if (player.getInventory().freeSlots() >= amount) { - if (player.getInventory().remove(new Item(item.getId(), amount))) { - Item newItem = new Item(item.getNoteChange(), amount); - player.getInventory().add(newItem); - player.getDialogueInterpreter().sendItemMessage(newItem, "You exchange your noted items."); - player.lock(1); - return true; - } - } else { - int toAdd = player.getInventory().freeSlots(); - if (player.getInventory().remove(new Item(item.getId(), toAdd))) { - Item newItem = new Item(item.getNoteChange(), toAdd); - player.getInventory().add(newItem); - player.getDialogueInterpreter().sendItemMessage(newItem, "You exchange your noted items."); - player.lock(1); - return true; - } - } - return false; - } - - @Override - public Location getDestination(Player player, Node with) { - if (with instanceof NPC) { - NPC npc = (NPC) with; - if (npc.getAttribute("facing_booth", false)) { - Direction dir = npc.getDirection(); - return npc.getLocation().transform(dir.getStepX() << 1, dir.getStepY() << 1, 0); - } - if (npc.getId() == 6533) { - return Location.create(3167, 3490, 0);// ge bankers. - } else if (npc.getId() == 6535) { - return Location.create(3162, 3489, 0); - } else if (npc.getId() == 4907) { - return npc.getLocation().transform(0, -2, 0); - } - } - return null; - } - - @Override - public boolean isDynamic() { - return true; - } -} diff --git a/Server/src/main/java/core/net/packet/in/ItemActionPacket.java b/Server/src/main/java/core/net/packet/in/ItemActionPacket.java index b152b8e75..40153ab31 100644 --- a/Server/src/main/java/core/net/packet/in/ItemActionPacket.java +++ b/Server/src/main/java/core/net/packet/in/ItemActionPacket.java @@ -16,7 +16,6 @@ import core.net.packet.PacketRepository; import core.net.packet.context.PlayerContext; import core.net.packet.out.ClearMinimapFlag; import org.rs09.consts.Items; -import rs09.game.interaction.ItemOnBankBooth; import rs09.game.interaction.InteractionListeners; import rs09.game.node.entity.skill.farming.CompostBins; import rs09.game.node.entity.skill.farming.FarmingPatch; @@ -234,10 +233,7 @@ public class ItemActionPacket implements IncomingPacket { if(PluginInteractionManager.handle(player,event)){ return; } - if(object.getName().toLowerCase().contains("bank booth")){ - new ItemOnBankBooth().handle(event); - return; - } + try { UseWithHandler.run(event); } catch (Exception e){ diff --git a/Server/src/main/kotlin/rs09/ServerConstants.kt b/Server/src/main/kotlin/rs09/ServerConstants.kt index c38e41c10..493a38223 100644 --- a/Server/src/main/kotlin/rs09/ServerConstants.kt +++ b/Server/src/main/kotlin/rs09/ServerConstants.kt @@ -113,6 +113,12 @@ class ServerConstants { @JvmField var BANK_BOOTH_QUICK_OPEN: Boolean = false + @JvmField + var BANK_BOOTH_NOTE_ENABLED: Boolean = true + + @JvmField + var BANK_BOOTH_NOTE_UIM: Boolean = true + @JvmField var GE_AUTOSAVE_FREQUENCY = secondsToTicks(3600) //1 hour diff --git a/Server/src/main/kotlin/rs09/game/interaction/ItemOnBankBooth.kt b/Server/src/main/kotlin/rs09/game/interaction/ItemOnBankBooth.kt deleted file mode 100644 index 80cbc35cd..000000000 --- a/Server/src/main/kotlin/rs09/game/interaction/ItemOnBankBooth.kt +++ /dev/null @@ -1,54 +0,0 @@ -package rs09.game.interaction - -import core.game.interaction.DestinationFlag -import core.game.interaction.MovementPulse -import core.game.interaction.NodeUsageEvent -import core.game.interaction.UseWithHandler -import core.game.node.item.Item -import core.plugin.Plugin - -class ItemOnBankBooth : UseWithHandler(0) { - - override fun handle(event: NodeUsageEvent?): Boolean { - event ?: return false - val player = event.player - player.pulseManager.run(object : MovementPulse(player, event.usedWith, DestinationFlag.OBJECT) { - override fun pulse(): Boolean { - return handleNote(event) - } - }, "movement") - return true - } - - fun handleNote(event: NodeUsageEvent?): Boolean { - event ?: return false - val item = event.usedItem - val player = event.player - if (item.noteChange != item.id) { - if (item.definition.isUnnoted) { - val amount = player.inventory.getAmount(item.id) - player.inventory.remove(Item(item.id, amount)) - player.inventory.add(Item(item.noteChange, amount)) - } else { - var amount = item.amount - if (amount > player.inventory.freeSlots()) { - amount = player.inventory.freeSlots() - } - player.inventory.remove(Item(item.id, amount)) - player.inventory.add(Item(item.noteChange, amount)) - } - return true - } else { - player.sendMessage("This item can't be noted.") - return true - } - } - - override fun newInstance(arg: Any?): Plugin { - return this - } - - override fun nodeAllowed(nodeId: Int): Boolean { - return true - } -} \ No newline at end of file diff --git a/Server/src/main/kotlin/rs09/game/interaction/object/BankBoothHandler.kt b/Server/src/main/kotlin/rs09/game/interaction/object/BankBoothHandler.kt index 9f1e7819e..cf10f5acb 100644 --- a/Server/src/main/kotlin/rs09/game/interaction/object/BankBoothHandler.kt +++ b/Server/src/main/kotlin/rs09/game/interaction/object/BankBoothHandler.kt @@ -1,11 +1,12 @@ package rs09.game.interaction.`object` -import api.openDialogue +import api.* import core.game.content.dialogue.DialogueInterpreter import core.game.node.Node import core.game.node.entity.npc.NPC import core.game.node.entity.player.Player import core.game.node.entity.player.link.IronmanMode +import core.game.node.item.Item import core.game.world.map.Direction import core.game.world.map.Location import org.rs09.consts.NPCs @@ -127,9 +128,51 @@ class BankBoothHandler : InteractionListener { return true } + private fun attemptToConvertItems(player: Player, used: Node, with: Node): Boolean { + if (!ServerConstants.BANK_BOOTH_NOTE_UIM && player.ironmanManager.checkRestriction(IronmanMode.ULTIMATE)) { + return true + } + + if (BankerNPC.checkLunarIsleRestriction(player, with)) { + tryInvokeBankerDialogue(player, with) + return true + } + + val item = used as Item + + if (item.noteChange != item.id) { + if (item.definition.isUnnoted) { + val amount = amountInInventory(player, item.id) + if (removeItem(player, Item(item.id, amount))) { + addItem(player, item.noteChange, amount) + } + } else { + var amount = item.amount + val freeSlotCount = freeSlots(player) + + if (amount > freeSlotCount) { + amount = freeSlotCount + } + + if (removeItem(player, Item(item.id, amount))) { + addItem(player, item.noteChange, amount) + } + } + + return true + } + + sendMessage(player, "This item can't be noted.") + return true + } + override fun defineListeners() { on(BANK_BOOTHS, SCENERY, "use-quickly", "bank", handler = ::quickBankBoothUse) on(BANK_BOOTHS, SCENERY, "use", handler = ::regularBankBoothUse) on(BANK_BOOTHS, SCENERY, "collect", handler = ::collectBankBoothUse) + + if (ServerConstants.BANK_BOOTH_NOTE_ENABLED) { + onUseAnyWith(SCENERY, *BANK_BOOTHS, handler = ::attemptToConvertItems) + } } } \ No newline at end of file diff --git a/Server/src/main/kotlin/rs09/game/system/config/ServerConfigParser.kt b/Server/src/main/kotlin/rs09/game/system/config/ServerConfigParser.kt index 4bc385a8a..5ab5ba58b 100644 --- a/Server/src/main/kotlin/rs09/game/system/config/ServerConfigParser.kt +++ b/Server/src/main/kotlin/rs09/game/system/config/ServerConfigParser.kt @@ -118,6 +118,8 @@ object ServerConfigParser { ServerConstants.PRELOAD_MAP = data.getBoolean("server.preload_map", false) ServerConstants.REVENANT_POPULATION = data.getLong("world.revenant_population", 30L).toInt() ServerConstants.BANK_BOOTH_QUICK_OPEN = data.getBoolean("world.bank_booth_quick_open", false) + ServerConstants.BANK_BOOTH_NOTE_ENABLED = data.getBoolean("world.bank_booth_note_enabled", true) + ServerConstants.BANK_BOOTH_NOTE_UIM = data.getBoolean("world.bank_booth_note_uim", true) ServerConstants.DISCORD_GE_WEBHOOK = data.getString("server.discord_webhook", "") }