RuneHive-Tarnish
Neural OSRS Enhancement Framework
Loading...
Searching...
No Matches
TrapManager.java
1package com.osroyale.content.skill.impl.hunter.trap;
2
3import com.osroyale.game.Animation;
4import com.osroyale.game.task.impl.HunterTask;
5import com.osroyale.game.world.entity.mob.npc.Npc;
6import com.osroyale.game.world.entity.mob.player.Player;
7import com.osroyale.game.world.entity.skill.Skill;
8import com.osroyale.game.world.object.CustomGameObject;
9import com.osroyale.game.world.object.GameObject;
10import com.osroyale.game.world.position.Position;
11import com.osroyale.util.Utility;
12
13import java.util.List;
14import java.util.concurrent.CopyOnWriteArrayList;
15
44
45public class TrapManager {
46
47 public static List<Trap> traps = new CopyOnWriteArrayList<Trap>();
48
49 public static List<Npc> HUNTER_NPC_LIST = new CopyOnWriteArrayList<Npc>();
50
51 private static final int[] exps = {3254, 3744, 6041, 8811, 10272};
52
53 public static void register(final Trap trap) {
54 trap.getGameObject().register();
55 traps.add(trap);
56 if (trap.getOwner() != null)
57 trap.getOwner().trapsLaid++;
58 }
59
60 public static void deregister(Trap trap) {
61 trap.getGameObject().unregister();
62 traps.remove(trap);
63 if (trap.getOwner() != null)
64 trap.getOwner().trapsLaid--;
65 }
66
67
68 public static boolean canLay(Player client) {
69 if (!goodArea(client)) {
70 client.message("You need to be in a hunting area to lay a trap.");
71 return false;
72 }
73// if (!client.getClickDelay().elapsed(2000))
74// return false;
75 for (final Trap trap : traps) {
76 if (trap == null)
77 continue;
78 if (trap.getGameObject().getPosition().getX() == client.getPosition().getX() && trap.getGameObject().getPosition().getY() == client.getPosition().getY()) {
79 client.message("There is already a trap here, please place yours somewhere else.");
80 return false;
81 }
82 }
83
84 int x = client.getPosition().getX();
85 int y = client.getPosition().getY();
86
87 for (final Npc npc : HUNTER_NPC_LIST) {
88 if (npc == null || !npc.isVisible())
89 continue;
90 if (x == npc.getPosition().getX() && y == npc.getPosition().getY() || x == npc.getX() && y == npc.getY()) {
91 client.message("You cannot place your trap right here, try placing it somewhere else.");
92 return false;
93 }
94 }
95 if (client.trapsLaid >= getMaximumTraps(client)) {
96 client.message("You can only have a max of " + getMaximumTraps(client) + " traps setup at once.");
97 return false;
98 }
99 return true;
100 }
101
102
103 public static void handleRegionChange(Player client) {
104 if (client.trapsLaid > 0) {
105 for (final Trap trap : traps) {
106 if (trap == null)
107 continue;
108 if (trap.getOwner() != null && trap.getOwner().getUsername().equals(client.getUsername()) && !trap.getGameObject().getPosition().isWithinDistance(client.getPosition(), 50)) {
109 deregister(trap);
110 client.message("You didn't watch over your trap well enough, it has collapsed.");
111 }
112 }
113 }
114 }
115
116 public static boolean goodArea(Player client) {
117 int x = client.getPosition().getX();
118 int y = client.getPosition().getY();
119 return x >= 2758 && x <= 2965 && y >= 2880 && y <= 2954 || x >= 2300 && x <= 2320 && y >= 9790 && y <= 9800;
120 }
121
122 public static int getMaximumTraps(Player client) {
123 return client.skills.getLevel(Skill.HUNTER) / 20 + 1;
124 }
125
126
127
128 public static int getObjectIDByNPCID(int npcId) {
129 switch (npcId) {
130 case 5549:
131 return 9373;
132 case 5551:
133 return 9377;
134 case 5552:
135 return 9379;
136 case 5550:
137 return 9375;
138 case 5548:
139 return 9348;
140 }
141 return 0;
142 }
143
144 public static Trap getTrapForGameObject(final GameObject object) {
145 for (final Trap trap : traps) {
146 if (trap == null)
147 continue;
148 if (trap.getGameObject().getPosition().equals(object.getPosition()))
149 return trap;
150 }
151 return null;
152 }
153
154 public static void dismantle(Player client, GameObject trap) {
155 if (trap == null)
156 return;
157 final Trap theTrap = getTrapForGameObject(trap);
158 if (theTrap != null && theTrap.getOwner() == client) {
159 deregister(theTrap);
160 if (theTrap instanceof SnareTrap)
161 client.inventory.add(10006, 1);
162 else if (theTrap instanceof BoxTrap) {
163 client.inventory.add(10008, 1);
164 client.animate(new Animation(827));
165 }
166 client.message("You dismantle the trap..");
167 } else
168 client.message("You cannot dismantle someone else's trap.");
169 }
170
171 public static void layTrap(Player client, Trap trap) {
172 int id = 10006;
173 if (trap instanceof BoxTrap) {
174 id = 10008;
175 if (client.skills.getLevel(Skill.HUNTER) < 60) {
176 client.message("You need a Hunter level of at least 60 to lay this trap.");
177 return;
178 }
179 }
180 if (!client.inventory.contains(id))
181 return;
182 if (canLay(client)) {
183 register(trap);
184// client.getClickDelay().reset();
185 client.takeStep();
186 client.face(trap.getGameObject());
187 client.animate(new Animation(827));
188 if (trap instanceof SnareTrap) {
189 client.message("You set up a bird snare..");
190 client.inventory.remove(10006, 1);
191 } else if (trap instanceof BoxTrap) {
192 if (client.skills.getLevel(Skill.HUNTER) < 27) {
193 client.message("You need a Hunter level of at least 27 to do this.");
194 return;
195 }
196 client.message("You set up a box trap..");
197 client.inventory.remove(10008, 1);
198 }
199 HunterTask.intialize();
200 }
201 }
202
203 public static int requiredLevel(int npcType) {
204 int levelToReturn = 1;
205 if (npcType == 5072)
206 levelToReturn = 19;
207 else if (npcType == 5074)
208 levelToReturn = 11;
209 else if (npcType == 5075)
210 levelToReturn = 5;
211 else if (npcType == 5076)
212 levelToReturn = 9;
213 else if (npcType == 5079)
214 levelToReturn = 53;
215 else if (npcType == 5080)
216 levelToReturn = 63;
217 return levelToReturn;
218 }
219
220 public static boolean isHunterNPC(int npc) {
221 return npc >= 5072 && npc <= 5080;
222 }
223
224 public static void lootTrap(Player client, GameObject trap) {
225 if (trap != null) {
226 client.face(trap.getPosition());
227 final Trap theTrap = getTrapForGameObject(trap);
228 if (theTrap != null) {
229 if (theTrap.getOwner() != null)
230 if (theTrap.getOwner() == client) {
231 if (theTrap instanceof SnareTrap) {
232 client.inventory.add(10006, 1);
233 client.inventory.add(526, 1);
234 if (theTrap.getGameObject().getId() == 19180) {
235 client.inventory.add(10088, 20 + Utility.random(30));
236 client.inventory.add(9978, 1);
237 client.message("You've succesfully caught a crimson swift.");
238 client.skills.addExperience(Skill.HUNTER, exps[0]);
239 } else if (theTrap.getGameObject().getId() == 19184) {
240 client.inventory.add(10090, 20 + Utility.random(30));
241 client.inventory.add(9978, 1);
242 client.message("You've succesfully caught a Golden Warbler.");
243 client.skills.addExperience(Skill.HUNTER, exps[1]);
244 } else if (theTrap.getGameObject().getId() == 19186) {
245 client.inventory.add(10091, 20 + Utility.random(50));
246 client.inventory.add(9978, 1);
247 client.message("You've succesfully caught a Copper Longtail.");
248 client.skills.addExperience(Skill.HUNTER, exps[2]);
249 } else if (theTrap.getGameObject().getId() == 19182) {
250 client.inventory.add(10089, 20 + Utility.random(30));
251 client.inventory.add(9978, 1);
252 client.message("You've succesfully caught a Cerulean Twitch.");
253 client.skills.addExperience(Skill.HUNTER, (exps[3]));
254 } else if (theTrap.getGameObject().getId() == 19178) {
255 client.inventory.add(10087, 20 + Utility.random(30));
256 client.inventory.add(9978, 1);
257 client.message("You've succesfully caught a Tropical Wagtail.");
258 client.skills.addExperience(Skill.HUNTER, exps[4]);
259 }
260 } else if (theTrap instanceof BoxTrap) {
261 client.inventory.add(10008, 1);
262 if (theTrap.getGameObject().getId() == 19191) {
263 client.inventory.add(10033, 1);
264 client.skills.addExperience(Skill.HUNTER, exps[6]);
265 client.message("You've succesfully caught a chinchompa!");
266 } else if (theTrap.getGameObject().getId() == 19189) {
267 client.inventory.add(10034, 1);
268 client.skills.addExperience(Skill.HUNTER, exps[7]);
269 client.message("You've succesfully caught a red chinchompa!");
270 }
271 }
272 deregister(theTrap);
273 client.animate(new Animation(827));
274 } else
275 client.message("This is not your trap.");
276 }
277 }
278 }
279
280 public static void catchNPC(Trap trap, Npc npc) {
281 if (trap.getTrapState().equals(Trap.TrapState.CAUGHT))
282 return;
283 if (trap.getOwner() != null) {
284 if (trap.getOwner().skills.getLevel(Skill.HUNTER) < requiredLevel(npc.id)) {
285 trap.getOwner().message("You failed to catch the animal because your Hunter level is too low.");
286 trap.getOwner().message("You need atleast " + requiredLevel(npc.id) + " Hunter to catch this animal");
287 return;
288 }
289 deregister(trap);
290 if (trap instanceof SnareTrap) {
291 GameObject object = new CustomGameObject(getObjectIDByNPCID(npc.id), new Position(trap.getGameObject().getPosition().getX(), trap.getGameObject().getPosition().getY()));
292 register(new SnareTrap(object, Trap.TrapState.CAUGHT, 100, trap.getOwner()));
293 } else {
294 GameObject object = new CustomGameObject(getObjectIDByNPCID(npc.id), new Position(trap.getGameObject().getPosition().getX(), trap.getGameObject().getPosition().getY()));
295 register(new BoxTrap(object, Trap.TrapState.CAUGHT, 100, trap.getOwner()));
296 }
297 HUNTER_NPC_LIST.remove(npc);
298 npc.setVisible(false);
299 npc.appendDeath();
300 }
301 }
302
303 public static boolean hasLarupia(Player client) {
304 return false;
305// return client.equipment.getItems()[Equipment.HEAD_SLOT].getId() == 10045 && client.getEquipment().getItem()[Equipment.BODY_SLOT].getId() == 10043 && client.getEquipment().getItem()[Equipment.LEG_SLOT].getId() == 10041;
306 }
307
308 public static void handleLogout(Player p) {
309 if (p.trapsLaid > 0) {
310 for (Trap trap : traps) {
311 if (trap != null) {
312 if (trap.getOwner() != null && trap.getOwner().getUsername().equals(p.getUsername())) {
313 deregister(trap);
314 if (trap instanceof SnareTrap)
315 p.inventory.add(10006, 1);
316 else if (trap instanceof BoxTrap) {
317 p.inventory.add(10008, 1);
318 p.animate(new Animation(827));
319 }
320 }
321 }
322 }
323 }
324 }
325}
void face(GameObject object)
Definition Mob.java:326
void addExperience(int id, double experience)