RuneHive-Tarnish
Neural OSRS Enhancement Framework
Loading...
Searching...
No Matches
ChopVineTask.java
1package com.osroyale.game.task.impl;
2
3import com.osroyale.content.skill.impl.woodcutting.AxeData;
4import com.osroyale.game.Animation;
5import com.osroyale.game.UpdatePriority;
6import com.osroyale.game.task.Task;
7import com.osroyale.game.world.entity.mob.Direction;
8import com.osroyale.game.world.entity.mob.player.Player;
9import com.osroyale.game.world.entity.skill.Skill;
10import com.osroyale.game.world.object.GameObject;
11import com.osroyale.net.packet.out.SendMessage;
12
13import java.util.Optional;
14
42
43public class ChopVineTask extends Task {
44
45 private int tick = 0;
46 private final Player player;
47 private final GameObject object;
48 private final int respawn;
49
50 public ChopVineTask(Player player, GameObject object, int respawn) {
51 super(true, 0);
52 this.player = player;
53 this.object = object;
54 this.respawn = respawn;
55 }
56
57 @Override
58 protected void onSchedule() {
59 if (!player.getPosition().isWithinDistance(object.getPosition(), 1)) {
60 cancel();
61 return;
62 }
63
64 if (player.skills.getLevel(Skill.WOODCUTTING) < 34) {
65 player.send(new SendMessage("You need a woodcutting level of 34 or more to cut this."));
66 cancel();
67 return;
68 }
69
70 Optional<AxeData> result = AxeData.getDefinition(player);
71
72 if (!result.isPresent()) {
73 player.send(new SendMessage("You need an axe to cut this."));
74 cancel();
75 return;
76 }
77
78 AxeData data = result.get();
79
80 player.animate(new Animation(data.animation, UpdatePriority.HIGH));
81 }
82
83 @Override
84 public void execute() {
85 if (tick == 1) {
86 object.unregister();
87 } else if (tick == respawn / 2) {
88 Direction direction = Direction.getDirection(player.getPosition(), object.getPosition());
89 player.walk(player.getPosition().transform(direction.getDirectionX() * 2, direction.getDirectionY() * 2), true);
90 } else if (tick >= respawn) {
91 object.register();
92 cancel();
93 }
94
95 tick++;
96 }
97
98 @Override
99 protected void onCancel(boolean logout) {
100
101 }
102
103}
synchronized final void cancel()
Definition Task.java:147
Task(boolean instant, int delay)
Definition Task.java:75
static Optional< AxeData > getDefinition(Player player)
Definition AxeData.java:111
static Direction getDirection(int deltaX, int deltaY)