From d38f7d428210786cbcb31575c3b57147c05b7e31 Mon Sep 17 00:00:00 2001 From: Ceikry Date: Mon, 27 Jun 2022 12:58:13 +0000 Subject: [PATCH] ContentAPI methods now all take 2nd bank into account --- Server/src/main/kotlin/api/ContentAPI.kt | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/Server/src/main/kotlin/api/ContentAPI.kt b/Server/src/main/kotlin/api/ContentAPI.kt index a6ae31eac..cfb5e08f4 100644 --- a/Server/src/main/kotlin/api/ContentAPI.kt +++ b/Server/src/main/kotlin/api/ContentAPI.kt @@ -112,8 +112,8 @@ fun amountInInventory(player: Player, id: Int): Int { * @param id the ID of the item to check for * @return the amount of the ID in the player's bank. */ -fun amountInBank(player: Player, id: Int): Int { - return player.bank.getAmount(id) +fun amountInBank(player: Player, id: Int, includeSecondary: Boolean = true): Int { + return player.bank.getAmount(id) + if (includeSecondary) player.bankSecondary.getAmount(id) else 0 } /** @@ -177,7 +177,7 @@ fun removeItem(player: Player, item: T, container: Container = Container.INV return when (container) { Container.INVENTORY -> player.inventory.remove(it) - Container.BANK -> player.bank.remove(it) + Container.BANK -> player.bank.remove(it) || player.bankSecondary.remove(it) Container.EQUIPMENT -> player.equipment.remove(it) } } @@ -256,7 +256,7 @@ fun poofClear(npc: NPC) { * @return true if the item exists in the given amount in the player's bank */ fun inBank(player: Player, item: Int, amount: Int = 1): Boolean { - return player.bank.contains(item, amount) + return player.bank.contains(item, amount) || player.bankSecondary.contains(item, amount) } /** @@ -1048,7 +1048,11 @@ fun removeAll(player: Player, item: T, container: Container) { when (container) { Container.EQUIPMENT -> player.equipment.remove(Item(it, amountInEquipment(player, it))) - Container.BANK -> player.bank.remove(Item(it, amountInBank(player, it))) + Container.BANK -> { + val amountInPrimary = amountInBank(player, it, false) + val amountInSecondary = amountInBank(player, it, true) - amountInPrimary + player.bank.remove(Item(it, amountInPrimary)) && player.bankSecondary.remove(Item(it, amountInSecondary)) + } Container.INVENTORY -> player.inventory.remove(Item(it, amountInInventory(player, it))) } }