slayerplugin: Correct Jad and Zuk task tracking

This commit is contained in:
Owain van Brakel
2019-07-24 00:50:01 +02:00
parent be27fa5399
commit 7afe4f4db3
3 changed files with 111 additions and 19 deletions

View File

@@ -709,7 +709,7 @@ public class SlayerPlugin extends Plugin
} }
} }
private void onExperienceChanged(ExperienceChanged event) void onExperienceChanged(ExperienceChanged event)
{ {
if (event.getSkill() != SLAYER) if (event.getSkill() != SLAYER)
{ {
@@ -724,6 +724,16 @@ public class SlayerPlugin extends Plugin
} }
if (cachedXp != 0) if (cachedXp != 0)
{
final int taskKillExp = Task.getTask(taskName).getExpectedKillExp();
// Only count exp gain as a kill if the task either has no expected exp for a kill, or if the exp gain is equal
// to the expected exp gain for the task.
if (taskKillExp == 0 || taskKillExp == slayerExp - cachedXp)
{
killedOne();
}
else
{ {
// this is not the initial xp sent on login so these are new xp gains // this is not the initial xp sent on login so these are new xp gains
int gains = slayerExp - cachedXp; int gains = slayerExp - cachedXp;
@@ -744,6 +754,7 @@ public class SlayerPlugin extends Plugin
currentTask.setElapsedXp(currentTask.getElapsedXp() + delta); currentTask.setElapsedXp(currentTask.getElapsedXp() + delta);
} }
} }
}
cachedXp = slayerExp; cachedXp = slayerExp;
} }
@@ -815,7 +826,10 @@ public class SlayerPlugin extends Plugin
config.amount(currentTask.getAmount()); // save changed value config.amount(currentTask.getAmount()); // save changed value
currentTask.setPaused(false); // no longer paused since xp is gained currentTask.setPaused(false); // no longer paused since xp is gained
if (panel != null)
{
panel.updateCurrentTask(true, currentTask.isPaused(), currentTask, false); panel.updateCurrentTask(true, currentTask.isPaused(), currentTask, false);
}
if (!this.showInfobox) if (!this.showInfobox)
{ {
@@ -978,7 +992,7 @@ public class SlayerPlugin extends Plugin
} }
} }
private void setTask(String name, int amt, int initAmt, boolean isNewAssignment, int lastCertainAmt) void setTask(String name, int amt, int initAmt, boolean isNewAssignment, int lastCertainAmt)
{ {
setTask(name, amt, initAmt, isNewAssignment, null, lastCertainAmt); setTask(name, amt, initAmt, isNewAssignment, null, lastCertainAmt);
} }

View File

@@ -155,7 +155,7 @@ enum Task
INFERNAL_MAGES("Infernal mages", ItemID.INFERNAL_MAGE, INFERNAL_MAGES("Infernal mages", ItemID.INFERNAL_MAGE,
asList("Malevolent mage"), Collections.emptyList()), asList("Malevolent mage"), Collections.emptyList()),
IRON_DRAGONS("Iron dragons", ItemID.IRON_DRAGON_MASK), IRON_DRAGONS("Iron dragons", ItemID.IRON_DRAGON_MASK),
JAD("TzTok-Jad", ItemID.TZREKJAD), JAD("TzTok-Jad", ItemID.TZREKJAD, 25250),
JELLIES("Jellies", ItemID.JELLY, JELLIES("Jellies", ItemID.JELLY,
asList("Jelly"), Collections.emptyList()), asList("Jelly"), Collections.emptyList()),
JUNGLE_HORROR("Jungle horrors", ItemID.ENSOULED_HORROR_HEAD), JUNGLE_HORROR("Jungle horrors", ItemID.ENSOULED_HORROR_HEAD),
@@ -237,7 +237,7 @@ enum Task
ZOMBIES("Zombies", ItemID.ZOMBIE_HEAD, ZOMBIES("Zombies", ItemID.ZOMBIE_HEAD,
asList("Undead"), Collections.emptyList()), asList("Undead"), Collections.emptyList()),
ZULRAH("Zulrah", ItemID.PET_SNAKELING), ZULRAH("Zulrah", ItemID.PET_SNAKELING),
ZUK("TzKal-Zuk", ItemID.TZREKZUK); ZUK("TzKal-Zuk", ItemID.TZREKZUK, 101890);
//</editor-fold> //</editor-fold>
private static final Map<String, Task> tasks; private static final Map<String, Task> tasks;
@@ -250,6 +250,7 @@ enum Task
private final boolean checkAsTokens; private final boolean checkAsTokens;
private final int weaknessThreshold; private final int weaknessThreshold;
private final int weaknessItem; private final int weaknessItem;
private final int expectedKillExp;
static static
{ {
@@ -273,6 +274,7 @@ enum Task
this.targetNames = new ArrayList<>(); this.targetNames = new ArrayList<>();
this.npcIds = new ArrayList<>(); this.npcIds = new ArrayList<>();
this.checkAsTokens = true; this.checkAsTokens = true;
this.expectedKillExp = 0;
} }
Task(String name, int itemSpriteId, int weaknessThreshold, int weaknessItem) Task(String name, int itemSpriteId, int weaknessThreshold, int weaknessItem)
@@ -285,6 +287,7 @@ enum Task
this.targetNames = new ArrayList<>(); this.targetNames = new ArrayList<>();
this.npcIds = new ArrayList<>(); this.npcIds = new ArrayList<>();
this.checkAsTokens = true; this.checkAsTokens = true;
this.expectedKillExp = 0;
} }
Task(String name, int itemSpriteId, boolean checkAsTokens) Task(String name, int itemSpriteId, boolean checkAsTokens)
@@ -297,6 +300,20 @@ enum Task
this.targetNames = new ArrayList<>(); this.targetNames = new ArrayList<>();
this.npcIds = new ArrayList<>(); this.npcIds = new ArrayList<>();
this.checkAsTokens = checkAsTokens; this.checkAsTokens = checkAsTokens;
this.expectedKillExp = 0;
}
Task(String name, int itemSpriteId, int expectedKillExp)
{
Preconditions.checkArgument(itemSpriteId >= 0);
this.name = name;
this.itemSpriteId = itemSpriteId;
this.weaknessThreshold = -1;
this.weaknessItem = -1;
this.targetNames = new ArrayList<>();
this.npcIds = new ArrayList<>();
this.checkAsTokens = true;
this.expectedKillExp = expectedKillExp;
} }
Task(String name, int itemSpriteId, List<String> targetNames, List<Integer> npcIds) Task(String name, int itemSpriteId, List<String> targetNames, List<Integer> npcIds)
@@ -309,6 +326,7 @@ enum Task
this.targetNames = targetNames; this.targetNames = targetNames;
this.npcIds = npcIds; this.npcIds = npcIds;
this.checkAsTokens = true; this.checkAsTokens = true;
this.expectedKillExp = 0;
} }
Task(String name, int itemSpriteId, List<String> targetNames, List<Integer> npcIds, int weaknessThreshold, int weaknessItem) Task(String name, int itemSpriteId, List<String> targetNames, List<Integer> npcIds, int weaknessThreshold, int weaknessItem)
@@ -321,6 +339,7 @@ enum Task
this.targetNames = targetNames; this.targetNames = targetNames;
this.npcIds = npcIds; this.npcIds = npcIds;
this.checkAsTokens = true; this.checkAsTokens = true;
this.expectedKillExp = 0;
} }
Task(String name, int itemSpriteId, List<String> targetNames, List<Integer> npcIds, boolean checkAsTokens) Task(String name, int itemSpriteId, List<String> targetNames, List<Integer> npcIds, boolean checkAsTokens)
@@ -333,6 +352,7 @@ enum Task
this.targetNames = targetNames; this.targetNames = targetNames;
this.npcIds = npcIds; this.npcIds = npcIds;
this.checkAsTokens = checkAsTokens; this.checkAsTokens = checkAsTokens;
this.expectedKillExp = 0;
} }
static Task getTask(String taskName) static Task getTask(String taskName)

View File

@@ -34,8 +34,10 @@ import net.runelite.api.ChatMessageType;
import static net.runelite.api.ChatMessageType.GAMEMESSAGE; import static net.runelite.api.ChatMessageType.GAMEMESSAGE;
import net.runelite.api.Client; import net.runelite.api.Client;
import net.runelite.api.MessageNode; import net.runelite.api.MessageNode;
import net.runelite.api.Player;
import net.runelite.api.Skill; import net.runelite.api.Skill;
import net.runelite.api.Varbits; import net.runelite.api.Varbits;
import net.runelite.api.coords.LocalPoint;
import net.runelite.api.events.ChatMessage; import net.runelite.api.events.ChatMessage;
import net.runelite.api.events.ExperienceChanged; import net.runelite.api.events.ExperienceChanged;
import net.runelite.api.events.GameTick; import net.runelite.api.events.GameTick;
@@ -453,4 +455,60 @@ public class SlayerPluginTest
assertEquals(name, name.toLowerCase()); assertEquals(name, name.toLowerCase());
} }
} }
@Test
public void testJadTaskKill()
{
final Player player = mock(Player.class);
when(player.getLocalLocation()).thenReturn(new LocalPoint(0, 0));
when(client.getLocalPlayer()).thenReturn(player);
final ExperienceChanged experienceChanged = new ExperienceChanged();
experienceChanged.setSkill(Skill.SLAYER);
when(client.getSkillExperience(Skill.SLAYER)).thenReturn(100);
slayerPlugin.onExperienceChanged(experienceChanged);
slayerPlugin.setTask("TzTok-Jad", 1, 1, true, 0);
// One bat kill
when(client.getSkillExperience(Skill.SLAYER)).thenReturn(110);
slayerPlugin.onExperienceChanged(experienceChanged);
assertEquals(1, slayerPlugin.getCurrentTask().getAmount());
// One Jad kill
when(client.getSkillExperience(Skill.SLAYER)).thenReturn(25_360);
slayerPlugin.onExperienceChanged(experienceChanged);
assertEquals(0, slayerPlugin.getCurrentTask().getAmount());
}
@Test
public void testZukTaskKill()
{
final Player player = mock(Player.class);
when(player.getLocalLocation()).thenReturn(new LocalPoint(0, 0));
when(client.getLocalPlayer()).thenReturn(player);
final ExperienceChanged experienceChanged = new ExperienceChanged();
experienceChanged.setSkill(Skill.SLAYER);
when(client.getSkillExperience(Skill.SLAYER)).thenReturn(100);
slayerPlugin.onExperienceChanged(experienceChanged);
slayerPlugin.setTask("TzKal-Zuk", 1, 1, true, 0);
// One bat kill
when(client.getSkillExperience(Skill.SLAYER)).thenReturn(125);
slayerPlugin.onExperienceChanged(experienceChanged);
assertEquals(1, slayerPlugin.getCurrentTask().getAmount());
// One Zuk kill
when(client.getSkillExperience(Skill.SLAYER)).thenReturn(102_015);
slayerPlugin.onExperienceChanged(experienceChanged);
assertEquals(0, slayerPlugin.getCurrentTask().getAmount());
}
} }