RuneHive-Game
Loading...
Searching...
No Matches
ForceMovementTask.java
Go to the documentation of this file.
1package com.runehive.game.task.impl;
2
3import com.runehive.game.Animation;
4import com.runehive.game.task.Task;
5import com.runehive.game.world.entity.mob.Mob;
6import com.runehive.game.world.entity.mob.player.ForceMovement;
7import com.runehive.game.world.position.Position;
8
9public class ForceMovementTask extends Task {
10 private final Mob mob;
11 private final Position start;
12 private final Position end;
13 private final Animation animation;
15
16 private final int moveDelay;
17 private int tick;
18
22
24 super(delay == 0, delay);
25 this.mob = mob;
26 this.start = forceMovement.getStart().copy();
27 this.end = forceMovement.getEnd().copy();
28 this.animation = animation;
29 this.forceMovement = forceMovement;
30 this.moveDelay = moveDelay;
31 }
32
33 @Override
34 protected boolean canSchedule() {
35 return mob.forceMovement == null;
36 }
37
38 @Override
39 protected void onSchedule() {
40 mob.getCombat().reset();
41 mob.movement.reset();
42 mob.animate(animation, true);
43 mob.setForceMovement(forceMovement);
44 }
45
46 @Override
47 public void execute() {
48 if (tick >= moveDelay) {
49 final int x = start.getX() + end.getX();
50 final int y = start.getY() + end.getY();
51 mob.move(new Position(x, y, mob.getHeight()));
52 mob.setForceMovement(null);
53 cancel();
54 }
55 tick++;
56 }
57}
Class that models a single animation used by an entity.
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
int delay
The cyclic delay.
Definition Task.java:17
ForceMovementTask(Mob mob, int delay, ForceMovement forceMovement, Animation animation)
boolean canSchedule()
A function executed on registration.
ForceMovementTask(Mob mob, int delay, int moveDelay, ForceMovement forceMovement, Animation animation)
void execute()
A function representing the unit of work that will be carried out.
void onSchedule()
A function executed on registration.
Handles the mob class.
Definition Mob.java:66
Represents a single tile on the game world.
Definition Position.java:14