From 1c3ccdf3a94b73161f0939d9541ff125b446f34e Mon Sep 17 00:00:00 2001 From: Adam Date: Thu, 2 Jun 2022 12:41:33 -0400 Subject: [PATCH 1/4] chat commands: fix !lvl cox cm The command could not work before because the capitalize in longBossName would produce a capital Of causing the hiscore skill name to not match. This normalizes from the hiscore name by removing : to compare it to our internal boss names. --- .../client/plugins/chatcommands/ChatCommandsPlugin.java | 5 ++++- .../client/plugins/chatcommands/ChatCommandsPluginTest.java | 6 +++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/chatcommands/ChatCommandsPlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/chatcommands/ChatCommandsPlugin.java index 32a552aebe..d1c114db9e 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/chatcommands/ChatCommandsPlugin.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/chatcommands/ChatCommandsPlugin.java @@ -2044,6 +2044,7 @@ public class ChatCommandsPlugin extends Plugin return "Chambers of Xeric 24+ players"; // Chambers of Xeric Challenge Mode + case "chambers of xeric: challenge mode": case "cox cm": case "xeric cm": case "chambers cm": @@ -2433,7 +2434,9 @@ public class ChatCommandsPlugin extends Plugin } for (HiscoreSkill skill : HiscoreSkill.values()) { - if (skill.getName().equals(s)) + // longBossName the skill name to normalize from hiscore name + // to our internal name (removing the colon) + if (longBossName(skill.getName()).equals(s)) { return skill; } diff --git a/runelite-client/src/test/java/net/runelite/client/plugins/chatcommands/ChatCommandsPluginTest.java b/runelite-client/src/test/java/net/runelite/client/plugins/chatcommands/ChatCommandsPluginTest.java index 08090286cd..2217626a3f 100644 --- a/runelite-client/src/test/java/net/runelite/client/plugins/chatcommands/ChatCommandsPluginTest.java +++ b/runelite-client/src/test/java/net/runelite/client/plugins/chatcommands/ChatCommandsPluginTest.java @@ -618,7 +618,7 @@ public class ChatCommandsPluginTest HiscoreResult hiscoreResult = new HiscoreResult(); hiscoreResult.setPlayer(PLAYER_NAME); - hiscoreResult.setZulrah(new Skill(10, 1000, -1)); + hiscoreResult.setChambersOfXericChallengeMode(new Skill(10, 1000, -1)); when(hiscoreClient.lookup(eq(PLAYER_NAME), nullable(HiscoreEndpoint.class))).thenReturn(hiscoreResult); @@ -628,9 +628,9 @@ public class ChatCommandsPluginTest chatMessage.setType(ChatMessageType.PUBLICCHAT); chatMessage.setName(PLAYER_NAME); chatMessage.setMessageNode(messageNode); - chatCommandsPlugin.playerSkillLookup(chatMessage, "!lvl zulrah"); + chatCommandsPlugin.playerSkillLookup(chatMessage, "!lvl cox cm"); - verify(messageNode).setRuneLiteFormatMessage("Level Zulrah: 1000 Rank: 10"); + verify(messageNode).setRuneLiteFormatMessage("Level Chambers of Xeric: Challenge Mode: 1000 Rank: 10"); } @Test From 672a57ebcd3b5aba3470e0b6a44047dd26daf3b2 Mon Sep 17 00:00:00 2001 From: Adam Date: Thu, 2 Jun 2022 12:00:55 -0400 Subject: [PATCH 2/4] api: deprecate if1 usage --- .../src/main/java/net/runelite/api/Client.java | 3 +++ .../src/main/java/net/runelite/api/MenuAction.java | 12 ++++++++++++ .../main/java/net/runelite/api/widgets/Widget.java | 2 ++ 3 files changed, 17 insertions(+) diff --git a/runelite-api/src/main/java/net/runelite/api/Client.java b/runelite-api/src/main/java/net/runelite/api/Client.java index 7972c54edc..3b0994fcd6 100644 --- a/runelite-api/src/main/java/net/runelite/api/Client.java +++ b/runelite-api/src/main/java/net/runelite/api/Client.java @@ -1804,6 +1804,7 @@ public interface Client extends OAuthApi, GameEngine * * @param delay the number of game cycles to delay dragging */ + @Deprecated void setInventoryDragDelay(int delay); /** @@ -1889,12 +1890,14 @@ public interface Client extends OAuthApi, GameEngine * * @return */ + @Deprecated Widget getIf1DraggedWidget(); /** * Get the item index of the item being dragged on an if1 widget * @return */ + @Deprecated int getIf1DraggedItemIndex(); /** diff --git a/runelite-api/src/main/java/net/runelite/api/MenuAction.java b/runelite-api/src/main/java/net/runelite/api/MenuAction.java index 36b28d1040..fd94ef7927 100644 --- a/runelite-api/src/main/java/net/runelite/api/MenuAction.java +++ b/runelite-api/src/main/java/net/runelite/api/MenuAction.java @@ -35,6 +35,7 @@ public enum MenuAction /** * Menu action for using an item in your inventory on a tile object (GameObject or GroundObject). */ + @Deprecated ITEM_USE_ON_GAME_OBJECT(1), /** * Menu action for using a widget on a tile object (GameObject or GroundObject). @@ -64,6 +65,7 @@ public enum MenuAction /** * Menu action for using an item in your inventory on an NPC. */ + @Deprecated ITEM_USE_ON_NPC(7), /** * Menu action for using a widget on an NPC. @@ -93,6 +95,7 @@ public enum MenuAction /** * Menu action for using an item on a player. */ + @Deprecated ITEM_USE_ON_PLAYER(14), /** * Menu action for using a widget on a player. @@ -102,6 +105,7 @@ public enum MenuAction /** * Menu action for using an item on an item on the ground. */ + @Deprecated ITEM_USE_ON_GROUND_ITEM(16), /** * Menu action for using a widget on an item on the ground. @@ -161,6 +165,7 @@ public enum MenuAction /** * Menu action when using an item on another item */ + @Deprecated ITEM_USE_ON_ITEM(31), /** * Menu action when using a component on an item @@ -170,26 +175,32 @@ public enum MenuAction /** * First menu action for an item. */ + @Deprecated ITEM_FIRST_OPTION(33), /** * Second menu action for an item. */ + @Deprecated ITEM_SECOND_OPTION(34), /** * Third menu action for an item. */ + @Deprecated ITEM_THIRD_OPTION(35), /** * Fourth menu action for an item. */ + @Deprecated ITEM_FOURTH_OPTION(36), /** * Fifth menu action for an item. */ + @Deprecated ITEM_FIFTH_OPTION(37), /** * Menu action to use an item. */ + @Deprecated ITEM_USE(38), /** @@ -252,6 +263,7 @@ public enum MenuAction /** * Menu action triggered by examining item in inventory. */ + @Deprecated EXAMINE_ITEM(1005), /** * Menu action triggered by canceling a menu. diff --git a/runelite-api/src/main/java/net/runelite/api/widgets/Widget.java b/runelite-api/src/main/java/net/runelite/api/widgets/Widget.java index afa6579099..385f442ef0 100644 --- a/runelite-api/src/main/java/net/runelite/api/widgets/Widget.java +++ b/runelite-api/src/main/java/net/runelite/api/widgets/Widget.java @@ -474,6 +474,7 @@ public interface Widget * * @return any items displayed, or null if there are no items */ + @Deprecated Collection getWidgetItems(); /** @@ -484,6 +485,7 @@ public interface Widget * does not exist * @throws IndexOutOfBoundsException if the index is out of bounds */ + @Deprecated WidgetItem getWidgetItem(int index); /** From 8116098792bd1277fa81936be4cb7ae633c4a2aa Mon Sep 17 00:00:00 2001 From: Adam Date: Thu, 2 Jun 2022 15:22:24 -0400 Subject: [PATCH 3/4] chat commands: add rifts closed to gotr bossnames The hiscore skill name for gotr is rifts closed --- .../runelite/client/plugins/chatcommands/ChatCommandsPlugin.java | 1 + 1 file changed, 1 insertion(+) diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/chatcommands/ChatCommandsPlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/chatcommands/ChatCommandsPlugin.java index d1c114db9e..22a9a6d998 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/chatcommands/ChatCommandsPlugin.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/chatcommands/ChatCommandsPlugin.java @@ -2345,6 +2345,7 @@ public class ChatCommandsPlugin extends Plugin // Guardians of the Rift case "gotr": case "runetodt": + case "rifts closed": return "Guardians of the Rift"; default: From 8aaaa320d308fa751a7acad6cf21a07b910c19ed Mon Sep 17 00:00:00 2001 From: superiorser9 <58041466+superiorser9@users.noreply.github.com> Date: Thu, 2 Jun 2022 23:44:54 +0100 Subject: [PATCH 4/4] timers: Check stamina effect using varbits (#15014) --- .../main/java/net/runelite/api/Varbits.java | 15 +++ .../client/plugins/timers/TimersPlugin.java | 100 +++++++----------- .../plugins/timers/TimersPluginTest.java | 26 ++--- 3 files changed, 62 insertions(+), 79 deletions(-) diff --git a/runelite-api/src/main/java/net/runelite/api/Varbits.java b/runelite-api/src/main/java/net/runelite/api/Varbits.java index b39df1a823..14fe41088d 100644 --- a/runelite-api/src/main/java/net/runelite/api/Varbits.java +++ b/runelite-api/src/main/java/net/runelite/api/Varbits.java @@ -47,6 +47,21 @@ public final class Varbits */ public static final int RUN_SLOWED_DEPLETION_ACTIVE = 25; + /** + * Stamina effect timer + * Number of game ticks remaining on stamina effect in intervals of 10; for a value X there are 10 * X game ticks remaining. + * The stamina effect expires once this reaches 0. + */ + public static final int STAMINA_EFFECT = 24; + + /** + * Ring of endurance effect timer, stamina duration extended from using the ring of endurance + * Number of game ticks remaining on ring of endurance effect in intervals of 10; for a value X there are 10 * X game ticks remaining. + * Unequipping the ring of endurance will cause this to change to 0. + * When this reaches 0, {@link #STAMINA_EFFECT} will begin counting down. + */ + public static final int RING_OF_ENDURANCE_EFFECT = 10385; + /** * If scrollbar in resizable mode chat is on the left */ 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 57da5b9b95..34713ea754 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 @@ -102,20 +102,15 @@ public class TimersPlugin extends Plugin private static final String EXTENDED_ANTIFIRE_DRINK_MESSAGE = "You drink some of your extended antifire potion."; private static final String EXTENDED_SUPER_ANTIFIRE_DRINK_MESSAGE = "You drink some of your extended super antifire potion."; private static final String FROZEN_MESSAGE = "You have been frozen!"; - private static final String GAUNTLET_ENTER_MESSAGE = "You enter the Gauntlet."; private static final String GOD_WARS_ALTAR_MESSAGE = "you recharge your prayer."; private static final String MAGIC_IMBUE_EXPIRED_MESSAGE = "Your Magic Imbue charge has ended."; private static final String MAGIC_IMBUE_MESSAGE = "You are charged to combine runes!"; private static final String STAFF_OF_THE_DEAD_SPEC_EXPIRED_MESSAGE = "Your protection fades away"; private static final String STAFF_OF_THE_DEAD_SPEC_MESSAGE = "Spirits of deceased evildoers offer you their protection"; - private static final String STAMINA_DRINK_MESSAGE = "You drink some of your stamina potion."; - private static final String STAMINA_SHARED_DRINK_MESSAGE = "You have received a shared dose of stamina potion."; - private static final String STAMINA_EXPIRED_MESSAGE = "Your stamina potion has expired."; private static final String SUPER_ANTIFIRE_DRINK_MESSAGE = "You drink some of your super antifire potion"; private static final String SUPER_ANTIFIRE_EXPIRED_MESSAGE = "Your super antifire potion has expired."; private static final String KILLED_TELEBLOCK_OPPONENT_TEXT = "Your Tele Block has been removed because you killed "; 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 String SHADOW_VEIL_MESSAGE = ">Your thieving abilities have been enhanced."; private static final String DEATH_CHARGE_MESSAGE = ">Upon the death of your next foe, some of your special attack energy will be restored."; private static final String DEATH_CHARGE_ACTIVATE_MESSAGE = ">Some of your special attack energy has been restored."; @@ -144,7 +139,6 @@ public class TimersPlugin extends Plugin private int freezeTime = -1; // time frozen, in game ticks private TimerTimer staminaTimer; - private boolean wasWearingEndurance; private int lastRaidVarb; private int lastVengCooldownVarb; @@ -154,6 +148,7 @@ public class TimersPlugin extends Plugin private int lastCorruptionVarb; private int lastHomeTeleport; private int lastMinigameTeleport; + private int lastStaminaEffect; private int lastImbuedHeartVarb; private boolean imbuedHeartTimerActive; private int nextPoisonTick; @@ -209,6 +204,7 @@ public class TimersPlugin extends Plugin lastImbuedHeartVarb = 0; lastHomeTeleport = 0; lastMinigameTeleport = 0; + lastStaminaEffect = 0; } @Subscribe @@ -223,6 +219,11 @@ public class TimersPlugin extends Plugin int imbuedHeartCooldownVarb = client.getVarbitValue(Varbits.IMBUED_HEART_COOLDOWN); int homeTeleportVarp = client.getVar(VarPlayer.LAST_HOME_TELEPORT); int minigameTeleportVarp = client.getVar(VarPlayer.LAST_MINIGAME_TELEPORT); + int staminaEffectActive = client.getVarbitValue(Varbits.RUN_SLOWED_DEPLETION_ACTIVE); + int staminaPotionEffectVarb = client.getVarbitValue(Varbits.STAMINA_EFFECT); + int enduranceRingEffectVarb = client.getVarbitValue(Varbits.RING_OF_ENDURANCE_EFFECT); + + final int totalStaminaEffect = staminaPotionEffectVarb + enduranceRingEffectVarb; if (lastRaidVarb != raidVarb) { @@ -341,6 +342,33 @@ public class TimersPlugin extends Plugin checkTeleport(VarPlayer.LAST_MINIGAME_TELEPORT); lastMinigameTeleport = minigameTeleportVarp; } + + // staminaEffectActive is checked to match https://github.com/Joshua-F/cs2-scripts/blob/741271f0c3395048c1bad4af7881a13734516adf/scripts/%5Bproc%2Cbuff_bar_get_value%5D.cs2#L25 + if (staminaEffectActive == 1 && lastStaminaEffect != totalStaminaEffect && config.showStamina()) + { + final Duration staminaDuration = Duration.of(10L * totalStaminaEffect, RSTimeUnit.GAME_TICKS); + + if (staminaTimer == null && totalStaminaEffect > 0) + { + staminaTimer = createGameTimer(STAMINA, staminaDuration); + } + else if (totalStaminaEffect == 0) + { + removeGameTimer(STAMINA); + staminaTimer = null; + } + else + { + Instant endInstant = Instant.now().plus(staminaDuration); + int timeDifference = (int) Duration.between(staminaTimer.getEndTime(), endInstant).getSeconds(); + if (timeDifference != 0) + { + Duration remainingDuration = Duration.between(staminaTimer.getStartTime(), endInstant); + staminaTimer.setDuration(remainingDuration); + } + } + lastStaminaEffect = totalStaminaEffect; + } } @Subscribe @@ -372,6 +400,7 @@ public class TimersPlugin extends Plugin if (!config.showStamina()) { removeGameTimer(STAMINA); + staminaTimer = null; } if (!config.showOverload()) @@ -468,18 +497,6 @@ public class TimersPlugin extends Plugin { if (event.isItemOp() && event.getMenuOption().equals("Drink")) { - if ((event.getItemId() == ItemID.STAMINA_MIX1 - || event.getItemId() == ItemID.STAMINA_MIX2 - || event.getItemId() == ItemID.EGNIOL_POTION_1 - || event.getItemId() == ItemID.EGNIOL_POTION_2 - || event.getItemId() == ItemID.EGNIOL_POTION_3 - || event.getItemId() == ItemID.EGNIOL_POTION_4) - && config.showStamina()) - { - // Needs menu option hook because mixes use a common drink message, distinct from their standard potion messages - createStaminaTimer(); - return; - } if ((event.getItemId() == ItemID.ANTIFIRE_MIX1 || event.getItemId() == ItemID.ANTIFIRE_MIX2) @@ -550,22 +567,6 @@ public class TimersPlugin extends Plugin createGameTimer(ABYSSAL_SIRE_STUN); } - if (message.equals(ENDURANCE_EFFECT_MESSAGE)) - { - wasWearingEndurance = true; - } - - if (config.showStamina() && (message.equals(STAMINA_DRINK_MESSAGE) || message.equals(STAMINA_SHARED_DRINK_MESSAGE))) - { - createStaminaTimer(); - } - - if (message.equals(STAMINA_EXPIRED_MESSAGE) || message.equals(GAUNTLET_ENTER_MESSAGE)) - { - removeGameTimer(STAMINA); - staminaTimer = null; - } - if (config.showAntiFire() && message.equals(ANTIFIRE_DRINK_MESSAGE)) { createGameTimer(ANTIFIRE); @@ -1064,7 +1065,7 @@ public class TimersPlugin extends Plugin } /** - * Remove SOTD timer and update stamina timer when equipment is changed. + * Remove SOTD timer when equipment is changed. */ @Subscribe public void onItemContainerChanged(ItemContainerChanged itemContainerChanged) @@ -1087,29 +1088,6 @@ public class TimersPlugin extends Plugin removeGameTimer(STAFF_OF_THE_DEAD); } - if (wasWearingEndurance) - { - Item ring = container.getItem(EquipmentInventorySlot.RING.getSlotIdx()); - - // when using the last ring charge the ring changes to the uncharged version, ignore that and don't - // halve the timer - if (ring == null || (ring.getId() != ItemID.RING_OF_ENDURANCE && ring.getId() != ItemID.RING_OF_ENDURANCE_UNCHARGED_24844)) - { - wasWearingEndurance = false; - if (staminaTimer != null) - { - // Remaining duration gets divided by 2 - Duration remainingDuration = Duration.between(Instant.now(), staminaTimer.getEndTime()).dividedBy(2); - // This relies on the chat message to be removed, which could be after the timer has been culled; - // so check there is still remaining time - if (!remainingDuration.isNegative() && !remainingDuration.isZero()) - { - log.debug("Halving stamina timer"); - staminaTimer.setDuration(remainingDuration); - } - } - } - } } @Subscribe @@ -1139,12 +1117,6 @@ public class TimersPlugin extends Plugin } } - private void createStaminaTimer() - { - Duration duration = Duration.ofMinutes(wasWearingEndurance ? 4 : 2); - staminaTimer = createGameTimer(STAMINA, duration); - } - private TimerTimer createGameTimer(final GameTimer timer) { if (timer.getDuration() == null) 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 35a85c7034..9e6aea3616 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 @@ -33,12 +33,9 @@ import java.time.Instant; import java.util.function.Predicate; import net.runelite.api.ChatMessageType; import net.runelite.api.Client; -import net.runelite.api.InventoryID; -import net.runelite.api.ItemContainer; 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.VarbitChanged; import net.runelite.client.game.ItemManager; import net.runelite.client.game.SpriteManager; @@ -59,7 +56,6 @@ import static org.mockito.ArgumentMatchers.nullable; import org.mockito.Mock; import static org.mockito.Mockito.atLeastOnce; import static org.mockito.Mockito.doAnswer; -import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -236,8 +232,10 @@ public class TimersPluginTest public void testStamina() { when(timersConfig.showStamina()).thenReturn(true); - ChatMessage chatMessage = new ChatMessage(null, ChatMessageType.SPAM, "", "You drink some of your stamina potion.", "", 0); - timersPlugin.onChatMessage(chatMessage); + when(client.getVarbitValue(Varbits.RUN_SLOWED_DEPLETION_ACTIVE)).thenReturn(1); + when(client.getVarbitValue(Varbits.STAMINA_EFFECT)).thenReturn(20); + when(client.getVarbitValue(Varbits.RING_OF_ENDURANCE_EFFECT)).thenReturn(0); + timersPlugin.onVarbitChanged(new VarbitChanged()); ArgumentCaptor captor = ArgumentCaptor.forClass(InfoBox.class); verify(infoBoxManager).addInfoBox(captor.capture()); @@ -264,12 +262,10 @@ public class TimersPluginTest public void testEndurance() { when(timersConfig.showStamina()).thenReturn(true); - - ChatMessage chatMessage = new ChatMessage(null, ChatMessageType.SPAM, "", "Your Ring of endurance doubles the duration of your stamina potion's effect.", "", 0); - timersPlugin.onChatMessage(chatMessage); - - chatMessage = new ChatMessage(null, ChatMessageType.SPAM, "", "You drink some of your stamina potion.", "", 0); - timersPlugin.onChatMessage(chatMessage); + when(client.getVarbitValue(Varbits.RUN_SLOWED_DEPLETION_ACTIVE)).thenReturn(1); + when(client.getVarbitValue(Varbits.STAMINA_EFFECT)).thenReturn(20); + when(client.getVarbitValue(Varbits.RING_OF_ENDURANCE_EFFECT)).thenReturn(20); + timersPlugin.onVarbitChanged(new VarbitChanged()); ArgumentCaptor captor = ArgumentCaptor.forClass(InfoBox.class); verify(infoBoxManager).addInfoBox(captor.capture()); @@ -278,10 +274,10 @@ public class TimersPluginTest assertEquals(Duration.ofMinutes(4), infoBox.getDuration()); // unwield ring - timersPlugin.onItemContainerChanged(new ItemContainerChanged(InventoryID.EQUIPMENT.getId(), mock(ItemContainer.class))); - // some time has elapsed in the test; this should be just under 2 mins + when(client.getVarbitValue(Varbits.RING_OF_ENDURANCE_EFFECT)).thenReturn(0); + timersPlugin.onVarbitChanged(new VarbitChanged()); int mins = (int) infoBox.getDuration().toMinutes(); - assertTrue(mins == 1 || mins == 2); + assertEquals(2, mins); } @Test