RuneHive-Game
Loading...
Searching...
No Matches
CombatSpecial.java
Go to the documentation of this file.
1package com.runehive.game.world.entity.combat.strategy.player.special;
2
3import com.runehive.content.activity.Activity;
4import com.runehive.game.Animation;
5import com.runehive.game.Graphic;
6import com.runehive.game.UpdatePriority;
7import com.runehive.game.world.entity.combat.Combat;
8import com.runehive.game.world.entity.combat.strategy.CombatStrategy;
9import com.runehive.game.world.entity.combat.strategy.player.special.melee.*;
10import com.runehive.game.world.entity.combat.strategy.player.special.range.*;
11import com.runehive.game.world.entity.mob.Mob;
12import com.runehive.game.world.entity.mob.player.Player;
13import com.runehive.game.world.entity.skill.Skill;
14import com.runehive.game.world.items.Item;
15import com.runehive.game.world.items.containers.equipment.Equipment;
16import com.runehive.net.packet.out.*;
17
18import java.util.Arrays;
19import java.util.Optional;
20
21/**
22 * The enumerated type whose elements represent the combat special attacks.
23 *
24 * @author Chex
25 * @author Daniel
26 */
27public enum CombatSpecial {
28 /* Abyssal **/
29 ABYSSAL_WHIP(new int[]{4151, 80, 21371, 15441, 15442, 15443, 15444}, 50, AbyssalWhip.get()),
31 ABYSSAL_DAGGER(new int[]{13265}, 50, AbyssalDagger.get()),
32 ABYSSAL_BLUDGEN(new int[]{13263}, 50, AbyssalBludgen.get()),
33
34
35 /* Dragon **/
36 DRAGON_DAGGER(new int[]{1215, 1231, 5680, 5698}, 25, DragonDagger.get()),
37 DRAGON_WARHAMMER(new int[]{13576}, 50, DragonWarhammer.get()),
38 DRAGON_LONGSWORD(new int[]{1305}, 25, DragonLongsword.get()),
39 DRAGON_SCIMITAR(new int[]{4587, 20000}, 55, DragonScimitar.get()),
40 DRAGON_HALBERD(new int[]{3204}, 30, DragonHaldberd.get()),
41 OSMUM_FANG(new int[]{26219, 27246}, 25, OsmumFang.get()),
42 DRAGON_CLAWS(new int[]{13652, 20784}, 50, DragonClaws.get()),
43 DRAGON_SPEAR(new int[]{1249, 1263, 5730, 3176, 5716, 11824, 11889}, 25, DragonSpear.get()),
44 DRAGON_MACE(new int[]{1434}, 25, DragonMace.get()),
45 DRAGON_2H(new int[]{7158}, 60, Dragon2h.get()),
46 VESTAS_LONGSWORD(new int[]{22613}, 25, VestaLongsword.get()),
47
48 STAFF_OF_DEAD(new int[]{11791, 12904}, 100, DefaultMelee.get()) {
49 @Override
50 public void enable(Player player) {
51 if (player.getSpecialPercentage().intValue() < player.getCombatSpecial().getAmount()) {
52 player.send(new SendMessage("You do not have enough special energy left!"));
53 return;
54 }
55 player.staffOfDeadSpecial.reset();
56 player.animate(1720, true);
57 player.graphic(new Graphic(1228, 0, 13107200, UpdatePriority.HIGH));
58 player.skills.setLevel(1, 125);
59 player.send(new SendMessage("Your defence has been boosted!"));
60 drain(player, 100);
61 }
62 },
63 DRAGON_AXE(new int[]{6739, 13241, 20011}, 100, DefaultMelee.get()) {
64 @Override
65 public void enable(Player player) {
66 if (player.getSpecialPercentage().intValue() < player.getCombatSpecial().getAmount()) {
67 player.send(new SendMessage("You do not have enough special energy left!"));
68 return;
69 }
70 player.skills.setLevel(8, player.skills.getLevel(Skill.WOODCUTTING) + 3);
71 player.animate(new Animation(2876, UpdatePriority.HIGH), true);
72 player.graphic(new Graphic(479, true, UpdatePriority.HIGH));
73 player.send(new SendMessage("Your Woodcutting rate has increased by x2!"));
74 drain(player, 100);
75 }
76 },
77 DRAGON_HARPOON(new int[]{21028,25373,21031}, 100, DefaultMelee.get()) {
78 @Override
79 public void enable(Player player) {
80 if (player.getSpecialPercentage().intValue() < player.getCombatSpecial().getAmount()) {
81 player.send(new SendMessage("You do not have enough special energy left!"));
82 return;
83 }
84 player.skills.setLevel(Skill.FISHING, player.skills.getLevel(Skill.FISHING) + 3);
85 player.animate(new Animation(1056, UpdatePriority.HIGH), true);
86 player.graphic(new Graphic(246, UpdatePriority.HIGH));
87 player.speak("Here fishy fishies!");
88 drain(player, 100);
89 }
90 },
91 DRAGON_PICKAXE(new int[]{11920, 12797, 23677, 25376,27695,13243}, 100, DefaultMelee.get()) {
92 @Override
93 public void enable(Player player) {
94 if (player.getSpecialPercentage().intValue() < player.getCombatSpecial().getAmount()) {
95 player.send(new SendMessage("You do not have enough special energy left!"));
96 return;
97 }
98 player.skills.setLevel(Skill.MINING, player.skills.getLevel(Skill.MINING) + 3);
99 player.animate(new Animation(7138, UpdatePriority.HIGH), true);
100 player.speak("Smashing!");
101 drain(player, 100);
102 }
103 },
104 DRAGON_BATTLEAXE(new int[]{1377}, 100, DefaultMelee.get()) {
105 @Override
106 public void enable(Player player) {
107 if (player.getSpecialPercentage().intValue() < player.getCombatSpecial().getAmount()) {
108 player.send(new SendMessage("You do not have enough special energy left!"));
109 return;
110 }
111 player.speak("Raarrrrrgggggghhhhhhh!");
112 player.animate(new Animation(1056, UpdatePriority.HIGH), true);
113 player.graphic(new Graphic(246, UpdatePriority.HIGH));
114 player.skills.modifyLevel(level -> level - level / 10, Skill.ATTACK);
115 player.skills.modifyLevel(level -> level - level / 10, Skill.DEFENCE);
116 player.skills.modifyLevel(level -> level - level / 10, Skill.RANGED);
117 player.skills.modifyLevel(level -> level - level / 10, Skill.MAGIC);
118 player.skills.modifyLevel(level -> level + 10 + (player.skills.getMaxLevel(Skill.STRENGTH) - level) / 4, Skill.STRENGTH, 0, 120);
119 player.skills.refresh(Skill.ATTACK);
120 player.skills.refresh(Skill.DEFENCE);
121 player.skills.refresh(Skill.STRENGTH);
122 player.skills.refresh(Skill.RANGED);
123 player.skills.refresh(Skill.MAGIC);
124 drain(player, 100);
125 }
126 },
127
128 /* Godsword **/
129 SARADOMIN_GODSWORD(new int[]{11806, 20372}, 50, SaradominGodsword.get()),
130 ARMADYL_GODSWORD(new int[]{11802, 81, 20368}, 50, ArmadylGodsword.get()),
131 ZAMORAK_GODSWORD(new int[]{11808, 20374}, 50, ZamorakGodsword.get()),
132 BANDOS_GODSWORD(new int[]{11804, 20370}, 50, BandosGodsword.get()),
133 ANCIENT_GODSWORD(new int[]{26233}, 50, AncientGodsword.get()),
134
135 /* Ranged **/
136 BLOW_PIPE(new int[]{12926}, 50, Blowpipe.get()),
137 DARK_BOW(new int[]{11235, 12765, 12766, 12767, 12768}, 55, DarkBow.get()),
138 MAGIC_SHORTBOW(new int[]{861, 12788}, 55, MagicShortbow.get()),
139 BALLISTA(new int[]{19478, 19481}, 55, Ballista.get()),
140 ARMADYL_CROSSBOW(new int[]{11785}, 40, ArmadylCrossbow.get()),
141 ZARYTE_CROSSBOW(new int[]{26374}, 75, ZaryteCrossbow.get()),
142 DRAGON_THROWNAXE(new int[]{20849}, 25, DragonThrownaxe.get()) {
143 @Override
144 public void enable(Player player) {
145 super.enable(player);
146 if (player.isSpecialActivated()) {
147 player.getCombat().setCooldown(0);
148 }
149 }
150 },
151
152 /* Other **/
153 SARADOMIN_SWORD(new int[]{11838, 12809}, 100, SaradominSword.get()),
154
155
156 STAFF_OF_THE_DEAD(new int[]{11791, 12904}, 100, DefaultMelee.get()) {
157 @Override
158 public void enable(Player player) {
159 if (player.getSpecialPercentage().intValue() < player.getCombatSpecial().getAmount()) {
160 player.send(new SendMessage("You do not have enough special energy left!"));
161 return;
162 }
163 player.animate(1720, true);
164 player.graphic(new Graphic(1228, 0, 13107200, UpdatePriority.HIGH));
165 player.skills.setLevel(1, 125);
166 player.staffOfDeadSpecial.reset();
167 player.send(new SendMessage("Your defence has been boosted!"));
168 drain(player, 100);
169 }
170 },
171 TOXIC_STAFF_OF_THE_DEAD(new int[]{12904}, 100, DefaultMelee.get()) {
172 @Override
173 public void enable(Player player) {
174 if (player.getSpecialPercentage().intValue() < player.getCombatSpecial().getAmount()) {
175 player.send(new SendMessage("You do not have enough special energy left!"));
176 return;
177 }
178 player.animate(1720, true);
179 player.graphic(new Graphic(1228, 0, 13107200, UpdatePriority.HIGH));
180 player.skills.setLevel(1, 125);
181 player.staffOfDeadSpecial.reset();
182 player.send(new SendMessage("Your defence has been boosted!"));
183 drain(player, 100);
184 }
185 },
186 GRANITE_MAUL(new int[]{4153, 24225}, 50, GraniteMaul.get()) {
187 @Override
188 public void enable(Player player) {
189 if (player.getSpecialPercentage().intValue() < player.getCombatSpecial().getAmount()) {
190 player.send(new SendMessage("You do not have enough special energy left!"));
191 return;
192 }
193
194 player.setSpecialActivated(true);
195 player.send(new SendConfig(301, 1));
196
197 Combat<Player> combat = player.getCombat();
198 Mob defender = combat.getLastVictim();
199
200 if (combat.isAttacking(defender)) {
201 combat.performChecks(defender);
202 combat.submitStrategy(defender, GraniteMaul.get());
203 }
204 }
205
206 @Override
207 public void disable(Player player, boolean clicked) {
208 // TODO: potential bug when specials are disabled other
209 // TODO: than in the spec bar, example: switching weapons
210
211 boolean doubleSpec = !player.attributes.has("granite-maul-spec");
212 int current = player.getSpecialPercentage().intValue();
213
214 if (clicked && doubleSpec && current >= getAmount()) {
215 player.attributes.set("granite-maul-spec", true);
216 } else {
217 player.attributes.remove("granite-maul-spec");
218 super.disable(player, clicked);
219 }
220 }
221 },
222
223 DINHS_BULWARK(new int[]{21015}, 50, DinhsBulwark.get()),
224
225
226 DRAGON_KNIVES(new int[] { 22804 }, 25, DragonKnife.get());
227
228 /**
229 * The identifiers for the weapons that perform this special.
230 */
231 private final int[] ids;
232
233 /**
234 * The amount of special energy drained by this attack.
235 */
236 private final int amount;
237
238 /**
239 * The strength bonus added when performing this special attack.
240 */
242
243 /**
244 * Creates a new {@link CombatSpecial}.
245 *
246 * @param ids the identifiers for the weapons that perform this special.
247 * @param amount the amount of special energy drained by this attack.
248 */
250 this.ids = ids;
251 this.amount = amount;
252 this.strategy = strategy;
253 }
254
255 public static Optional<CombatSpecial> forId(int weapon) {
256 Optional<CombatSpecial> special = Arrays.stream(CombatSpecial.values()).filter(c -> Arrays.stream(c.getIds()).anyMatch(id -> weapon == id)).findFirst();
257 return special;
258 }
259
260 /**
261 * Executes exactly when {@code player} activates the special bar.
262 *
263 * @return the combat strategy
264 */
266 return strategy;
267 }
268
269 /**
270 * Drains the special bar for {@code player}.
271 *
272 * @param player the player who's special bar will be drained.
273 */
274 public void drain(Player player) {
275 player.send(new SendSpecialEnabled(0));
276 player.getSpecialPercentage().decrementAndGet(amount, 0);
278 disable(player, false);
279 }
280
281 public static void drain(Player player, int toDrain) {
282 player.send(new SendSpecialEnabled(0));
283 player.getSpecialPercentage().decrementAndGet(toDrain, 0);
285 }
286
287
288 /**
289 * Restores the special bar for {@code player}.
290 *
291 * @param player the player who's special bar will be restored.
292 * @param amount the amount of energy to restore to the special bar.
293 */
294 public static void restore(Player player, int amount) {
295 player.getSpecialPercentage().incrementAndGet(amount, 100);
297 }
298
299 /**
300 * Updates the special bar with the amount of special energy {@code player}
301 * has.
302 *
303 * @param player the player who's special bar will be updated.
304 */
305 public static void updateSpecialAmount(Player player) {
306 if (player.getWeapon().getSpecialBar() == -1 || player.getWeapon().getSpecialMeter() == -1) {
307 return;
308 }
309
310 int specialBar = player.getWeapon().getSpecialMeter();
311 int specialAmount = player.getSpecialPercentage().get() / 10;
312 player.send(new SendSpecialAmount());
313
314 for (int i = 10; i > 0; i--) {
315 player.send(new SendMoveComponent(specialAmount >= i ? 500 : 0, 0, --specialBar));
316 }
317 }
318
319
320 /**
321 * Updates the weapon itemcontainer with a special bar if needed.
322 *
323 * @param player the player to update the itemcontainer for.
324 */
325 public static void assign(Player player) {
326 if (player.getCombatSpecial() != null) {
327 player.getCombatSpecial().disable(player, false);
328 }
329
330 if (player.getWeapon().getSpecialBar() == -1) {
331 player.setCombatSpecial(null);
332 player.send(new SendInterfaceLayer(player.getWeapon().getSpecialBar(), true));
333 return;
334 }
335
336 Item item = player.equipment.get(Equipment.WEAPON_SLOT);
337 if (item == null) {
338 player.setCombatSpecial(null);
339 player.send(new SendInterfaceLayer(player.getWeapon().getSpecialBar(), true));
340 return;
341 }
342
343 Optional<CombatSpecial> special = Arrays.stream(CombatSpecial.values()).filter(c -> Arrays.stream(c.getIds()).anyMatch(id -> item.getId() == id)).findFirst();
344 if (special.isPresent()) {
345 player.send(new SendInterfaceLayer(player.getWeapon().getSpecialBar(), false));
346 player.setCombatSpecial(special.get());
347 return;
348 }
349
350 player.send(new SendInterfaceLayer(player.getWeapon().getSpecialBar(), true));
351 player.setCombatSpecial(null);
352 }
353
354 /**
355 * Gets the identifiers for the weapons that perform this special.
356 *
357 * @return the identifiers for the weapons.
358 */
359 public final int[] getIds() {
360 return ids;
361 }
362
363 /**
364 * Gets the amount of special energy drained by this attack.
365 *
366 * @return the amount of special energy drained.
367 */
368 public final int getAmount() {
369 return amount;
370 }
371
372 public void enable(Player player) {
373 if (Activity.evaluate(player, it -> !it.canUseSpecial(player))) {
374 return;
375 }
376
377 if (!player.isSpecialActivated()) {
378 if (player.getSpecialPercentage().intValue() < player.getCombatSpecial().getAmount()) {
379 player.send(new SendMessage("You do not have enough special energy left!"));
380 return;
381 }
382
383 player.send(new SendConfig(301, 1));
384 player.setSpecialActivated(true);
385 }
386 }
387
388 public void disable(Player player, boolean clicked) {
389 if (player.isSpecialActivated()) {
390 player.send(new SendConfig(301, 0));
391 player.setSpecialActivated(false);
392 }
393 }
394
395}
A Activity object constructs an in-game activity and sequences it through the start() and finish() me...
Definition Activity.java:31
static boolean evaluate(Mob mob, Predicate< Activity > predicate)
Definition Activity.java:74
Class that models a single animation used by an entity.
Represents a single graphic that can be used by entities.
Definition Graphic.java:10
Handles the magic shortbow weapon special attack.
Definition DarkBow.java:24
Handles the mob class.
Definition Mob.java:66
final GenericAttributes attributes
Definition Mob.java:95
This class represents a character controlled by a player.
Definition Player.java:125
Represents a trainable and usable skill.
Definition Skill.java:18
static final int WOODCUTTING
The woodcutting skill id.
Definition Skill.java:45
static final int RANGED
The ranged skill id.
Definition Skill.java:33
static final int FISHING
The fishing skill id.
Definition Skill.java:51
static final int DEFENCE
The defence skill id.
Definition Skill.java:24
static final int MAGIC
The magic skill id.
Definition Skill.java:39
static final int ATTACK
The attack skill id.
Definition Skill.java:21
static final int STRENGTH
The strength skill id.
Definition Skill.java:27
static final int MINING
The mining skill id.
Definition Skill.java:63
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
The container that manages the equipment for a player.
The OutgoingPacket responsible for changing settings on a client.
Shows an itemcontainer inside another itemcontainer.
The OutgoingPacket that sends a message to a Players chatbox in the client.
Handles sending the special attack amount (used for the orb).
public< K > void remove(K key)
Removes a generic attribute.
public< K, E > void set(K key, E attribute)
Sets a generic attribute.
public< K > boolean has(K key)
Checks if a key is in the list of generic attribute.
Represents different priorities for updating.
final CombatStrategy< Player > strategy
The strength bonus added when performing this special attack.
void drain(Player player)
Drains the special bar for player.
static void updateSpecialAmount(Player player)
Updates the special bar with the amount of special energy player has.
final int amount
The amount of special energy drained by this attack.
static void assign(Player player)
Updates the weapon itemcontainer with a special bar if needed.
static void restore(Player player, int amount)
Restores the special bar for player.
final int[] ids
The identifiers for the weapons that perform this special.
CombatStrategy< Player > getStrategy()
Executes exactly when player activates the special bar.
final int[] getIds()
Gets the identifiers for the weapons that perform this special.
CombatSpecial(int[] ids, int amount, CombatStrategy< Player > strategy)
Creates a new CombatSpecial.
final int getAmount()
Gets the amount of special energy drained by this attack.