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