RuneHive-Tarnish
Neural OSRS Enhancement Framework
Loading...
Searching...
No Matches
SkillAction.java
1package com.osroyale.content.skill;
2
3import com.osroyale.game.Animation;
4import com.osroyale.game.action.Action;
5import com.osroyale.game.world.entity.mob.Mob;
6import com.osroyale.game.world.position.Position;
7
8import java.util.Optional;
9
50
51public abstract class SkillAction extends Action<Mob> {
52
56 private final Optional<Position> position;
57
66 public SkillAction(Mob mob, Optional<Position> position, int delay, boolean instant) {
67 super(mob, delay, instant);
68 this.position = position;
69 }
70
78 public SkillAction(Mob mob, Optional<Position> position, boolean instant) {
79 this(mob, position, 1, instant);
80 }
81
85 public final void start() {
86 //determine if this task can be initialized.
87 if (!canInit()) {
88 return;
89 }
90
91 //reset any other action.
92 getMob().action.clearNonWalkableActions();
93
94 //submit this action.
95 getMob().action.execute(this, false);
96 position.ifPresent(getMob()::face);
97 }
98
104 public abstract boolean canInit();
105
109 public abstract void init();
110
114 public abstract void onExecute();
115
121 public abstract Optional<SkillAnimation> animation();
122
128 public abstract double experience();
129
133 public abstract int skill();
134
140 public boolean ignore() {
141 return false;
142 }
143
147 private int animationCounter;
148
149 @Override
150 protected final void onSchedule() {
151 if (!canRun() || !canInit()) {
152 this.cancel();
153 return;
154 }
155 if (animation().isPresent() && animation().get().instant) {
156 getMob().animate(animation().get().animation);
157 }
158 init();
159 }
160
161 @Override
162 protected final void execute() {
163 if (!canRun()) {
164 cancel();
165 return;
166 }
167
168 if (animation().isPresent() && animationCounter++ > animation().get().delay) {
169 getMob().animate(animation().get().animation);
170 animationCounter = 0;
171 }
172
173 onExecute();
174 }
175
183 public final class SkillAnimation {
184
188 public final Animation animation;
189
193 public final int delay;
194
198 public final boolean instant;
199
208 this.animation = animation;
209 this.delay = delay;
210 this.instant = instant;
211 }
212
220 this(animation, delay, true);
221 }
222 }
223}
SkillAnimation(Animation animation, int delay, boolean instant)
SkillAction(Mob mob, Optional< Position > position, boolean instant)
SkillAction(Mob mob, Optional< Position > position, int delay, boolean instant)
abstract Optional< SkillAnimation > animation()
Action(T mob, int delay, boolean instant)
Definition Action.java:24
synchronized final void cancel()
Definition Task.java:147