RuneHive-Game
Loading...
Searching...
No Matches
TeleportAction.java
Go to the documentation of this file.
1package com.runehive.game.action.impl;
2
3import com.runehive.Config;
4import com.runehive.content.skill.impl.magic.teleport.TeleportationData;
5import com.runehive.game.Animation;
6import com.runehive.game.Graphic;
7import com.runehive.game.action.Action;
8import com.runehive.game.action.ConsecutiveAction;
9import com.runehive.game.action.policy.WalkablePolicy;
10import com.runehive.game.world.entity.mob.Mob;
11import com.runehive.game.world.entity.mob.UpdateFlag;
12import com.runehive.game.world.position.Position;
13import com.runehive.net.packet.out.SendMessage;
14import com.runehive.net.packet.out.SendString;
15
16/**
17 * Teleports an entity to another part of the world.
18 *
19 * @author Daniel
20 * @author Michael | Chex
21 */
22public final class TeleportAction extends ConsecutiveAction<Mob> {
23
24 /** The teleport position. */
25 private final Position position;
26
27 /** The teleportType */
28 private final TeleportationData type;
29
30 /** The destination randomevent */
31 private final Runnable onDestination;
32
33 /** Constructs a new {@code TeleportAction} object. */
35 super(entity);
36 this.position = position;
37 this.type = type;
38 this.onDestination = onDestination;
39 }
40
41 @Override
42 protected void onSchedule() {
43 if (getMob().isPlayer() && getMob().getPlayer().isTeleblocked()) {
44 cancel();
45 getMob().getPlayer().message("You are currently under the affects of a teleblock spell and can not teleport!");
46 return;
47 }
48
49 if (!valid(this)) {
50 cancel();
51 } else {
52 init();
53 }
54 }
55
56 private void init() {
57 add(this::start);
58 add(this::move);
60 add(this::end);
61 add(this::reset);
62 }
63
64 private boolean valid(Action<Mob> action) {
65 if (type == TeleportationData.HOME && action.getMob().getCombat().inCombat()) {
66 if (action.getMob().isPlayer()) {
67 action.getMob().getPlayer().send(new SendMessage("You can't teleport home while in combat!"));
68 }
69 cancel();
70 return false;
71 }
72 return true;
73 }
74
75 private void start(Action<Mob> action) {
77 action.getMob().inTeleport = true;
78
79 action.setDelay(type.getDelay());
80 action.getMob().movement.reset();
81 type.getStartAnimation().ifPresent(action.getMob()::animate);
82 type.getStartGraphic().ifPresent(action.getMob()::graphic);
83
84 if (type.lockMovement()) {
85 action.getMob().locking.lock();
86 }
87
89 addFirst(this::startTablet);
90 }
91 }
92
94 action.setDelay(type.getDelay());
95 type.getEndAnimation().ifPresent(action.getMob()::animate);
96 }
97
98 private void move(Action<Mob> action) {
99 if (valid(action)) {
100 action.setDelay(1);
101 action.getMob().move(position);
102 action.getMob().inTeleport = true;
103 action.getMob().teleporting = true;
104
105 if (action.getMob().isPlayer()) {
106 action.getMob().getPlayer().send(new SendString("[CLOSE_MENU]", 0));
107 }
108 } else {
109 reset(action);
110 onDestination.run();
111 }
112 }
113
114 private void end(Action<Mob> action) {
115 type.getEndGraphic().ifPresent(action.getMob()::graphic);
116 type.getEndAnimation().ifPresent(action.getMob()::animate);
117
118 if (type.getEndAnimation().isPresent() || type.getEndGraphic().isPresent()) {
119 action.setDelay(type.getDelay());
120 }
121
122 onDestination.run();
123 action.getMob().onStep();
124
125 //This is for overrides - updates appearance after teleport to account for duel arena
126 action.getMob().updateFlags.add(UpdateFlag.APPEARANCE);
127 }
128
129 private void reset(Action<Mob> action) {
130 action.getMob().inTeleport = false;
131 cancel();
132 }
133
134 @Override
135 protected void onCancel(boolean logout) {
136 getMob().animate(Animation.RESET, true);
137 getMob().graphic(Graphic.RESET, true);
138 getMob().inTeleport = false;
139 getMob().teleporting = false;
140
142 getMob().getPlayer().pvpInstance = false;
143 getMob().instance = Mob.DEFAULT_INSTANCE;
144 if (getMob().getPlayer().pet != null) {
145 getMob().getPlayer().pet.instance = getMob().instance;
146 }
147 }
148 }
149
150 @Override
151 public String getName() {
152 return "teleport_action";
153 }
154
155 @Override
156 public boolean prioritized() {
157 return false;
158 }
159
160 @Override
164
165}
Class that models a single animation used by an entity.
static final Animation RESET
Represents a single graphic that can be used by entities.
Definition Graphic.java:10
static final Graphic RESET
Definition Graphic.java:17
Represents an action an entity can execute.
Definition Action.java:12
void addFirst(Consumer< Action< T > > action)
Adds an action to the actions list.
ConsecutiveAction(T mob)
Generates a new ConsecutiveAction object.
void add(Consumer< Action< T > > action)
Adds an action to the actions list.
final TeleportationData type
The teleportType.
TeleportAction(Mob entity, Position position, TeleportationData type, Runnable onDestination)
Constructs a new TeleportAction object.
final Position position
The teleport position.
final Runnable onDestination
The destination randomevent.
Handles the mob class.
Definition Mob.java:66
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.
The OutgoingPacket that sends a string to a Players itemcontainer in the client.
A queue policy determines whether the action can occur while walking.
NON_WALKABLE
This indicates actions cannot occur while walking.