RuneHive-Tarnish
Neural OSRS Enhancement Framework
Loading...
Searching...
No Matches
LeverAction.java
1package com.osroyale.game.action.impl;
2
3import com.osroyale.content.skill.impl.magic.teleport.Teleportation;
4import com.osroyale.content.skill.impl.magic.teleport.TeleportationData;
5import com.osroyale.game.Animation;
6import com.osroyale.game.UpdatePriority;
7import com.osroyale.game.action.Action;
8import com.osroyale.game.action.policy.WalkablePolicy;
9import com.osroyale.game.world.entity.mob.Direction;
10import com.osroyale.game.world.entity.mob.player.Player;
11import com.osroyale.game.world.object.GameObject;
12import com.osroyale.game.world.position.Position;
13import com.osroyale.net.packet.out.SendMessage;
14import com.osroyale.util.MessageColor;
15
16import java.util.function.Predicate;
17
18public class LeverAction extends Action<Player> {
19 private int count;
20 private final GameObject lever;
21 private final Position position;
22 private final Direction face;
23 private final Predicate<Player> condition;
24 private final String message;
25
26 public LeverAction(Player mob, GameObject lever, Position position, Direction face) {
27 this(mob, lever, position, face, null, null);
28 }
29
30 private LeverAction(Player mob, GameObject lever, Position position, Direction face, Predicate<Player> condition, String message) {
31 super(mob, 1, false);
32 this.lever = lever;
33 this.position = position;
34 this.face = face;
35 this.condition = condition;
36 this.message = message;
37 }
38
39 @Override
40 protected boolean canSchedule() {
41 if (condition != null && !condition.test(getMob())) {
42 getMob().send(new SendMessage(message, MessageColor.RED));
43 return false;
44 }
45 return true;
46 }
47
48 @Override
49 protected void onSchedule() {
50 getMob().locking.lock();
51 getMob().face(position);
52 getMob().getCombat().reset();
53 getMob().damageImmunity.reset(3_000);
54 }
55
56 @Override
57 public void execute() {
58 if (count == 0) {
59 getMob().send(new SendMessage("You pull the lever..."));
60 getMob().animate(new Animation(2140, UpdatePriority.VERY_HIGH));
61 } else if (count == 1) {
62 Teleportation.activateOverride(getMob(), position, TeleportationData.MODERN);
63 cancel();
64 }
65 count++;
66 }
67
68 @Override
69 protected void onCancel(boolean logout) {
70 getMob().locking.unlock();
71 }
72
73 @Override
74 public WalkablePolicy getWalkablePolicy() {
75 return WalkablePolicy.NON_WALKABLE;
76 }
77
78 @Override
79 public String getName() {
80 return "Lever action";
81 }
82
83 @Override
84 public boolean prioritized() {
85 return false;
86 }
87}
abstract WalkablePolicy getWalkablePolicy()
synchronized final void cancel()
Definition Task.java:147