47 public static List<Trap> traps =
new CopyOnWriteArrayList<Trap>();
49 public static List<Npc> HUNTER_NPC_LIST =
new CopyOnWriteArrayList<Npc>();
51 private static final int[] exps = {3254, 3744, 6041, 8811, 10272};
53 public static void register(
final Trap trap) {
54 trap.getGameObject().register();
56 if (trap.getOwner() !=
null)
57 trap.getOwner().trapsLaid++;
60 public static void deregister(
Trap trap) {
61 trap.getGameObject().unregister();
63 if (trap.getOwner() !=
null)
64 trap.getOwner().trapsLaid--;
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.");
75 for (
final Trap trap : traps) {
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.");
87 for (
final Npc npc : HUNTER_NPC_LIST) {
88 if (npc ==
null || !npc.isVisible())
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.");
95 if (client.trapsLaid >= getMaximumTraps(client)) {
96 client.message(
"You can only have a max of " + getMaximumTraps(client) +
" traps setup at once.");
103 public static void handleRegionChange(
Player client) {
104 if (client.trapsLaid > 0) {
105 for (
final Trap trap : traps) {
108 if (trap.getOwner() !=
null && trap.getOwner().getUsername().equals(client.getUsername()) && !trap.getGameObject().getPosition().isWithinDistance(client.
getPosition(), 50)) {
110 client.message(
"You didn't watch over your trap well enough, it has collapsed.");
116 public static boolean goodArea(
Player client) {
119 return x >= 2758 && x <= 2965 && y >= 2880 && y <= 2954 || x >= 2300 && x <= 2320 && y >= 9790 && y <= 9800;
122 public static int getMaximumTraps(
Player client) {
128 public static int getObjectIDByNPCID(
int npcId) {
144 public static Trap getTrapForGameObject(
final GameObject object) {
145 for (
final Trap trap : traps) {
148 if (trap.getGameObject().getPosition().equals(
object.getPosition()))
157 final Trap theTrap = getTrapForGameObject(trap);
158 if (theTrap !=
null && theTrap.getOwner() == client) {
161 client.inventory.
add(10006, 1);
162 else if (theTrap instanceof
BoxTrap) {
163 client.inventory.
add(10008, 1);
166 client.message(
"You dismantle the trap..");
168 client.message(
"You cannot dismantle someone else's trap.");
171 public static void layTrap(
Player client,
Trap trap) {
176 client.message(
"You need a Hunter level of at least 60 to lay this trap.");
182 if (canLay(client)) {
186 client.
face(trap.getGameObject());
189 client.message(
"You set up a bird snare..");
190 client.inventory.
remove(10006, 1);
191 }
else if (trap instanceof
BoxTrap) {
193 client.message(
"You need a Hunter level of at least 27 to do this.");
196 client.message(
"You set up a box trap..");
197 client.inventory.
remove(10008, 1);
203 public static int requiredLevel(
int npcType) {
204 int levelToReturn = 1;
207 else if (npcType == 5074)
209 else if (npcType == 5075)
211 else if (npcType == 5076)
213 else if (npcType == 5079)
215 else if (npcType == 5080)
217 return levelToReturn;
220 public static boolean isHunterNPC(
int npc) {
221 return npc >= 5072 && npc <= 5080;
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) {
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.");
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.");
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.");
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.");
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.");
260 }
else if (theTrap instanceof
BoxTrap) {
261 client.inventory.
add(10008, 1);
262 if (theTrap.getGameObject().
getId() == 19191) {
263 client.inventory.
add(10033, 1);
265 client.message(
"You've succesfully caught a chinchompa!");
266 }
else if (theTrap.getGameObject().
getId() == 19189) {
267 client.inventory.
add(10034, 1);
269 client.message(
"You've succesfully caught a red chinchompa!");
275 client.message(
"This is not your trap.");
280 public static void catchNPC(
Trap trap,
Npc npc) {
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");
291 GameObject object =
new CustomGameObject(getObjectIDByNPCID(npc.id),
new Position(trap.getGameObject().getPosition().getX(), trap.getGameObject().getPosition().getY()));
294 GameObject object =
new CustomGameObject(getObjectIDByNPCID(npc.id),
new Position(trap.getGameObject().getPosition().getX(), trap.getGameObject().getPosition().getY()));
297 HUNTER_NPC_LIST.remove(npc);
298 npc.setVisible(
false);
303 public static boolean hasLarupia(
Player client) {
308 public static void handleLogout(
Player p) {
309 if (p.trapsLaid > 0) {
310 for (
Trap trap : traps) {
312 if (trap.getOwner() !=
null && trap.getOwner().getUsername().equals(p.getUsername())) {
315 p.inventory.
add(10006, 1);
316 else if (trap instanceof
BoxTrap) {
317 p.inventory.
add(10008, 1);