RuneHive-Tarnish
Neural OSRS Enhancement Framework
Loading...
Searching...
No Matches
DonatorDeposit.java
1package com.osroyale.game.world.items.containers.bank;
2
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.containers.ItemContainer;
8import com.osroyale.net.packet.out.SendItemOnInterface;
9import com.osroyale.net.packet.out.SendMessage;
10import com.osroyale.net.packet.out.SendString;
11
12import java.util.Arrays;
13import java.util.Objects;
14
56
57public class DonatorDeposit extends ItemContainer {
58
59 private static final int DONATOR_DEPOSIT_BOX_DISPLAY_ID = 57207;
60
62 private final Player player;
63
64
65
67 public DonatorDeposit(Player player) {
68 super(28, ItemContainer.StackPolicy.STANDARD);
69 this.player = player;
70 }
71
73 public void open() {
74 if (!PlayerRight.isDonator(player)) {
75 player.dialogueFactory.sendStatement("You need to be a donator to use this feature!", "The donator deposit allows donators to deposit a certain amount", "of items into their banks every 2 minutes.").execute();
76 return;
77 }
78 refresh();
79 player.attributes.set("DONATOR_DEPOSIT_KEY", Boolean.TRUE);
80 player.interfaceManager.openInventory(57200, 5063);
81 }
82
84 public void close() {
85 for (Item item : getItems()) {
86 if (item == null)
87 continue;
88 if (remove(item))
89 player.inventory.add(item);
90 }
91 clear(false);
92 refresh();
93 player.attributes.set("DONATOR_DEPOSIT_KEY", Boolean.FALSE);
94 }
95
97 public void confirm() {
98 if (!player.interfaceManager.isInterfaceOpen(57200)) {
99 return;
100 }
101 if (isEmpty()) {
102 player.send(new SendMessage("There are no items to deposit!"));
103 return;
104 }
105 if (player.bank.getFreeSlots() < this.size()) {
106 player.message("You do not have enough space in your bank to deposit these items.");
107 return;
108 }
109
110 player.send(new SendMessage("You have deposited " + this.size() + " items into your bank."));
111
112 Arrays.stream(this.getItems()).filter(Objects::nonNull).forEach(item -> {
113 if(player.bank.depositFromNothing(item, 0) > 0) {
114 remove(item, -1, false);
115 }
116 });
117
118 clear(false);
119 refresh();
120 }
121
123 public boolean deposit(int id, int slot, int amount) {
124 if (!player.interfaceManager.isInterfaceOpen(57200)) {
125 return false;
126 }
127
128 Item item = player.inventory.get(slot);
129
130 if (item == null || item.getId() != id) {
131 return false;
132 }
133 int contain = player.inventory.computeAmountForId(id);
134
135 if (contain < amount) {
136 amount = contain;
137 }
138
139 int allowedSize = PlayerRight.getDepositAmount(player);
140 if (size() >= allowedSize) {
141 player.dialogueFactory.sendStatement("You can only deposit up to " + allowedSize + " items.", "The higher your donator rank the more spaces unlocked!").execute();
142 return false;
143 }
144
145 if(!add(item.getId(), amount)) {
146 return false;
147 }
148
149 Item current = new Item(item.getId(), amount);
150
151 if (item.isStackable() || amount == 1) {
152 player.inventory.remove(current, slot, false);
153 } else {
154 player.inventory.remove(current, -1, false);
155 }
156
157 refresh();
158
159 return true;
160 }
161
163 public boolean withdraw(int id, int slot, int amount) {
164 if (!player.interfaceManager.isInterfaceOpen(57200)) {
165 return false;
166 }
167
168 Item item = get(slot);
169
170 if (item == null || item.getId() != id) {
171 return false;
172 }
173
174 int contain = computeAmountForId(id);
175
176 if (contain < amount) {
177 amount = contain;
178 }
179
180 Item current = new Item(id, amount);
181
182 if(!player.inventory.add(current)) {
183 return false;
184 }
185
186 if (item.isStackable() || amount == 1) {
187 remove(current, slot, false);
188 } else {
189 remove(current, slot, false);
190 }
191
192 shift();
193 refresh();
194
195 return true;
196 }
197
198 private void refresh() {
199 refresh(player, DONATOR_DEPOSIT_BOX_DISPLAY_ID);
200 }
201
202 @Override
203 public void onRefresh() {
204 player.inventory.refresh();
205 player.send(new SendString(this.size() + "/" + this.capacity(), 57206));
206 player.send(new SendItemOnInterface(InterfaceConstants.INVENTORY_STORE, player.inventory.toArray()));
207 }
208}
ItemContainer(int capacity, StackPolicy policy, Item[] items)