RuneHive-Tarnish
Neural OSRS Enhancement Framework
Loading...
Searching...
No Matches
Obelisks.java
1package com.osroyale.content;
2
3import com.osroyale.content.skill.impl.magic.teleport.Teleportation;
4import com.osroyale.content.skill.impl.magic.teleport.TeleportationData;
5import com.osroyale.content.writer.InterfaceWriter;
6import com.osroyale.content.writer.impl.ObeliskWriter;
7import com.osroyale.game.task.Task;
8import com.osroyale.game.task.impl.ObjectReplacementEvent;
9import com.osroyale.game.world.World;
10import com.osroyale.game.world.entity.mob.player.Player;
11import com.osroyale.game.world.entity.mob.player.PlayerRight;
12import com.osroyale.game.world.object.GameObject;
13import com.osroyale.game.world.position.Boundary;
14import com.osroyale.game.world.position.Position;
15import com.osroyale.net.packet.out.SendMessage;
16import com.osroyale.net.packet.out.SendString;
17import com.osroyale.util.Utility;
18
19import java.util.*;
20
61
62public class Obelisks {
63
64 private static Map<Integer, Boolean> state = new HashMap<>();
65 private static Obelisks INSTANCE = new Obelisks();
66
67 public static Obelisks get() {
68 return INSTANCE;
69 }
70
71 static {
72 for (ObeliskData location : ObeliskData.values()) {
73 state.put(location.objectId, false);
74 }
75 }
76
77 public void open(Player player, int obj) {
78 if (!PlayerRight.isSuper(player)) {
79 player.dialogueFactory.sendStatement("You need to be a super donator to use this feature!").execute();
80 return;
81 }
82 player.attributes.set("OBELISK", obj);
83 InterfaceWriter.write(new ObeliskWriter(player));
84 player.send(new SendString("Wilderness Obelisk", 51002));
85 player.send(new SendString("Click on the obelisk you would like to teleport too", 51003));
86 player.interfaceManager.open(51000);
87 }
88
89 public boolean activate(Player player, int objectId) {
90 ObeliskData location = ObeliskData.forObject(objectId);
91 return location != null && activate(player, objectId, ObeliskData.getRandom(location));
92 }
93
94 public boolean activate(Player player, int objectId, ObeliskData destination) {
95 ObeliskData location = ObeliskData.forObject(objectId);
96
97 if (location == null)
98 return false;
99
100 boolean active = state.get(objectId);
101
102 if (active) {
103 player.send(new SendMessage("The obelisk is already active, please wait."));
104 return true;
105 }
106
107 state.put(objectId, true);
108 int x = location.getBoundaries().getMinimumX();
109 int y = location.getBoundaries().getMinimumY();
110 GameObject one = World.getRegions().getRegion(player.getPosition()).getGameObject(objectId, new Position(x, y, player.getHeight()));
111 GameObject two = World.getRegions().getRegion(player.getPosition()).getGameObject(objectId, new Position(x + 4, y, player.getHeight()));
112 GameObject three = World.getRegions().getRegion(player.getPosition()).getGameObject(objectId, new Position(x, y + 4, player.getHeight()));
113 GameObject four = World.getRegions().getRegion(player.getPosition()).getGameObject(objectId, new Position(x + 4, y + 4, player.getHeight()));
114 World.schedule(new ObjectReplacementEvent(one, 14825, 15));
115 World.schedule(new ObjectReplacementEvent(two, 14825, 15));
116 World.schedule(new ObjectReplacementEvent(three, 14825, 15));
117 World.schedule(new ObjectReplacementEvent(four, 14825, 15));
118 player.attributes.set("OBELISK", -1);
119
120 World.schedule(new Task(14) {
121 @Override
122 protected void execute() {
123 state.put(location.objectId, false);
124 Boundary boundary = new Boundary(location.boundary.getMinimumX() + 1, location.boundary.getMinimumY() + 1, location.boundary.getMinimumX() + 3, location.boundary.getMinimumY() + 3);
125 List<Player> players = Boundary.getPlayers(boundary);
126
127 if (players.size() > 0) {
128 for (Player p : players) {
129 if (p.isDead())
130 continue;
131 int x = destination.getBoundaries().getMinimumX() + 1;
132 int y = destination.getBoundaries().getMinimumY() + 1;
133 Position position = new Position(x + Utility.random(2), y + Utility.random(2), player.getHeight());
134 Teleportation.activateOverride(p, position, TeleportationData.OBELISK);
135 }
136 }
137 cancel();
138 }
139 });
140 return true;
141 }
142
143public enum ObeliskData {
144 LEVEL_13(14829, new Boundary(3154, 3618, 3158, 3622)),
145 LEVEL_19(14830, new Boundary(3225, 3665, 3229, 3669)),
146 LEVEL_27(14827, new Boundary(3033, 3730, 3037, 3734)),
147 LEVEL_35(14828, new Boundary(3104, 3792, 3108, 3796)),
148 LEVEL_44(14826, new Boundary(2978, 3864, 2982, 3868)),
149 LEVEL_50(14831, new Boundary(3305, 3914, 3309, 3918));
150
151 private final int objectId;
152 private final Boundary boundary;
153
154 ObeliskData(int objectId, Boundary boundary) {
155 this.objectId = objectId;
156 this.boundary = boundary;
157 }
158
159 public Boundary getBoundaries() {
160 return boundary;
161 }
162
163 static ObeliskData forObject(int objectId) {
164 for (ObeliskData l : values()) {
165 if (l.objectId == objectId) {
166 return l;
167 }
168 }
169 return null;
170 }
171
172 static ObeliskData getRandom(ObeliskData exclude) {
173 ArrayList<ObeliskData> locations = new ArrayList<>(Arrays.asList(values()));
174 locations.remove(exclude);
175 return locations.get(Utility.random(locations.size() - 1));
176 }
177 }
178}
179
180
final DialogueFactory sendStatement(String... lines)
static void schedule(Task task)
Definition World.java:284
GameObject getGameObject(int id, Position position)
Definition Region.java:220