73public class PestControlGame
extends LobbyNode {
79 private static final Position OUTSIDE_BOAT_POSITION =
new Position(2657, 2639);
82 private final PestControlListener listener =
new PestControlListener(
this);
88 private static final String[] PORTAL_NAMES = {
96 private final Portal[] portals =
new Portal[] {
109 private static final int[] RAVAGERS = {1704, 1705, 1706, 1707, 1708};
110 private static final int[] SPLATTERS = {1691, 1692};
111 private static final int[] SHIFTERS = {1698, 1699, 1700, 1701};
112 private static final int[] DEFILERS = {1728, 1729};
113 private static final int[] TORCHERS = {1728, 1729};
116 private static final String[] VOID_KNIGHT_MESSAGES = {
118 "Take down the portals",
119 "The Void Knights will not fall!",
120 "Hail the Void Knights!",
121 "We are beating these scum!"
125 private Set<Npc> monsters =
new HashSet<>();
128 private Set<Npc> portalSet =
new HashSet<>();
132 setInstance(
Entity.DEFAULT_INSTANCE);
154 forEachActivity((mob, activity) -> activity.getPanel().ifPresent(panel -> ((PestControlPanel) panel).update()));
158 protected void onStart() {
160 if (mob.isPlayer()) {
161 mob.getPlayer().playerAssistant.restore();
166 voidKnight.blockFace =
true;
168 for (Npc portal : portals) {
170 portalSet.add(portal);
173 groupMessage(
"Protect the void knight at all costs, good luck!");
180 Npc npc = mob.getNpc();
182 if (npc.id >= 1739 && npc.id <= 1742) {
183 portalSet.remove(npc);
185 groupMessage(
"The " + PORTAL_NAMES[npc.id - 1739] +
" is dead! The Void Knight has gained 25 HP.");
187 monsters.remove(mob.getNpc());
193 mob.getPlayer().animate(
Animation.RESET,
true);
194 mob.getPlayer().graphic(
Graphic.RESET,
true);
204 public boolean canLogout(
Player player) {
205 player.message(
"You cannot log out during a Pest Control game.");
211 if (!
Area.inPestControl(player)) {
218 if (event.getObject().getId() == 14314) {
219 manager.leave(player);
229 monsters.forEach(this::remove);
230 portalSet.forEach(this::remove);
237 return Optional.of(listener);
251 PestControlNode node =
new PestControlNode(player);
253 PestControlPanel panel =
new PestControlPanel(player, node);
260 protected boolean finished() {
266 if (portalSet.isEmpty()) {
270 if (voidKnight.isRegistered() && voidKnight.getCurrentHealth() <= 0) {
278 private void spawnMonsters() {
279 for (
int index = 0; index < 5; index++) {
280 spawn(Utility.randomElement(RAVAGERS), BLUE_BOUNDS, 5);
282 for (
int index = 0; index < 5; index++) {
283 spawn(Utility.randomElement(RAVAGERS), RED_BOUNDS, 5);
285 for (
int index = 0; index < 5; index++) {
286 spawn(Utility.randomElement(RAVAGERS), YELLOW_BOUNDS, 5);
288 for (
int index = 0; index < 5; index++) {
289 spawn(Utility.randomElement(RAVAGERS), PURPLE_BOUNDS, 5);
291 for (
int index = 0; index < 2; index++) {
292 spawn(Utility.randomElement(RAVAGERS), KNIGHT_BOUNDS, 6);
296 private void spawn(
int id, Position southWest,
int size) {
297 Position target = RandomUtils.random(TraversalMap.getTraversableTiles(southWest, size, size));
298 Npc monster =
new Npc(
id, target);
299 monsters.add(monster);
303 private void agressiveMonsters() {
304 if (monsters.isEmpty())
306 if (voidKnight ==
null)
308 for (Npc monster : monsters) {
309 if (monster.getCombat().inCombat())
311 if (monster.getPosition().isWithinDistance(voidKnight.getPosition(), 10)) {
312 monster.getCombat().attack(voidKnight);
318 if (monster.getPosition().isWithinDistance(mob.getPosition(), 8))
319 monster.getCombat().attack(mob);
324 private class Portal
extends Npc {
325 Portal(
int id, Position position) {
332 public class PestControlNode
extends Activity {
336 private final Player player;
338 private PestControlNode(Player player) {
339 super(1, Entity.DEFAULT_INSTANCE);
340 this.player = player;
344 protected void start() {
345 player.move(BOAT.
transform(Utility.random(4), Utility.random(6)));
346 player.dialogueFactory.sendNpcChat(1756,
"Go with strength!",
"Defend the void knight and destroy the portals!",
"You are our only hope!").execute();
351 if (!inLobby() && !Area.inPestControl(player)) {
355 getPanel().ifPresent(Activity_Panel::close);
356 player.move(OUTSIDE_BOAT_POSITION);
357 player.playerAssistant.restore();
358 player.animate(Animation.RESET,
true);
359 player.graphic(Graphic.RESET,
true);
365 if (voidKnight.getCurrentHealth() <= 0) {
366 player.dialogueFactory.sendNpcChat(1756,
"You let the Void Knight die!",
"Keep him alive you noobs...").execute();
370 if (portalSet.isEmpty()) {
372 player.dialogueFactory.sendNpcChat(1756,
"You have disgraced your squad by not dealing any damage.",
"As punishment, you get no points! Teamwork next time!").execute();
377 player.dialogueFactory.sendNpcChat(1756,
"You only dealt " + damage +
" damage this round.",
"You need to deal at least 50 damage to receive a reward.").execute();
381 int points = PlayerRight.getBloodMoney(player) / 100;
382 AchievementHandler.activate(player, AchievementKey.PEST_CONTROL);
383 player.activityLogger.add(ActivityLog.PEST_CONTROL);
384 player.pestPoints += points;
385 player.dialogueFactory.sendNpcChat(1756,
"You have beaten the minigame!",
"You were rewarded with " + points +
" pest control points.",
"You now have: " + player.pestPoints +
".").execute();
387 player.dialogueFactory.sendNpcChat(1756,
"You have run out of time!",
"You failed the mission and don't get any points.").execute();
395 public ActivityType getType() {
396 return ActivityType.PEST_CONTROL;
402 player.send(
new SendMessage(
"Talk to the void-knight next to the boat to leave."));
407 private final PestControlNode node;
409 private PestControlPanel(
Player player, PestControlNode node) {
410 super(player,
"Pest Control");
418 set(1,
"Players Ready: <col=FF5500>" +
getActiveSize() +
"</col>");
419 set(2,
"(Need <col=FF5500>" + manager.getMinimumRequired() +
"</col> to " + manager.getPlayerCapacity() +
" players)");
420 set(3,
"Points: <col=FF5500>" + node.player.pestPoints +
"</col>");
421 setFooter(
"Players Ready:");
425 set(1,
"Knight's health: <col=FF5500>" + voidKnight.getCurrentHealth() +
"</col>");
426 set(2,
"Damage: <col=FF5500>" + node.damage +
"</col>");
428 for (
int index = 0; index <= 3; index++) {
429 String value =
"dead";
430 Portal portal = portals[index];
431 if (portal.getCurrentHealth() > 0) {
432 value = String.valueOf(portal.getCurrentHealth());
436 set(3 + index, PORTAL_NAMES[index] +
": <col=FF5500>" + value +
"</col>");
438 setFooter(
"Minigame Completion:");
439 setProgress((
int) Utility.getPercentageAmount(dead, 4));
441 setItem(
new Item(11666));