RuneHive-Game
Loading...
Searching...
No Matches
DragonSpear.java
Go to the documentation of this file.
1package com.runehive.game.world.entity.combat.strategy.player.special.melee;
2
3import com.runehive.game.Animation;
4import com.runehive.game.Graphic;
5import com.runehive.game.UpdatePriority;
6import com.runehive.game.world.entity.combat.hit.CombatHit;
7import com.runehive.game.world.entity.combat.hit.Hit;
8import com.runehive.game.world.entity.combat.strategy.player.PlayerMeleeStrategy;
9import com.runehive.game.world.entity.mob.Direction;
10import com.runehive.game.world.entity.mob.Mob;
11import com.runehive.game.world.entity.mob.data.LockType;
12import com.runehive.game.world.entity.mob.player.Player;
13import com.runehive.game.world.pathfinding.TraversalMap;
14import com.runehive.game.world.position.Position;
15import com.runehive.net.packet.out.SendMessage;
16
17/**
18 * Handles the dragon spear weapon special attack.
19 *
20 * @author Daniel
21 */
22public class DragonSpear extends PlayerMeleeStrategy {
23 private static final DragonSpear INSTANCE = new DragonSpear();
24 private static final Animation ANIMATION = new Animation(1064, UpdatePriority.HIGH);
25 private static final Graphic GRAPHIC = new Graphic(253, true, UpdatePriority.HIGH);
26
27 @Override
28 public boolean canAttack(Player attacker, Mob defender) {
29 if (defender.isPlayer() && defender.width() > 1 && defender.length() > 1) {
30 attacker.send(new SendMessage("That creature is too large to knock back!"));
31 return false;
32 }
33
34 Direction direction = Direction.getDirection(attacker.getPosition(), defender.getPosition());
35
36 if (!TraversalMap.isTraversable(defender.getPosition(), direction, false)) {
37 attacker.send(new SendMessage("That entity can not be knocked back as something is blocking it!"));
38 return false;
39 }
40
41 return super.canAttack(attacker, defender);
42 }
43
44 @Override
45 public void hit(Player attacker, Mob defender, Hit hit) {
46 super.hit(attacker, defender, hit);
47
48 Direction direction = Direction.getDirection(attacker.getPosition(), defender.getPosition());
49 Position position = defender.getPosition().transform(direction.getFaceLocation());
50
51 hit.setDamage(-1);
52 attacker.graphic(GRAPHIC);
53 defender.movement.reset();
54 defender.getCombat().clearIncoming();
55
56 defender.locking.lock(3, LockType.STUN);
57 defender.movement.walkTo(position);
58 }
59
60 @Override
61 public CombatHit[] getHits(Player attacker, Mob defender) {
62 return new CombatHit[] { nextMeleeHit(attacker, defender) };
63 }
64
65 @Override
66 public Animation getAttackAnimation(Player attacker, Mob defender) {
67 return ANIMATION;
68 }
69
70 public static DragonSpear get() {
71 return INSTANCE;
72 }
73
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
A wrapper for a Hit object, adding additional variables for hit and hitsplat delays.
A Hit object holds the damage amount and hitsplat data.
Definition Hit.java:10
Handles the mob class.
Definition Mob.java:66
abstract Combat<? extends Mob > getCombat()
The combat of the mob.
final boolean isPlayer()
Check if an entity is a player.
Definition Mob.java:564
Optional< Graphic > graphic
Definition Mob.java:91
void walkTo(int x, int y)
Handles mob walking to certain coordinates.
Definition Movement.java:77
void reset()
Resets the walking queue so it contains no more steps.
This class represents a character controlled by a player.
Definition Player.java:125
Contains traversal data for a set of regions.
static boolean isTraversable(Position from, Direction direction, int size)
Tests whether or not a specified position is traversable in the specified direction.
Represents a single tile on the game world.
Definition Position.java:14
Position transform(int diffX, int diffY, int diffZ)
Creates a new location based on this location.
The OutgoingPacket that sends a message to a Players chatbox in the client.
Represents different priorities for updating.
Represents the enumerated directions an entity can walk or face.
static Direction getDirection(int deltaX, int deltaY)
Gets the direction between two locations.