idle notifier: add spec regen notifier

Co-authored-by: Justin Kufro <kufroj@gmail.com>
This commit is contained in:
Adam
2018-12-09 10:46:53 -05:00
parent 40c235b594
commit 1ad41c76fd
3 changed files with 54 additions and 0 deletions

View File

@@ -107,4 +107,15 @@ public interface IdleNotifierConfig extends Config
{
return 0;
}
@ConfigItem(
keyName = "spec",
name = "Special Attack Energy Notification Threshold",
position = 8,
description = "The amount of spec energy reached to send a notification at. A value of 0 will disable notification."
)
default int getSpecEnergyThreshold()
{
return 0;
}
}

View File

@@ -42,6 +42,7 @@ import net.runelite.api.NPC;
import net.runelite.api.NPCComposition;
import net.runelite.api.Player;
import net.runelite.api.Skill;
import net.runelite.api.VarPlayer;
import net.runelite.api.Varbits;
import net.runelite.api.events.AnimationChanged;
import net.runelite.api.events.GameStateChanged;
@@ -89,6 +90,7 @@ public class IdleNotifierPlugin extends Plugin
private boolean notifyOxygen = true;
private boolean notifyIdleLogout = true;
private boolean notify6HourLogout = true;
private int lastSpecEnergy = 1000;
private int lastCombatCountdown = 0;
private Instant sixHourWarningTime;
private boolean ready;
@@ -382,6 +384,30 @@ public class IdleNotifierPlugin extends Plugin
{
notifier.notify("[" + local.getName() + "] has low oxygen!");
}
if (checkFullSpecEnergy())
{
notifier.notify("[" + local.getName() + "] has restored spec energy!");;
}
}
private boolean checkFullSpecEnergy()
{
int currentSpecEnergy = client.getVar(VarPlayer.SPECIAL_ATTACK_PERCENT);
int threshold = config.getSpecEnergyThreshold() * 10;
if (threshold == 0)
{
lastSpecEnergy = currentSpecEnergy;
return false;
}
// Check if we have regenerated over the threshold, and that the
// regen was small enough.
boolean notify = lastSpecEnergy < threshold && currentSpecEnergy >= threshold
&& currentSpecEnergy - lastSpecEnergy <= 100;
lastSpecEnergy = currentSpecEnergy;
return notify;
}
private boolean checkLowOxygen()

View File

@@ -35,6 +35,7 @@ import net.runelite.api.Hitsplat;
import net.runelite.api.NPC;
import net.runelite.api.NPCComposition;
import net.runelite.api.Player;
import net.runelite.api.VarPlayer;
import net.runelite.api.events.AnimationChanged;
import net.runelite.api.events.GameStateChanged;
import net.runelite.api.events.GameTick;
@@ -44,9 +45,11 @@ import net.runelite.client.Notifier;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Matchers;
import static org.mockito.Matchers.any;
import org.mockito.Mock;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -255,4 +258,18 @@ public class IdleNotifierPluginTest
plugin.onGameTick(new GameTick());
verify(notifier, times(1)).notify(any());
}
@Test
public void testSpecRegen()
{
when(config.getSpecEnergyThreshold()).thenReturn(50);
when(client.getVar(Matchers.eq(VarPlayer.SPECIAL_ATTACK_PERCENT))).thenReturn(400); // 40%
plugin.onGameTick(new GameTick()); // once to set lastSpecEnergy to 400
verify(notifier, never()).notify(any());
when(client.getVar(Matchers.eq(VarPlayer.SPECIAL_ATTACK_PERCENT))).thenReturn(500); // 50%
plugin.onGameTick(new GameTick());
verify(notifier).notify(Matchers.eq("[" + PLAYER_NAME + "] has restored spec energy!"));
}
}