RuneHive-Game
Loading...
Searching...
No Matches
com.runehive.content.combat.cannon.CannonFireAction Class Reference
Inheritance diagram for com.runehive.content.combat.cannon.CannonFireAction:
Collaboration diagram for com.runehive.content.combat.cannon.CannonFireAction:

Public Member Functions

 CannonFireAction (Player player, Cannon cannon)
void execute ()
 A function representing the unit of work that will be carried out.
Public Member Functions inherited from com.runehive.game.task.Task
Task attach (Object newKey)
 Attaches a new key.
synchronized final void cancel ()
 Cancels all subsequent executions.
synchronized final void cancel (boolean logout)
 Cancels all subsequent executions.
boolean canRun ()
 Determines if the task can be ran.
Optional< Object > getAttachment ()
String getCreationStackTraceStr ()
int getDelay ()
Long getElapsedTimeFromRunStartTime ()
Optional< Long > getRunStartTime ()
long getTaskCreationTime ()
String getTaskId ()
boolean isInstant ()
boolean isRunning ()
void setDelay (int delay)
 Sets the cyclic delay.
void setExecutionTime ()
 Task (boolean instant, int delay)
 Creates a new Task.
 Task (int delay)
 Creates a new Task that doesn't execute instantly.

Private Attributes

final Cannon cannon
final Player player

Additional Inherited Members

Protected Member Functions inherited from com.runehive.game.task.Task
void baseExecute ()
boolean canSchedule ()
 A function executed on registration.
void onCancel (boolean logout)
 A function executed on cancellation.
void onSchedule ()
 A function executed on registration.
Package Functions inherited from com.runehive.game.task.Task
void onException (Exception e)
 A function executed on thrown exceptions.
void onLoop ()
 A function executed when iterated over.
final synchronized void process ()
synchronized void setRunning (boolean running)

Detailed Description

Definition at line 12 of file CannonFireAction.java.

Constructor & Destructor Documentation

◆ CannonFireAction()

com.runehive.content.combat.cannon.CannonFireAction.CannonFireAction ( Player player,
Cannon cannon )

Definition at line 16 of file CannonFireAction.java.

16 {
17 super(true, 2);
18 this.player = player;
19 this.cannon = cannon;
20 }

References cannon, and player.

Member Function Documentation

◆ execute()

void com.runehive.content.combat.cannon.CannonFireAction.execute ( )

A function representing the unit of work that will be carried out.

Reimplemented from com.runehive.game.task.Task.

Definition at line 23 of file CannonFireAction.java.

23 {
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
58 CannonManager.rotate(cannon);
59
60 Npc[] mobs = CannonManager.getNpc(cannon);
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 }

References com.runehive.game.task.Task.cancel(), cannon, com.runehive.game.world.entity.combat.hit.HitIcon.CANON, com.runehive.content.combat.cannon.CannonManager.Rotation.EAST, com.runehive.content.combat.cannon.CannonManager.getCannonFire(), com.runehive.content.combat.cannon.CannonManager.getNpc(), com.runehive.content.combat.cannon.CannonManager.Rotation.NORTH, com.runehive.content.combat.cannon.CannonManager.Rotation.NORTH_EAST, com.runehive.content.combat.cannon.CannonManager.Rotation.NORTH_WEST, player, com.runehive.content.combat.cannon.CannonManager.rotate(), com.runehive.game.world.World.sendProjectile(), com.runehive.content.combat.cannon.CannonManager.Rotation.SOUTH, com.runehive.content.combat.cannon.CannonManager.Rotation.SOUTH_EAST, com.runehive.content.combat.cannon.CannonManager.Rotation.SOUTH_WEST, and com.runehive.content.combat.cannon.CannonManager.Rotation.WEST.

Here is the call graph for this function:

Member Data Documentation

◆ cannon

final Cannon com.runehive.content.combat.cannon.CannonFireAction.cannon
private

Definition at line 14 of file CannonFireAction.java.

Referenced by CannonFireAction(), and execute().

◆ player

final Player com.runehive.content.combat.cannon.CannonFireAction.player
private

Definition at line 13 of file CannonFireAction.java.

Referenced by CannonFireAction(), and execute().


The documentation for this class was generated from the following file: