slayer plugin: better support multikills
This observes deaths of tagged npcs each tick and will use those if available instead of assuming one kill per xpdrop
This commit is contained in:
@@ -28,19 +28,25 @@ import com.google.inject.Guice;
|
||||
import com.google.inject.testing.fieldbinder.Bind;
|
||||
import com.google.inject.testing.fieldbinder.BoundFieldModule;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import javax.inject.Inject;
|
||||
import net.runelite.api.ChatMessageType;
|
||||
import static net.runelite.api.ChatMessageType.GAMEMESSAGE;
|
||||
import net.runelite.api.Client;
|
||||
import net.runelite.api.GameState;
|
||||
import net.runelite.api.Hitsplat;
|
||||
import net.runelite.api.MessageNode;
|
||||
import net.runelite.api.NPC;
|
||||
import net.runelite.api.NPCComposition;
|
||||
import net.runelite.api.Player;
|
||||
import net.runelite.api.Skill;
|
||||
import net.runelite.api.coords.LocalPoint;
|
||||
import net.runelite.api.events.ActorDeath;
|
||||
import net.runelite.api.events.ChatMessage;
|
||||
import net.runelite.api.events.GameStateChanged;
|
||||
import net.runelite.api.events.GameTick;
|
||||
import net.runelite.api.events.HitsplatApplied;
|
||||
import net.runelite.api.events.StatChanged;
|
||||
import net.runelite.api.widgets.Widget;
|
||||
import net.runelite.api.widgets.WidgetInfo;
|
||||
@@ -771,7 +777,7 @@ public class SlayerPluginTest
|
||||
slayerPlugin.onChatMessage(chatMessage);
|
||||
|
||||
assertEquals("Suqahs", slayerPlugin.getTaskName());
|
||||
slayerPlugin.killedOne();
|
||||
slayerPlugin.killed(1);
|
||||
assertEquals(30, slayerPlugin.getAmount());
|
||||
}
|
||||
|
||||
@@ -863,4 +869,67 @@ public class SlayerPluginTest
|
||||
|
||||
verify(infoBoxManager, never()).addInfoBox(any());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultikill()
|
||||
{
|
||||
final Player player = mock(Player.class);
|
||||
when(player.getLocalLocation()).thenReturn(new LocalPoint(0, 0));
|
||||
when(client.getLocalPlayer()).thenReturn(player);
|
||||
|
||||
// Setup xp cache
|
||||
StatChanged statChanged = new StatChanged(
|
||||
Skill.SLAYER,
|
||||
0,
|
||||
1,
|
||||
1
|
||||
);
|
||||
slayerPlugin.onStatChanged(statChanged);
|
||||
|
||||
NPCComposition npcComposition = mock(NPCComposition.class);
|
||||
when(npcComposition.getActions()).thenReturn(new String[]{"Attack"});
|
||||
|
||||
NPC npc1 = mock(NPC.class);
|
||||
when(npc1.getName()).thenReturn("Suqah");
|
||||
when(npc1.getTransformedComposition()).thenReturn(npcComposition);
|
||||
|
||||
NPC npc2 = mock(NPC.class);
|
||||
when(npc2.getName()).thenReturn("Suqah");
|
||||
when(npc2.getTransformedComposition()).thenReturn(npcComposition);
|
||||
|
||||
when(client.getNpcs()).thenReturn(Arrays.asList(npc1, npc2));
|
||||
|
||||
// Set task
|
||||
Widget npcDialog = mock(Widget.class);
|
||||
when(npcDialog.getText()).thenReturn(TASK_NEW);
|
||||
when(client.getWidget(WidgetInfo.DIALOG_NPC_TEXT)).thenReturn(npcDialog);
|
||||
slayerPlugin.onGameTick(new GameTick());
|
||||
|
||||
// Damage both npcs
|
||||
Hitsplat hitsplat = new Hitsplat(Hitsplat.HitsplatType.DAMAGE_ME, 1, 1);
|
||||
HitsplatApplied hitsplatApplied = new HitsplatApplied();
|
||||
hitsplatApplied.setHitsplat(hitsplat);
|
||||
hitsplatApplied.setActor(npc1);
|
||||
slayerPlugin.onHitsplatApplied(hitsplatApplied);
|
||||
|
||||
hitsplatApplied.setActor(npc2);
|
||||
slayerPlugin.onHitsplatApplied(hitsplatApplied);
|
||||
|
||||
// Kill both npcs
|
||||
slayerPlugin.onActorDeath(new ActorDeath(npc1));
|
||||
slayerPlugin.onActorDeath(new ActorDeath(npc2));
|
||||
|
||||
slayerPlugin.onGameTick(new GameTick());
|
||||
|
||||
statChanged = new StatChanged(
|
||||
Skill.SLAYER,
|
||||
105,
|
||||
2,
|
||||
2
|
||||
);
|
||||
slayerPlugin.onStatChanged(statChanged);
|
||||
|
||||
assertEquals("Suqahs", slayerPlugin.getTaskName());
|
||||
assertEquals(229, slayerPlugin.getAmount()); // 2 kills
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user