diff --git a/Server/src/main/content/global/ame/events/drilldemon/DrillDemonUtils.kt b/Server/src/main/content/global/ame/events/drilldemon/DrillDemonUtils.kt index 8c90bd77f..287406ad5 100644 --- a/Server/src/main/content/global/ame/events/drilldemon/DrillDemonUtils.kt +++ b/Server/src/main/content/global/ame/events/drilldemon/DrillDemonUtils.kt @@ -73,9 +73,9 @@ object DrillDemonUtils { fun reward(player: Player) { queueScript(player, 2, QueueStrength.SOFT) { - val hasHat = hasAnItem(player, Items.CAMO_HELMET_6656).container != null - val hasShirt = hasAnItem(player, Items.CAMO_TOP_6654).container != null - val hasPants = hasAnItem(player, Items.CAMO_BOTTOMS_6655).container != null + val hasHat = hasAnItem(player, Items.CAMO_HELMET_6656, checkPOH = true).exists() + val hasShirt = hasAnItem(player, Items.CAMO_TOP_6654, checkPOH = true).exists() + val hasPants = hasAnItem(player, Items.CAMO_BOTTOMS_6655, checkPOH = true).exists() when { !hasHat -> addItemOrDrop(player, Items.CAMO_HELMET_6656) !hasShirt -> addItemOrDrop(player, Items.CAMO_TOP_6654) diff --git a/Server/src/main/content/global/ame/events/freakyforester/FreakUtils.kt b/Server/src/main/content/global/ame/events/freakyforester/FreakUtils.kt index 84e491f89..b6fbd647d 100644 --- a/Server/src/main/content/global/ame/events/freakyforester/FreakUtils.kt +++ b/Server/src/main/content/global/ame/events/freakyforester/FreakUtils.kt @@ -35,9 +35,9 @@ object FreakUtils{ } fun reward(player: Player){ - val hasHat = hasAnItem(player, Items.LEDERHOSEN_HAT_6182).container != null - val hasTop = hasAnItem(player, Items.LEDERHOSEN_TOP_6180).container != null - val hasShort = hasAnItem(player, Items.LEDERHOSEN_SHORTS_6181).container != null + val hasHat = hasAnItem(player, Items.LEDERHOSEN_HAT_6182, checkPOH = true).exists() + val hasTop = hasAnItem(player, Items.LEDERHOSEN_TOP_6180, checkPOH = true).exists() + val hasShort = hasAnItem(player, Items.LEDERHOSEN_SHORTS_6181, checkPOH = true).exists() sendNPCDialogue(player, freakNpc, "You get a lederhosen item as a reward for your help, many thanks!") when{ (!hasHat) -> addItemOrDrop(player, Items.LEDERHOSEN_HAT_6182, 1) diff --git a/Server/src/main/core/api/ContentAPI.kt b/Server/src/main/core/api/ContentAPI.kt index 7423518a7..ad27dedc3 100644 --- a/Server/src/main/core/api/ContentAPI.kt +++ b/Server/src/main/core/api/ContentAPI.kt @@ -266,36 +266,39 @@ class ContainerisedItem(val container: core.game.container.Container?, val itemI } /** - * Check if player has the specified item ID equipped, in inventory, or in their bank + * Check if player has the specified item ID equipped, in inventory, in their active bank, or in their POH storage. * @param id The item ID to check + * @param checkInactiveBank Whether to check the player's inactive bank (default false). + * @param checkPOH Whether to check a player's POH storage (default false). * @return A ContainerisedItem containing the container and the item ID if found, otherwise ContainerisedItem(null, -1) if not found */ -fun hasAnItem(player: Player, id: Int): ContainerisedItem { - return hasAnItem(player, arrayOf(id), false) +@JvmOverloads +fun hasAnItem(player: Player, id: Int, checkInactiveBank: Boolean = false, checkPOH: Boolean = false): ContainerisedItem { + return hasAnItem(player, arrayOf(id), checkInactiveBank, checkPOH) } /** - * Check if player has the specified item ID equipped, in inventory, or in their bank - * @param id The item ID to check - * @param checkSecondBank Whether to check the player's second bank. - * @return A ContainerisedItem containing the container and the item ID if found, otherwise ContainerisedItem(null, -1) if not found - */ -fun hasAnItem(player: Player, id: Int, checkSecondBank: Boolean): ContainerisedItem { - return hasAnItem(player, arrayOf(id), checkSecondBank) -} - -/** - * Check if player has any of the specified item IDs equipped, in inventory, or in their bank + * Check if player has any of the specified item IDs equipped, in inventory, in their active bank, or in their POH storage. * @param ids An array of item IDs to check - * @param checkSecondBank Whether to check the player's second bank. + * @param checkInactiveBank Whether to check the player's inactive bank (default false). + * @param checkPOH Whether to check a player's POH storage (default false). * @return A ContainerisedItem containing the container and the item ID if found, otherwise ContainerisedItem(null, -1) if not found */ -fun hasAnItem(player: Player, ids: Array, checkSecondBank: Boolean): ContainerisedItem { - // Search bank/equip/inv and return if item is found there. - val searchSpace = if (checkSecondBank) { - arrayOf(player.inventory, player.equipment, player.bankPrimary, player.bankSecondary) +fun hasAnItem(player: Player, ids: Array, checkInactiveBank: Boolean = false, checkPOH: Boolean = false): ContainerisedItem { + // Gets which bank account is active. + val (active, inactive) = if (isUsingSecondaryBankAccount(player)) { + // Active // Inactive + player.bankSecondary to player.bankPrimary } else { - arrayOf(player.inventory, player.equipment, player.bankPrimary) + // Active // Inactive + player.bankPrimary to player.bankSecondary + } + + // Search bank/equip/inv and return if item is found there. + val searchSpace = if (checkInactiveBank) { + arrayOf(player.inventory, player.equipment, active, inactive) + } else { + arrayOf(player.inventory, player.equipment, active) } for (container in searchSpace) { for (id in ids) { @@ -305,15 +308,17 @@ fun hasAnItem(player: Player, ids: Array, checkSecondBank: Boolean): Contai } } - // Check all costume storage containers and return if item is found there. - for (id in ids) { - if (StorableFamily.values().any { family -> - player.getPOHStorageState() - .getContainer(family) - .contains(id) - }) { - // Note that this proxy container is a fake container just used to get the correct return type. - return ContainerisedItem(player.POHStorageProxyContainer, id) + // Check all costume storage and bookcase containers and return if item is found there. + if (checkPOH) { + for (id in ids) { + if (StorableFamily.values().any { family -> + player.getPOHStorageState() + .getContainer(family) + .contains(id) + }) { + // Note that this proxy container is a fake container just used to get the correct return type. + return ContainerisedItem(player.POHStorageProxyContainer, id) + } } } @@ -2809,7 +2814,7 @@ fun toggleBankAccount(player: Player) { } /** - * Checks if a player is currentl using their secondary bank account. + * Checks if a player is currently using their secondary bank account. * * @author vddCore * @param player The player whose bank account toggle state to inspect.