RuneHive-Game
Loading...
Searching...
No Matches
ChopVineTask.java
Go to the documentation of this file.
1package com.runehive.game.task.impl;
2
3import com.runehive.content.skill.impl.woodcutting.AxeData;
4import com.runehive.game.Animation;
5import com.runehive.game.UpdatePriority;
6import com.runehive.game.task.Task;
7import com.runehive.game.world.entity.mob.Direction;
8import com.runehive.game.world.entity.mob.player.Player;
9import com.runehive.game.world.entity.skill.Skill;
10import com.runehive.game.world.object.GameObject;
11import com.runehive.net.packet.out.SendMessage;
12
13import java.util.Optional;
14
15public class ChopVineTask extends Task {
16
17 private int tick = 0;
18 private final Player player;
19 private final GameObject object;
20 private final int respawn;
21
23 super(true, 0);
24 this.player = player;
25 this.object = object;
26 this.respawn = respawn;
27 }
28
29 @Override
30 protected void onSchedule() {
31 if (!player.getPosition().isWithinDistance(object.getPosition(), 1)) {
32 cancel();
33 return;
34 }
35
36 if (player.skills.getLevel(Skill.WOODCUTTING) < 34) {
37 player.send(new SendMessage("You need a woodcutting level of 34 or more to cut this."));
38 cancel();
39 return;
40 }
41
42 Optional<AxeData> result = AxeData.getDefinition(player);
43
44 if (!result.isPresent()) {
45 player.send(new SendMessage("You need an axe to cut this."));
46 cancel();
47 return;
48 }
49
50 AxeData data = result.get();
51
52 player.animate(new Animation(data.animation, UpdatePriority.HIGH));
53 }
54
55 @Override
56 public void execute() {
57 if (tick == 1) {
58 object.unregister();
59 } else if (tick == respawn / 2) {
60 Direction direction = Direction.getDirection(player.getPosition(), object.getPosition());
61 player.walk(player.getPosition().transform(direction.getDirectionX() * 2, direction.getDirectionY() * 2), true);
62 } else if (tick >= respawn) {
63 object.register();
64 cancel();
65 }
66
67 tick++;
68 }
69
70 @Override
71 protected void onCancel(boolean logout) {
72
73 }
74
75}
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
void onSchedule()
A function executed on registration.
void execute()
A function representing the unit of work that will be carried out.
ChopVineTask(Player player, GameObject object, int respawn)
void onCancel(boolean logout)
A function executed on cancellation.
This class represents a character controlled by a player.
Definition Player.java:125
Represents a trainable and usable skill.
Definition Skill.java:18
static final int WOODCUTTING
The woodcutting skill id.
Definition Skill.java:45
The OutgoingPacket that sends a message to a Players chatbox in the client.
static Optional< AxeData > getDefinition(Player player)
Gets the definition for this hatchet.
Definition AxeData.java:74
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.