RuneHive-Game
Loading...
Searching...
No Matches
DoorAction.java
Go to the documentation of this file.
1package com.runehive.game.action.impl;
2
3import com.runehive.game.action.Action;
4import com.runehive.game.action.policy.WalkablePolicy;
5import com.runehive.game.world.entity.mob.Direction;
6import com.runehive.game.world.entity.mob.player.Player;
7import com.runehive.game.world.position.Position;
8import com.runehive.game.world.object.GameObject;
9import com.runehive.net.packet.out.SendMessage;
10import com.runehive.util.MessageColor;
11import com.runehive.util.Utility;
12
13import java.util.function.Predicate;
14
15/**
16 * Handles going through a door. (Cheap fix doesn't actually open the door)
17 *
18 * @author Daniel
19 */
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())) {
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();
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}
T getMob()
Gets the player.
Definition Action.java:44
Action(T mob, int delay, boolean instant)
Creates a new Action randomevent.
Definition Action.java:24
void onCancel(boolean logout)
A function executed on cancellation.
boolean prioritized()
Determines if this action is prioritized.
final Predicate< Player > condition
DoorAction(Player player, GameObject door, Position destination, Direction face)
boolean canSchedule()
A function executed on registration.
void execute()
A function representing the unit of work that will be carried out.
DoorAction(Player player, GameObject door, Position destination, Direction face, Predicate< Player > condition, String message)
WalkablePolicy getWalkablePolicy()
Gets the WalkablePolicy of this action.
String getName()
Gets the name of this action.
synchronized final void cancel()
Cancels all subsequent executions.
Definition Task.java:113
This class represents a character controlled by a player.
Definition Player.java:125
Represents a single tile on the game world.
Definition Position.java:14
The OutgoingPacket that sends a message to a Players chatbox in the client.
Handles miscellaneous methods.
Definition Utility.java:27
static boolean within(Position source, Position target, int distance)
Definition Utility.java:676
A queue policy determines whether the action can occur while walking.
NON_WALKABLE
This indicates actions cannot occur while walking.
Represents the enumerated directions an entity can walk or face.
static Direction getOppositeDirection(Direction direction)
Holds an enum of colors for ease.