RuneHive-Game
Loading...
Searching...
No Matches
DonatorDeposit.java
Go to the documentation of this file.
1package com.runehive.game.world.items.containers.bank;
2
3import com.runehive.game.world.InterfaceConstants;
4import com.runehive.game.world.entity.mob.player.Player;
5import com.runehive.game.world.entity.mob.player.PlayerRight;
6import com.runehive.game.world.items.Item;
7import com.runehive.game.world.items.containers.ItemContainer;
8import com.runehive.net.packet.out.SendItemOnInterface;
9import com.runehive.net.packet.out.SendMessage;
10import com.runehive.net.packet.out.SendString;
11
12import java.util.Arrays;
13import java.util.Objects;
14
15/**
16 * Handles the donator deposit box.
17 *
18 * @author Daniel
19 */
20public class DonatorDeposit extends ItemContainer {
21
22 private static final int DONATOR_DEPOSIT_BOX_DISPLAY_ID = 57207;
23
24 /** The player instance. */
25 private final Player player;
26
27
28
29 /** * Constructs a new <code>DonatorDeposit</code>. */
31 super(28, ItemContainer.StackPolicy.STANDARD);
32 this.player = player;
33 }
34
35 /** Handles opening the donator deposit box. */
36 public void open() {
38 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();
39 return;
40 }
41 refresh();
42 player.attributes.set("DONATOR_DEPOSIT_KEY", Boolean.TRUE);
43 player.interfaceManager.openInventory(57200, 5063);
44 }
45
46 /** Handles closing the donator deposit box. */
47 public void close() {
48 for (Item item : getItems()) {
49 if (item == null)
50 continue;
51 if (remove(item))
52 player.inventory.add(item);
53 }
54 clear(false);
55 refresh();
56 player.attributes.set("DONATOR_DEPOSIT_KEY", Boolean.FALSE);
57 }
58
59 /** Handles confirming the deposit. */
60 public void confirm() {
61 if (!player.interfaceManager.isInterfaceOpen(57200)) {
62 return;
63 }
64 if (isEmpty()) {
65 player.send(new SendMessage("There are no items to deposit!"));
66 return;
67 }
68 if (player.bank.getFreeSlots() < this.size()) {
69 player.message("You do not have enough space in your bank to deposit these items.");
70 return;
71 }
72
73 player.send(new SendMessage("You have deposited " + this.size() + " items into your bank."));
74
75 Arrays.stream(this.getItems()).filter(Objects::nonNull).forEach(item -> {
76 if(player.bank.depositFromNothing(item, 0) > 0) {
77 remove(item, -1, false);
78 }
79 });
80
81 clear(false);
82 refresh();
83 }
84
85 /** Handles deposting items into the container. */
86 public boolean deposit(int id, int slot, int amount) {
87 if (!player.interfaceManager.isInterfaceOpen(57200)) {
88 return false;
89 }
90
91 Item item = player.inventory.get(slot);
92
93 if (item == null || item.getId() != id) {
94 return false;
95 }
96 int contain = player.inventory.computeAmountForId(id);
97
98 if (contain < amount) {
99 amount = contain;
100 }
101
102 int allowedSize = PlayerRight.getDepositAmount(player);
103 if (size() >= allowedSize) {
104 player.dialogueFactory.sendStatement("You can only deposit up to " + allowedSize + " items.", "The higher your donator rank the more spaces unlocked!").execute();
105 return false;
106 }
107
108 if(!add(item.getId(), amount)) {
109 return false;
110 }
111
112 Item current = new Item(item.getId(), amount);
113
114 if (item.isStackable() || amount == 1) {
115 player.inventory.remove(current, slot, false);
116 } else {
117 player.inventory.remove(current, -1, false);
118 }
119
120 refresh();
121
122 return true;
123 }
124
125 /** Handles withdrawing items from the container. */
126 public boolean withdraw(int id, int slot, int amount) {
127 if (!player.interfaceManager.isInterfaceOpen(57200)) {
128 return false;
129 }
130
131 Item item = get(slot);
132
133 if (item == null || item.getId() != id) {
134 return false;
135 }
136
137 int contain = computeAmountForId(id);
138
139 if (contain < amount) {
140 amount = contain;
141 }
142
143 Item current = new Item(id, amount);
144
145 if(!player.inventory.add(current)) {
146 return false;
147 }
148
149 if (item.isStackable() || amount == 1) {
150 remove(current, slot, false);
151 } else {
152 remove(current, slot, false);
153 }
154
155 shift();
156 refresh();
157
158 return true;
159 }
160
164
165 @Override
166 public void onRefresh() {
167 player.inventory.refresh();
168 player.send(new SendString(this.size() + "/" + this.capacity(), 57206));
169 player.send(new SendItemOnInterface(InterfaceConstants.INVENTORY_STORE, player.inventory.toArray()));
170 }
171}
The class that contains helpful information on interfaces.
This class represents a character controlled by a player.
Definition Player.java:125
The container class that represents an item that can be interacted with.
Definition Item.java:21
final int getId()
Gets the identification of this item.
Definition Item.java:324
ItemContainer(int capacity, StackPolicy policy, Item[] items)
Creates a new ItemContainer.
final int computeAmountForId(int id)
Computes the total quantity of the Items in this container with id.
boolean add(Item item)
Attempts to deposit item into this container.
final int capacity
The capacity of this container.
void shift()
Percolates the null indices to the end of the stack.
void clear()
Removes all of the items from this container.
boolean withdraw(int id, int slot, int amount)
Handles withdrawing items from the container.
void onRefresh()
Any functionality that should occur when refreshed.
void close()
Handles closing the donator deposit box.
void open()
Handles opening the donator deposit box.
boolean deposit(int id, int slot, int amount)
Handles deposting items into the container.
The OutgoingPacket that sends a message to a Players chatbox in the client.
The OutgoingPacket that sends a string to a Players itemcontainer in the client.
static boolean isDonator(Player player)
Checks if the player has donator status.
static int getDepositAmount(Player player)
Gets the deposit amount.