RuneHive-Tarnish
Neural OSRS Enhancement Framework
Loading...
Searching...
No Matches
DoorAction.java
1package com.osroyale.game.action.impl;
2
3import com.osroyale.game.action.Action;
4import com.osroyale.game.action.policy.WalkablePolicy;
5import com.osroyale.game.world.entity.mob.Direction;
6import com.osroyale.game.world.entity.mob.player.Player;
7import com.osroyale.game.world.position.Position;
8import com.osroyale.game.world.object.GameObject;
9import com.osroyale.net.packet.out.SendMessage;
10import com.osroyale.util.MessageColor;
11import com.osroyale.util.Utility;
12
13import java.util.function.Predicate;
14
20public final class DoorAction extends Action<Player> {
21 private int count;
22 private final GameObject door;
23 private final Position position;
24 private final Predicate<Player> condition;
25 private final String message;
26 private final Direction face;
27
28 public DoorAction(Player player, GameObject door, Position destination, Direction face) {
29 this(player, door, destination, face, null, null);
30 }
31
32 public DoorAction(Player player, GameObject door, Position destination, Direction face, Predicate<Player> condition, String message) {
33 super(player, 1, true);
34 this.count = 0;
35 this.door = door;
36 this.position = destination;
37 this.face = face;
38 this.condition = condition;
39 this.message = message;
40 }
41
42 @Override
43 protected boolean canSchedule() {
44 if (condition != null && !condition.test(getMob())) {
45 getMob().send(new SendMessage(message, MessageColor.RED));
46 return false;
47 }
48 return true;
49 }
50
51 @Override
52 public void execute() {
53 if (!Utility.within(getMob().getPosition(), door.getPosition(), 1)) {
54 if (!getMob().movement.isMoving())
55 getMob().walk(door.getPosition());
56 return;
57 }
58
59 if (getMob().getCombat().inCombat())
60 getMob().getCombat().reset();
61
62 if (count == 0) {
63 getMob().face(face);
64 getMob().locking.lock();
65 } else if (count == 1) {
66 getMob().move(position);
67 getMob().locking.unlock();
68 getMob().face(Direction.getOppositeDirection(face));
69 cancel();
70 }
71 count++;
72 }
73
74 @Override
75 protected void onCancel(boolean logout) {
76 getMob().locking.unlock();
77 }
78
79 @Override
80 public String getName() {
81 return "Open door";
82 }
83
84 @Override
85 public boolean prioritized() {
86 return false;
87 }
88
89 @Override
93}
Action(T mob, int delay, boolean instant)
Definition Action.java:24
synchronized final void cancel()
Definition Task.java:147