RuneHive-Tarnish
Neural OSRS Enhancement Framework
Loading...
Searching...
No Matches
TeleportAction.java
1package com.osroyale.game.action.impl;
2
3import com.osroyale.Config;
4import com.osroyale.content.skill.impl.magic.teleport.TeleportationData;
5import com.osroyale.game.Animation;
6import com.osroyale.game.Graphic;
7import com.osroyale.game.action.Action;
8import com.osroyale.game.action.ConsecutiveAction;
9import com.osroyale.game.action.policy.WalkablePolicy;
10import com.osroyale.game.world.entity.mob.Mob;
11import com.osroyale.game.world.entity.mob.UpdateFlag;
12import com.osroyale.game.world.position.Position;
13import com.osroyale.net.packet.out.SendMessage;
14import com.osroyale.net.packet.out.SendString;
15
22public final class TeleportAction extends ConsecutiveAction<Mob> {
23
25 private final Position position;
26
28 private final TeleportationData type;
29
31 private final Runnable onDestination;
32
34 public TeleportAction(Mob entity, Position position, TeleportationData type, Runnable onDestination) {
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);
59 if (type != TeleportationData.TABLET)
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) {
76 if (type != TeleportationData.HOME)
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
88 if (type == TeleportationData.TABLET) {
89 addFirst(this::startTablet);
90 }
91 }
92
93 private void startTablet(Action<Mob> action) {
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
141 if (type == TeleportationData.TABLET) {
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
161 public WalkablePolicy getWalkablePolicy() {
162 return WalkablePolicy.NON_WALKABLE;
163 }
164
165}
abstract WalkablePolicy getWalkablePolicy()
Action(T mob, int delay, boolean instant)
Definition Action.java:24
TeleportAction(Mob entity, Position position, TeleportationData type, Runnable onDestination)