RuneHive-Game
Loading...
Searching...
No Matches
Obelisks.java
Go to the documentation of this file.
1package com.runehive.content;
2
3import com.runehive.content.skill.impl.magic.teleport.Teleportation;
4import com.runehive.content.skill.impl.magic.teleport.TeleportationData;
5import com.runehive.content.writer.InterfaceWriter;
6import com.runehive.content.writer.impl.ObeliskWriter;
7import com.runehive.game.task.Task;
8import com.runehive.game.task.impl.ObjectReplacementEvent;
9import com.runehive.game.world.World;
10import com.runehive.game.world.entity.mob.player.Player;
11import com.runehive.game.world.entity.mob.player.PlayerRight;
12import com.runehive.game.world.object.GameObject;
13import com.runehive.game.world.position.Boundary;
14import com.runehive.game.world.position.Position;
15import com.runehive.net.packet.out.SendMessage;
16import com.runehive.net.packet.out.SendString;
17import com.runehive.util.Utility;
18
19import java.util.*;
20
21/**
22 * Created by Daniel on 2017-11-24.
23 */
24public class Obelisks {
25
26 private static Map<Integer, Boolean> state = new HashMap<>();
27 private static Obelisks INSTANCE = new Obelisks();
28
29 public static Obelisks get() {
30 return INSTANCE;
31 }
32
33 static {
34 for (ObeliskData location : ObeliskData.values()) {
35 state.put(location.objectId, false);
36 }
37 }
38
39 public void open(Player player, int obj) {
40 if (!PlayerRight.isSuper(player)) {
41 player.dialogueFactory.sendStatement("You need to be a super donator to use this feature!").execute();
42 return;
43 }
44 player.attributes.set("OBELISK", obj);
46 player.send(new SendString("Wilderness Obelisk", 51002));
47 player.send(new SendString("Click on the obelisk you would like to teleport too", 51003));
48 player.interfaceManager.open(51000);
49 }
50
51 public boolean activate(Player player, int objectId) {
52 ObeliskData location = ObeliskData.forObject(objectId);
53 return location != null && activate(player, objectId, ObeliskData.getRandom(location));
54 }
55
56 public boolean activate(Player player, int objectId, ObeliskData destination) {
57 ObeliskData location = ObeliskData.forObject(objectId);
58
59 if (location == null)
60 return false;
61
62 boolean active = state.get(objectId);
63
64 if (active) {
65 player.send(new SendMessage("The obelisk is already active, please wait."));
66 return true;
67 }
68
69 state.put(objectId, true);
70 int x = location.getBoundaries().getMinimumX();
71 int y = location.getBoundaries().getMinimumY();
72 GameObject one = World.getRegions().getRegion(player.getPosition()).getGameObject(objectId, new Position(x, y, player.getHeight()));
73 GameObject two = World.getRegions().getRegion(player.getPosition()).getGameObject(objectId, new Position(x + 4, y, player.getHeight()));
74 GameObject three = World.getRegions().getRegion(player.getPosition()).getGameObject(objectId, new Position(x, y + 4, player.getHeight()));
75 GameObject four = World.getRegions().getRegion(player.getPosition()).getGameObject(objectId, new Position(x + 4, y + 4, player.getHeight()));
76 World.schedule(new ObjectReplacementEvent(one, 14825, 15));
77 World.schedule(new ObjectReplacementEvent(two, 14825, 15));
78 World.schedule(new ObjectReplacementEvent(three, 14825, 15));
79 World.schedule(new ObjectReplacementEvent(four, 14825, 15));
80 player.attributes.set("OBELISK", -1);
81
82 World.schedule(new Task(14) {
83 @Override
84 protected void execute() {
85 state.put(location.objectId, false);
86 Boundary boundary = new Boundary(location.boundary.getMinimumX() + 1, location.boundary.getMinimumY() + 1, location.boundary.getMinimumX() + 3, location.boundary.getMinimumY() + 3);
87 List<Player> players = Boundary.getPlayers(boundary);
88
89 if (players.size() > 0) {
90 for (Player p : players) {
91 if (p.isDead())
92 continue;
93 int x = destination.getBoundaries().getMinimumX() + 1;
94 int y = destination.getBoundaries().getMinimumY() + 1;
95 Position position = new Position(x + Utility.random(2), y + Utility.random(2), player.getHeight());
97 }
98 }
99 cancel();
100 }
101 });
102 return true;
103 }
104
105 public enum ObeliskData {
106 LEVEL_13(14829, new Boundary(3154, 3618, 3158, 3622)),
107 LEVEL_19(14830, new Boundary(3225, 3665, 3229, 3669)),
108 LEVEL_27(14827, new Boundary(3033, 3730, 3037, 3734)),
109 LEVEL_35(14828, new Boundary(3104, 3792, 3108, 3796)),
110 LEVEL_44(14826, new Boundary(2978, 3864, 2982, 3868)),
111 LEVEL_50(14831, new Boundary(3305, 3914, 3309, 3918));
112
113 private final int objectId;
114 private final Boundary boundary;
115
117 this.objectId = objectId;
118 this.boundary = boundary;
119 }
120
122 return boundary;
123 }
124
126 for (ObeliskData l : values()) {
127 if (l.objectId == objectId) {
128 return l;
129 }
130 }
131 return null;
132 }
133
135 ArrayList<ObeliskData> locations = new ArrayList<>(Arrays.asList(values()));
136 locations.remove(exclude);
137 return locations.get(Utility.random(locations.size() - 1));
138 }
139 }
140}
141
142
Created by Daniel on 2017-11-24.
Definition Obelisks.java:24
boolean activate(Player player, int objectId)
Definition Obelisks.java:51
static Map< Integer, Boolean > state
Definition Obelisks.java:26
void open(Player player, int obj)
Definition Obelisks.java:39
boolean activate(Player player, int objectId, ObeliskData destination)
Definition Obelisks.java:56
final DialogueFactory execute()
Retrieves the next dialogue in the chain and executes it.
final DialogueFactory sendStatement(String... lines)
Appends a StatementDialogue to the current dialogue chain.
static void activateOverride(Mob mob, Position position, TeleportationData teleport)
Handles writing on an itemcontainer.
static void write(InterfaceWriter writer)
Class handles writing on the obelisk itemcontainer.
A game representing a cyclic unit of work.
Definition Task.java:11
An randomevent which replaces an object with another object.
Represents the game world.
Definition World.java:46
static void schedule(Task task)
Submits a new event.
Definition World.java:247
static RegionManager getRegions()
Definition World.java:552
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
Created by Daniel on 2017-11-24.
Definition Boundary.java:12
static List< Player > getPlayers(Boundary boundary)
Definition Boundary.java:70
Represents a single tile on the game world.
Definition Position.java:14
GameObject getGameObject(int id, Position position)
Definition Region.java:183
Region getRegion(Position position)
Gets a region by position.
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 int random(int bound)
Definition Utility.java:239
public< K, E > void set(K key, E attribute)
Sets a generic attribute.
static ObeliskData getRandom(ObeliskData exclude)
ObeliskData(int objectId, Boundary boundary)
static ObeliskData forObject(int objectId)
static boolean isSuper(Player player)
Checks if the player has super donator status.