RuneHive-Game
Loading...
Searching...
No Matches
LadderAction.java
Go to the documentation of this file.
1package com.runehive.game.action.impl;
2
3import com.runehive.game.Animation;
4import com.runehive.game.UpdatePriority;
5import com.runehive.game.action.Action;
6import com.runehive.game.action.policy.WalkablePolicy;
7import com.runehive.game.world.entity.mob.player.Player;
8import com.runehive.game.world.object.GameObject;
9import com.runehive.game.world.position.Position;
10import com.runehive.net.packet.out.SendMessage;
11import com.runehive.util.MessageColor;
12
13import java.util.function.Predicate;
14
15/**
16 * Created by Daniel on 2017-10-12.
17 */
18public class LadderAction extends Action<Player> {
19 private int count;
20 private final GameObject ladder;
21 private final Position position;
22 private final Predicate<Player> condition;
23 private final String message;
24
26 this(mob, ladder, position, null, null);
27 }
28
29 public LadderAction(Player mob, GameObject ladder, Position position, Predicate<Player> condition, String message) {
30 super(mob, 1, false);
31 this.ladder = ladder;
32 this.position = position;
33 this.condition = condition;
34 this.message = message;
35 }
36
37 @Override
38 protected boolean canSchedule() {
39 if (condition != null && !condition.test(getMob())) {
41 return false;
42 }
43 return true;
44 }
45
46 @Override
47 protected void onSchedule() {
48 getMob().locking.lock();
49 getMob().face(ladder.getPosition());
50 getMob().getCombat().reset();
51 getMob().damageImmunity.reset(3_000);
52 }
53
54 @Override
55 public void execute() {
56 if (count == 0) {
57 getMob().animate(new Animation(828, UpdatePriority.VERY_HIGH));
58 } else if (count == 1) {
59 getMob().move(position);
60 cancel();
61 }
62 count++;
63 }
64
65 @Override
66 protected void onCancel(boolean logout) {
67 }
68
69 @Override
73
74 @Override
75 public String getName() {
76 return "Ladder action";
77 }
78
79 @Override
80 public boolean prioritized() {
81 return false;
82 }
83}
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
LadderAction(Player mob, GameObject ladder, Position position, Predicate< Player > condition, String message)
WalkablePolicy getWalkablePolicy()
Gets the WalkablePolicy of this action.
boolean prioritized()
Determines if this action is prioritized.
boolean canSchedule()
A function executed on registration.
void execute()
A function representing the unit of work that will be carried out.
LadderAction(Player mob, GameObject ladder, Position position)
void onSchedule()
A function executed on registration.
String getName()
Gets the name of this action.
void onCancel(boolean logout)
A function executed on cancellation.
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.
Holds an enum of colors for ease.