RuneHive-Tarnish
Neural OSRS Enhancement Framework
Loading...
Searching...
No Matches
Jewellery.java
1package com.osroyale.content.skill.impl.crafting.impl;
2
3import com.osroyale.Config;
4import com.osroyale.game.Animation;
5import com.osroyale.game.action.Action;
6import com.osroyale.game.action.policy.WalkablePolicy;
7import com.osroyale.game.world.entity.mob.player.Player;
8import com.osroyale.game.world.entity.skill.Skill;
9import com.osroyale.game.world.items.Item;
10import com.osroyale.game.world.items.ItemDefinition;
11import com.osroyale.net.packet.out.SendInterfaceConfig;
12import com.osroyale.net.packet.out.SendItemOnInterfaceSlot;
13import com.osroyale.net.packet.out.SendMessage;
14import com.osroyale.util.Utility;
15
16import java.util.Arrays;
17import java.util.Optional;
18
51
52public final class Jewellery {
53
57public enum JewelleryType {
58 RING(4233),
59 NECKLACE(4239),
60 AMULET(4245);
61
65 public final int identification;
66
73 this.identification = identification;
74 }
75 }
76
83 public enum JewelleryData {
84 GOLD_RING(1635, 5, 15, JewelleryType.RING, new Item(1592), new Item(2357)),
85 SAPPHIRE_RING(1637, 20, 40, JewelleryType.RING, new Item(1592), new Item(2357), new Item(1607)),
86 EMERALD_RING(1639, 27, 55, JewelleryType.RING, new Item(1592), new Item(2357), new Item(1605)),
87 RUBY_RING(1641, 34, 70, JewelleryType.RING, new Item(1592), new Item(2357), new Item(1603)),
88 DIAMOND_RING(1643, 43, 85, JewelleryType.RING, new Item(1592), new Item(2357), new Item(1601)),
89 DRAGONSTONE_RING(1645, 55, 100, JewelleryType.RING, new Item(1592), new Item(2357), new Item(1615)),
90 ONYX_RING(6575, 67, 85, JewelleryType.RING, new Item(1592), new Item(2357), new Item(6573)),
91
92 GOLD_NECKLACE(1654, 6, 20, JewelleryType.NECKLACE, new Item(1597), new Item(2357)),
93 SAPPHIRE_NECKLACE(1656, 22, 55, JewelleryType.NECKLACE, new Item(1597), new Item(2357), new Item(1607)),
94 EMERALD_NECKLACE(1658, 29, 60, JewelleryType.NECKLACE, new Item(1597), new Item(2357), new Item(1605)),
95 RUBY_NECKLACE(1660, 40, 75, JewelleryType.NECKLACE, new Item(1597), new Item(2357), new Item(1603)),
96 DIAMOND_NECKLACE(1662, 56, 90, JewelleryType.NECKLACE, new Item(1597), new Item(2357), new Item(1601)),
97 DRAGONSTONE_NECKLACE(1664, 72, 105, JewelleryType.NECKLACE, new Item(1597), new Item(2357), new Item(1615)),
98 ONYX_NECKLACE(6577, 82, 120, JewelleryType.NECKLACE, new Item(1597), new Item(2357), new Item(6573)),
99
100 GOLD_AMULET(1673, 8, 30, JewelleryType.AMULET, new Item(1595), new Item(2357)),
101 SAPPHIRE_AMULET(1675, 24, 65, JewelleryType.AMULET, new Item(1595), new Item(2357), new Item(1607)),
102 EMERALD_AMULET(1677, 31, 61, JewelleryType.AMULET, new Item(1595), new Item(2357), new Item(1605)),
103 RUBY_AMULET(1679, 50, 85, JewelleryType.AMULET, new Item(1595), new Item(2357), new Item(1603)),
104 DIAMOND_AMULET(1681, 70, 100, JewelleryType.AMULET, new Item(1595), new Item(2357), new Item(1601)),
105 DRAGONSTONE_AMULET(1683, 80, 125, JewelleryType.AMULET, new Item(1595), new Item(2357), new Item(1615)),
106 ONYX_AMULET(6579, 90, 150, JewelleryType.AMULET, new Item(1595), new Item(2357), new Item(6573));
107
111 public int product;
112
116 public int level;
117
121 public double experience;
122
127
131 public Item[] materials;
132
143 this.product = product;
144 this.level = level;
145 this.experience = experience;
146 this.type = type;
147 this.materials = materials;
148 }
149
156 public static int getSize(JewelleryType type) {
157 int count = 0;
158 for (JewelleryData data : values()) {
159 if (data.type == type) {
160 count++;
161 }
162 }
163 return count;
164 }
165
172 public static int[] getItems(JewelleryType type) {
173 int[] items = new int[getSize(type)];
174 int count = 0;
175 for (JewelleryData data : values()) {
176 if (data.type == type) {
177 items[count] = data.product;
178 count++;
179 }
180 }
181 return items;
182 }
183
190 public static Optional<JewelleryData> forItem(int item) {
191 return Arrays.stream(values()).filter(i -> i.product == item).findAny();
192 }
193 }
194
200 public static void open(Player player) {
201 int[] items = JewelleryData.getItems(JewelleryType.RING);
202 for (int i = 0; i < items.length; i++) {
203 player.send(new SendItemOnInterfaceSlot(JewelleryType.RING.identification, items[i], 1, i));
204 }
205
206 items = JewelleryData.getItems(JewelleryType.NECKLACE);
207 for (int i = 0; i < items.length; i++) {
208 player.send(new SendItemOnInterfaceSlot(JewelleryType.NECKLACE.identification, items[i], 1, i));
209 }
210
211 items = JewelleryData.getItems(JewelleryType.AMULET);
212 for (int i = 0; i < items.length; i++) {
213 player.send(new SendItemOnInterfaceSlot(JewelleryType.AMULET.identification, items[i], 1, i));
214 }
215
216 player.send(new SendInterfaceConfig(4229, 0, -1));
217 player.send(new SendInterfaceConfig(4235, 0, -1));
218 player.send(new SendInterfaceConfig(4241, 0, -1));
219 player.interfaceManager.open(4161);
220 }
221
229 public static void click(Player player, int item, int amount) {
230 if (!JewelleryData.forItem(item).isPresent()) {
231 return;
232 }
233
234 JewelleryData jewellery = JewelleryData.forItem(item).get();
235
236 if (player.skills.getMaxLevel(Skill.CRAFTING) < jewellery.level) {
237 String name = ItemDefinition.get(jewellery.product).getName();
238 player.send(new SendMessage("You need a crafting level of " + jewellery.level + " to craft " + Utility.getAOrAn(name) + " " + name + "."));
239 return;
240 }
241
242 boolean contains = true;
243 for (Item i : jewellery.materials) {
244 if (!player.inventory.contains(i)) {
245 String req = i.getName();
246 player.send(new SendMessage("You need " + Utility.getAOrAn(req) + " " + req + " to make this!"));
247 contains = false;
248 }
249 }
250
251 if (!contains)
252 return;
253
254 player.interfaceManager.close();
255 player.action.execute(craft(player, jewellery, amount), true);
256 }
257
266 private static Action<Player> craft(Player player, JewelleryData jewellery, int amount) {
267 return new Action<Player>(player, 4, true) {
268 int ticks = 0;
269
270 @Override
271 public void execute() {
272 if (!player.inventory.containsAll(jewellery.materials)) {
273 player.send(new SendMessage("You do not have the required items to craft this!"));
274 cancel();
275 return;
276 }
277
278 player.animate(new Animation(899));
279
280 for (int index = 0; index < jewellery.materials.length; index++) {
281 if (index != 0) {
282 player.inventory.remove(jewellery.materials[index], -1, false);
283 }
284 }
285
286 player.inventory.add(new Item(jewellery.product), -1, true);
287 player.skills.addExperience(Skill.CRAFTING, jewellery.experience * Config.CRAFTING_MODIFICATION);
288 player.send(new SendMessage("You have crafted " + Utility.getAOrAn(new Item(jewellery.product).getName()) + " " + new Item(jewellery.product).getName() + "."));
289
290 if (++ticks == amount) {
291 cancel();
292 return;
293 }
294 }
295
296 @Override
297 public String getName() {
298 return "Jewellery crafting";
299 }
300
301 @Override
302 public boolean prioritized() {
303 return false;
304 }
305
306 @Override
307 public WalkablePolicy getWalkablePolicy() {
308 return WalkablePolicy.NON_WALKABLE;
309 }
310 };
311 }
312}
static final double CRAFTING_MODIFICATION
Definition Config.java:295
static void click(Player player, int item, int amount)
void addExperience(int id, double experience)
static String getAOrAn(String nextWord)
Definition Utility.java:153
JewelleryData(int product, int level, double experience, JewelleryType type, Item... materials)