ContentAPI methods now all take 2nd bank into account

This commit is contained in:
Ceikry
2022-06-27 12:58:13 +00:00
committed by Ryan
parent cee4f7b072
commit d38f7d4282
+9 -5
View File
@@ -112,8 +112,8 @@ fun amountInInventory(player: Player, id: Int): Int {
* @param id the ID of the item to check for * @param id the ID of the item to check for
* @return the amount of the ID in the player's bank. * @return the amount of the ID in the player's bank.
*/ */
fun amountInBank(player: Player, id: Int): Int { fun amountInBank(player: Player, id: Int, includeSecondary: Boolean = true): Int {
return player.bank.getAmount(id) return player.bank.getAmount(id) + if (includeSecondary) player.bankSecondary.getAmount(id) else 0
} }
/** /**
@@ -177,7 +177,7 @@ fun <T> removeItem(player: Player, item: T, container: Container = Container.INV
return when (container) { return when (container) {
Container.INVENTORY -> player.inventory.remove(it) 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) 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 * @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 { 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 <T> removeAll(player: Player, item: T, container: Container) {
when (container) { when (container) {
Container.EQUIPMENT -> player.equipment.remove(Item(it, amountInEquipment(player, it))) 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))) Container.INVENTORY -> player.inventory.remove(Item(it, amountInInventory(player, it)))
} }
} }