SlayerPlugin extends Plugin { @Subscribe public void onGameTick(GameTick tick) { Widget npcDialog = client.getWidget(WidgetInfo.DIALOG_NPC_TEXT); if (npcDialog != null) { String npcText = Text.sanitizeMultilineText(npcDialog.getText()); final Matcher mAssign = NPC_ASSIGN_MESSAGE.matcher(npcText); final Matcher mAssignFirst = NPC_ASSIGN_FIRST_MESSAGE.matcher(npcText); final Matcher mAssignBoss = NPC_ASSIGN_BOSS_MESSAGE.matcher(npcText); final Matcher mCurrent = NPC_CURRENT_MESSAGE.matcher(npcText); if (mAssign.find()) { String name = mAssign.group("name"); int amount = Integer.parseInt(mAssign.group("amount")); String location = mAssign.group("location"); setTask(name, amount, amount, location); } else if (mAssignFirst.find()) { int amount = Integer.parseInt(mAssignFirst.group(2)); setTask(mAssignFirst.group(1), amount, amount); } else if (mAssignBoss.find()) { int amount = Integer.parseInt(mAssignBoss.group(2)); setTask(mAssignBoss.group(1), amount, amount); int points = Integer.parseInt(mAssignBoss.group(3).replaceAll(",", "")); config.points(points); } else if (mCurrent.find()) { String name = mCurrent.group("name"); int amount = Integer.parseInt(mCurrent.group("amount")); String location = mCurrent.group("location"); setTask(name, amount, initialAmount, location); } } Widget braceletBreakWidget = client.getWidget(WidgetInfo.DIALOG_SPRITE_TEXT); if (braceletBreakWidget != null) { String braceletText = Text.removeTags(braceletBreakWidget.getText()); if (braceletText.contains("bracelet of slaughter")) { slaughterChargeCount = SLAUGHTER_CHARGE; config.slaughter(slaughterChargeCount); } else if (braceletText.contains("expeditious bracelet")) { expeditiousChargeCount = EXPEDITIOUS_CHARGE; config.expeditious(expeditiousChargeCount); } } Widget rewardsBarWidget = client.getWidget(WidgetInfo.SLAYER_REWARDS_TOPBAR); if (rewardsBarWidget != null) { for (Widget w : rewardsBarWidget.getDynamicChildren()) { Matcher mPoints = REWARD_POINTS.matcher(w.getText()); if (mPoints.find()) { final int prevPoints = config.points(); int points = Integer.parseInt(mPoints.group(1).replaceAll(",", "")); if (prevPoints != points) { config.points(points); removeCounter(); addCounter(); } break; } } } if (infoTimer != null && config.statTimeout() != 0) { Duration timeSinceInfobox = Duration.between(infoTimer, Instant.now()); Duration statTimeout = Duration.ofMinutes(config.statTimeout()); if (timeSinceInfobox.compareTo(statTimeout) >= 0) { removeCounter(); } } taggedNpcsDiedPrevTick = taggedNpcsDiedThisTick; taggedNpcsDiedThisTick = 0; }  @Subscribe void onGameStateChanged(GameStateChanged event); @Subscribe void onNpcSpawned(NpcSpawned npcSpawned); @Subscribe void onNpcDespawned(NpcDespawned npcDespawned); @Subscribe void onGameTick(GameTick tick); @Subscribe void onChatMessage(ChatMessage event); @Subscribe void onStatChanged(StatChanged statChanged); @Subscribe void onHitsplatApplied(HitsplatApplied hitsplatApplied); @Subscribe void onActorDeath(ActorDeath actorDeath);  }
@Test public void testNewKonarTask2() { Widget npcDialog = mock(Widget.class); when(npcDialog.getText()).thenReturn(TASK_NEW_KONAR_2); when(client.getWidget(WidgetInfo.DIALOG_NPC_TEXT)).thenReturn(npcDialog); slayerPlugin.onGameTick(new GameTick()); assertEquals("Hellhounds", slayerPlugin.getTaskName()); assertEquals(142, slayerPlugin.getAmount()); assertEquals("Witchhaven Dungeon", slayerPlugin.getTaskLocation()); }
@Test public void testNewKonarTask3() { Widget npcDialog = mock(Widget.class); when(npcDialog.getText()).thenReturn(TASK_NEW_KONAR_3); when(client.getWidget(WidgetInfo.DIALOG_NPC_TEXT)).thenReturn(npcDialog); slayerPlugin.onGameTick(new GameTick()); assertEquals("Trolls", slayerPlugin.getTaskName()); assertEquals(135, slayerPlugin.getAmount()); assertEquals("Mount Quidamortem", slayerPlugin.getTaskLocation()); }
@Test public void testFirstTask() { Widget npcDialog = mock(Widget.class); when(npcDialog.getText()).thenReturn(TASK_NEW_FIRST); when(client.getWidget(WidgetInfo.DIALOG_NPC_TEXT)).thenReturn(npcDialog); slayerPlugin.onGameTick(new GameTick()); assertEquals("goblins", slayerPlugin.getTaskName()); assertEquals(17, slayerPlugin.getAmount()); }
@Test public void testFirstTaskKonar() { Widget npcDialog = mock(Widget.class); when(npcDialog.getText()).thenReturn(TASK_NEW_FIRST_KONAR); when(client.getWidget(WidgetInfo.DIALOG_NPC_TEXT)).thenReturn(npcDialog); slayerPlugin.onGameTick(new GameTick()); assertEquals("cows", slayerPlugin.getTaskName()); assertEquals(44, slayerPlugin.getAmount()); }
@Test public void testNewNpcContactTask() { Widget npcDialog = mock(Widget.class); when(npcDialog.getText()).thenReturn(TASK_NEW_NPC_CONTACT); when(client.getWidget(WidgetInfo.DIALOG_NPC_TEXT)).thenReturn(npcDialog); slayerPlugin.onGameTick(new GameTick()); assertEquals("Suqahs", slayerPlugin.getTaskName()); assertEquals(211, slayerPlugin.getAmount()); }
@Test public void testBossTask() { Widget npcDialog = mock(Widget.class); when(npcDialog.getText()).thenReturn(TASK_BOSS_NEW); when(client.getWidget(WidgetInfo.DIALOG_NPC_TEXT)).thenReturn(npcDialog); slayerPlugin.onGameTick(new GameTick()); assertEquals("Vet'ion", slayerPlugin.getTaskName()); assertEquals(3, slayerPlugin.getAmount()); verify(slayerConfig).points(914); }
@Test public void testBossTaskThe() { Widget npcDialog = mock(Widget.class); when(npcDialog.getText()).thenReturn(TASK_BOSS_NEW_THE); when(client.getWidget(WidgetInfo.DIALOG_NPC_TEXT)).thenReturn(npcDialog); slayerPlugin.onGameTick(new GameTick()); assertEquals("Chaos Elemental", slayerPlugin.getTaskName()); assertEquals(3, slayerPlugin.getAmount()); verify(slayerConfig).points(914); }
@Test public void testKonarBossTask() { Widget npcDialog = mock(Widget.class); when(npcDialog.getText()).thenReturn(TASK_KONAR_BOSS); when(client.getWidget(WidgetInfo.DIALOG_NPC_TEXT)).thenReturn(npcDialog); slayerPlugin.onGameTick(new GameTick()); assertEquals("Alchemical Hydra", slayerPlugin.getTaskName()); assertEquals(35, slayerPlugin.getAmount()); verify(slayerConfig).points(724); }
@Test public void testExistingTask() { Widget npcDialog = mock(Widget.class); when(npcDialog.getText()).thenReturn(TASK_EXISTING); when(client.getWidget(WidgetInfo.DIALOG_NPC_TEXT)).thenReturn(npcDialog); slayerPlugin.onGameTick(new GameTick()); assertEquals("suqahs", slayerPlugin.getTaskName()); assertEquals(222, slayerPlugin.getAmount()); }
@Test public void testExistingTaskKonar() { Widget npcDialog = mock(Widget.class); when(npcDialog.getText()).thenReturn(TASK_EXISTING_KONAR); when(client.getWidget(WidgetInfo.DIALOG_NPC_TEXT)).thenReturn(npcDialog); slayerPlugin.onGameTick(new GameTick()); assertEquals("adamant dragons", slayerPlugin.getTaskName()); assertEquals(3, slayerPlugin.getAmount()); assertEquals("Lithkren Vault", slayerPlugin.getTaskLocation()); }
@Test public void testExistingTaskWilderness() { Widget npcDialog = mock(Widget.class); when(npcDialog.getText()).thenReturn(TASK_EXISTING_WILDERNESS); when(client.getWidget(WidgetInfo.DIALOG_NPC_TEXT)).thenReturn(npcDialog); slayerPlugin.onGameTick(new GameTick()); assertEquals("bandits", slayerPlugin.getTaskName()); assertEquals(99, slayerPlugin.getAmount()); assertEquals("Wilderness", slayerPlugin.getTaskLocation()); }
@Test public void testSlayergemActivate() { Widget npcDialog = mock(Widget.class); when(npcDialog.getText()).thenReturn(TASK_ACTIVATESLAYERGEM); when(client.getWidget(WidgetInfo.DIALOG_NPC_TEXT)).thenReturn(npcDialog); slayerPlugin.onGameTick(new GameTick()); assertEquals("fossil island wyverns", slayerPlugin.getTaskName()); assertEquals(23, slayerPlugin.getAmount()); }
@Test public void testSlayergemActivateKonar() { Widget npcDialog = mock(Widget.class); when(npcDialog.getText()).thenReturn(TASK_ACTIVATESLAYERGEM_KONAR); when(client.getWidget(WidgetInfo.DIALOG_NPC_TEXT)).thenReturn(npcDialog); slayerPlugin.onGameTick(new GameTick()); assertEquals("adamant dragons", slayerPlugin.getTaskName()); assertEquals(3, slayerPlugin.getAmount()); assertEquals("Lithkren Vault", slayerPlugin.getTaskLocation()); }
@Test public void testSlayergemActivateWilderness() { Widget npcDialog = mock(Widget.class); when(npcDialog.getText()).thenReturn(TASK_ACTIVATESLAYERGEM_WILDERNESS); when(client.getWidget(WidgetInfo.DIALOG_NPC_TEXT)).thenReturn(npcDialog); slayerPlugin.onGameTick(new GameTick()); assertEquals("bandits", slayerPlugin.getTaskName()); assertEquals(99, slayerPlugin.getAmount()); assertEquals("Wilderness", slayerPlugin.getTaskLocation()); }
@Test public void testRewardPointsWidget() { Widget rewardBar = mock(Widget.class); Widget rewardBarText = mock(Widget.class); Widget[] rewardBarChildren = new Widget[]{rewardBarText}; when(rewardBar.getDynamicChildren()).thenReturn(rewardBarChildren); when(rewardBarText.getText()).thenReturn(REWARD_POINTS); when(client.getWidget(WidgetInfo.SLAYER_REWARDS_TOPBAR)).thenReturn(rewardBar); slayerPlugin.onGameTick(new GameTick()); verify(slayerConfig).points(17566); }
@Test public void updateInitialAmount() { Widget npcDialog = mock(Widget.class); when(npcDialog.getText()).thenReturn(TASK_EXISTING); when(client.getWidget(WidgetInfo.DIALOG_NPC_TEXT)).thenReturn(npcDialog); slayerPlugin.onGameTick(new GameTick()); assertEquals(222, slayerPlugin.getInitialAmount()); }
@Test public void testNewTask() { Widget npcDialog = mock(Widget.class); when(npcDialog.getText()).thenReturn(TASK_NEW); when(client.getWidget(WidgetInfo.DIALOG_NPC_TEXT)).thenReturn(npcDialog); slayerPlugin.onGameTick(new GameTick()); assertEquals("Suqahs", slayerPlugin.getTaskName()); assertEquals(231, slayerPlugin.getAmount()); }
@Test public void testNewKonarTask() { Widget npcDialog = mock(Widget.class); when(npcDialog.getText()).thenReturn(TASK_NEW_KONAR); when(client.getWidget(WidgetInfo.DIALOG_NPC_TEXT)).thenReturn(npcDialog); slayerPlugin.onGameTick(new GameTick()); assertEquals("Wyrms", slayerPlugin.getTaskName()); assertEquals(147, slayerPlugin.getAmount()); assertEquals("Karuulm Slayer Dungeon", slayerPlugin.getTaskLocation()); }