From 2be9fe9df3357b3d27863b0efeb7224d564b1c93 Mon Sep 17 00:00:00 2001 From: Adam Date: Mon, 25 Jan 2021 13:03:09 -0500 Subject: [PATCH] slayer plugin: update task completion message parsing --- .../client/plugins/slayer/SlayerPlugin.java | 47 +++++++---------- .../plugins/slayer/SlayerPluginTest.java | 51 ++++++++++++++++--- 2 files changed, 64 insertions(+), 34 deletions(-) diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/slayer/SlayerPlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/slayer/SlayerPlugin.java index 72ad3524ee..db9b247fe3 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/slayer/SlayerPlugin.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/slayer/SlayerPlugin.java @@ -99,7 +99,7 @@ public class SlayerPlugin extends Plugin //Chat messages private static final Pattern CHAT_GEM_PROGRESS_MESSAGE = Pattern.compile("^(?:You're assigned to kill|You have received a new Slayer assignment from .*:) (?:[Tt]he )?(?.+?)(?: (?:in|on|south of) (?:the )?(?[^;]+))?(?:; only | \\()(?\\d+)(?: more to go\\.|\\))$"); private static final String CHAT_GEM_COMPLETE_MESSAGE = "You need something new to hunt."; - private static final Pattern CHAT_COMPLETE_MESSAGE = Pattern.compile("(?:\\d+,)*\\d+"); + private static final Pattern CHAT_COMPLETE_MESSAGE = Pattern.compile("You've completed (?:at least )?(?[\\d,]+) (?:Wilderness )?tasks?(?: and received \\d+ points, giving you a total of (?[\\d,]+)| and reached the maximum amount of Slayer points \\((?[\\d,]+)\\))?"); private static final String CHAT_CANCEL_MESSAGE = "Your task has been cancelled."; private static final String CHAT_CANCEL_MESSAGE_JAD = "You no longer have a slayer task as you left the fight cave."; private static final String CHAT_CANCEL_MESSAGE_ZUK = "You no longer have a slayer task as you left the Inferno."; @@ -450,6 +450,7 @@ public class SlayerPlugin extends Plugin expeditiousChargeCount = Integer.parseInt(mExpeditious.group(1)); config.expeditious(expeditiousChargeCount); } + if (chatMsg.startsWith(CHAT_BRACELET_SLAUGHTER_CHARGE)) { Matcher mSlaughter = CHAT_BRACELET_SLAUGHTER_CHARGE_REGEX.matcher(chatMsg); @@ -466,35 +467,25 @@ public class SlayerPlugin extends Plugin { Matcher mComplete = CHAT_COMPLETE_MESSAGE.matcher(chatMsg); - List matches = new ArrayList<>(); - while (mComplete.find()) + if (mComplete.find()) { - matches.add(mComplete.group(0).replaceAll(",", "")); - } + String mTasks = mComplete.group("tasks"); + String mPoints = mComplete.group("points"); + if (mPoints == null) + { + mPoints = mComplete.group("points2"); + } - int streak = -1, points = -1; - switch (matches.size()) - { - case 0: - streak = 1; - break; - case 1: - streak = Integer.parseInt(matches.get(0)); - break; - case 3: - streak = Integer.parseInt(matches.get(0)); - points = Integer.parseInt(matches.get(2)); - break; - default: - log.warn("Unreachable default case for message ending in '; return to Slayer master'"); - } - if (streak != -1) - { - config.streak(streak); - } - if (points != -1) - { - config.points(points); + if (mTasks != null) + { + int streak = Integer.parseInt(mTasks.replace(",", "")); + config.streak(streak); + } + if (mPoints != null) + { + int points = Integer.parseInt(mPoints.replace(",", "")); + config.points(points); + } } setTask("", 0, 0); diff --git a/runelite-client/src/test/java/net/runelite/client/plugins/slayer/SlayerPluginTest.java b/runelite-client/src/test/java/net/runelite/client/plugins/slayer/SlayerPluginTest.java index d2b4b13f5a..967802b2cf 100644 --- a/runelite-client/src/test/java/net/runelite/client/plugins/slayer/SlayerPluginTest.java +++ b/runelite-client/src/test/java/net/runelite/client/plugins/slayer/SlayerPluginTest.java @@ -101,11 +101,14 @@ public class SlayerPluginTest private static final String REWARD_POINTS = "Reward points: 17,566"; - private static final String TASK_ONE = "You've completed one task; return to a Slayer master."; - private static final String TASK_COMPLETE_NO_POINTS = "You've completed 3 tasks; return to a Slayer master."; - private static final String TASK_POINTS = "You've completed 9 tasks and received 0 points, giving you a total of 18,000; return to a Slayer master."; - private static final String TASK_LARGE_STREAK = "You've completed 2,465 tasks and received 15 points, giving you a total of 17,566,000; return to a Slayer master."; - private static final String TASK_COMPETE_TURAEL = "You've completed 104 tasks. You'll be eligible to earn reward points if you complete tasks from a more advanced Slayer Master."; + private static final String TASK_ONE = "You've completed 1 task and will need 4 more before you start receiving Slayer points; return to a Slayer master."; + private static final String TASK_COMPLETE_NO_POINTS = "You've completed 3 tasks and will need 2 more before you start receiving Slayer points; return to a Slayer master."; + private static final String TASK_POINTS = "You've completed 9 tasks and received 10 points, giving you a total of 18,000; return to a Slayer master."; + private static final String TASK_LARGE_STREAK = "You've completed 2,465 tasks and received 15 points, giving you a total of 131,071; return to a Slayer master."; + private static final String TASK_COMPETE_TURAEL = "You've completed 104 tasks . You'll be eligible to earn reward points if you complete tasks from a more advanced Slayer Master."; + private static final String TASK_MAX_STREAK = "You've completed at least 16,000 tasks and received 15 points, giving you a total of 131,071; return to a Slayer master."; + private static final String TASK_MAX_POINTS = "You've completed 9 tasks and reached the maximum amount of Slayer points (131,071); return to a Slayer master."; + private static final String TASK_WILDERNESS = "You've completed 9 Wilderness tasks and received 10 points, giving you a total of 18,000; return to a Slayer master."; private static final String TASK_COMPLETE = "You need something new to hunt."; private static final String TASK_CANCELED = "Your task has been cancelled."; @@ -483,7 +486,7 @@ public class SlayerPluginTest verify(slayerConfig).streak(2465); assertEquals("", slayerPlugin.getTaskName()); assertEquals(0, slayerPlugin.getAmount()); - verify(slayerConfig).points(17_566_000); + verify(slayerConfig).points(131_071); } @Test @@ -497,6 +500,42 @@ public class SlayerPluginTest assertEquals(0, slayerPlugin.getAmount()); } + @Test + public void testTaskMaxStreak() + { + ChatMessage chatMessageEvent = new ChatMessage(null, GAMEMESSAGE, "", TASK_MAX_STREAK, null, 0); + slayerPlugin.onChatMessage(chatMessageEvent); + + verify(slayerConfig).streak(16_000); + verify(slayerConfig).points(131_071); + assertEquals("", slayerPlugin.getTaskName()); + assertEquals(0, slayerPlugin.getAmount()); + } + + @Test + public void testTaskMaxPoints() + { + ChatMessage chatMessageEvent = new ChatMessage(null, GAMEMESSAGE, "", TASK_MAX_POINTS, null, 0); + slayerPlugin.onChatMessage(chatMessageEvent); + + verify(slayerConfig).streak(9); + verify(slayerConfig).points(131_071); + assertEquals("", slayerPlugin.getTaskName()); + assertEquals(0, slayerPlugin.getAmount()); + } + + @Test + public void testTaskWilderness() + { + ChatMessage chatMessageEvent = new ChatMessage(null, GAMEMESSAGE, "", TASK_WILDERNESS, null, 0); + slayerPlugin.onChatMessage(chatMessageEvent); + + verify(slayerConfig).streak(9); + verify(slayerConfig).points(18_000); + assertEquals("", slayerPlugin.getTaskName()); + assertEquals(0, slayerPlugin.getAmount()); + } + @Test public void testComplete() {