chat commands: fix tob hm/sm kc/pb tracking

The : in the boss name breaks for logged in users, so remap it to a
clean name instead. Also add short names.
This commit is contained in:
Adam
2021-06-04 23:40:45 -04:00
parent d3a2e4bbc2
commit c271580e74
2 changed files with 55 additions and 6 deletions

View File

@@ -98,7 +98,7 @@ public class ChatCommandsPlugin extends Plugin
private static final String COX_TEAM_SIZES = "(?:\\d+(?:\\+|-\\d+)? players|Solo)";
private static final Pattern RAIDS_PB_PATTERN = Pattern.compile("<col=ef20ff>Congratulations - your raid is complete!</col><br>Team size: <col=ff0000>" + COX_TEAM_SIZES + "</col> Duration:</col> <col=ff0000>(?<pb>[0-9:]+(?:\\.[0-9]+)?)</col> \\(new personal best\\)</col>");
private static final Pattern RAIDS_DURATION_PATTERN = Pattern.compile("<col=ef20ff>Congratulations - your raid is complete!</col><br>Team size: <col=ff0000>" + COX_TEAM_SIZES + "</col> Duration:</col> <col=ff0000>[0-9:.]+</col> Personal best: </col><col=ff0000>(?<pb>[0-9:]+(?:\\.[0-9]+)?)</col>");
private static final Pattern TOB_WAVE_PB_PATTERN = Pattern.compile("^.*Theatre of Blood wave completion time: <col=ff0000>(?<pb>[0-9:]+(?:\\.[0-9]+)?)</col> \\(Personal best!\\)");
private static final Pattern TOB_WAVE_PB_PATTERN = Pattern.compile("^.*Theatre of Blood wave completion time: <col=ff0000>(?<pb>[0-9:]+(?:\\.[0-9]+)?)</col> \\((Personal best!|new personal best)\\)");
private static final Pattern TOB_WAVE_DURATION_PATTERN = Pattern.compile("^.*Theatre of Blood wave completion time: <col=ff0000>[0-9:.]+</col><br></col>Personal best: (?<pb>[0-9:]+(?:\\.[0-9]+)?)");
private static final Pattern KILL_DURATION_PATTERN = Pattern.compile("(?i)^(?:(?:Fight |Lap |Challenge |Corrupted challenge )?duration:|Subdued in) <col=[0-9a-f]{6}>[0-9:.]+</col>\\. Personal best: (?:<col=ff0000>)?(?<pb>[0-9:]+(?:\\.[0-9]+)?)");
private static final Pattern NEW_PB_PATTERN = Pattern.compile("(?i)^(?:(?:Fight |Lap |Challenge |Corrupted challenge )?duration:|Subdued in) <col=[0-9a-f]{6}>(?<pb>[0-9:]+(?:\\.[0-9]+)?)</col> \\(new personal best\\)");
@@ -245,6 +245,11 @@ public class ChatCommandsPlugin extends Plugin
configManager.setRSProfileConfiguration("killcount", boss.toLowerCase(), killcount);
}
private void unsetKc(String boss)
{
configManager.unsetRSProfileConfiguration("killcount", boss.toLowerCase());
}
private int getKc(String boss)
{
Integer killCount = configManager.getRSProfileConfiguration("killcount", boss.toLowerCase(), int.class);
@@ -256,6 +261,11 @@ public class ChatCommandsPlugin extends Plugin
configManager.setRSProfileConfiguration("personalbest", boss.toLowerCase(), seconds);
}
private void unsetPb(String boss)
{
configManager.unsetRSProfileConfiguration("personalbest", boss.toLowerCase());
}
private double getPb(String boss)
{
Double personalBest = configManager.getRSProfileConfiguration("personalbest", boss.toLowerCase(), double.class);
@@ -280,19 +290,30 @@ public class ChatCommandsPlugin extends Plugin
String boss = matcher.group(1);
int kc = Integer.parseInt(matcher.group(2));
boss = KILLCOUNT_RENAMES.getOrDefault(boss, boss);
String renamedBoss = KILLCOUNT_RENAMES
.getOrDefault(boss, boss)
// The config service doesn't support keys with colons in them
.replace(":", "");
if (boss != renamedBoss)
{
// Unset old TOB kc
unsetKc(boss);
unsetPb(boss);
unsetKc(boss.replace(":", "."));
unsetPb(boss.replace(":", "."));
}
setKc(boss, kc);
setKc(renamedBoss, kc);
// We either already have the pb, or need to remember the boss for the upcoming pb
if (lastPb > -1)
{
log.debug("Got out-of-order personal best for {}: {}", boss, lastPb);
setPb(boss, lastPb);
log.debug("Got out-of-order personal best for {}: {}", renamedBoss, lastPb);
setPb(renamedBoss, lastPb);
lastPb = -1;
}
else
{
lastBossKill = boss;
lastBossKill = renamedBoss;
lastBossTime = client.getTickCount();
}
return;
@@ -1687,6 +1708,19 @@ public class ChatCommandsPlugin extends Plugin
case "raids 2":
return "Theatre of Blood";
case "Theatre of Blood: Story Mode":
case "tob sm":
case "tob story mode":
case "tob story":
return "Theatre of Blood Story Mode";
case "Theatre of Blood: Hard Mode":
case "tob cm":
case "tob hm":
case "tob hard mode":
case "tob hard":
return "Theatre of Blood Hard Mode";
// agility course
case "prif":
case "prifddinas":

View File

@@ -194,6 +194,21 @@ public class ChatCommandsPluginTest
verify(configManager).setRSProfileConfiguration("personalbest", "theatre of blood", 37 * 60 + 4.4);
}
@Test
public void testTheatreOfBloodStoryMode()
{
ChatMessage chatMessage = new ChatMessage(null, GAMEMESSAGE, "",
"Theatre of Blood wave completion time: <col=ff0000>5:04</col> (new personal best)<br>" +
"Theatre of Blood total completion time: <col=ff0000>24:39</col> (new personal best)", null, 0);
chatCommandsPlugin.onChatMessage(chatMessage);
ChatMessage chatMessageEvent = new ChatMessage(null, GAMEMESSAGE, "", "Your completed Theatre of Blood: Story Mode count is: <col=ff0000>73</col>.", null, 0);
chatCommandsPlugin.onChatMessage(chatMessageEvent);
verify(configManager).setRSProfileConfiguration("killcount", "theatre of blood story mode", 73);
verify(configManager).setRSProfileConfiguration("personalbest", "theatre of blood story mode", 5 * 60 + 4.0);
}
@Test
public void testWintertodt()
{