Slayer plugin: change regex groups to named groups

This commit is contained in:
Charlie Waters
2019-01-13 19:54:17 -05:00
parent 9e439dc1a2
commit 2e148782d7

View File

@@ -81,7 +81,7 @@ import net.runelite.client.util.Text;
public class SlayerPlugin extends Plugin public class SlayerPlugin extends Plugin
{ {
//Chat messages //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 .*:) (?:the )?(.*?)(?: in the Wilderness)?(?:; only | \\()(\\d*)(?: more to go\\.|\\))$"); 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 )?(?<name>.+?)(?: (?:in|on) (?:the )?(?:[^;]+))?(?:; only | \\()(?<amount>\\d+)(?: more to go\\.|\\))$");
private static final String CHAT_GEM_COMPLETE_MESSAGE = "You need something new to hunt."; 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("(?:\\d+,)*\\d+");
private static final String CHAT_CANCEL_MESSAGE = "Your task has been cancelled."; private static final String CHAT_CANCEL_MESSAGE = "Your task has been cancelled.";
@@ -98,10 +98,10 @@ public class SlayerPlugin extends Plugin
private static final Pattern COMBAT_BRACELET_TASK_UPDATE_MESSAGE = Pattern.compile("^You still need to kill (\\d+) monsters to complete your current Slayer assignment"); private static final Pattern COMBAT_BRACELET_TASK_UPDATE_MESSAGE = Pattern.compile("^You still need to kill (\\d+) monsters to complete your current Slayer assignment");
//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|You are to bring balance to)\\s*(?<amount>\\d+) (?<name>.+?)(?: (?:in|on) (?:the )?(?:.+))?\\.");
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_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_ASSIGN_FIRST_MESSAGE = Pattern.compile("^We'll start you off hunting (.*), you'll need to kill (\\d*) of them."); private static final Pattern NPC_ASSIGN_FIRST_MESSAGE = Pattern.compile("^We'll start you off hunting (.*), you'll need to kill (\\d*) of them.");
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|bringing balance to) (?<name>.+)(?: (?:in|on) (?:the )?(?:.+), with|; you have) (?<amount>\\d+) to go\\..*");
//Reward UI //Reward UI
private static final Pattern REWARD_POINTS = Pattern.compile("Reward points: ((?:\\d+,)*\\d+)"); private static final Pattern REWARD_POINTS = Pattern.compile("Reward points: ((?:\\d+,)*\\d+)");
@@ -287,8 +287,9 @@ public class SlayerPlugin extends Plugin
if (mAssign.find()) if (mAssign.find())
{ {
int amount = Integer.parseInt(mAssign.group(1)); String name = mAssign.group("name");
setTask(mAssign.group(2), amount, amount); int amount = Integer.parseInt(mAssign.group("amount"));
setTask(name, amount, amount);
} }
else if (mAssignFirst.find()) else if (mAssignFirst.find())
{ {
@@ -303,8 +304,9 @@ public class SlayerPlugin extends Plugin
} }
else if (mCurrent.find()) else if (mCurrent.find())
{ {
int amount = Integer.parseInt(mCurrent.group(2)); String name = mCurrent.group("name");
setTask(mCurrent.group(1), amount, amount); int amount = Integer.parseInt(mCurrent.group("amount"));
setTask(name, amount, initialAmount);
} }
} }
@@ -447,9 +449,9 @@ public class SlayerPlugin extends Plugin
if (mProgress.find()) if (mProgress.find())
{ {
String gemTaskName = mProgress.group(1); String name = mProgress.group("name");
int gemAmount = Integer.parseInt(mProgress.group(2)); int gemAmount = Integer.parseInt(mProgress.group("amount"));
setTask(gemTaskName, gemAmount, initialAmount); setTask(name, gemAmount, initialAmount);
return; return;
} }