timers: add duration and cooldown timers for arceuus spells

Co-authored-by: Adam <Adam@sigterm.info>
This commit is contained in:
Hydrox6
2021-06-17 10:36:48 +01:00
committed by Adam
parent a2eb773e20
commit f7136f7aeb
6 changed files with 290 additions and 72 deletions

View File

@@ -76,7 +76,16 @@ enum GameTimer
DIVINE_BATTLEMAGE(ItemID.DIVINE_BATTLEMAGE_POTION4, GameTimerImageType.ITEM, "Divine Battlemage", 5, ChronoUnit.MINUTES),
ANTIPOISON(ItemID.ANTIPOISON4, GameTimerImageType.ITEM, "Antipoison", false),
ANTIVENOM(ItemID.ANTIVENOM4, GameTimerImageType.ITEM, "Anti-venom", false),
TELEBLOCK(SpriteID.SPELL_TELE_BLOCK, GameTimerImageType.SPRITE, "Teleblock", true);
TELEBLOCK(SpriteID.SPELL_TELE_BLOCK, GameTimerImageType.SPRITE, "Teleblock", true),
SHADOW_VEIL(SpriteID.SPELL_SHADOW_VEIL, GameTimerImageType.SPRITE, "Shadow veil", true),
RESURRECT_THRALL(SpriteID.SPELL_RESURRECT_SUPERIOR_SKELETON, GameTimerImageType.SPRITE, "Resurrect thrall", false),
WARD_OF_ARCEUUS(SpriteID.SPELL_WARD_OF_ARCEUUS, GameTimerImageType.SPRITE, "Ward of Arceuus", true),
DEATH_CHARGE(SpriteID.SPELL_DEATH_CHARGE, GameTimerImageType.SPRITE, "Death charge", false),
SHADOW_VEIL_COOLDOWN(SpriteID.SPELL_SHADOW_VEIL_DISABLED, GameTimerImageType.SPRITE, "Shadow veil cooldown", 30, ChronoUnit.SECONDS),
RESURRECT_THRALL_COOLDOWN(SpriteID.SPELL_RESURRECT_SUPERIOR_SKELETON_DISABLED, GameTimerImageType.SPRITE, "Resurrect thrall cooldown", 12, GAME_TICKS),
WARD_OF_ARCEUUS_COOLDOWN(SpriteID.SPELL_WARD_OF_ARCEUUS_DISABLED, GameTimerImageType.SPRITE, "Ward of Arceuus cooldown", 30, ChronoUnit.SECONDS),
DEATH_CHARGE_COOLDOWN(SpriteID.SPELL_DEATH_CHARGE_DISABLED, GameTimerImageType.SPRITE, "Death charge cooldown", 60, ChronoUnit.SECONDS),
CORRUPTION_COOLDOWN(SpriteID.SPELL_GREATER_CORRUPTION_DISABLED, GameTimerImageType.SPRITE, "Corruption cooldown", 30, ChronoUnit.SECONDS);
@Nullable
private final Duration duration;

View File

@@ -263,4 +263,24 @@ public interface TimersConfig extends Config
{
return true;
}
@ConfigItem(
keyName = "showArceuus",
name = "Arceuus spells duration",
description = "Whether to show Arceuus spellbook spell timers"
)
default boolean showArceuus()
{
return true;
}
@ConfigItem(
keyName = "showArceuusCooldown",
name = "Arceuus spells cooldown",
description = "Whether to show cooldown timers for Arceuus spellbook spells"
)
default boolean showArceuusCooldown()
{
return false;
}
}

View File

@@ -76,6 +76,7 @@ import net.runelite.client.plugins.PluginDescriptor;
import static net.runelite.client.plugins.timers.GameIndicator.VENGEANCE_ACTIVE;
import static net.runelite.client.plugins.timers.GameTimer.*;
import net.runelite.client.ui.overlay.infobox.InfoBoxManager;
import net.runelite.client.util.RSTimeUnit;
import org.apache.commons.lang3.ArrayUtils;
@PluginDescriptor(
@@ -113,6 +114,14 @@ public class TimersPlugin extends Plugin
private static final String KILLED_TELEBLOCK_OPPONENT_TEXT = "Your Tele Block has been removed because you killed ";
private static final String PRAYER_ENHANCE_EXPIRED = "<col=ff0000>Your prayer enhance effect has worn off.</col>";
private static final String ENDURANCE_EFFECT_MESSAGE = "Your Ring of endurance doubles the duration of your stamina potion's effect.";
private static final String SHADOW_VEIL_MESSAGE = ">Your thieving abilities have been enhanced.</col>";
private static final String DEATH_CHARGE_MESSAGE = ">Upon the death of your next foe, some of your special attack energy will be restored.</col>";
private static final String DEATH_CHARGE_ACTIVATE_MESSAGE = ">Some of your special attack energy has been restored.</col>";
private static final String RESURRECT_THRALL_MESSAGE_START = ">You resurrect a ";
private static final String RESURRECT_THRALL_MESSAGE_END = " thrall.</col>";
private static final String RESURRECT_THRALL_DISAPPEAR_MESSAGE_START = ">Your ";
private static final String RESURRECT_THRALL_DISAPPEAR_MESSAGE_END = " thrall returns to the grave.</col>";
private static final String WARD_OF_ARCEUUS_MESSAGE = ">Your defence against Arceuus magic has been strengthened.</col>";
private static final Pattern TELEBLOCK_PATTERN = Pattern.compile("A Tele Block spell has been cast on you(?: by .+)?\\. It will expire in (?<mins>\\d+) minutes?(?:, (?<secs>\\d+) seconds?)?\\.");
private static final Pattern DIVINE_POTION_PATTERN = Pattern.compile("You drink some of your divine (.+) potion\\.");
@@ -138,6 +147,7 @@ public class TimersPlugin extends Plugin
private int lastIsVengeancedVarb;
private int lastPoisonVarp;
private int lastPvpVarb;
private int lastCorruptionVarb;
private int nextPoisonTick;
private WorldPoint lastPoint;
private TeleportWidget lastTeleportClicked;
@@ -202,6 +212,7 @@ public class TimersPlugin extends Plugin
int isVengeancedVarb = client.getVar(Varbits.VENGEANCE_ACTIVE);
int poisonVarp = client.getVar(VarPlayer.POISON);
int pvpVarb = client.getVar(Varbits.PVP_SPEC_ORB);
int corruptionCooldownVarb = client.getVar(Varbits.CORRUPTION_COOLDOWN);
if (lastRaidVarb != raidVarb)
{
@@ -224,6 +235,20 @@ public class TimersPlugin extends Plugin
lastVengCooldownVarb = vengCooldownVarb;
}
if (lastCorruptionVarb != corruptionCooldownVarb && config.showArceuusCooldown())
{
if (corruptionCooldownVarb == 1)
{
createGameTimer(CORRUPTION_COOLDOWN);
}
else
{
removeGameTimer(CORRUPTION_COOLDOWN);
}
lastCorruptionVarb = corruptionCooldownVarb;
}
if (lastIsVengeancedVarb != isVengeancedVarb && config.showVengeanceActive())
{
if (isVengeancedVarb == 1)
@@ -665,6 +690,55 @@ public class TimersPlugin extends Plugin
}
}
if (config.showArceuus())
{
Duration duration = Duration.of(client.getRealSkillLevel(Skill.MAGIC), RSTimeUnit.GAME_TICKS);
if (message.endsWith(SHADOW_VEIL_MESSAGE))
{
createGameTimer(SHADOW_VEIL, duration);
}
else if (message.endsWith(WARD_OF_ARCEUUS_MESSAGE))
{
createGameTimer(WARD_OF_ARCEUUS, duration);
}
else if (message.endsWith(DEATH_CHARGE_MESSAGE))
{
createGameTimer(DEATH_CHARGE, duration);
}
else if (message.endsWith(DEATH_CHARGE_ACTIVATE_MESSAGE))
{
removeGameTimer(DEATH_CHARGE);
}
else if (message.contains(RESURRECT_THRALL_MESSAGE_START) && message.endsWith(RESURRECT_THRALL_MESSAGE_END))
{
createGameTimer(RESURRECT_THRALL, duration);
}
else if (message.contains(RESURRECT_THRALL_DISAPPEAR_MESSAGE_START) && message.endsWith(RESURRECT_THRALL_DISAPPEAR_MESSAGE_END))
{
removeGameTimer(RESURRECT_THRALL);
}
}
if (config.showArceuusCooldown())
{
if (message.endsWith(SHADOW_VEIL_MESSAGE))
{
createGameTimer(SHADOW_VEIL_COOLDOWN);
}
else if (message.endsWith(DEATH_CHARGE_MESSAGE))
{
createGameTimer(DEATH_CHARGE_COOLDOWN);
}
else if (message.endsWith(WARD_OF_ARCEUUS_MESSAGE))
{
createGameTimer(WARD_OF_ARCEUUS_COOLDOWN);
}
else if (message.contains(RESURRECT_THRALL_MESSAGE_START) && message.endsWith(RESURRECT_THRALL_MESSAGE_END))
{
createGameTimer(RESURRECT_THRALL_COOLDOWN);
}
}
if (message.equals(TZHAAR_DEFEATED_MESSAGE) || TZHAAR_COMPLETE_MESSAGE.matcher(message).matches())
{
log.debug("Stopping tzhaar timer");

View File

@@ -30,6 +30,7 @@ import com.google.inject.testing.fieldbinder.Bind;
import com.google.inject.testing.fieldbinder.BoundFieldModule;
import java.time.Duration;
import java.time.Instant;
import java.util.function.Predicate;
import net.runelite.api.ChatMessageType;
import net.runelite.api.Client;
import net.runelite.api.Experience;
@@ -37,15 +38,19 @@ import net.runelite.api.InventoryID;
import net.runelite.api.ItemContainer;
import net.runelite.api.ItemID;
import net.runelite.api.Skill;
import net.runelite.api.Varbits;
import net.runelite.api.events.ChatMessage;
import net.runelite.api.events.ItemContainerChanged;
import net.runelite.api.events.MenuOptionClicked;
import net.runelite.api.events.StatChanged;
import net.runelite.api.events.VarbitChanged;
import net.runelite.client.game.ItemManager;
import net.runelite.client.game.SpriteManager;
import net.runelite.client.ui.overlay.infobox.InfoBox;
import net.runelite.client.ui.overlay.infobox.InfoBoxManager;
import net.runelite.client.util.RSTimeUnit;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
@@ -377,6 +382,165 @@ public class TimersPluginTest
assertEquals("00:06", timer.getText());
}
// region Arceuus spells
@Test
public void testDeathChargeCast()
{
when(timersConfig.showArceuus()).thenReturn(true);
when(client.getRealSkillLevel(Skill.MAGIC)).thenReturn(50);
ChatMessage chatMessage = new ChatMessage(null, ChatMessageType.GAMEMESSAGE, "", "<col=6800bf>Upon the death of your next foe, some of your special attack energy will be restored.</col>", "", 0);
timersPlugin.onChatMessage(chatMessage);
ArgumentCaptor<InfoBox> ibcaptor = ArgumentCaptor.forClass(InfoBox.class);
verify(infoBoxManager).addInfoBox(ibcaptor.capture());
TimerTimer infoBox = (TimerTimer) ibcaptor.getValue();
assertEquals(GameTimer.DEATH_CHARGE, infoBox.getTimer());
assertEquals(Duration.of(50, RSTimeUnit.GAME_TICKS), infoBox.getDuration());
}
@Test
public void testDeathChargeCooldown()
{
when(timersConfig.showArceuusCooldown()).thenReturn(true);
ChatMessage chatMessage = new ChatMessage(null, ChatMessageType.GAMEMESSAGE, "", "<col=6800bf>Upon the death of your next foe, some of your special attack energy will be restored.</col>", "", 0);
timersPlugin.onChatMessage(chatMessage);
ArgumentCaptor<InfoBox> ibcaptor = ArgumentCaptor.forClass(InfoBox.class);
verify(infoBoxManager).addInfoBox(ibcaptor.capture());
TimerTimer infoBox = (TimerTimer) ibcaptor.getValue();
assertEquals(GameTimer.DEATH_CHARGE_COOLDOWN, infoBox.getTimer());
}
@Test
public void testDeathChargeRestore()
{
when(timersConfig.showArceuus()).thenReturn(true);
ChatMessage chatMessage = new ChatMessage(null, ChatMessageType.GAMEMESSAGE, "", "<col=6800bf>Some of your special attack energy has been restored.</col>", "", 0);
timersPlugin.onChatMessage(chatMessage);
TimerTimer correctInfoBox = new TimerTimer(GameTimer.DEATH_CHARGE, Duration.ofSeconds(1), timersPlugin);
TimerTimer incorrectInfoBox = new TimerTimer(GameTimer.WARD_OF_ARCEUUS, Duration.ofSeconds(1), timersPlugin);
ArgumentCaptor<Predicate<InfoBox>> prcaptor = ArgumentCaptor.forClass(Predicate.class);
verify(infoBoxManager).removeIf(prcaptor.capture());
Predicate<InfoBox> pred = prcaptor.getValue();
assertTrue(pred.test(correctInfoBox));
assertFalse(pred.test(incorrectInfoBox));
}
@Test
public void testArceuusWard()
{
when(timersConfig.showArceuus()).thenReturn(true);
when(client.getRealSkillLevel(Skill.MAGIC)).thenReturn(57);
ChatMessage chatMessage = new ChatMessage(null, ChatMessageType.GAMEMESSAGE, "", "<col=0000b2>Your defence against Arceuus magic has been strengthened.</col>", "", 0);
timersPlugin.onChatMessage(chatMessage);
ArgumentCaptor<InfoBox> captor = ArgumentCaptor.forClass(InfoBox.class);
verify(infoBoxManager).addInfoBox(captor.capture());
TimerTimer infoBox = (TimerTimer) captor.getValue();
assertEquals(GameTimer.WARD_OF_ARCEUUS, infoBox.getTimer());
assertEquals(Duration.of(57, RSTimeUnit.GAME_TICKS), infoBox.getDuration());
}
@Test
public void testArceuusWardCooldown()
{
when(timersConfig.showArceuusCooldown()).thenReturn(true);
ChatMessage chatMessage = new ChatMessage(null, ChatMessageType.GAMEMESSAGE, "", "<col=0000b2>Your defence against Arceuus magic has been strengthened.</col>", "", 0);
timersPlugin.onChatMessage(chatMessage);
ArgumentCaptor<InfoBox> captor = ArgumentCaptor.forClass(InfoBox.class);
verify(infoBoxManager).addInfoBox(captor.capture());
TimerTimer infoBox = (TimerTimer) captor.getValue();
assertEquals(GameTimer.WARD_OF_ARCEUUS_COOLDOWN, infoBox.getTimer());
}
@Test
public void testCorruptionCooldown()
{
when(timersConfig.showArceuusCooldown()).thenReturn(true);
when(client.getVar(any(Varbits.class))).thenReturn(0);
when(client.getVar(Varbits.CORRUPTION_COOLDOWN)).thenReturn(1);
timersPlugin.onVarbitChanged(new VarbitChanged());
ArgumentCaptor<InfoBox> captor = ArgumentCaptor.forClass(InfoBox.class);
verify(infoBoxManager).addInfoBox(captor.capture());
TimerTimer infoBox = (TimerTimer) captor.getValue();
assertEquals(GameTimer.CORRUPTION_COOLDOWN, infoBox.getTimer());
}
@Test
public void testShadowVail()
{
when(timersConfig.showArceuus()).thenReturn(true);
when(client.getRealSkillLevel(Skill.MAGIC)).thenReturn(57);
ChatMessage chatMessage = new ChatMessage(null, ChatMessageType.GAMEMESSAGE, "", "<col=6800bf>Your thieving abilities have been enhanced.</col>", "", 0);
timersPlugin.onChatMessage(chatMessage);
ArgumentCaptor<InfoBox> captor = ArgumentCaptor.forClass(InfoBox.class);
verify(infoBoxManager).addInfoBox(captor.capture());
TimerTimer infoBox = (TimerTimer) captor.getValue();
assertEquals(GameTimer.SHADOW_VEIL, infoBox.getTimer());
}
@Test
public void testShadowVailCooldown()
{
when(timersConfig.showArceuusCooldown()).thenReturn(true);
ChatMessage chatMessage = new ChatMessage(null, ChatMessageType.GAMEMESSAGE, "", "<col=6800bf>Your thieving abilities have been enhanced.</col>", "", 0);
timersPlugin.onChatMessage(chatMessage);
ArgumentCaptor<InfoBox> captor = ArgumentCaptor.forClass(InfoBox.class);
verify(infoBoxManager).addInfoBox(captor.capture());
TimerTimer infoBox = (TimerTimer) captor.getValue();
assertEquals(GameTimer.SHADOW_VEIL_COOLDOWN, infoBox.getTimer());
}
@Test
public void testThrall()
{
when(timersConfig.showArceuus()).thenReturn(true);
when(client.getRealSkillLevel(Skill.MAGIC)).thenReturn(50);
ChatMessage chatMessage = new ChatMessage(null, ChatMessageType.GAMEMESSAGE, "", "<col=ef0083>You resurrect a greater zombified thrall.</col>", "", 0);
timersPlugin.onChatMessage(chatMessage);
ArgumentCaptor<InfoBox> ibcaptor = ArgumentCaptor.forClass(InfoBox.class);
verify(infoBoxManager).addInfoBox(ibcaptor.capture());
TimerTimer infoBox = (TimerTimer) ibcaptor.getValue();
assertEquals(GameTimer.RESURRECT_THRALL, infoBox.getTimer());
}
@Test
public void testThrallCooldown()
{
when(timersConfig.showArceuusCooldown()).thenReturn(true);
ChatMessage chatMessage = new ChatMessage(null, ChatMessageType.GAMEMESSAGE, "", "<col=ef0083>You resurrect a greater zombified thrall.</col>", "", 0);
timersPlugin.onChatMessage(chatMessage);
ArgumentCaptor<InfoBox> ibcaptor = ArgumentCaptor.forClass(InfoBox.class);
verify(infoBoxManager).addInfoBox(ibcaptor.capture());
TimerTimer infoBox = (TimerTimer) ibcaptor.getValue();
assertEquals(GameTimer.RESURRECT_THRALL_COOLDOWN, infoBox.getTimer());
}
@Test
public void testThrallEnd()
{
when(timersConfig.showArceuus()).thenReturn(true);
when(client.getRealSkillLevel(Skill.MAGIC)).thenReturn(50);
ChatMessage chatMessage = new ChatMessage(null, ChatMessageType.GAMEMESSAGE, "", "<col=ef0083>Your greater zombified thrall returns to the grave.</col>", "", 0);
timersPlugin.onChatMessage(chatMessage);
verify(infoBoxManager).removeIf(any());
}
// endregion
@Test
public void testImbuedHeartBoost()
{