RuneHive-Game
Loading...
Searching...
No Matches
Autocast.java
Go to the documentation of this file.
1package com.runehive.game.world.entity.combat.magic;
2
3import com.runehive.Config;
4import com.runehive.net.packet.out.SendConfig;
5import com.runehive.net.packet.out.SendMessage;
6import com.runehive.net.packet.out.SendString;
7import com.runehive.game.world.entity.mob.player.Player;
8import com.runehive.game.world.entity.mob.player.PlayerRight;
9import com.runehive.content.skill.impl.magic.Spellbook;
10import com.runehive.game.world.items.Item;
11import com.runehive.util.MessageColor;
12import com.runehive.util.StringUtils;
13
14public class Autocast {
15 private final static int[] ANCIENT_STAFFS = {21006, 4675, 4710, 11791, 12904, 6914};
16 private final static int[] NO_AUTOCAST = {12899, 11907, 11908};
17
18 public static boolean clickButton(Player player, int button) {
19 switch (button) {
20 case 2004:
21 case 6161:
22 case -20754:
23 case -21584:
25 player.getCombat().reset();
26 return true;
27 case 24111:
28 case 349:
29 if (!player.isAutocast()) {
30 Item weapon = player.equipment.getWeapon();
31
32 if (weapon != null) {
33 sendSelectionInterface(player, weapon.getId());
34 }
35 } else {
36 reset(player);
37 }
38 player.getCombat().reset();
39 return true;
40
41 //Strike spells
42 case 1830:
43 case -20753:
44 setAutocast(player, 1152);
45 return true;
46 case 1834:
47 case -20752:
48 setAutocast(player, 1154);
49 return true;
50 case 1838:
51 case -20751:
52 setAutocast(player, 1156);
53 return true;
54 case 1842:
55 case -20750:
56 setAutocast(player, 1158);
57 return true;
58
59 //Bolt
60 case 1831:
61 case -20749:
62 setAutocast(player, 1160);
63 return true;
64 case 1835:
65 case -20748:
66 setAutocast(player, 1163);
67 return true;
68 case 1839:
69 case -20747:
70 setAutocast(player, 1166);
71 return true;
72 case 1843:
73 case -20746:
74 setAutocast(player, 1169);
75 return true;
76
77 //Blast spells
78 case 1832:
79 case -20745:
80 setAutocast(player, 1172);
81 return true;
82 case 1836:
83 case -20744:
84 setAutocast(player, 1175);
85 return true;
86 case 1840:
87 case -20743:
88 setAutocast(player, 1177);
89 return true;
90 case 1844:
91 case -20742:
92 setAutocast(player, 1181);
93 return true;
94
95 //Wave
96 case 1833:
97 case -20741:
98 setAutocast(player, 1183);
99 return true;
100 case 1837:
101 case -20740:
102 setAutocast(player, 1185);
103 return true;
104 case 1841:
105 case -20739:
106 setAutocast(player, 1188);
107 return true;
108 case 1845:
109 case -20738:
110 setAutocast(player, 1189);
111 return true;
112
113 //Surge spells
114 case -20737:
115 setAutocast(player, 40140);
116 return true;
117 case -20736:
118 setAutocast(player, 40150);
119 return true;
120 case -20735:
121 setAutocast(player, 40170);
122 return true;
123 case -20734:
124 setAutocast(player, 40190);
125 return true;
126
127 //Smoke rush
128 case 13189:
129 case -21583:
130 setAutocast(player, 12939);
131 return true;
132 //Smoke burst
133 case 13215:
134 case -21579:
135 setAutocast(player, 12963);
136 return true;
137 case 13202:
138 //Smoke blitz
139 case -21575:
140 setAutocast(player, 12951);
141 return true;
142 //Smoke barrage
143 case 13228:
144 case -21571:
145 setAutocast(player, 12975);
146 return true;
147
148 //Shadow rush
149 case 13241:
150 case -21582:
151 setAutocast(player, 12987);
152 return true;
153 //Shadow burst
154 case 13267:
155 case -21578:
156 setAutocast(player, 13011);
157 return true;
158 //Shadow blitz
159 case 13254:
160 case -21574:
161 setAutocast(player, 12999);
162 return true;
163 //Smoke barrage
164 case 13280:
165 case -21570:
166 setAutocast(player, 13023);
167 return true;
168
169 //Blood rush
170 case 13147:
171 case -21581:
172 setAutocast(player, 12901);
173 return true;
174 //Blood burst
175 case 13167:
176 case -21577:
177 setAutocast(player, 12919);
178 return true;
179 //Blood blitz
180 case 13158:
181 case -21573:
182 setAutocast(player, 12911);
183 return true;
184 //Blood barrage
185 case 13178:
186 case -21569:
187 setAutocast(player, 12929);
188 return true;
189
190 //Ice rush
191 case 6162:
192 case -21580:
193 setAutocast(player, 12861);
194 return true;
195 //Ice burst
196 case 13125:
197 case -21576:
198 setAutocast(player, 12881);
199 return true;
200 //Ice blitz
201 case 13114:
202 case -21572:
203 setAutocast(player, 12871);
204 return true;
205 //Ice barrage
206 case 13136:
207 case -21568:
208 setAutocast(player, 12891);
209 return true;
210 }
211 return false;
212 }
213
214 public static void reset(Player player) {
215 if (player.isAutocast()) {
216 player.setAutocast(null);
217 player.send(new SendConfig(108, 0));
218 player.send(new SendString("Spell", 18584));
219 }
220 }
221
222 private static void sendSelectionInterface(Player player, int weaponId) {
223 for (int id : NO_AUTOCAST) {
224 if (weaponId == id) {
225 player.send(new SendMessage("You can't autocast with this weapon!"));
226 return;
227 }
228 }
229
230 if (player.spellbook == null) {
231 player.spellbook = Spellbook.MODERN;
232 }
233
234 switch (player.spellbook) {
235 case ANCIENT:
236 if (!player.equipment.containsAny(ANCIENT_STAFFS)) {
237 if (!player.equipment.hasWeapon()) {
238 return;
239 }
240
241 String def = player.equipment.getWeapon().getName().toLowerCase();
242 player.send(new SendMessage("You can't autocast ancient magicks with " + StringUtils.getAOrAn(def) + " " + def + "."));
243 return;
244 }
245 player.interfaceManager.setSidebar(Config.ATTACK_TAB, 43950); //1689
246 break;
247 case LUNAR:
248 player.send(new SendMessage("You can't autocast lunar magicks!"));
249 break;
250 case MODERN:
251 if (player.equipment.contains(4675)) {
252 player.send(new SendMessage("You can't autocast normal magicks with this staff!"));
253 return;
254 }
255 player.interfaceManager.setSidebar(Config.ATTACK_TAB, 44780); //1829
256 break;
257 }
258 }
259
260 private static void setAutocast(Player player, int id) {
261 CombatSpell spell = CombatSpell.get(id);
262
263 if (spell == null) {
264 player.send(new SendMessage("[ERROR] No spell definition found.", MessageColor.LIGHT_RED));
265 return;
266 }
267
268 if (!PlayerRight.isAdministrator(player) && !MagicRune.hasRunes(player, spell.getRunes())) {
269 player.send(new SendMessage("You don't have the runes required for this spell!"));
270 return;
271 }
272
273 player.setAutocast(spell);
274 player.send(new SendConfig(43, 3));
275 player.send(new SendConfig(108, 1));
277 }
278}
The class that contains setting-related constants for the server.
Definition Config.java:24
static final int ATTACK_TAB
All the tab identifications.
Definition Config.java:194
static void setAutocast(Player player, int id)
static void sendSelectionInterface(Player player, int weaponId)
static boolean clickButton(Player player, int button)
Definition Autocast.java:18
This class represents a character controlled by a player.
Definition Player.java:125
Combat< Player > getCombat()
The combat of the mob.
Definition Player.java:759
The container class that represents an item that can be interacted with.
Definition Item.java:21
final boolean containsAny(int... identifiers)
Determines if this container contains any identifiers.
boolean contains(int[] bowsWithNoArrowsRequired)
The OutgoingPacket responsible for changing settings on a client.
The OutgoingPacket that sends a message to a Players chatbox in the client.
The OutgoingPacket that sends a string to a Players itemcontainer in the client.
static String getAOrAn(String nextWord)
The in-game spellbooks for players.
Definition Spellbook.java:8
static boolean hasRunes(Player player, Item[] required)
static boolean isAdministrator(Player player)
Checks if the player is a privileged member.
Holds an enum of colors for ease.