RuneHive-Tarnish
Neural OSRS Enhancement Framework
Loading...
Searching...
No Matches
LootingBag.java
1package com.osroyale.game.world.items.containers.impl;
2
3import com.osroyale.Config;
4import com.osroyale.game.world.InterfaceConstants;
5import com.osroyale.game.world.entity.mob.player.Player;
6import com.osroyale.game.world.items.Item;
7import com.osroyale.game.world.items.containers.ItemContainer;
8import com.osroyale.game.world.items.containers.ItemContainerAdapter;
9import com.osroyale.game.world.items.containers.pricechecker.PriceType;
10import com.osroyale.game.world.position.Area;
11import com.osroyale.net.packet.out.*;
12import com.osroyale.util.Utility;
13import plugin.itemon.item.LootingBagPlugin;
14
56
57public class LootingBag extends ItemContainer {
58
62 private final Player player;
63
67 public LootingBag(Player player) {
68 super(28, StackPolicy.STANDARD);
69 this.addListener(new LootingBagListener(player));
70 this.player = player;
71 }
72
73 public void open() {
74 onRefresh();
75 player.interfaceManager.setSidebar(Config.INVENTORY_TAB, 26700);
76 player.send(new SendForceTab(Config.INVENTORY_TAB));
77 }
78
82 public void close() {
83 if (player.attributes.get("BANK_KEY", Boolean.class)) {
84 player.interfaceManager.openInventory(60000, InterfaceConstants.INVENTORY_STORE - 1);
85 return;
86 }
87 player.interfaceManager.setSidebar(Config.INVENTORY_TAB, 3213);
88 }
89
93 private boolean allowed(Item item) {
94 if (!Area.inWilderness(player)) {
95 player.send(new SendMessage("You can't put items in the bag unless you're in the Wilderness."));
96 return false;
97 }
98 if (!item.isTradeable()) {
99 player.send(new SendMessage("You can't deposit un-tradeable items into the looting bag."));
100 return false;
101 }
102 if (!player.inventory.contains(item)) {
103 player.send(new SendMessage("You can not deposit an item that you do not have!"));
104 return false;
105 }
106 return true;
107 }
108
109 public Item[] getDeathItems() {
110 if (!player.inventory.contains(LootingBagPlugin.OPENED_ID) && !player.inventory.contains(LootingBagPlugin.CLOSED_ID)) {
111 return null;
112 }
113 return toNonNullArray();
114 }
115
119 public void depositMenu(Item item) {
120 player.dialogueFactory.sendOption(
121 "Deposit 1", () -> deposit(item, 1),
122 "Deposit 5", () -> deposit(item, 5),
123 "Deposit All", () -> deposit(item, item.getAmount()),
124 "Deposit X", () ->
125 player.dialogueFactory.onAction(() -> player.send(new SendInputMessage("Enter the amount you would like to deposit into the looting bag:", 12, input -> {
126 player.dialogueFactory.clear();
127 deposit(item, Integer.parseInt(input));
128 })))).execute();
129 }
130
134 public boolean deposit(Item item, int amount) {
135 if (!allowed(item)) {
136 return false;
137 }
138 int contain = player.inventory.computeAmountForId(item.getId());
139 if (contain < amount) {
140 amount = contain;
141 }
142 Item current = new Item(item.getId(), amount);
143 if (!add(current)) {
144 return false;
145 }
146 player.inventory.remove(current);
147 player.send(new SendMessage("You have deposited " + amount + " " + current.getName() + " into the looting bag."));
148 onRefresh();
149 return true;
150 }
151
155 public void withdrawBank(Item item, int slot) {
156 int amount = computeAmountForId(item.getId());
157 if (item.getAmount() > amount) {
158 item = item.createWithAmount(amount);
159 }
160 int removed = 0;
161 if (item.isStackable()) {
162 removed = player.bank.depositFromNothing(item, player.bank.bankTab);
163 } else {
164 while (removed < item.getAmount()) {
165 int deposited = player.bank.depositFromNothing(item, player.bank.bankTab);
166 if (deposited == 0) {
167 break;
168 }
169 removed += deposited;
170 }
171 }
172 if (removed > 0) {
173 remove(item.createWithAmount(removed), slot, false);
174 }
175 player.bank.refresh();
176 onRefresh();
177 }
178
179 @Override
180 public void onRefresh() {
181 player.send(new SendItemOnInterface(26706, toArray()));
182 player.send(new SendString("Value: " + Utility.formatDigits(containerValue(PriceType.VALUE)) + " coins", 26707));
183 }
184
188 private static final class LootingBagListener extends ItemContainerAdapter {
189
190 LootingBagListener(Player player) {
191 super(player);
192 }
193
194 @Override
195 public int getWidgetId() {
196 return 26706;
197 }
198
199 @Override
200 public String getCapacityExceededMsg() {
201 return "You do not have enough space in your looting bag.";
202 }
203 }
204}
ItemContainer(int capacity, StackPolicy policy, Item[] items)
final boolean addListener(ItemContainerListener listener)
static String formatDigits(final int amount)
Definition Utility.java:78