slayer: Fix name matching
The Slayer plugin highlights target monsters based on their name rather than NPC ID, as many common monsters (skeletons, zombies, etc.) have nearly endless variations for different models and combat levels. Previously, this name matching was done via a simple `String#contains()`, which led to some incorrect matches such as pirates being highlighted while on rat tasks and Jonny the beard being highlighted while on bear tasks. This commit changes matching to use regex to match string boundaries or whitespace at either end of the task string, ensuring these substring matches can only happen when word breaks occur. The only known existing case where this would apply is for baby dragons and brutal dragons, which are valid alternatives for their respective chromatic dragon tasks.
This commit is contained in:
@@ -60,6 +60,8 @@ import net.runelite.client.game.npcoverlay.NpcOverlayService;
|
||||
import net.runelite.client.ui.overlay.OverlayManager;
|
||||
import net.runelite.client.ui.overlay.infobox.InfoBoxManager;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -926,4 +928,30 @@ public class SlayerPluginTest
|
||||
assertEquals("Suqahs", slayerPlugin.getTaskName());
|
||||
assertEquals(229, slayerPlugin.getAmount()); // 2 kills
|
||||
}
|
||||
|
||||
@Test
|
||||
public void npcMatching()
|
||||
{
|
||||
assertTrue(matches("Abyssal demon", Task.ABYSSAL_DEMONS));
|
||||
assertTrue(matches("Baby blue dragon", Task.BLUE_DRAGONS));
|
||||
assertTrue(matches("Duck", Task.BIRDS));
|
||||
assertTrue(matches("Donny the Lad", Task.BANDITS));
|
||||
|
||||
assertFalse(matches("Rat", Task.PIRATES));
|
||||
assertFalse(matches("Wolf", Task.WEREWOLVES));
|
||||
assertFalse(matches("Scorpia's offspring", Task.SCORPIA));
|
||||
assertFalse(matches("Jonny the beard", Task.BEARS));
|
||||
}
|
||||
|
||||
private boolean matches(final String npcName, final Task task)
|
||||
{
|
||||
final NPC npc = mock(NPC.class);
|
||||
final NPCComposition comp = mock(NPCComposition.class);
|
||||
when(npc.getTransformedComposition()).thenReturn(comp);
|
||||
when(comp.getName()).thenReturn(npcName);
|
||||
when(comp.getActions()).thenReturn(new String[] { "Attack" });
|
||||
|
||||
slayerPlugin.setTask(task.getName(), 0, 0);
|
||||
return slayerPlugin.isTarget(npc);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user