RuneHive-Tarnish
Neural OSRS Enhancement Framework
Loading...
Searching...
No Matches
BankVault.java
1package com.osroyale.game.world.items.containers.bank;
2
3import com.osroyale.game.world.entity.mob.player.Player;
4import com.osroyale.game.world.entity.mob.player.PlayerRight;
5import com.osroyale.game.world.items.Item;
6import com.osroyale.net.packet.out.SendItemOnInterface;
7import com.osroyale.net.packet.out.SendMessage;
8import com.osroyale.net.packet.out.SendString;
9import com.osroyale.util.MessageColor;
10import com.osroyale.util.Utility;
11
12import static com.osroyale.game.world.items.containers.bank.VaultCurrency.BLOOD_MONEY;
13import static com.osroyale.game.world.items.containers.bank.VaultCurrency.COINS;
14
57
58public class BankVault {
59
61 private final Player player;
62
63 public long coinsContainer;
64 public long bloodMoneyContainer;
65
66
68 public BankVault(Player player) {
69 this.player = player;
70 }
71
72 public void open() {
73 long coins = getContainer(COINS);
74 long bloodMoney = getContainer(BLOOD_MONEY);
75 player.send(new SendString(Utility.formatDigits(coins), 56311));
76 player.send(new SendString(Utility.formatDigits(bloodMoney), 56312));
77 player.send(new SendItemOnInterface(56314, new Item(995, coins), new Item(13307, bloodMoney)));
78 player.interfaceManager.open(56300);
79 }
80
81 private long getContainer(VaultCurrency currency) {
82 return currency == COINS ? coinsContainer : bloodMoneyContainer;
83 }
84
86 public void value(VaultCurrency currency) {
87 long container = getContainer(currency);
88 player.send(new SendMessage("You currently have " + Utility.formatDigits(container) + " " + currency.name + " stored inside your bank vault.", MessageColor.DARK_RED));
89 }
90
92 public boolean contains(VaultCurrency currency, int amount) {
93 return getContainer(currency) >= amount;
94 }
95
97 public boolean add(VaultCurrency currency, long amount) {
98 return add(currency, amount, false);
99 }
100
102 public boolean add(VaultCurrency currency, long amount, boolean message) {
103 long container = getContainer(currency);
104
105 if (player.right == PlayerRight.ULTIMATE_IRONMAN) {
106 player.inventory.addOrDrop(new Item(currency.id, (int) amount));
107 return true;
108 }
109
110 if (container + amount >= Long.MAX_VALUE) {
111 return false;
112 }
113
114 if (currency == COINS) {
115 coinsContainer += amount;
116 } else if (currency == BLOOD_MONEY) {
117 bloodMoneyContainer += amount;
118 }
119
120 if (message) {
121 player.send(new SendMessage(Utility.formatDigits(amount) + " " + currency.name + " have been added into your bank vault.", MessageColor.DARK_BLUE));
122 }
123 return true;
124 }
125
127 public void remove(VaultCurrency currency, int amount) {
128 if (currency == COINS) {
129 coinsContainer -= amount;
130 } else if (currency == BLOOD_MONEY) {
131 bloodMoneyContainer -= amount;
132 }
133 }
134
136 public void deposit(VaultCurrency currency, int amount) {
137 long container = getContainer(currency);
138
139 if (Long.MAX_VALUE == container) {
140 player.send(new SendMessage("Your vault is currently full and can no longer hold any more " + currency.name + "!", MessageColor.RED));
141 return;
142 }
143
144 if (Long.MAX_VALUE - container < amount) {
145 amount = (int) (Long.MAX_VALUE - container);
146 }
147
148 int invAmount = player.inventory.computeAmountForId(currency.id);
149 int bankAmount = 0;
150
151 if (invAmount < amount) {
152 bankAmount = player.bank.computeAmountForId(currency.id);
153 if (invAmount + bankAmount <= 0) {
154 player.send(new SendMessage("You don't have any " + currency.name + " you noob!", MessageColor.RED));
155 return;
156 }
157 }
158
159 if (invAmount > amount) {
160 invAmount = amount;
161 }
162
163 if (bankAmount > amount - invAmount) {
164 bankAmount = amount - invAmount;
165 }
166
167 amount = invAmount + bankAmount;
168
169 if (invAmount > 0)
170 player.inventory.remove(currency.id, invAmount);
171 if (bankAmount > 0)
172 player.bank.remove(currency.id, bankAmount);
173
174 add(currency, amount);
175 player.bank.refresh();
176 player.send(new SendMessage("You now have " + Utility.formatDigits(container) + " " + currency.name + " stored inside your bank vault.", MessageColor.DARK_RED));
177
178 if (player.interfaceManager.isInterfaceOpen(56300)) {
179 long coins = getContainer(COINS);
180 long bloodMoney = getContainer(BLOOD_MONEY);
181 player.send(new SendString(Utility.formatDigits(coins), 56311));
182 player.send(new SendString(Utility.formatDigits(bloodMoney), 56312));
183 player.send(new SendItemOnInterface(56314, new Item(995, coins), new Item(13307, bloodMoney)));
184 }
185 }
186
188 public void withdraw(VaultCurrency currency, long amount) {
189 long container = getContainer(currency);
190 if (amount < 0) {
191 return;
192 }
193 if (container == 0) {
194 player.send(new SendMessage("Your bank vault is currently empty.", MessageColor.RED));
195 return;
196 }
197 if (amount > Integer.MAX_VALUE) {
198 player.send(new SendMessage("You can not hold more than " + Utility.formatPrice(Integer.MAX_VALUE) + " " + currency.name + " at a time.", MessageColor.RED));
199 return;
200 }
201 if (amount > container) {
202 amount = container;
203 }
204 int contain = player.inventory.computeAmountForId(currency.id);
205 if (contain + amount > Integer.MAX_VALUE) {
206 amount = contain - amount;
207 }
208 if (player.inventory.add(new Item(currency.id, (int) amount))) {
209 remove(currency, (int) amount);
210 player.send(new SendMessage("You have successfully withdrawn " + Utility.formatDigits(amount) + " " + currency.name + "."));
211 player.bank.refresh();
212 }
213 if (player.interfaceManager.isInterfaceOpen(56300)) {
214 long coins = getContainer(COINS);
215 long bloodMoney = getContainer(BLOOD_MONEY);
216 player.send(new SendString(Utility.formatDigits(coins), 56311));
217 player.send(new SendString(Utility.formatDigits(bloodMoney), 56312));
218 player.send(new SendItemOnInterface(56314, new Item(995, (int) coins), new Item(13307, (int) bloodMoney)));
219 }
220 }
221}
boolean add(VaultCurrency currency, long amount, boolean message)
boolean add(VaultCurrency currency, long amount)
void deposit(VaultCurrency currency, int amount)
void withdraw(VaultCurrency currency, long amount)
boolean contains(VaultCurrency currency, int amount)
static String formatDigits(final int amount)
Definition Utility.java:78
static String formatPrice(final long amount)
Definition Utility.java:93