RuneHive-Tarnish
Neural OSRS Enhancement Framework
Loading...
Searching...
No Matches
TeleportHandler.java
1package com.osroyale.content.teleport;
2
3import com.osroyale.content.activity.impl.barrows.Barrows;
4import com.osroyale.content.activity.impl.godwars.GodwarsActivity;
5import com.osroyale.content.activity.impl.warriorguild.WarriorGuild;
6import com.osroyale.content.activity.inferno.Inferno;
7import com.osroyale.content.dialogue.DialogueFactory;
8import com.osroyale.content.skill.impl.magic.teleport.TeleportType;
9import com.osroyale.content.skill.impl.magic.teleport.Teleportation;
10import com.osroyale.game.world.entity.mob.player.Player;
11import com.osroyale.game.world.entity.mob.player.PlayerRight;
12import com.osroyale.game.world.items.Item;
13import com.osroyale.game.world.position.Position;
14import com.osroyale.net.packet.out.*;
15import com.osroyale.util.Utility;
16
17import java.util.ArrayList;
18import java.util.List;
19
61
62public class TeleportHandler {
63
65 private static final String[] TITLES = {"Favorites", "Minigames", "Skilling", "Monster Killing", "Player Killing", "Boss Killing"};
66
68 public static void open(Player player) {
69 open(player, TeleportType.FAVORITES, 0);
70 }
71
73 public static void open(Player player, TeleportType type) {
74 open(player, type, 0);
75 }
76
78 public static void open(Player player, TeleportType type, int teleportIndex) {
79 List<Teleport> teleports = type == TeleportType.FAVORITES ? player.favoriteTeleport : getTeleports(type);
80 player.attributes.set("TELEPORT_TYPE_KEY", type);
81 if (player.attributes.get("TELEPORT_INDEX_KEY", Integer.class) == null)
82 player.attributes.set("TELEPORT_INDEX_KEY", 0);
83 int size = teleports.size();
84 for (int index = 0, string = 58009; index < 6; index++) {
85 String color = "<col=" + (type.ordinal() == index ? "ffffff" : "ff9933") + ">";
86 player.send(new SendString(color + TITLES[index], string));
87 string += 4;
88 }
89 for (int index = 0, string = 58052; index < (size < 9 ? 9 : size); index++, string += 2) {
90 if (index >= size) {
91 player.send(new SendString("", string));
92 continue;
93 }
94 Teleport teleport = teleports.get(index);
95 String prefex = teleportIndex == index ? "<col=ffffff>" : "</col>";
96 String favorite = player.favoriteTeleport.contains(teleport) ? "<clan=6> " : "";
97 player.send(new SendString(favorite + prefex + teleport.getName(), string));
98 }
99 if (type == TeleportType.FAVORITES && player.favoriteTeleport.isEmpty()) {
100 display(player, null);
101 } else {
102 display(player, teleports.get(teleportIndex));
103 }
104 player.send(new SendScrollbar(58050, size <= 9 ? 225 : (size * 25)));
105 player.interfaceManager.open(58000);
106 }
107
109 public static void display(Player player, Teleport teleport) {
110 player.attributes.set("TELEPORT", teleport);
111 player.send(new SendConfig(348, player.favoriteTeleport.contains(teleport) ? 0 : 1));
112
113 if (teleport != null) {
114 Item items[] = new Item[3];
115 for (int index = 0, count = 0; index < teleport.getDisplay().length; index++, count++) {
116 if (teleport.getDisplay()[index] == -1) {
117 items[count] = null;
118 continue;
119 }
120 Item item = new Item(teleport.getDisplay()[index]);
121 if (item.isStackable())
122 item.setAmount(50000);
123 items[count] = item;
124 }
125 player.send(new SendItemOnInterface(58041, items));
126 }
127
128 if (teleport != null && teleport.getStrings()[0].length() == 0 && teleport.getStrings()[1].length() == 0) {
129 player.send(new SendString(teleport.getName(), 58031));
130 player.send(new SendString("", 58032));
131 player.send(new SendString("", 58033));
132 return;
133 } else if (teleport == null) {
134 player.send(new SendString("", 58031));
135 player.send(new SendString("You do not have any teleport selected", 58032));
136 player.send(new SendString("", 58033));
137 player.send(new SendItemOnInterface(58041));
138 return;
139 }
140
141 player.send(new SendString(teleport.getName(), 58031));
142 player.send(new SendString("<col=ff7000>" + teleport.getStrings()[0], 58032));
143 player.send(new SendString("<col=ff7000>" + teleport.getStrings()[1], 58033));
144 }
145
147 public static void click(Player player, int button) {
148 TeleportType type = player.attributes.get("TELEPORT_TYPE_KEY", TeleportType.class);
149 List<Teleport> teleports = type == TeleportType.FAVORITES ? player.favoriteTeleport : getTeleports(type);
150 int index = getOrdinal(button);
151 player.attributes.set("TELEPORT_INDEX_KEY", index);
152 open(player, type, index);
153 if (index < teleports.size()) {
154 display(player, teleports.get(index));
155 }
156 }
157
159 public static void teleport(Player player) {
160 if (player.wilderness > 20 && !PlayerRight.isAdministrator(player)) {
161 player.send(new SendMessage("You can't teleport past 20 wilderness!"));
162 return;
163 }
164
165
166 Teleport teleport = player.attributes.get("TELEPORT", Teleport.class);
167 if (teleport == null) {
168 player.send(new SendMessage("You have not selected a destination to teleport to!"));
169 return;
170 }
171 player.lastTeleport = teleport;
172 if (teleport.getName() == "Inferno") {
173 Inferno.create(player);
174 player.message("Welcome To Inferno " + player.getUsername());
175 }
176 if (teleport.isSpecial()) {
177 special(player, teleport);
178 return;
179 }
180 Teleportation.teleport(player, teleport.getPosition());
181 player.send(new SendMessage("You have teleported to " + teleport.getName() + ".", true));
182 }
183
185 public static void favorite(Player player) {
186 Teleport teleport = player.attributes.get("TELEPORT", Teleport.class);
187 if (teleport == null) {
188 player.send(new SendMessage("You have not selected a teleport to favorite!"));
189 player.send(new SendConfig(348, 1));
190 return;
191 }
192 boolean isFavorite = player.favoriteTeleport.contains(teleport);
193 int index = player.attributes.get("TELEPORT_INDEX_KEY", Integer.class);
194 if (index == -1) {
195 index = 0;
196 }
197
198 if (isFavorite) {
199 player.favoriteTeleport.remove(teleport);
200 index = 0;
201 } else {
202 player.favoriteTeleport.add(teleport);
203 }
204
205 isFavorite = player.favoriteTeleport.contains(teleport);
206 player.send(new SendConfig(348, isFavorite ? 0 : 1));
207 player.send(new SendMessage("You have " + (isFavorite ? "" : "un-") + "favorited the " + teleport.getName() + " teleport."));
208 TeleportType type = player.attributes.get("TELEPORT_TYPE_KEY", TeleportType.class);
209 open(player, type, index);
210 }
211
213 public static void special(Player player, Teleport teleport) {
214 //TODO : Add birdhouse teleports. (https://oldschool.runescape.wiki/w/Bird_house_trapping#Locations) - Add teleport to fossil island tree, have tree display tele options.
215 if (player.isTeleblocked()) {
216 player.message("You are currently under the affects of a teleblock spell and can not teleport!");
217 return;
218 }
219
220 DialogueFactory factory = player.dialogueFactory;
221
222 switch (teleport) {
223 case FARMING:
224 factory.sendOption("Catherby", () -> {
225 Teleportation.teleport(player, new Position(2805, 3464, 0));
226 player.message(true, "You have teleported to the Catherby farming area.");
227 }, "Ardougne", () -> {
228 Teleportation.teleport(player, new Position(2662, 3375, 0));
229 player.message(true, "You have teleported to the Ardougne farming area.");
230 }, "Falador", () -> {
231 Teleportation.teleport(player, new Position(3056, 3310, 0));
232 player.message(true, "You have teleported to the Falador farming area.");
233 }, "Phasmatys", () -> {
234 Teleportation.teleport(player, new Position(3600, 3524, 0));
235 player.message(true, "You have teleported to the Phasmatys farming area.");
236 }).execute();
237 break;
238 case AGILITY:
239 factory.sendOption("Gnome agility course (Level 1 agility req.)", () -> {
240 Teleportation.teleport(player, new Position(2480, 3437, 0));
241 player.send(new SendMessage("You have teleported to the Gnome agility course.", true));
242 }, "Barbarian agility course (Level 35 agility req.)", () -> {
243 Teleportation.teleport(player, new Position(2546, 3551, 0));
244 player.send(new SendMessage("You have teleported to the Barbarian agility course.", true));
245 }, "Wilderness agility course (Level 49 agility req.)", () -> {
246 Teleportation.teleport(player, new Position(2998, 3915, 0));
247 player.send(new SendMessage("You have teleported to the Wilderness agility course.", true));
248 }, "Rooftop courses", () -> {
249 factory.sendStatement("Loading").sendOption("Seer's Village rooftop course (Level 60 agility req.)", () -> {
250 Teleportation.teleport(player, new Position(2729, 3488, 0));
251 player.send(new SendMessage("You have teleported to the Seer's Village rooftop agility course.", true));
252 }, "Ardougne rooftop course (Level 90 agility req.)", () -> {
253 Teleportation.teleport(player, new Position(2674, 3297, 0));
254 player.send(new SendMessage("You have teleported to the Ardougne rooftop agility course.", true));
255 }).execute();
256 }, "Nevermind", factory::clear).execute();
257 break;
258 case MINING:
259 factory.sendOption("Varrock", () -> {
260 Teleportation.teleport(player, new Position(3285, 3365, 0));
261 player.send(new SendMessage("You have teleported to the varrock mining area.", true));
262 }, "Falador", () -> {
263 Teleportation.teleport(player, new Position(3044, 9785, 0));
264 player.send(new SendMessage("You have teleported to the falador mining area.", true));
265 }, "Rune Essence", () -> {
266 Teleportation.teleport(player, new Position(2910, 4832, 0));
267 player.send(new SendMessage("You have teleported to the rune essence mining area.", true));
268 }, "Shilo Village", () -> {
269 Teleportation.teleport(player, new Position(2826, 2997, 0));
270 player.send(new SendMessage("You have teleported to the shilo village mining area.", true));
271 }, "Nevermind", factory::clear).execute();
272 break;
273 case RUNECRAFTING:
274 factory.sendOption("Abyss", () -> {
275 Teleportation.teleport(player, new Position(3039, 4836, 0));
276 player.send(new SendMessage("You have teleported to the abyss area.", true));
277 }, "Astral Altar", () -> {
278 Teleportation.teleport(player, new Position(2155, 3857, 0));
279 player.send(new SendMessage("You have teleported to the astral altar.", true));
280 }, "Wrath Altar", () -> {
281 Teleportation.teleport(player, new Position(2335, 4826, 0));
282 player.send(new SendMessage("You have teleported to the wrath altar.", true));
283 }, "Ournia Altar", () -> {
284 Teleportation.teleport(player, new Position(2464, 3249, 0));
285 player.send(new SendMessage("You have teleported to the ournia altar.", true));
286 }, "Nevermind", factory::clear).execute();
287 break;
288 case WOODCUTTING:
289 factory.sendOption("Camelot", () -> {
290 Teleportation.teleport(player, new Position(2724, 3475, 0));
291 player.send(new SendMessage("You have teleported to the camelot woodcutting area.", true));
292 }, "Woodcutting Guild", () -> {
293 Teleportation.teleport(player, new Position(1587, 3488, 0));
294 player.send(new SendMessage("You have teleported to the woodcutting guild.", true));
295 }, "Nevermind", factory::clear).execute();
296 break;
297 case HUNTER:
298 factory.sendOption("Puro Puro", () -> {
299 Position[] teleports = {new Position(2619, 4292), new Position(2564, 4292), new Position(2564, 4347), new Position(2619, 4347)};
300 Teleportation.teleport(player, Utility.randomElement(teleports));
301 player.send(new SendMessage("You have teleported to the puro puro hunter area.", true));
302 }, "Nevermind", factory::clear).execute();
303 break;
304 case FISHING:
305 factory.sendOption("Catherby", () -> {
306 Teleportation.teleport(player, new Position(2809, 3435, 0));
307 player.send(new SendMessage("You have teleported to the catherby fishing area.", true));
308 }, "Fishing Guild", () -> {
309 if(player.skills.getLevel(10) >= 68) {
310 Teleportation.teleport(player, new Position(2594, 3415, 0));
311 player.send(new SendMessage("You have teleported to the fishing guild.", true));
312 } else {
313 player.send(new SendMessage("You need 68 fishing to access the fishing guild."));
314
315 }
316 }, "Nevermind", factory::clear).execute();
317 break;
318 case GODWARS:
319 Teleportation.teleport(player, new Position(2882, 5308, 2), 20, () -> GodwarsActivity.create(player));
320
321
322 /* factory.sendOption("General Graardor", () -> {
323 Teleportation.teleport(player, new Position(2864, 5354, 2));
324 player.send(new SendMessage("You have teleported to the General Graardor boss."));
325 }, "Commander Zilyana", () -> {
326 Teleportation.teleport(player, new Position(2907, 5265, 0));
327 player.send(new SendMessage("You have teleported to the Commander Zilyana boss."));
328 }, "K'ril Tsutsaroth", () -> {
329 Teleportation.teleport(player, new Position(2925, 5331, 2));
330 player.send(new SendMessage("You have teleported to the K'ril Tsutsaroth boss."));
331 }, "Kree'arra", () -> {
332 Teleportation.teleport(player, new Position(2839, 5296, 2));
333 player.send(new SendMessage("You have teleported to the Kree'arra boss."));
334 }, "Nevermind", factory::clear).execute();*/
335 break;
336 case WARRIOR_GUILD:
337 Teleportation.teleport(player, new Position(2846, 3541, 0), 20, () -> WarriorGuild.create(player));
338 break;
339 case BARROWS:
340 Teleportation.teleport(player, new Position(3565, 3315, 0), 20, () -> Barrows.create(player));
341 break;
342 }
343 }
344
346 private static List<Teleport> getTeleports(TeleportType type) {
347 List<Teleport> list = new ArrayList<>();
348 for (Teleport t : Teleport.values()) {
349 if (t.getType() == type) list.add(t);
350 }
351 return list;
352 }
353
355 private static int getOrdinal(int button) {
356 int base_button = -7484;
357 int ordinal = Math.abs((base_button - button) / 2);
358 return ordinal;
359 }
360}
final DialogueFactory sendStatement(String... lines)
final DialogueFactory sendOption(String option1, Runnable action1, String option2, Runnable action2)
static void open(Player player, TeleportType type)
static void special(Player player, Teleport teleport)
static void open(Player player, TeleportType type, int teleportIndex)
static void click(Player player, int button)
static void display(Player player, Teleport teleport)
static< T > T randomElement(Collection< T > collection)
Definition Utility.java:285