Correctly parse slayer task with the and breaks in npc name
This fixes e.g chaos elemental task assignment. Signed-off-by: Tomas Slusny <slusnucky@gmail.com>
This commit is contained in:
@@ -416,11 +416,7 @@ public class ClueScrollPlugin extends Plugin
|
||||
}
|
||||
|
||||
// Remove line breaks and also the rare occasion where there are double line breaks
|
||||
final String text = Text.removeTags(clueScrollText.getText()
|
||||
.replaceAll("-<br>", "-")
|
||||
.replaceAll("<br>", " ")
|
||||
.replaceAll("[ ]+", " ")
|
||||
.toLowerCase());
|
||||
final String text = Text.sanitizeMultilineText(clueScrollText.getText()).toLowerCase();
|
||||
|
||||
// Early return if this is same clue as already existing one
|
||||
if (clue instanceof TextClueScroll)
|
||||
|
||||
@@ -95,7 +95,7 @@ public class SlayerPlugin extends Plugin
|
||||
|
||||
//NPC messages
|
||||
private static final Pattern NPC_ASSIGN_MESSAGE = Pattern.compile(".*Your new task is to kill\\s*(\\d*) (.*)\\.");
|
||||
private static final Pattern NPC_ASSIGN_BOSS_MESSAGE = Pattern.compile("^Excellent. You're now assigned to kill (.*) (\\d+) times.*Your reward point tally is (.*)\\.$");
|
||||
private static final Pattern NPC_ASSIGN_BOSS_MESSAGE = Pattern.compile("^Excellent. You're now assigned to kill (?:the )?(.*) (\\d+) times.*Your reward point tally is (.*)\\.$");
|
||||
private static final Pattern NPC_CURRENT_MESSAGE = Pattern.compile("You're still hunting (.*); you have (\\d*) to go\\..*");
|
||||
|
||||
//Reward UI
|
||||
@@ -259,13 +259,13 @@ public class SlayerPlugin extends Plugin
|
||||
@Subscribe
|
||||
public void onGameTick(GameTick tick)
|
||||
{
|
||||
Widget NPCDialog = client.getWidget(WidgetInfo.DIALOG_NPC_TEXT);
|
||||
if (NPCDialog != null)
|
||||
Widget npcDialog = client.getWidget(WidgetInfo.DIALOG_NPC_TEXT);
|
||||
if (npcDialog != null)
|
||||
{
|
||||
String NPCText = Text.removeTags(NPCDialog.getText()); //remove color and linebreaks
|
||||
final Matcher mAssign = NPC_ASSIGN_MESSAGE.matcher(NPCText); //number, name
|
||||
final Matcher mAssignBoss = NPC_ASSIGN_BOSS_MESSAGE.matcher(NPCText); // name, number, points
|
||||
final Matcher mCurrent = NPC_CURRENT_MESSAGE.matcher(NPCText); //name, number
|
||||
String npcText = Text.sanitizeMultilineText(npcDialog.getText()); //remove color and linebreaks
|
||||
final Matcher mAssign = NPC_ASSIGN_MESSAGE.matcher(npcText); //number, name
|
||||
final Matcher mAssignBoss = NPC_ASSIGN_BOSS_MESSAGE.matcher(npcText); // name, number, points
|
||||
final Matcher mCurrent = NPC_CURRENT_MESSAGE.matcher(npcText); //name, number
|
||||
|
||||
if (mAssign.find())
|
||||
{
|
||||
|
||||
@@ -48,10 +48,26 @@ public class Text
|
||||
/**
|
||||
* In addition to removing all tags, replaces nbsp with space, trims string and lowercases it
|
||||
* @param str The string to standardize
|
||||
*
|
||||
* @return The given `str` that is standardized
|
||||
*/
|
||||
public static String standardize(String str)
|
||||
{
|
||||
return Text.removeTags(str).replace('\u00A0', ' ').trim().toLowerCase();
|
||||
return removeTags(str).replace('\u00A0', ' ').trim().toLowerCase();
|
||||
}
|
||||
|
||||
/**
|
||||
* In addition to removing all tags, replaces all <br> delimited text with spaces and all multiple continuous
|
||||
* spaces with single space
|
||||
*
|
||||
* @param str The string to sanitize
|
||||
* @return sanitized string
|
||||
*/
|
||||
public static String sanitizeMultilineText(String str)
|
||||
{
|
||||
return removeTags(str
|
||||
.replaceAll("-<br>", "-")
|
||||
.replaceAll("<br>", " ")
|
||||
.replaceAll("[ ]+", " "));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,6 +60,7 @@ public class SlayerPluginTest
|
||||
private static final String TASK_CHECKSLAYERGEM = "You're assigned to kill Suqahs; only 211 more to go.";
|
||||
|
||||
private static final String TASK_BOSS_NEW = "Excellent. You're now assigned to kill Vet'ion 3 times.<br>Your reward point tally is 914.";
|
||||
private static final String TASK_BOSS_NEW_THE = "Excellent. You're now assigned to kill the Chaos <br>Elemental 3 times. Your reward point tally is 914.";
|
||||
|
||||
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.";
|
||||
|
||||
@@ -167,6 +168,19 @@ public class SlayerPluginTest
|
||||
assertEquals(914, slayerPlugin.getPoints());
|
||||
}
|
||||
|
||||
@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());
|
||||
assertEquals(914, slayerPlugin.getPoints());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPartnerTask()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user