RuneHive-Tarnish
Neural OSRS Enhancement Framework
Loading...
Searching...
No Matches
MagicRune.java
1package com.osroyale.game.world.entity.combat.magic;
2
3import com.osroyale.game.world.entity.mob.player.Player;
4import com.osroyale.game.world.items.Item;
5import com.osroyale.game.world.items.containers.ItemContainer;
6
7import java.util.LinkedList;
8import java.util.List;
9
27
28public enum MagicRune {
29 AIR_RUNE(556, new int[]{4695, 4696, 4697}, new int[]{1381, 1397, 1405, 11998, 12000, 20730, 20733, 20736, 20739}),
30 FIRE_RUNE(554, new int[]{4694, 4697, 4699}, new int[]{1387, 1393, 1401, 11998, 12000, 11787, 3053, 3054, 12795}),
31 WATER_RUNE(555, new int[]{4694, 4695, 4698}, new int[]{1383, 1395, 1403, 20730, 20733, 6562, 6563, 11787, 11789, 12795, 21006}),
32 EARTH_RUNE(557, new int[]{4698, 4696, 4699}, new int[]{3053, 3054, 1385, 1399, 1407, 6562, 6563, 20736, 20739}),
33 MIND_RUNE(558, null, null),
34 BODY_RUNE(559, null, null),
35 DEATH_RUNE(560, null, null),
36 NATURE_RUNE(561, null, null),
37 CHAOS_RUNE(562, null, null),
38 LAW_RUNE(563, null, null),
39 COSMIC_RUNE(564, null, null),
40 BLOOD_RUNE(565, null, null),
41 SOUL_RUNE(566, null, null),
42 ASTRAL_RUNE(9075, null, null),
43 WRATH_RUNE(21880, null, null);
44
45 private final int mainId;
46 private final int[] combos;
47 private final int[] staffs;
48
49 MagicRune(int mainId, int[] combos, int[] staffs) {
50 this.mainId = mainId;
51 this.combos = combos;
52 this.staffs = staffs;
53 }
54
55 public int getMainId() {
56 return mainId;
57 }
58
59 public int[] getCombos() {
60 return combos;
61 }
62
63 public int[] getStaffs() {
64 return staffs;
65 }
66
67 public static MagicRune forMainId(int id) {
68 for (MagicRune rune : values()) {
69 if (rune.mainId == id)
70 return rune;
71 }
72 return null;
73 }
74
75 public boolean isStaff(int id) {
76 if (staffs == null) return false;
77 for (int staff : staffs) {
78 if (staff == id) {
79 return true;
80 }
81 }
82 return false;
83 }
84
85 public boolean containsCombo(ItemContainer container, int amount) {
86 if (combos == null) return false;
87 for (int combo : combos) {
88 if (container.contains(combo, amount)) {
89 return true;
90 }
91 }
92 return false;
93 }
94
95 public static boolean hasRunes(Player player, Item[] required) {
96 Item wepon = player.equipment.getWeapon();
97 for (Item item : required) {
98 MagicRune rune = forMainId(item.getId());
99
100 if (rune == null)
101 continue;
102
103 if (player.runePouch.contains(item))
104 continue;
105
106 if (wepon != null && rune.isStaff(wepon.getId()))
107 continue;
108
109 if (player.inventory.contains(rune.mainId, item.getAmount()))
110 continue;
111
112 if (rune.containsCombo(player.inventory, item.getAmount()))
113 continue;
114
115 /* does not have runes */
116 return false;
117 }
118 return true;
119 }
120
121 public static void remove(Player player, Item[] required) {
122 Item wepon = player.equipment.getWeapon();
123 boolean refresh = false;
124 player.inventory.setFiringEvents(false);
125 for (Item item : required) {
126 MagicRune rune = forMainId(item.getId());
127
128 if (rune == null)
129 continue;
130
131 if (wepon != null && rune.isStaff(wepon.getId()))
132 continue;
133
134 if (player.runePouch.contains(item)) {
135 player.runePouch.remove(item);
136 continue;
137 }
138
139 if (player.inventory.contains(rune.mainId, item.getAmount())) {
140 refresh |= player.inventory.remove(rune.mainId, item.getAmount());
141 continue;
142 }
143
144 if (rune.combos != null && rune.containsCombo(player.inventory, item.getAmount())) {
145 for (int combo : rune.combos) {
146 if (player.inventory.contains(combo, item.getAmount())) {
147 refresh |= player.inventory.remove(combo, item.getAmount());
148 break;
149 }
150 }
151 }
152 }
153
154 player.inventory.setFiringEvents(true);
155 if (refresh) player.inventory.refresh();
156 }
157
158 public static boolean hasRunes(Player player, RequiredRune[] runes) {
159 List<Item> required = new LinkedList<>();
160 for (RequiredRune rune : runes) {
161 required.add(new Item(rune.getMainId(), rune.getAmount()));
162 }
163 return hasRunes(player, required.toArray(new Item[required.size()]));
164 }
165
166 public static void remove(Player player, RequiredRune[] runes) {
167 List<Item> required = new LinkedList<>();
168 for (RequiredRune rune : runes) {
169 required.add(new Item(rune.getMainId(), rune.getAmount()));
170 }
171 remove(player, required.toArray(new Item[required.size()]));
172 }
173
174}