Merge pull request #5627 from Nightfirecat/fix-boss-task-assignment
slayer plugin: Add parsing for boss task assignments
This commit is contained in:
@@ -95,6 +95,7 @@ public class SlayerPlugin extends Plugin
|
|||||||
|
|
||||||
//NPC messages
|
//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_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_CURRENT_MESSAGE = Pattern.compile("You're still hunting (.*); you have (\\d*) to go\\..*");
|
private static final Pattern NPC_CURRENT_MESSAGE = Pattern.compile("You're still hunting (.*); you have (\\d*) to go\\..*");
|
||||||
|
|
||||||
//Reward UI
|
//Reward UI
|
||||||
@@ -262,19 +263,23 @@ public class SlayerPlugin extends Plugin
|
|||||||
if (NPCDialog != null)
|
if (NPCDialog != null)
|
||||||
{
|
{
|
||||||
String NPCText = Text.removeTags(NPCDialog.getText()); //remove color and linebreaks
|
String NPCText = Text.removeTags(NPCDialog.getText()); //remove color and linebreaks
|
||||||
Matcher mAssign = NPC_ASSIGN_MESSAGE.matcher(NPCText); //number, name
|
final Matcher mAssign = NPC_ASSIGN_MESSAGE.matcher(NPCText); //number, name
|
||||||
Matcher mCurrent = NPC_CURRENT_MESSAGE.matcher(NPCText); //name, number
|
final Matcher mAssignBoss = NPC_ASSIGN_BOSS_MESSAGE.matcher(NPCText); // name, number, points
|
||||||
boolean found1 = mAssign.find();
|
final Matcher mCurrent = NPC_CURRENT_MESSAGE.matcher(NPCText); //name, number
|
||||||
boolean found2 = mCurrent.find();
|
|
||||||
if (!found1 && !found2)
|
if (mAssign.find())
|
||||||
{
|
{
|
||||||
return;
|
setTask(mAssign.group(2), Integer.parseInt(mAssign.group(1)));
|
||||||
|
}
|
||||||
|
else if (mAssignBoss.find())
|
||||||
|
{
|
||||||
|
setTask(mAssignBoss.group(1), Integer.parseInt(mAssignBoss.group(2)));
|
||||||
|
points = Integer.parseInt(mAssignBoss.group(3).replaceAll(",", ""));
|
||||||
|
}
|
||||||
|
else if (mCurrent.find())
|
||||||
|
{
|
||||||
|
setTask(mCurrent.group(1), Integer.parseInt(mCurrent.group(2)));
|
||||||
}
|
}
|
||||||
|
|
||||||
String taskName = found1 ? mAssign.group(2) : mCurrent.group(1);
|
|
||||||
int amount = Integer.parseInt(found1 ? mAssign.group(1) : mCurrent.group(2));
|
|
||||||
|
|
||||||
setTask(taskName, amount);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget braceletBreakWidget = client.getWidget(WidgetInfo.DIALOG_SPRITE_TEXT);
|
Widget braceletBreakWidget = client.getWidget(WidgetInfo.DIALOG_SPRITE_TEXT);
|
||||||
|
|||||||
@@ -56,6 +56,8 @@ public class SlayerPluginTest
|
|||||||
private static final String TASK_NEW = "Your new task is to kill 231 Suqahs.";
|
private static final String TASK_NEW = "Your new task is to kill 231 Suqahs.";
|
||||||
private static final String TASK_NEW_NPC_CONTACT = "Excellent, you're doing great. Your new task is to kill<br>211 Suqahs.";
|
private static final String TASK_NEW_NPC_CONTACT = "Excellent, you're doing great. Your new task is to kill<br>211 Suqahs.";
|
||||||
|
|
||||||
|
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_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 = "You're still hunting suqahs; you have 222 to go. Come<br>back when you've finished your task.";
|
||||||
|
|
||||||
private static final String REWARD_POINTS = "Reward points: 17,566";
|
private static final String REWARD_POINTS = "Reward points: 17,566";
|
||||||
@@ -149,6 +151,19 @@ public class SlayerPluginTest
|
|||||||
assertEquals(211, slayerPlugin.getAmount());
|
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());
|
||||||
|
assertEquals(914, slayerPlugin.getPoints());
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testExistingTask()
|
public void testExistingTask()
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user