From 7ba679339d90a7437fe7be2344097df311ec1afe Mon Sep 17 00:00:00 2001 From: LlemonDuck Date: Wed, 26 May 2021 19:41:40 -0400 Subject: [PATCH] Reset spec counter when leaving instanced fights When leaving Vorkath or Alchemical Hydra fights, the spec counter does not reset, despite the boss resetting their stats. This could cause the spec counter to add the player's next trip spec to that, giving an inaccurate total spec count. This clears that counter when leaving the vork + hydra region instances. --- .../specialcounter/SpecialCounterPlugin.java | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/specialcounter/SpecialCounterPlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/specialcounter/SpecialCounterPlugin.java index 655c3745ba..6c612efff9 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/specialcounter/SpecialCounterPlugin.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/specialcounter/SpecialCounterPlugin.java @@ -43,7 +43,9 @@ import net.runelite.api.ItemContainer; import net.runelite.api.NPC; import net.runelite.api.NpcID; import net.runelite.api.VarPlayer; +import net.runelite.api.coords.WorldPoint; import net.runelite.api.events.GameStateChanged; +import net.runelite.api.events.GameTick; import net.runelite.api.events.HitsplatApplied; import net.runelite.api.events.InteractingChanged; import net.runelite.api.events.NpcDespawned; @@ -72,12 +74,20 @@ public class SpecialCounterPlugin extends Plugin NpcID.DARK_ENERGY_CORE, NpcID.ZOMBIFIED_SPAWN, NpcID.ZOMBIFIED_SPAWN_8063, NpcID.COMBAT_DUMMY, NpcID.UNDEAD_COMBAT_DUMMY ); + + private static final Set RESET_ON_LEAVE_INSTANCED_REGIONS = ImmutableSet.of( + 9023, // vorkath + 5536 // hydra + ); private int currentWorld; private int specialPercentage; private Actor lastSpecTarget; private int lastSpecTick; + private int previousRegion; + private boolean wasInInstance; + private SpecialWeapon specialWeapon; private final Set interactedNpcIds = new HashSet<>(); private final SpecialCounter[] specialCounter = new SpecialCounter[SpecialWeapon.values().length]; @@ -129,6 +139,31 @@ public class SpecialCounterPlugin extends Plugin removeCounters(); wsClient.unregisterMessage(SpecialCounterUpdate.class); } + + @Subscribe + public void onGameTick(GameTick event) + { + if (client.getGameState() != GameState.LOGGED_IN) + { + return; + } + + assert client.getLocalPlayer() != null; + int currentRegion = WorldPoint.fromLocalInstance(client, client.getLocalPlayer().getLocalLocation()).getRegionID(); + boolean inInstance = client.isInInstancedRegion(); + + // if the player left the region/instance and was fighting boss that resets, reset specs + if (currentRegion != previousRegion || (wasInInstance && !inInstance)) + { + if (RESET_ON_LEAVE_INSTANCED_REGIONS.contains(previousRegion)) + { + removeCounters(); + } + } + + previousRegion = currentRegion; + wasInInstance = inInstance; + } @Subscribe public void onGameStateChanged(GameStateChanged event)