1package com.osroyale.game.world.items.containers.bank;
3import com.osroyale.game.world.InterfaceConstants;
4import com.osroyale.game.world.entity.mob.player.Player;
5import com.osroyale.game.world.entity.mob.player.PlayerRight;
6import com.osroyale.game.world.items.Item;
7import com.osroyale.game.world.items.ItemDefinition;
8import com.osroyale.game.world.items.containers.ItemContainer;
9import com.osroyale.game.world.items.containers.ItemContainerAdapter;
10import com.osroyale.game.world.items.containers.pricechecker.PriceType;
11import com.osroyale.net.packet.out.*;
12import com.osroyale.util.Utility;
13import plugin.itemon.item.LootingBagPlugin;
15import java.util.Arrays;
16import java.util.Optional;
64 public static final int SIZE = 360;
70 private final Player player;
88 this.placeHolder =
false;
94 if (player.right.equals(
PlayerRight.ULTIMATE_IRONMAN)) {
95 player.send(
new SendMessage(
"As an ultimate iron man you may not use banks!"));
98 if (player.bankPin.hasPin() && !player.bankPin.entered) {
99 player.bankPin.enter();
104 player.attributes.set(
"BANK_KEY", Boolean.TRUE);
114 player.send(
new SendTooltip((
noting ?
"Disable" :
"Enable") +
" noting", 60007));
119 player.inventory.refresh();
124 public void sendValue() {
126 int start = slotForTab(
bankTab);
132 for (
int slot = start; slot < end; slot++) {
133 Item item =
get(slot);
134 if (item ==
null)
continue;
136 if (value >= Long.MAX_VALUE - price * item.getAmount()) {
137 value = Long.MAX_VALUE;
139 value += price * item.getAmount();
146 player.attributes.set(
"BANK_KEY", Boolean.FALSE);
148 if (player.pvpInstance) {
149 player.playerAssistant.setValueIcon();
158 withdraw(item, slot, Integer.MAX_VALUE);
166 boolean withinBank = player.interfaceManager.isInterfaceOpen(60000) || player.interfaceManager.isInterfaceOpen(4465);
168 System.out.println(
"interface: " + player.interfaceManager.getMain());
172 Item item = player.inventory.get(slot);
176 int id = item.getId();
178 if (LootingBagPlugin.isLootingBag(item) && !player.lootingBag.isEmpty()) {
179 player.interfaceManager.openInventory(60000, 26700);
183 int invAmount = player.inventory.computeAmountForId(
id);
185 if (invAmount < amount) {
192 id = item.getUnnotedId();
196 player.message(
"Your bank is full! You need to clear some items from your bank.");
205 swap(
true, from, to,
false);
208 if (Integer.MAX_VALUE - fucking.getAmount() < amount) {
209 amount = Integer.MAX_VALUE - fucking.getAmount();
210 player.send(
new SendMessage(
"Your bank didn't have enough space to deposit all that!"));
212 fucking.incrementAmountBy(amount);
216 if(item.getId() == 12791) player.runePouch.clearInterface();
217 player.inventory.remove(item.getId(), amount);
225 public void withdraw(
int itemId,
int slot,
int amount) {
226 if (!player.interfaceManager.isInterfaceOpen(60000)) {
230 if (itemId < 0)
return;
232 Item item =
get(slot);
233 if (item ==
null || itemId != item.getId())
236 if (item.getAmount() == 0) {
240 int tab = tabForSlot(tabSlot);
249 if (item.getAmount() < amount) {
250 amount = item.getAmount();
253 int id = item.getId();
255 if (!item.isNoteable()) {
256 player.send(
new SendMessage(
"This item cannot be withdrawn as a note."));
258 id = item.getNotedId();
263 if (!
new Item(
id).isStackable() && amount > player.inventory.getFreeSlots()) {
264 amount = player.inventory.getFreeSlots();
265 }
else if (
ItemDefinition.
get(
id).isStackable() && player.inventory.getFreeSlots() == 0) {
266 if (!player.inventory.contains(
id)) {
268 }
else if (player.inventory.computeAmountForId(
id) + amount > Integer.MAX_VALUE) {
269 amount = Integer.MAX_VALUE - player.inventory.computeAmountForId(
id);
274 player.send(
new SendMessage(
"You do not have enough inventory spaces to withdraw this item."));
278 int fuckingSlot = player.inventory.computeIndexForId(
id);
279 if (fuckingSlot != -1) {
280 Item fuckingStan = player.inventory.get(fuckingSlot);
281 if (Integer.MAX_VALUE - fuckingStan.getAmount() < amount) {
282 amount = Integer.MAX_VALUE - fuckingStan.getAmount();
283 player.send(
new SendMessage(
"Your inventory didn't have enough space to withdraw all that!"));
288 if (
remove(item.getId(), amount)) {
289 player.inventory.add(
id, amount);
290 if(
id == 12791) player.runePouch.refresh();
293 int tab = tabForSlot(slot);
307 public void collapse(
int tab,
boolean collapseAll) {
308 if (!player.interfaceManager.isInterfaceOpen(60000)) {
311 if (tab == 0 && collapseAll) {
320 if (tabAmount > 0) moveTab(tab, 0);
323 recursiveCollapse(tab);
327 private void recursiveCollapse(
int tab) {
329 moveTab(tab + 1, tab);
330 recursiveCollapse(tab + 1);
333 private void moveTab(
int tab,
int toTab) {
335 int fromSlot = slotForTab(tab);
336 int toSlot = slotForTab(toTab) + 1;
341 for (
int i = 0; i < tabAmount; i++) {
342 swap(
true, fromSlot, toSlot,
false);
364 public int depositFromNothing(Item item,
int tab) {
367 int id = item.getUnnotedId();
373 add(
id, item.getAmount());
376 int to = slotForTab(tab);
377 swap(
true, from, to,
false);
380 if (Integer.MAX_VALUE - fucking.getAmount() < item.getAmount()) {
381 item.setAmount(Integer.MAX_VALUE - fucking.getAmount());
383 fucking.incrementAmountBy(item.getAmount());
386 return item.getAmount();
392 while (tab > 0 &&
tabAmounts[tab - 1] <= 0) tab--;
393 Item[] items = player.inventory.getItems();
394 for (
int index = 0; index < items.length; index++) {
395 if (items[index] ==
null)
continue;
396 Item item = items[index].copy();
397 item.setAmount(depositFromNothing(item, tab));
398 if(item.getId() == 12791) player.runePouch.clearInterface();
399 if (item.getAmount() > 0)
400 player.inventory.remove(item, index,
false);
403 player.send(
new SendMessage(
"You deposited all your inventory items."));
411 while (tab > 0 &&
tabAmounts[tab - 1] <= 0) tab--;
412 Item[] items = player.equipment.getItems();
413 for (
int index = 0; index < items.length; index++) {
414 if (items[index] ==
null)
continue;
415 Item item = items[index].copy();
416 item.setAmount(depositFromNothing(item, tab));
417 if (item.getAmount() > 0)
418 player.equipment.remove(item, index,
false);
421 player.send(
new SendMessage(
"You deposited all your worn equipment."));
423 player.equipment.login();
427 private void itemToTab(
int slot,
int toTab) {
428 int fromTab = tabForSlot(slot);
431 if (fromTab == toTab)
return;
443 int toSlot = slotForTab(toTab);
449 swap(
true, slot, toSlot,
false);
466 public void moveItem(
int opcode,
int from,
int to) {
469 }
else if (opcode == 1) {
470 swap(
true, from, to,
false);
471 int fromTab = tabForSlot(from);
472 int toTab = tabForSlot(to);
473 if (fromTab != toTab) {
483 public int tabForSlot(
int slot) {
487 for (
int tab = 0; tab <
tabAmounts.length; tab++) {
495 private int slotForTab(
int tab) {
497 for (
int index = tab; index >= 0; index--) {
513 amounts = Arrays.copyOf(amounts, amounts.length);
514 System.arraycopy(amounts, 0,
tabAmounts, 0, amounts.length);
535 return "Your bank is currently full!";
539 public void itemUpdated(
ItemContainer container, Optional<Item> oldItem, Optional<Item> newItem,
int index,
boolean refresh,
boolean login) {
static ItemDefinition get(int id)
abstract String getCapacityExceededMsg()
abstract int getWidgetId()
ItemContainer(int capacity, StackPolicy policy, Item[] items)
void setFiringEvents(boolean firingEvents)
final void swap(int oldIndex, int newIndex)
final boolean addListener(ItemContainerListener listener)
final int computeIndexForId(int id)
void depositeEquipment(boolean message)
void depositeInventory(boolean message)
void placeHolder(int item, int slot)
void withdraw(int itemId, int slot, int amount)
void changeTabAmount(int tab, int amount)
void collapse(int tab, boolean collapseAll)
void deposit(int slot, int amount)
void moveItem(int opcode, int from, int to)
static String formatPrice(final long amount)