From 7a42de63dcb66449d78eca5527109849d7712c4b Mon Sep 17 00:00:00 2001 From: bushtail Date: Sat, 18 Feb 2023 02:36:12 +0000 Subject: [PATCH] Players can now cut down jungle bushes while wielding a machete Added inEquipmentOrInventory function to content API --- .../region/karamja/handlers/JungleBushHandler.kt | 6 ++++-- Server/src/main/core/api/ContentAPI.kt | 11 +++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/Server/src/main/content/region/karamja/handlers/JungleBushHandler.kt b/Server/src/main/content/region/karamja/handlers/JungleBushHandler.kt index f5da3dc61..8e4462110 100644 --- a/Server/src/main/content/region/karamja/handlers/JungleBushHandler.kt +++ b/Server/src/main/content/region/karamja/handlers/JungleBushHandler.kt @@ -1,5 +1,7 @@ package content.region.karamja.handlers +import core.api.inEquipmentOrInventory +import core.api.inInventory import core.game.node.scenery.Scenery import core.game.node.scenery.SceneryBuilder import core.game.node.entity.player.Player @@ -47,11 +49,11 @@ class JungleBushHandler : InteractionListener { } - fun checkRequirement(player: Player): Boolean{ + private fun checkRequirement(player: Player): Boolean{ val machete = Item(Items.MACHETE_975) val jade_machete = Item(Items.JADE_MACHETE_6315) val opal_machete = Item(Items.OPAL_MACHETE_6313) val red_topaz_machete = Item(Items.RED_TOPAZ_MACHETE_6317) - return player.inventory.containsItem(machete) || player.inventory.containsItem(jade_machete) || player.inventory.containsItem(opal_machete) || player.inventory.containsItem(red_topaz_machete) + return inEquipmentOrInventory(player, machete.id) || inEquipmentOrInventory(player, jade_machete.id) || inEquipmentOrInventory(player, opal_machete.id) || inEquipmentOrInventory(player, red_topaz_machete.id) } } diff --git a/Server/src/main/core/api/ContentAPI.kt b/Server/src/main/core/api/ContentAPI.kt index d9242a991..51dcf255d 100644 --- a/Server/src/main/core/api/ContentAPI.kt +++ b/Server/src/main/core/api/ContentAPI.kt @@ -330,6 +330,17 @@ fun inEquipment(player: Player, item: Int, amount: Int = 1): Boolean { return player.equipment.contains(item, amount) } +/** + * Check if an item exists in a player's equipment or inventory + * @param player the player whose equipment to check + * @param item the ID of the item to check for + * @param amount the amount to check for, defaults to 1 + * @return true if the item exists in the given amount in the player's equipment or inventory + */ +fun inEquipmentOrInventory(player: Player, item: Int, amount: Int = 1): Boolean { + return inInventory(player, item, amount) || inEquipment(player, item, amount) +} + /** * Get number of free slots in a player's inventory * @param player the player to check