From 01447e52a70cdd10bfa7db96946ef7b43afbf149 Mon Sep 17 00:00:00 2001 From: Adam Date: Wed, 9 Sep 2020 10:37:32 -0400 Subject: [PATCH] timers: consolidate teleblock timers --- .../client/plugins/timers/GameTimer.java | 9 +-- .../client/plugins/timers/TimersPlugin.java | 58 ++++------------- .../plugins/timers/TimersPluginTest.java | 64 +++++++++++++------ 3 files changed, 59 insertions(+), 72 deletions(-) diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/timers/GameTimer.java b/runelite-client/src/main/java/net/runelite/client/plugins/timers/GameTimer.java index 2bbdae61d6..a751b7f3f9 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/timers/GameTimer.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/timers/GameTimer.java @@ -46,12 +46,6 @@ enum GameTimer OVERLOAD(ItemID.OVERLOAD_4, GameTimerImageType.ITEM, "Overload", 5, ChronoUnit.MINUTES, true), CANNON(ItemID.CANNON_BARRELS, GameTimerImageType.ITEM, "Cannon", 25, ChronoUnit.MINUTES), MAGICIMBUE(SpriteID.SPELL_MAGIC_IMBUE, GameTimerImageType.SPRITE, "Magic imbue", 21, GAME_TICKS), - FULLTB(SpriteID.SPELL_TELE_BLOCK, GameTimerImageType.SPRITE, "Full Teleblock", 5, ChronoUnit.MINUTES, true), - HALFTB(SpriteID.SPELL_TELE_BLOCK, GameTimerImageType.SPRITE, "Half Teleblock", 150, ChronoUnit.SECONDS, true), - DMM_FULLTB(SpriteID.SPELL_TELE_BLOCK, GameTimerImageType.SPRITE, "Deadman Mode Full Teleblock", 150, ChronoUnit.SECONDS, true), - DMM_HALFTB(SpriteID.SPELL_TELE_BLOCK, GameTimerImageType.SPRITE, "Deadman Mode Half Teleblock", 75, ChronoUnit.SECONDS, true), - MAGE_ARENA_FULLTB(SpriteID.SPELL_TELE_BLOCK, GameTimerImageType.SPRITE, "Mage Arena 2 Full Teleblock", 2, ChronoUnit.MINUTES, true), - MAGE_ARENA_HALFTB(SpriteID.SPELL_TELE_BLOCK, GameTimerImageType.SPRITE, "Mage Arena 2 Half Teleblock", 1, ChronoUnit.MINUTES, true), SUPERANTIFIRE(ItemID.SUPER_ANTIFIRE_POTION4, GameTimerImageType.ITEM, "Super antifire", 3, ChronoUnit.MINUTES), BIND(SpriteID.SPELL_BIND, GameTimerImageType.SPRITE, "Bind", GraphicID.BIND, 8, GAME_TICKS, true), SNARE(SpriteID.SPELL_SNARE, GameTimerImageType.SPRITE, "Snare", GraphicID.SNARE, 16, GAME_TICKS, true), @@ -81,7 +75,8 @@ enum GameTimer DIVINE_BASTION(ItemID.DIVINE_BASTION_POTION4, GameTimerImageType.ITEM, "Divine Bastion", 5, ChronoUnit.MINUTES), 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); + ANTIVENOM(ItemID.ANTIVENOM4, GameTimerImageType.ITEM, "Anti-venom", false), + TELEBLOCK(SpriteID.SPELL_TELE_BLOCK, GameTimerImageType.SPRITE, "Teleblock", true); @Nullable private final Duration duration; diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/timers/TimersPlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/timers/TimersPlugin.java index 243250b880..dcf01d3daf 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/timers/TimersPlugin.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/timers/TimersPlugin.java @@ -114,11 +114,7 @@ public class TimersPlugin extends Plugin private static final String PRAYER_ENHANCE_EXPIRED = "Your prayer enhance effect has worn off."; private static final String ENDURANCE_EFFECT_MESSAGE = "Your Ring of endurance doubles the duration of your stamina potion's effect."; - private static final Pattern DEADMAN_HALF_TELEBLOCK_PATTERN = Pattern.compile("A Tele Block spell has been cast on you by (.+)\\. It will expire in 1 minute, 15 seconds\\."); - private static final Pattern FULL_TELEBLOCK_PATTERN = Pattern.compile("A Tele Block spell has been cast on you by (.+)\\. It will expire in 5 minutes\\."); - private static final Pattern HALF_TELEBLOCK_PATTERN = Pattern.compile("A Tele Block spell has been cast on you by (.+)\\. It will expire in 2 minutes, 30 seconds\\."); - private static final Pattern MAGE_ARENA_FULL_TELEBLOCK_PATTERN = Pattern.compile("A Tele Block spell has been cast on you\\. It will expire in 2 minutes\\."); - private static final Pattern MAGE_ARENA_HALF_TELEBLOCK_PATTERN = Pattern.compile("A Tele Block spell has been cast on you\\. It will expire in 1 minute\\."); + private static final Pattern TELEBLOCK_PATTERN = Pattern.compile("A Tele Block spell has been cast on you(?: by .+)?\\. It will expire in (?\\d+) minutes?(?:, (?\\d+) seconds?)?\\."); private static final Pattern DIVINE_POTION_PATTERN = Pattern.compile("You drink some of your divine (.+) potion\\."); private static final int VENOM_VALUE_CUTOFF = -40; // Antivenom < -40 <= Antipoison < 0 private static final int POISON_TICK_LENGTH = 30; @@ -239,7 +235,7 @@ public class TimersPlugin extends Plugin && inWilderness == 0) { log.debug("Left wilderness in non-PVP world, clearing Teleblock timer."); - removeTbTimers(); + removeGameTimer(TELEBLOCK); } lastWildernessVarb = inWilderness; @@ -366,7 +362,7 @@ public class TimersPlugin extends Plugin if (!config.showTeleblock()) { - removeTbTimers(); + removeGameTimer(TELEBLOCK); } if (!config.showFreezes()) @@ -542,36 +538,18 @@ public class TimersPlugin extends Plugin if (config.showTeleblock()) { - if (FULL_TELEBLOCK_PATTERN.matcher(event.getMessage()).find()) + Matcher m = TELEBLOCK_PATTERN.matcher(event.getMessage()); + if (m.find()) { - createGameTimer(FULLTB); - } - else if (HALF_TELEBLOCK_PATTERN.matcher(event.getMessage()).find()) - { - if (client.getWorldType().contains(WorldType.DEADMAN)) - { - createGameTimer(DMM_FULLTB); - } - else - { - createGameTimer(HALFTB); - } - } - else if (DEADMAN_HALF_TELEBLOCK_PATTERN.matcher(event.getMessage()).find()) - { - createGameTimer(DMM_HALFTB); - } - else if (MAGE_ARENA_FULL_TELEBLOCK_PATTERN.matcher(event.getMessage()).find()) - { - createGameTimer(MAGE_ARENA_FULLTB); - } - else if (MAGE_ARENA_HALF_TELEBLOCK_PATTERN.matcher(event.getMessage()).find()) - { - createGameTimer(MAGE_ARENA_HALFTB); + String minss = m.group("mins"); + String secss = m.group("secs"); + int mins = Integer.parseInt(minss); + int secs = secss != null ? Integer.parseInt(secss) : 0; + createGameTimer(TELEBLOCK, Duration.ofSeconds(mins * 60 + secs)); } else if (event.getMessage().contains(KILLED_TELEBLOCK_OPPONENT_TEXT)) { - removeTbTimers(); + removeGameTimer(TELEBLOCK); } } @@ -785,7 +763,7 @@ public class TimersPlugin extends Plugin if (widget != null && !widget.isSelfHidden()) { log.debug("Entered safe zone in PVP world, clearing Teleblock timer."); - removeTbTimers(); + removeGameTimer(TELEBLOCK); } } @@ -812,7 +790,7 @@ public class TimersPlugin extends Plugin } removeTzhaarTimer(); // will be readded by the wave message - removeTbTimers(); + removeGameTimer(TELEBLOCK); break; case LOGGED_IN: loggedInRace = true; @@ -1074,14 +1052,4 @@ public class TimersPlugin extends Plugin { infoBoxManager.removeIf(t -> t instanceof IndicatorIndicator && ((IndicatorIndicator) t).getIndicator() == indicator); } - - private void removeTbTimers() - { - removeGameTimer(FULLTB); - removeGameTimer(HALFTB); - removeGameTimer(DMM_FULLTB); - removeGameTimer(DMM_HALFTB); - removeGameTimer(MAGE_ARENA_FULLTB); - removeGameTimer(MAGE_ARENA_HALFTB); - } } diff --git a/runelite-client/src/test/java/net/runelite/client/plugins/timers/TimersPluginTest.java b/runelite-client/src/test/java/net/runelite/client/plugins/timers/TimersPluginTest.java index bddcee697a..494db7bd9d 100644 --- a/runelite-client/src/test/java/net/runelite/client/plugins/timers/TimersPluginTest.java +++ b/runelite-client/src/test/java/net/runelite/client/plugins/timers/TimersPluginTest.java @@ -30,12 +30,10 @@ 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.EnumSet; import net.runelite.api.ChatMessageType; import net.runelite.api.Client; import net.runelite.api.InventoryID; import net.runelite.api.ItemContainer; -import net.runelite.api.WorldType; import net.runelite.api.events.ChatMessage; import net.runelite.api.events.ItemContainerChanged; import net.runelite.client.game.ItemManager; @@ -65,11 +63,6 @@ import org.mockito.stubbing.Answer; @RunWith(MockitoJUnitRunner.class) public class TimersPluginTest { - private static final String DMM_HALF_TELEBLOCK_MESSAGE = "A Tele Block spell has been cast on you by Runelite. It will expire in 1 minute, 15 seconds."; - private static final String FULL_TELEBLOCK_MESSAGE = "A Tele Block spell has been cast on you by Runelite. It will expire in 5 minutes."; - private static final String HALF_TELEBLOCK_MESSAGE = "A Tele Block spell has been cast on you by Runelite. It will expire in 2 minutes, 30 seconds."; - private static final String TRANSPARENT_CHATBOX_FULL_TELEBLOCK_MESSAGE = "A Tele Block spell has been cast on you by Alexsuperfly. It will expire in 5 minutes."; - private static final String TRANSPARENT_CHATBOX_TELEBLOCK_REMOVED_MESSAGE = "Your Tele Block has been removed because you killed Alexsuperfly."; private static final int FIGHT_CAVES_REGION_ID = 9551; @Inject @@ -105,54 +98,56 @@ public class TimersPluginTest public void testHalfTeleblock() { when(timersConfig.showTeleblock()).thenReturn(true); - when(client.getWorldType()).thenReturn(EnumSet.of(WorldType.MEMBERS)); - ChatMessage chatMessage = new ChatMessage(null, ChatMessageType.SPAM, "", HALF_TELEBLOCK_MESSAGE, "", 0); + ChatMessage chatMessage = new ChatMessage(null, ChatMessageType.SPAM, "", "A Tele Block spell has been cast on you by Runelite. It will expire in 2 minutes, 30 seconds.", "", 0); timersPlugin.onChatMessage(chatMessage); ArgumentCaptor captor = ArgumentCaptor.forClass(InfoBox.class); verify(infoBoxManager).addInfoBox(captor.capture()); TimerTimer infoBox = (TimerTimer) captor.getValue(); - assertEquals(GameTimer.HALFTB, infoBox.getTimer()); + assertEquals(GameTimer.TELEBLOCK, infoBox.getTimer()); + assertEquals(Duration.ofSeconds(2 * 60 + 30), infoBox.getDuration()); } @Test public void testFullTeleblock() { when(timersConfig.showTeleblock()).thenReturn(true); - ChatMessage chatMessage = new ChatMessage(null, ChatMessageType.SPAM, "", FULL_TELEBLOCK_MESSAGE, "", 0); + ChatMessage chatMessage = new ChatMessage(null, ChatMessageType.SPAM, "", "A Tele Block spell has been cast on you by Runelite. It will expire in 5 minutes.", "", 0); timersPlugin.onChatMessage(chatMessage); ArgumentCaptor captor = ArgumentCaptor.forClass(InfoBox.class); verify(infoBoxManager).addInfoBox(captor.capture()); TimerTimer infoBox = (TimerTimer) captor.getValue(); - assertEquals(GameTimer.FULLTB, infoBox.getTimer()); + assertEquals(GameTimer.TELEBLOCK, infoBox.getTimer()); + assertEquals(Duration.ofMinutes(5), infoBox.getDuration()); } @Test public void testDmmHalfTb() { when(timersConfig.showTeleblock()).thenReturn(true); - ChatMessage chatMessage = new ChatMessage(null, ChatMessageType.SPAM, "", DMM_HALF_TELEBLOCK_MESSAGE, "", 0); + ChatMessage chatMessage = new ChatMessage(null, ChatMessageType.SPAM, "", "A Tele Block spell has been cast on you by Runelite. It will expire in 1 minute, 15 seconds.", "", 0); timersPlugin.onChatMessage(chatMessage); ArgumentCaptor captor = ArgumentCaptor.forClass(InfoBox.class); verify(infoBoxManager).addInfoBox(captor.capture()); TimerTimer infoBox = (TimerTimer) captor.getValue(); - assertEquals(GameTimer.DMM_HALFTB, infoBox.getTimer()); + assertEquals(GameTimer.TELEBLOCK, infoBox.getTimer()); + assertEquals(Duration.ofSeconds(60 + 15), infoBox.getDuration()); } @Test public void testDmmFullTb() { when(timersConfig.showTeleblock()).thenReturn(true); - when(client.getWorldType()).thenReturn(EnumSet.of(WorldType.DEADMAN)); - ChatMessage chatMessage = new ChatMessage(null, ChatMessageType.SPAM, "", HALF_TELEBLOCK_MESSAGE, "", 0); + ChatMessage chatMessage = new ChatMessage(null, ChatMessageType.SPAM, "", "A Tele Block spell has been cast on you by Runelite. It will expire in 2 minutes, 30 seconds.", "", 0); timersPlugin.onChatMessage(chatMessage); ArgumentCaptor captor = ArgumentCaptor.forClass(InfoBox.class); verify(infoBoxManager).addInfoBox(captor.capture()); TimerTimer infoBox = (TimerTimer) captor.getValue(); - assertEquals(GameTimer.DMM_FULLTB, infoBox.getTimer()); + assertEquals(GameTimer.TELEBLOCK, infoBox.getTimer()); + assertEquals(Duration.ofSeconds(60 * 2 + 30), infoBox.getDuration()); } @Test @@ -185,25 +180,54 @@ public class TimersPluginTest public void testTransparentChatboxTb() { when(timersConfig.showTeleblock()).thenReturn(true); - ChatMessage chatMessage = new ChatMessage(null, ChatMessageType.SPAM, "", TRANSPARENT_CHATBOX_FULL_TELEBLOCK_MESSAGE, "", 0); + ChatMessage chatMessage = new ChatMessage(null, ChatMessageType.SPAM, "", "A Tele Block spell has been cast on you by Alexsuperfly. It will expire in 5 minutes.", "", 0); timersPlugin.onChatMessage(chatMessage); ArgumentCaptor captor = ArgumentCaptor.forClass(InfoBox.class); verify(infoBoxManager).addInfoBox(captor.capture()); TimerTimer infoBox = (TimerTimer) captor.getValue(); - assertEquals(GameTimer.FULLTB, infoBox.getTimer()); + assertEquals(GameTimer.TELEBLOCK, infoBox.getTimer()); + assertEquals(Duration.ofMinutes(5), infoBox.getDuration()); } @Test public void testTransparentChatboxTbRemoved() { when(timersConfig.showTeleblock()).thenReturn(true); - ChatMessage chatMessage = new ChatMessage(null, ChatMessageType.SPAM, "", TRANSPARENT_CHATBOX_TELEBLOCK_REMOVED_MESSAGE, "", 0); + ChatMessage chatMessage = new ChatMessage(null, ChatMessageType.SPAM, "", "Your Tele Block has been removed because you killed Alexsuperfly.", "", 0); timersPlugin.onChatMessage(chatMessage); verify(infoBoxManager, atLeastOnce()).removeIf(any()); } + @Test + public void testMageArena2TbFull() + { + when(timersConfig.showTeleblock()).thenReturn(true); + ChatMessage chatMessage = new ChatMessage(null, ChatMessageType.SPAM, "", "A Tele Block spell has been cast on you. It will expire in 2 minutes.", "", 0); + timersPlugin.onChatMessage(chatMessage); + + ArgumentCaptor captor = ArgumentCaptor.forClass(InfoBox.class); + verify(infoBoxManager).addInfoBox(captor.capture()); + TimerTimer infoBox = (TimerTimer) captor.getValue(); + assertEquals(GameTimer.TELEBLOCK, infoBox.getTimer()); + assertEquals(Duration.ofMinutes(2), infoBox.getDuration()); + } + + @Test + public void testMageArena2TbHalf() + { + when(timersConfig.showTeleblock()).thenReturn(true); + ChatMessage chatMessage = new ChatMessage(null, ChatMessageType.SPAM, "", "A Tele Block spell has been cast on you. It will expire in 1 minute.", "", 0); + timersPlugin.onChatMessage(chatMessage); + + ArgumentCaptor captor = ArgumentCaptor.forClass(InfoBox.class); + verify(infoBoxManager).addInfoBox(captor.capture()); + TimerTimer infoBox = (TimerTimer) captor.getValue(); + assertEquals(GameTimer.TELEBLOCK, infoBox.getTimer()); + assertEquals(Duration.ofMinutes(1), infoBox.getDuration()); + } + @Test public void testStamina() {