slayerplugin: Fix first slayer kill not being registered
Because a user can have 0 slayer experience on a new account, we cannot rely on 0 as the pre-login value. Prior to this change, a player getting their first slayer kill in the described scenario would cause it not to be counted toward the tracked task.
This commit is contained in:
@@ -204,7 +204,7 @@ public class SlayerPlugin extends Plugin
|
|||||||
private int points;
|
private int points;
|
||||||
|
|
||||||
private TaskCounter counter;
|
private TaskCounter counter;
|
||||||
private int cachedXp;
|
private int cachedXp = -1;
|
||||||
private Instant infoTimer;
|
private Instant infoTimer;
|
||||||
private boolean loginFlag;
|
private boolean loginFlag;
|
||||||
private List<String> targetNames = new ArrayList<>();
|
private List<String> targetNames = new ArrayList<>();
|
||||||
@@ -217,15 +217,19 @@ public class SlayerPlugin extends Plugin
|
|||||||
overlayManager.add(targetWeaknessOverlay);
|
overlayManager.add(targetWeaknessOverlay);
|
||||||
overlayManager.add(targetMinimapOverlay);
|
overlayManager.add(targetMinimapOverlay);
|
||||||
|
|
||||||
if (client.getGameState() == GameState.LOGGED_IN
|
if (client.getGameState() == GameState.LOGGED_IN)
|
||||||
&& config.amount() != -1
|
|
||||||
&& !config.taskName().isEmpty())
|
|
||||||
{
|
{
|
||||||
points = config.points();
|
cachedXp = client.getSkillExperience(SLAYER);
|
||||||
streak = config.streak();
|
|
||||||
setExpeditiousChargeCount(config.expeditious());
|
if (config.amount() != -1
|
||||||
setSlaughterChargeCount(config.slaughter());
|
&& !config.taskName().isEmpty())
|
||||||
clientThread.invoke(() -> setTask(config.taskName(), config.amount(), config.initialAmount(), config.taskLocation()));
|
{
|
||||||
|
points = config.points();
|
||||||
|
streak = config.streak();
|
||||||
|
setExpeditiousChargeCount(config.expeditious());
|
||||||
|
setSlaughterChargeCount(config.slaughter());
|
||||||
|
clientThread.invoke(() -> setTask(config.taskName(), config.amount(), config.initialAmount(), config.taskLocation()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
chatCommandManager.registerCommandAsync(TASK_COMMAND_STRING, this::taskLookup, this::taskSubmit);
|
chatCommandManager.registerCommandAsync(TASK_COMMAND_STRING, this::taskLookup, this::taskSubmit);
|
||||||
@@ -240,6 +244,7 @@ public class SlayerPlugin extends Plugin
|
|||||||
overlayManager.remove(targetMinimapOverlay);
|
overlayManager.remove(targetMinimapOverlay);
|
||||||
removeCounter();
|
removeCounter();
|
||||||
highlightedTargets.clear();
|
highlightedTargets.clear();
|
||||||
|
cachedXp = -1;
|
||||||
|
|
||||||
chatCommandManager.unregisterCommand(TASK_COMMAND_STRING);
|
chatCommandManager.unregisterCommand(TASK_COMMAND_STRING);
|
||||||
}
|
}
|
||||||
@@ -257,7 +262,7 @@ public class SlayerPlugin extends Plugin
|
|||||||
{
|
{
|
||||||
case HOPPING:
|
case HOPPING:
|
||||||
case LOGGING_IN:
|
case LOGGING_IN:
|
||||||
cachedXp = 0;
|
cachedXp = -1;
|
||||||
taskName = "";
|
taskName = "";
|
||||||
amount = 0;
|
amount = 0;
|
||||||
loginFlag = true;
|
loginFlag = true;
|
||||||
@@ -528,7 +533,7 @@ public class SlayerPlugin extends Plugin
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cachedXp == 0)
|
if (cachedXp == -1)
|
||||||
{
|
{
|
||||||
// this is the initial xp sent on login
|
// this is the initial xp sent on login
|
||||||
cachedXp = slayerExp;
|
cachedXp = slayerExp;
|
||||||
|
|||||||
@@ -681,4 +681,26 @@ public class SlayerPluginTest
|
|||||||
|
|
||||||
verify(chatMessageManager, never()).update(any(MessageNode.class));
|
verify(chatMessageManager, never()).update(any(MessageNode.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testNewAccountSlayerKill()
|
||||||
|
{
|
||||||
|
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);
|
||||||
|
|
||||||
|
slayerPlugin.setTaskName("Bears");
|
||||||
|
slayerPlugin.setAmount(35);
|
||||||
|
|
||||||
|
when(client.getSkillExperience(Skill.SLAYER)).thenReturn(0);
|
||||||
|
slayerPlugin.onExperienceChanged(experienceChanged);
|
||||||
|
|
||||||
|
when(client.getSkillExperience(Skill.SLAYER)).thenReturn(27);
|
||||||
|
slayerPlugin.onExperienceChanged(experienceChanged);
|
||||||
|
|
||||||
|
assertEquals(34, slayerPlugin.getAmount());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user