RuneHive-Game
Loading...
Searching...
No Matches
WeaponInterface.java
Go to the documentation of this file.
1package com.runehive.game.world.entity.combat.weapon;
2
3import com.runehive.Config;
4import com.runehive.game.world.entity.combat.attack.FightStyle;
5import com.runehive.game.world.entity.combat.attack.FightType;
6import com.runehive.game.world.entity.combat.magic.Autocast;
7import com.runehive.game.world.entity.combat.strategy.player.special.CombatSpecial;
8import com.runehive.game.world.entity.mob.player.Player;
9import com.runehive.game.world.items.Item;
10import com.runehive.net.packet.out.SendConfig;
11import com.runehive.net.packet.out.SendString;
12import it.unimi.dsi.fastutil.objects.Object2ObjectMap;
13import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
14
15import java.util.Optional;
16
17/**
18 * The enumerated type whose elements represent the weapon interfaces.
19 *
20 * @author lare96 <http://github.com/lare96>
21 */
22public enum WeaponInterface {
23 UNARMED(5855, "unarmed",5857, 7737, 7749, 7761, new FightType[]{
27 }),
28
29 DART(4446, "thrown", 4449, 7637, 7649, 7661, new FightType[]{
33 }),
34
35 STAFF(6103, "staff", 6132, 6104, 6117, 6129, new FightType[]{
39 }),
40
41 MAGIC_STAFF(328, "staff", 355, 340, 18566, 18569, new FightType[]{
45 }),
46 NIGHTMARE_STAFF(328, "staff", 355, 340, 18566, 18569, new FightType[]{
50 }),
51
52
53 WARHAMMER(425, "blunt", 428, 7473, 7474, 7486, new FightType[]{
57 }),
58
59 SCYTHE(776, "scythe", 779, -1, -1, -1, new FightType[]{
64 }),
65 VITUR(776, "scythe", 779, -1, -1, -1, new FightType[]{
70 }),
71
72
73 BATTLEAXE(1698, "weapon", 1701, 7498, 7499, 7511, new FightType[]{
78 }),
79
80 CROSSBOW(1764, "crossbow", 1767, 7548, 7549, 7561, new FightType[]{
84 }),
85 ZARYTE_CROSSBOW(1764, "crossbow", 1767, 7548, 7549, 7561, new FightType[]{
89 }),
90
91 SHORTBOW(1764, "bow", 1767, 7548, 7549, 7561, new FightType[]{
95 }),
96
97 LONGBOW(1764, "bow", 1767, 7548, 7549, 7561, new FightType[]{
101 }),
102
103 DARK_BOW(1764, "bow", 1767, 7548, 7549, 7561, new FightType[]{
107 }),
108
109 COMPOSITE_BOW(1764, "bow", 1767, 7548, 7549, 7561, new FightType[]{
113 }),
114
115 DAGGER(2276, "stab_sword", 2279, 7562, 7574, 7586, new FightType[]{
120 }),
121
122 SWORD(2276, "slash_sword", 2279, 7562, 7574, 7586, new FightType[]{
127 }),
128
129 SCIMITAR(2423, "slash_sword", 2426, 7587, 7599, 7611, new FightType[]{
134 }),
135
136 LONGSWORD(2423, "slash_sword", 2426, 7587, 7599, 7611, new FightType[]{
141 }),
142
143 MACE(3796, "spiked", 3799, 7623, 7624, 7636, new FightType[]{
148 }),
149 VIGGORA_MACE(3796, "spiked", 3799, 7623, 7624, 7636, new FightType[]{
154 }),
155
156 INQUISITOR_MACE(3796, "spiked", 3799, 7623, 7624, 7636, new FightType[]{
161 }),
162
163 KNIFE(4446, "thrown", 4449, 7637, 7649, 7661, new FightType[]{
167 }),
168
169 SPEAR(4679, "spear", 4682, 7662, 7674, 7686, new FightType[]{
174 }),
175 HUNTER_LANCE(4679, "spear", 4682, 7662, 7674, 7686, new FightType[]{
180 }),
181
182 TWO_HANDED_SWORD(4705, "2h_sword", 4708, 7687, 7699, 7711, new FightType[]{
187 }),
188
189 PICKAXE(5570, "pickaxe", 5573, 7723, 7724, 7736, new FightType[]{
194 }),
195
196 CLAWS(7762, "claw", 7765, 7788, 7800, 7812, new FightType[]{
201 }),
202
203 HALBERD(8460, "polearm", 8463, 8481, 8493, 8505, new FightType[]{
207 }),
208
209 WHIP(12290, "weapon", 12293, 12322, 12323, 12335, new FightType[]{
213 }),
214
215 THROWNAXE(4446, "thrown", 4449, 7637, 7649, 7661, new FightType[]{
219 }),
220
221 CHINCHOMPA(24055, "chinchompas", 24056, -1, -1, -1, new FightType[]{
225 }),
226
227 SALAMANDER(24074, "salamander", 24075, -1, -1, -1, new FightType[]{
231 }),
232
233 TRIDENT(4446, "powered_staff", 4449, 7637, 7649, 7661, new FightType[]{
237 }),
238 SHADOW(4446, "powered_staff", 4449, 7637, 7649, 7661, new FightType[]{
242 }),
243
244 BLOWPIPE(4446, "thrown", 4449, 7637, 7649, 7661, new FightType[]{
248 }),
249
250 BULWARK(425, "bulwark", 428, 7473, 7474, 7486, new FightType[]{
254 }),
255
256 GRANITE_MAUL(425, "blunt", 428, 7473, 7474, 7486, new FightType[]{
260 }),
261
262 ELDER_MAUL(425, "blunt", 428, 7473, 7474, 7486, new FightType[]{
266 }),
267
268 GREATAXE(1698, "axe", 1701, 7498, 7499, 7591, new FightType[]{
273 }),
274
275 KARIL_CROSSBOW(1764, "crossbow", 1767, 7548, 7549, 7561, new FightType[]{
279 }),
280
281 BALLISTA(1764, "crossbow", 1767, 7548, 7549, 7561, new FightType[]{
285 }),
286
287 DRAGON_DAGGER(2276, "stab_sword", 2279, 7562, 7574, 7586, new FightType[]{
292 }),
293
294 FLAIL(3796, "spiked", 3799, 7623, 7624, 7636, new FightType[]{
299 }),
300
301 GODSWORD_SWORD(4705, "2h_sword", 4708, 7687, 7699, 7711, new FightType[]{
306 }),
307 SAELDOR_SWORD(2423, "slash_sword", 2426, 7587, 7599, 7611, new FightType[]{
312 }),
313 OSMUM_SWORD(2276, "stab_sword", 2279, 7562, 7574, 7586, new FightType[]{
318 }),
319 GHRAZI_SWORD(2276, "stab_sword", 2279, 7562, 7574, 7586, new FightType[]{
324 }),
325
326
327
328 SARADOMIN_SWORD(4705, "2h_sword", 4708, 7687, 7699, 7711, new FightType[]{
333 }),
334
335 BLUDGEN(4705, "bludgeon", 4708, 7687, 7699, 7711, new FightType[]{
340 });
341
342 /**
343 * The identification of the interface that will be displayed.
344 */
345 private final int id;
346
347 private final String newDefName;
348
349 /**
350 * The identification of the line the weapon name will be displayed on.
351 */
352 private final int nameLine;
353
354 /**
355 * The fight types that correspond with this interface.
356 */
357 private final FightType[] fightTypes;
358
359 /**
360 * The identification of the special bar for this interface.
361 */
362 private final int specialButton;
363
364 /**
365 * The identification of the special bar for this interface.
366 */
367 private final int specialBar;
368
369 /**
370 * The identification of the special meter for this interface.
371 */
372 private final int specialMeter;
373
374 /**
375 * Creates a new {@link WeaponInterface}.
376 *
377 * @param id the identification of the interface that will be
378 * displayed.
379 * @param nameLine the identification of the line the weapon name will
380 * be displayed on.
381 * @param fightTypes the fight types that correspond with this interface.
382 */
384 this.id = id;
385 this.newDefName = newDefName;
386 this.nameLine = nameLine;
387 this.fightTypes = fightTypes;
388 this.specialButton = specialButton;
389 this.specialBar = specialBar;
390 this.specialMeter = specialMeter;
391 }
392
393 /**
394 * The method executed when weapon {@code item} is equipped or unequipped
395 * that assigns a weapon interface to {@code player}.
396 *
397 * @param player the player equipping the item.
398 * @param item the item the player is equipping, or {@code null} if a
399 * weapon was unequipped.
400 */
401
402 public static void execute(Player player, Item item) {
403 execute(player, item, false);
404 }
405
406 public static void execute(Player player, Item item, boolean login) {
407 WeaponInterface weapon = item == null ? null : item.getWeaponInterface();
408 if (weapon == null) weapon = WeaponInterface.UNARMED;
409
410 FightType[] oldTypes = player.getWeapon().fightTypes;
411 FightType[] newTypes = weapon.fightTypes;
412 FightType result = null;
413
414 for (int index = 0; index < oldTypes.length; index++) {
415 if (newTypes.length == index) {
416 break;
417 }
418
419 if (newTypes[index].getStyle().equals(FightStyle.DEFENSIVE)
420 && player.getCombat().getFightType().getStyle().equals(FightStyle.DEFENSIVE)) {
421 result = newTypes[index];
422 break;
423 }
424
425 if (oldTypes[index] == player.getCombat().getFightType()) {
426 boolean oldControlled = oldTypes[index].getStyle().equals(FightStyle.CONTROLLED);
427 boolean newControlled = newTypes[index].getStyle().equals(FightStyle.CONTROLLED);
428
429 if (newControlled != oldControlled) {
430 continue;
431 }
432
433 result = newTypes[index];
434 break;
435 }
436 }
437
438 if (result == null) {
439 if (player.getCombat().getFightType().getStyle().equals(FightStyle.DEFENSIVE)) {
440 result = newTypes[newTypes.length - 1];
441 } else {
442 result = newTypes[1];
443 }
444 }
445 player.setWeapon(weapon);
446
447 if(!login) {
448 player.getCombat().setFightType(result);
449 player.send(new SendConfig(result.getParent(), result.getChild()));
450 }
451
452 if (weapon == WeaponInterface.UNARMED) {
454 return;
455 }
456
457 CombatSpecial.assign(player);
459 Autocast.reset(player);
460 player.setSingleCast(null);
461
462 player.send(new SendString(item.getName(), weapon.nameLine));
464 player.equipment.updateAnimation();
465 }
466
467 private static void defaultWeaponInterface(Player player) {
468 CombatSpecial.assign(player);
470 Autocast.reset(player);
471 player.setSingleCast(null);
472
473 player.send(new SendString("<col=ff7000>Unarmed", WeaponInterface.UNARMED.nameLine));
475 player.equipment.updateAnimation();
476 }
477
478 /**
479 * Gets the identification of the interface that will be displayed.
480 *
481 * @return the identification of the interface.
482 */
483 public final int getId() {
484 return id;
485 }
486
487 public String getNewDefName() {
488 return newDefName;
489 }
490
491 /**
492 * Gets the fight types that correspond with this interface.
493 *
494 * @return the fight types that correspond.
495 */
496 public final FightType[] getFightTypes() {
497 return fightTypes;
498 }
499
500 /**
501 * Gets the identification of the special bar for this interface.
502 *
503 * @return the identification of the special bar.
504 */
505 public final int getSpecialBar() {
506 return specialBar;
507 }
508
509 /**
510 * Gets the identification of the special meter for this interface.
511 *
512 * @return the identification of the special meter.
513 */
514 public final int getSpecialMeter() {
515 return specialMeter;
516 }
517
518 public Optional<FightType> forFightButton(int button) {
519 for (FightType type : fightTypes) {
520 if (type.getButton() == button) {
521 return Optional.of(type);
522 }
523 }
524 return Optional.empty();
525 }
526
527 public static boolean isSpecialButton(int button) {
528 for (WeaponInterface weaponInterface : values()) {
529 if (weaponInterface.specialButton == button) {
530 return true;
531 }
532 }
533 return false;
534 }
535
536 public static final WeaponInterface[] values = values();
537
538 private static final Object2ObjectMap<String, WeaponInterface> newNameToValue
539 = new Object2ObjectOpenHashMap<>(values.length);
540
541 public static WeaponInterface forNewName(String newDefName) {
542 return newNameToValue.get(newDefName);
543 }
544
545 static {
546 for (WeaponInterface value : values) {
547 newNameToValue.putIfAbsent(value.getNewDefName(), value);
548 }
549 }
550
551}
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
This class represents a character controlled by a player.
Definition Player.java:125
void setSingleCast(CombatSpell singleCast)
Definition Player.java:848
void setWeapon(WeaponInterface weapon)
Definition Player.java:893
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
WeaponInterface getWeaponInterface()
Definition Item.java:488
The OutgoingPacket responsible for changing settings on a client.
The OutgoingPacket that sends a string to a Players itemcontainer in the client.
The enumerated type whose elements represent the fighting styles.
The enumerated type whose elements represent the fighting types.
final int getChild()
Gets the child config identification.
final int getParent()
Gets the parent config identification.
final FightStyle getStyle()
Gets the style active when this type is active.
The enumerated type whose elements represent the combat special attacks.
static void updateSpecialAmount(Player player)
Updates the special bar with the amount of special energy player has.
static void assign(Player player)
Updates the weapon itemcontainer with a special bar if needed.
The enumerated type whose elements represent the weapon interfaces.
final int nameLine
The identification of the line the weapon name will be displayed on.
static void execute(Player player, Item item, boolean login)
final int specialMeter
The identification of the special meter for this interface.
final int id
The identification of the interface that will be displayed.
final int specialBar
The identification of the special bar for this interface.
final int getId()
Gets the identification of the interface that will be displayed.
final FightType[] getFightTypes()
Gets the fight types that correspond with this interface.
WeaponInterface(int id, String newDefName, int nameLine, int specialButton, int specialBar, int specialMeter, FightType[] fightTypes)
Creates a new WeaponInterface.
final FightType[] fightTypes
The fight types that correspond with this interface.
static void execute(Player player, Item item)
The method executed when weapon item is equipped or unequipped that assigns a weapon interface to pla...
final int getSpecialMeter()
Gets the identification of the special meter for this interface.
final int getSpecialBar()
Gets the identification of the special bar for this interface.
static final Object2ObjectMap< String, WeaponInterface > newNameToValue
final int specialButton
The identification of the special bar for this interface.