RuneHive-Game
Loading...
Searching...
No Matches
TeleportHandler.java
Go to the documentation of this file.
1package com.runehive.content.teleport;
2
3import com.runehive.content.activity.impl.barrows.Barrows;
4import com.runehive.content.activity.impl.godwars.GodwarsActivity;
5import com.runehive.content.activity.impl.warriorguild.WarriorGuild;
6import com.runehive.content.activity.inferno.Inferno;
7import com.runehive.content.dialogue.DialogueFactory;
8import com.runehive.content.skill.impl.magic.teleport.TeleportType;
9import com.runehive.content.skill.impl.magic.teleport.Teleportation;
10import com.runehive.game.world.entity.mob.player.Player;
11import com.runehive.game.world.entity.mob.player.PlayerRight;
12import com.runehive.game.world.items.Item;
13import com.runehive.game.world.position.Position;
14import com.runehive.net.packet.out.*;
15import com.runehive.util.Utility;
16
17import java.util.ArrayList;
18import java.util.List;
19
20/**
21 * Handles teleporting to various locations around OS Royale.
22 *
23 * @author Daniel
24 */
25public class TeleportHandler {
26
27 /** Holds the teleport titles names. */
28 private static final String[] TITLES = {"Favorites", "Minigames", "Skilling", "Monster Killing", "Player Killing", "Boss Killing"};
29
30 /** Opens the teleport itemcontainer. */
31 public static void open(Player player) {
32 open(player, TeleportType.FAVORITES, 0);
33 }
34
35 /** Opens the teleport itemcontainer. */
36 public static void open(Player player, TeleportType type) {
37 open(player, type, 0);
38 }
39
40 /** Opens the teleport itemcontainer to a certain teleportNoChecks type. */
41 public static void open(Player player, TeleportType type, int teleportIndex) {
42 List<Teleport> teleports = type == TeleportType.FAVORITES ? player.favoriteTeleport : getTeleports(type);
43 player.attributes.set("TELEPORT_TYPE_KEY", type);
44 if (player.attributes.get("TELEPORT_INDEX_KEY", Integer.class) == null)
45 player.attributes.set("TELEPORT_INDEX_KEY", 0);
46 int size = teleports.size();
47 for (int index = 0, string = 58009; index < 6; index++) {
48 String color = "<col=" + (type.ordinal() == index ? "ffffff" : "ff9933") + ">";
49 player.send(new SendString(color + TITLES[index], string));
50 string += 4;
51 }
52 for (int index = 0, string = 58052; index < (size < 9 ? 9 : size); index++, string += 2) {
53 if (index >= size) {
54 player.send(new SendString("", string));
55 continue;
56 }
57 Teleport teleport = teleports.get(index);
58 String prefex = teleportIndex == index ? "<col=ffffff>" : "</col>";
59 String favorite = player.favoriteTeleport.contains(teleport) ? "<clan=6> " : "";
60 player.send(new SendString(favorite + prefex + teleport.getName(), string));
61 }
62 if (type == TeleportType.FAVORITES && player.favoriteTeleport.isEmpty()) {
63 display(player, null);
64 } else {
65 display(player, teleports.get(teleportIndex));
66 }
67 player.send(new SendScrollbar(58050, size <= 9 ? 225 : (size * 25)));
68 player.interfaceManager.open(58000);
69 }
70
71 /** Displays all the teleport text on the itemcontainer. */
72 public static void display(Player player, Teleport teleport) {
73 player.attributes.set("TELEPORT", teleport);
74 player.send(new SendConfig(348, player.favoriteTeleport.contains(teleport) ? 0 : 1));
75
76 if (teleport != null) {
77 Item items[] = new Item[3];
78 for (int index = 0, count = 0; index < teleport.getDisplay().length; index++, count++) {
79 if (teleport.getDisplay()[index] == -1) {
80 items[count] = null;
81 continue;
82 }
83 Item item = new Item(teleport.getDisplay()[index]);
84 if (item.isStackable())
85 item.setAmount(50000);
86 items[count] = item;
87 }
88 player.send(new SendItemOnInterface(58041, items));
89 }
90
91 if (teleport != null && teleport.getStrings()[0].length() == 0 && teleport.getStrings()[1].length() == 0) {
92 player.send(new SendString(teleport.getName(), 58031));
93 player.send(new SendString("", 58032));
94 player.send(new SendString("", 58033));
95 return;
96 } else if (teleport == null) {
97 player.send(new SendString("", 58031));
98 player.send(new SendString("You do not have any teleport selected", 58032));
99 player.send(new SendString("", 58033));
100 player.send(new SendItemOnInterface(58041));
101 return;
102 }
103
104 player.send(new SendString(teleport.getName(), 58031));
105 player.send(new SendString("<col=ff7000>" + teleport.getStrings()[0], 58032));
106 player.send(new SendString("<col=ff7000>" + teleport.getStrings()[1], 58033));
107 }
108
109 /** Handles clicking teleport buttons on the itemcontainer. */
110 public static void click(Player player, int button) {
111 TeleportType type = player.attributes.get("TELEPORT_TYPE_KEY", TeleportType.class);
112 List<Teleport> teleports = type == TeleportType.FAVORITES ? player.favoriteTeleport : getTeleports(type);
113 int index = getOrdinal(button);
114 player.attributes.set("TELEPORT_INDEX_KEY", index);
115 open(player, type, index);
116 if (index < teleports.size()) {
117 display(player, teleports.get(index));
118 }
119 }
120
121 /** Handles teleporting to the destination. */
122 public static void teleport(Player player) {
123 if (player.wilderness > 20 && !PlayerRight.isAdministrator(player)) {
124 player.send(new SendMessage("You can't teleport past 20 wilderness!"));
125 return;
126 }
127
128
129 Teleport teleport = player.attributes.get("TELEPORT", Teleport.class);
130 if (teleport == null) {
131 player.send(new SendMessage("You have not selected a destination to teleport to!"));
132 return;
133 }
134 player.lastTeleport = teleport;
135 if (teleport.getName() == "Inferno") {
136 Inferno.create(player);
137 player.message("Welcome To Inferno " + player.getUsername());
138 }
139 if (teleport.isSpecial()) {
140 special(player, teleport);
141 return;
142 }
143 Teleportation.teleport(player, teleport.getPosition());
144 player.send(new SendMessage("You have teleported to " + teleport.getName() + ".", true));
145 }
146
147 /** Handles favorite a teleport. */
148 public static void favorite(Player player) {
149 Teleport teleport = player.attributes.get("TELEPORT", Teleport.class);
150 if (teleport == null) {
151 player.send(new SendMessage("You have not selected a teleport to favorite!"));
152 player.send(new SendConfig(348, 1));
153 return;
154 }
155 boolean isFavorite = player.favoriteTeleport.contains(teleport);
156 int index = player.attributes.get("TELEPORT_INDEX_KEY", Integer.class);
157 if (index == -1) {
158 index = 0;
159 }
160
161 if (isFavorite) {
162 player.favoriteTeleport.remove(teleport);
163 index = 0;
164 } else {
165 player.favoriteTeleport.add(teleport);
166 }
167
168 isFavorite = player.favoriteTeleport.contains(teleport);
169 player.send(new SendConfig(348, isFavorite ? 0 : 1));
170 player.send(new SendMessage("You have " + (isFavorite ? "" : "un-") + "favorited the " + teleport.getName() + " teleport."));
171 TeleportType type = player.attributes.get("TELEPORT_TYPE_KEY", TeleportType.class);
172 open(player, type, index);
173 }
174
175 /** Handles special case TELEPORT. */
176 public static void special(Player player, Teleport teleport) {
177 //TODO : Add birdhouse teleports. (https://oldschool.runescape.wiki/w/Bird_house_trapping#Locations) - Add teleport to fossil island tree, have tree display tele options.
178 if (player.isTeleblocked()) {
179 player.message("You are currently under the affects of a teleblock spell and can not teleport!");
180 return;
181 }
182
183 DialogueFactory factory = player.dialogueFactory;
184
185 switch (teleport) {
186 case FARMING:
187 factory.sendOption("Catherby", () -> {
188 Teleportation.teleport(player, new Position(2805, 3464, 0));
189 player.message(true, "You have teleported to the Catherby farming area.");
190 }, "Ardougne", () -> {
191 Teleportation.teleport(player, new Position(2662, 3375, 0));
192 player.message(true, "You have teleported to the Ardougne farming area.");
193 }, "Falador", () -> {
194 Teleportation.teleport(player, new Position(3056, 3310, 0));
195 player.message(true, "You have teleported to the Falador farming area.");
196 }, "Phasmatys", () -> {
197 Teleportation.teleport(player, new Position(3600, 3524, 0));
198 player.message(true, "You have teleported to the Phasmatys farming area.");
199 }).execute();
200 break;
201 case AGILITY:
202 factory.sendOption("Gnome agility course (Level 1 agility req.)", () -> {
203 Teleportation.teleport(player, new Position(2480, 3437, 0));
204 player.send(new SendMessage("You have teleported to the Gnome agility course.", true));
205 }, "Barbarian agility course (Level 35 agility req.)", () -> {
206 Teleportation.teleport(player, new Position(2546, 3551, 0));
207 player.send(new SendMessage("You have teleported to the Barbarian agility course.", true));
208 }, "Wilderness agility course (Level 49 agility req.)", () -> {
209 Teleportation.teleport(player, new Position(2998, 3915, 0));
210 player.send(new SendMessage("You have teleported to the Wilderness agility course.", true));
211 }, "Rooftop courses", () -> {
212 factory.sendStatement("Loading").sendOption("Seer's Village rooftop course (Level 60 agility req.)", () -> {
213 Teleportation.teleport(player, new Position(2729, 3488, 0));
214 player.send(new SendMessage("You have teleported to the Seer's Village rooftop agility course.", true));
215 }, "Ardougne rooftop course (Level 90 agility req.)", () -> {
216 Teleportation.teleport(player, new Position(2674, 3297, 0));
217 player.send(new SendMessage("You have teleported to the Ardougne rooftop agility course.", true));
218 }).execute();
219 }, "Nevermind", factory::clear).execute();
220 break;
221 case MINING:
222 factory.sendOption("Varrock", () -> {
223 Teleportation.teleport(player, new Position(3285, 3365, 0));
224 player.send(new SendMessage("You have teleported to the varrock mining area.", true));
225 }, "Falador", () -> {
226 Teleportation.teleport(player, new Position(3044, 9785, 0));
227 player.send(new SendMessage("You have teleported to the falador mining area.", true));
228 }, "Rune Essence", () -> {
229 Teleportation.teleport(player, new Position(2910, 4832, 0));
230 player.send(new SendMessage("You have teleported to the rune essence mining area.", true));
231 }, "Shilo Village", () -> {
232 Teleportation.teleport(player, new Position(2826, 2997, 0));
233 player.send(new SendMessage("You have teleported to the shilo village mining area.", true));
234 }, "Nevermind", factory::clear).execute();
235 break;
236 case RUNECRAFTING:
237 factory.sendOption("Abyss", () -> {
238 Teleportation.teleport(player, new Position(3039, 4836, 0));
239 player.send(new SendMessage("You have teleported to the abyss area.", true));
240 }, "Astral Altar", () -> {
241 Teleportation.teleport(player, new Position(2155, 3857, 0));
242 player.send(new SendMessage("You have teleported to the astral altar.", true));
243 }, "Wrath Altar", () -> {
244 Teleportation.teleport(player, new Position(2335, 4826, 0));
245 player.send(new SendMessage("You have teleported to the wrath altar.", true));
246 }, "Ournia Altar", () -> {
247 Teleportation.teleport(player, new Position(2464, 3249, 0));
248 player.send(new SendMessage("You have teleported to the ournia altar.", true));
249 }, "Nevermind", factory::clear).execute();
250 break;
251 case WOODCUTTING:
252 factory.sendOption("Camelot", () -> {
253 Teleportation.teleport(player, new Position(2724, 3475, 0));
254 player.send(new SendMessage("You have teleported to the camelot woodcutting area.", true));
255 }, "Woodcutting Guild", () -> {
256 Teleportation.teleport(player, new Position(1587, 3488, 0));
257 player.send(new SendMessage("You have teleported to the woodcutting guild.", true));
258 }, "Nevermind", factory::clear).execute();
259 break;
260 case HUNTER:
261 factory.sendOption("Puro Puro", () -> {
262 Position[] teleports = {new Position(2619, 4292), new Position(2564, 4292), new Position(2564, 4347), new Position(2619, 4347)};
263 Teleportation.teleport(player, Utility.randomElement(teleports));
264 player.send(new SendMessage("You have teleported to the puro puro hunter area.", true));
265 }, "Nevermind", factory::clear).execute();
266 break;
267 case FISHING:
268 factory.sendOption("Catherby", () -> {
269 Teleportation.teleport(player, new Position(2809, 3435, 0));
270 player.send(new SendMessage("You have teleported to the catherby fishing area.", true));
271 }, "Fishing Guild", () -> {
272 if(player.skills.getLevel(10) >= 68) {
273 Teleportation.teleport(player, new Position(2594, 3415, 0));
274 player.send(new SendMessage("You have teleported to the fishing guild.", true));
275 } else {
276 player.send(new SendMessage("You need 68 fishing to access the fishing guild."));
277
278 }
279 }, "Nevermind", factory::clear).execute();
280 break;
281 case GODWARS:
282 Teleportation.teleport(player, new Position(2882, 5308, 2), 20, () -> GodwarsActivity.create(player));
283
284
285 /* factory.sendOption("General Graardor", () -> {
286 Teleportation.teleport(player, new Position(2864, 5354, 2));
287 player.send(new SendMessage("You have teleported to the General Graardor boss."));
288 }, "Commander Zilyana", () -> {
289 Teleportation.teleport(player, new Position(2907, 5265, 0));
290 player.send(new SendMessage("You have teleported to the Commander Zilyana boss."));
291 }, "K'ril Tsutsaroth", () -> {
292 Teleportation.teleport(player, new Position(2925, 5331, 2));
293 player.send(new SendMessage("You have teleported to the K'ril Tsutsaroth boss."));
294 }, "Kree'arra", () -> {
295 Teleportation.teleport(player, new Position(2839, 5296, 2));
296 player.send(new SendMessage("You have teleported to the Kree'arra boss."));
297 }, "Nevermind", factory::clear).execute();*/
298 break;
299 case WARRIOR_GUILD:
300 Teleportation.teleport(player, new Position(2846, 3541, 0), 20, () -> WarriorGuild.create(player));
301 break;
302 case BARROWS:
303 Teleportation.teleport(player, new Position(3565, 3315, 0), 20, () -> Barrows.create(player));
304 break;
305 }
306 }
307
308 /** Gets a list of teleports based off the teleport type. */
309 private static List<Teleport> getTeleports(TeleportType type) {
310 List<Teleport> list = new ArrayList<>();
311 for (Teleport t : Teleport.values()) {
312 if (t.getType() == type) list.add(t);
313 }
314 return list;
315 }
316
317 /** Gets the ordinal of a teleport based on the list ordinal. */
318 private static int getOrdinal(int button) {
319 int base_button = -7484;
320 int ordinal = Math.abs((base_button - button) / 2);
321 return ordinal;
322 }
323}
static GodwarsActivity create(Player player)
Creates the godwars activity for the player.
This class handles the warrior's guild activity.
static WarriorGuild create(Player player)
Handes creating a new warrior guild activity for the player.
static Inferno create(Player player)
Definition Inferno.java:58
Represents a factory class that contains important functions for building dialogues.
final DialogueFactory sendStatement(String... lines)
Appends a StatementDialogue to the current dialogue chain.
final DialogueFactory sendOption(String option1, Runnable action1, String option2, Runnable action2)
Appends the OptionDialogue onto the current dialogue chain.
static boolean teleport(Player player, Position position)
Handles teleporting to various locations around OS Royale.
static void click(Player player, int button)
Handles clicking teleport buttons on the itemcontainer.
static void teleport(Player player)
Handles teleporting to the destination.
static int getOrdinal(int button)
Gets the ordinal of a teleport based on the list ordinal.
static void display(Player player, Teleport teleport)
Displays all the teleport text on the itemcontainer.
static void open(Player player)
Opens the teleport itemcontainer.
static void open(Player player, TeleportType type, int teleportIndex)
Opens the teleport itemcontainer to a certain teleportNoChecks type.
static final String[] TITLES
Holds the teleport titles names.
static void open(Player player, TeleportType type)
Opens the teleport itemcontainer.
static void favorite(Player player)
Handles favorite a teleport.
static void special(Player player, Teleport teleport)
Handles special case TELEPORT.
static List< Teleport > getTeleports(TeleportType type)
Gets a list of teleports based off the teleport type.
final GenericAttributes attributes
Definition Mob.java:95
void open(int identification)
Opens an interface for the player.
This class represents a character controlled by a player.
Definition Player.java:125
int getLevel(int id)
Gets the level of a skill.
The container class that represents an item that can be interacted with.
Definition Item.java:21
final void setAmount(int amount)
Sets the quantity of this item.
Definition Item.java:351
Represents a single tile on the game world.
Definition Position.java:14
The OutgoingPacket responsible for changing settings on a client.
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.
Handles miscellaneous methods.
Definition Utility.java:27
static< T > T randomElement(Collection< T > collection)
Picks a random element out of any array type.
Definition Utility.java:248
public< K, E > E get(K key)
Gets a generic attribute.
public< K, E > void set(K key, E attribute)
Sets a generic attribute.
static boolean isAdministrator(Player player)
Checks if the player is a privileged member.