RuneHive-Game
Loading...
Searching...
No Matches
LeverAction.java
Go to the documentation of this file.
1package com.runehive.game.action.impl;
2
3import com.runehive.content.skill.impl.magic.teleport.Teleportation;
4import com.runehive.content.skill.impl.magic.teleport.TeleportationData;
5import com.runehive.game.Animation;
6import com.runehive.game.UpdatePriority;
7import com.runehive.game.action.Action;
8import com.runehive.game.action.policy.WalkablePolicy;
9import com.runehive.game.world.entity.mob.Direction;
10import com.runehive.game.world.entity.mob.player.Player;
11import com.runehive.game.world.object.GameObject;
12import com.runehive.game.world.position.Position;
13import com.runehive.net.packet.out.SendMessage;
14import com.runehive.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
29
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())) {
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) {
63 cancel();
64 }
65 count++;
66 }
67
68 @Override
69 protected void onCancel(boolean logout) {
70 getMob().locking.unlock();
71 }
72
73 @Override
77
78 @Override
79 public String getName() {
80 return "Lever action";
81 }
82
83 @Override
84 public boolean prioritized() {
85 return false;
86 }
87}
static void activateOverride(Mob mob, Position position, TeleportationData teleport)
Class that models a single animation used by an entity.
T getMob()
Gets the player.
Definition Action.java:44
final T mob
The Mob associated with this ActionEvent.
Definition Action.java:15
Action(T mob, int delay, boolean instant)
Creates a new Action randomevent.
Definition Action.java:24
boolean canSchedule()
A function executed on registration.
void execute()
A function representing the unit of work that will be carried out.
String getName()
Gets the name of this action.
void onCancel(boolean logout)
A function executed on cancellation.
boolean prioritized()
Determines if this action is prioritized.
LeverAction(Player mob, GameObject lever, Position position, Direction face)
LeverAction(Player mob, GameObject lever, Position position, Direction face, Predicate< Player > condition, String message)
WalkablePolicy getWalkablePolicy()
Gets the WalkablePolicy of this action.
void onSchedule()
A function executed on registration.
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.
Represents different priorities for updating.
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.
Holds an enum of colors for ease.