RuneHive-Game
Loading...
Searching...
No Matches
CannonFireAction.java
Go to the documentation of this file.
1package com.runehive.content.combat.cannon;
2
3import com.runehive.content.combat.cannon.CannonManager.Rotation;
4import com.runehive.game.task.Task;
5import com.runehive.game.world.World;
6import com.runehive.game.world.entity.combat.hit.Hit;
7import com.runehive.game.world.entity.combat.hit.HitIcon;
8import com.runehive.game.world.entity.mob.npc.Npc;
9import com.runehive.game.world.entity.mob.player.Player;
10import com.runehive.net.packet.out.SendMessage;
11
12public final class CannonFireAction extends Task {
13 private final Player player;
14 private final Cannon cannon;
15
17 super(true, 2);
18 this.player = player;
19 this.cannon = cannon;
20 }
21
22 @Override
23 public void execute() {
24 if (cannon.getAmmunition() <= 0) {
25 player.send(new SendMessage("Your cannon has run out of ammunition!"));
26 cannon.setFiring(false);
27 cancel();
28 return;
29 }
30
31 switch (cannon.getRotation()) {
32 case NORTH:
33 cannon.setRotation(Rotation.NORTH_EAST);
34 break;
35 case NORTH_EAST:
36 cannon.setRotation(Rotation.EAST);
37 break;
38 case EAST:
39 cannon.setRotation(Rotation.SOUTH_EAST);
40 break;
41 case SOUTH_EAST:
42 cannon.setRotation(Rotation.SOUTH);
43 break;
44 case SOUTH:
45 cannon.setRotation(Rotation.SOUTH_WEST);
46 break;
47 case SOUTH_WEST:
48 cannon.setRotation(Rotation.WEST);
49 break;
50 case WEST:
51 cannon.setRotation(Rotation.NORTH_WEST);
52 break;
53 case NORTH_WEST:
54 cannon.setRotation(Rotation.NORTH);
55 break;
56 }
57
59
61
62 if (mobs != null) {
63 for (Npc i : mobs) {
64 if (i != null) {
65 int lockon = i.getIndex() + 1;
66 byte offsetX = (byte) ((i.getPosition().getY() - i.getPosition().getY()) * -1);
67 byte offsetY = (byte) ((i.getPosition().getX() - i.getPosition().getX()) * -1);
68 World.sendProjectile(CannonManager.getCannonFire(), cannon.getPosition(), cannon.instance, lockon, offsetX, offsetY);
69
70 Hit hit = new Hit(3, HitIcon.CANON);
71
72 i.damage(hit);
73 cannon.setAmmunition(cannon.getAmmunition() - 1);
74 }
75 }
76 }
77 }
78}
void execute()
A function representing the unit of work that will be carried out.
synchronized final void cancel()
Cancels all subsequent executions.
Definition Task.java:113
Task(boolean instant, int delay)
Creates a new Task.
Definition Task.java:41
Represents the game world.
Definition World.java:46
static void sendProjectile(Projectile projectile, Position position, int instance, int lock, byte offsetX, byte offsetY)
Sends a world projectile.
Definition World.java:295
A Hit object holds the damage amount and hitsplat data.
Definition Hit.java:10
Represents a non-player character in the in-game world.
Definition Npc.java:29
This class represents a character controlled by a player.
Definition Player.java:125
The OutgoingPacket that sends a message to a Players chatbox in the client.
The enumerated type whose elements represent the hit icon of a Hit.
Definition HitIcon.java:8