RuneHive-Tarnish
Neural OSRS Enhancement Framework
Loading...
Searching...
No Matches
RunePouch.java
1package com.osroyale.content.skill.impl.magic;
2
3import com.osroyale.game.world.entity.mob.player.Player;
4import com.osroyale.game.world.items.Item;
5import com.osroyale.game.world.position.Area;
6import com.osroyale.net.packet.out.SendItemOnInterface;
7import com.osroyale.util.Utility;
8
9import java.util.LinkedList;
10import java.util.List;
11
53
54public class RunePouch {
55
57 private static final int MAXIMUM_RUNE_CAPACITY = 16_000;
58
60 private final Item[] ALLOWED_RUNES = {
61 new Item(554), new Item(555), new Item(556), new Item(557), new Item(558),
62 new Item(559), new Item(560), new Item(561), new Item(562), new Item(563),
63 new Item(564), new Item(565), new Item(566), new Item(9075), new Item(21880)
64 };
65
67 private final Player player;
68
70 public List<Item> runes = new LinkedList<>();
71
73 public RunePouch(Player player) {
74 this.player = player;
75 }
76
77 public void open() {
78 refresh();
79 player.interfaceManager.open(41700);
80 }
81
82 public void clear(boolean open) {
83 if(open) runes.forEach(player.inventory::add);
84 runes.clear();
85 if(open) player.interfaceManager.open(41700);
86 refresh();
87 }
88
89 public void clear() {
90 clear(true);
91 }
92
93 public void refresh() {
94 player.send(new SendItemOnInterface(41710, runes.toArray(new Item[runes.size()])));
95 player.send(new SendItemOnInterface(41711, player.inventory.getItems()));
96 }
97
98 public void clearInterface() {
99 player.send(new SendItemOnInterface(41710, new Item[0]));
100 }
101
102 public void withdraw(int item, int amount) {
103 for (Item rune : runes) {
104 if (rune.getId() == item) {
105 int current = player.inventory.computeAmountForId(item);
106 if (rune.getAmount() - amount < 0) amount = rune.getAmount();
107 player.inventory.add(item, amount);
108 int newAm = player.inventory.computeAmountForId(item);
109 if (newAm - current < amount) amount = newAm - current;
110 rune.decrementAmountBy(amount);
111 if (rune.getAmount() == 0)
112 runes.remove(rune);
113 refresh();
114 return;
115 }
116 }
117 }
118
119 public void deposit(Item item, int amount) {
120 boolean allowed = false;
121 for (Item rune : ALLOWED_RUNES) {
122 if (rune.getId() == item.getId()) {
123 allowed = true;
124 break;
125 }
126 }
127 if (!allowed) {
128 player.message("You can only deposit runes into the rune pouch!");
129 return;
130 }
131
132 for (Item rune : runes) {
133 if (item.getId() == rune.getId()) {
134 if (rune.getAmount() + amount > MAXIMUM_RUNE_CAPACITY) {
135 amount = MAXIMUM_RUNE_CAPACITY - rune.getAmount();
136 player.message("You can only have a total of " + Utility.formatDigits(MAXIMUM_RUNE_CAPACITY) + " of the same rune in your rune pouch.");
137 }
138 player.inventory.remove(item.getId(), amount);
139 rune.incrementAmountBy(amount);
140 refresh();
141 return;
142 }
143 }
144
145 if (runes.size() >= 3) {
146 player.message("Your rune pouch is currently full and can not hold any more types of runes!");
147 return;
148 }
149
150 if (amount > MAXIMUM_RUNE_CAPACITY) {
151 amount = MAXIMUM_RUNE_CAPACITY;
152 player.message("You can only have a total of " + Utility.formatDigits(MAXIMUM_RUNE_CAPACITY) + " of the same rune in your rune pouch.");
153 }
154
155 player.inventory.remove(item.getId(), amount);
156 runes.add(new Item(item.getId(), amount));
157 refresh();
158 }
159
160 public int getRuneAmount() {
161 int amount = 0;
162 for (Item rune : runes) {
163 amount += rune.getAmount();
164 }
165 return amount;
166 }
167
168 public int getRuneAmount(int id) {
169 int amount = 0;
170 for (Item rune : runes) {
171 if (rune.getId() == id)
172 amount += rune.getAmount();
173 }
174 return amount;
175 }
176
177 public boolean contains(Item item) {
178 for (Item rune : runes) {
179 if (rune.getId() == item.getId() && rune.getAmount() >= item.getAmount())
180 return true;
181 }
182 return false;
183 }
184
185 public boolean containsId(int item) {
186 for (Item rune : runes) {
187 if (rune.getId() == item)
188 return true;
189 }
190 return false;
191 }
192
193 public void remove(Item item) {
194 for (Item rune : runes) {
195 if (rune.equalIds(item)) {
196 rune.decrementAmountBy(item.getAmount());
197 if (rune.getAmount() == 0)
198 runes.remove(rune);
199 return;
200 }
201 }
202 }
203
204 public boolean death(Item item) {
205 if (item.getId() == 12971 && Area.inWilderness(player)) {
206 runes.clear();
207 return true;
208 }
209
210 return false;
211 }
212}