slayer: Parse task information from gem activate chat (#11866)

This commit is contained in:
PresNL
2020-06-14 09:58:23 +02:00
committed by GitHub
parent e5adab24dd
commit ba7f6de445
2 changed files with 71 additions and 1 deletions

View File

@@ -111,7 +111,7 @@ public class SlayerPlugin extends Plugin
private static final Pattern NPC_ASSIGN_MESSAGE = Pattern.compile(".*(?:Your new task is to kill|You are to bring balance to)\\s*(?<amount>\\d+) (?<name>.+?)(?: (?:in|on|south of) (?:the )?(?<location>.+))?\\.");
private static final Pattern NPC_ASSIGN_BOSS_MESSAGE = Pattern.compile("^(?:Excellent\\. )?You're now assigned to (?:kill|bring balance to) (?:the )?(.*) (\\d+) times.*Your reward point tally is (.*)\\.$");
private static final Pattern NPC_ASSIGN_FIRST_MESSAGE = Pattern.compile("^We'll start you off (?:hunting|bringing balance to) (.*), you'll need to kill (\\d*) of them\\.$");
private static final Pattern NPC_CURRENT_MESSAGE = Pattern.compile("^You're still (?:hunting|bringing balance to) (?<name>.+)(?: (?:in|on|south of) (?:the )?(?<location>.+), with|; you have) (?<amount>\\d+) to go\\..*");
private static final Pattern NPC_CURRENT_MESSAGE = Pattern.compile("^You're (?:still(?: meant to be)?|currently assigned to) (?:hunting|bringing balance to|kill|bring balance to|slaying) (?<name>.+?)(?: (?:in|on|south of) (?:the )?(?<location>.+))?(?:, with|; (?:you have|only)) (?<amount>\\d+)(?: more)? to go\\..*");
//Reward UI
private static final Pattern REWARD_POINTS = Pattern.compile("Reward points: ((?:\\d+,)*\\d+)");

View File

@@ -86,6 +86,12 @@ public class SlayerPluginTest
private static final String TASK_KONAR_BOSS = "You're now assigned to bring balance to the Alchemical<br>Hydra 35 times. Your reward point tally is 724.";
private static final String TASK_EXISTING = "You're still hunting suqahs; you have 222 to go. Come<br>back when you've finished your task.";
private static final String TASK_EXISTING_KONAR = "You're still bringing balance to adamant dragons in the Lithkren Vault, with 3 to go. Come back when you're finished.";
private static final String TASK_EXISTING_WILDERNESS = "You're still meant to be slaying bandits in the Wilderness; you have 99 to go. Come back when you've finished your task.";
private static final String TASK_ACTIVATESLAYERGEM = "You're currently assigned to kill fossil island wyverns; only 23 more to go. Your reward point tally is 46.";
private static final String TASK_ACTIVATESLAYERGEM_KONAR = "You're currently assigned to bring balance to adamant dragons in the Lithkren Vault; you have 3 more to go. Your reward point tally is 16.";
private static final String TASK_ACTIVATESLAYERGEM_WILDERNESS = "You're currently assigned to kill bandits in the Wilderness; only 99 more to go. Your reward point tally is 34.";
private static final String REWARD_POINTS = "Reward points: 17,566";
@@ -348,6 +354,70 @@ public class SlayerPluginTest
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()
{