diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/specialcounter/Boss.java b/runelite-client/src/main/java/net/runelite/client/plugins/specialcounter/Boss.java index a9b4434797..295194a961 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/specialcounter/Boss.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/specialcounter/Boss.java @@ -34,25 +34,23 @@ import net.runelite.api.NpcID; @ToString enum Boss { - ABYSSAL_SIRE(1.25d, NpcID.ABYSSAL_SIRE, NpcID.ABYSSAL_SIRE_5887, NpcID.ABYSSAL_SIRE_5888, NpcID.ABYSSAL_SIRE_5889, NpcID.ABYSSAL_SIRE_5890, NpcID.ABYSSAL_SIRE_5891, NpcID.ABYSSAL_SIRE_5908), - CALLISTO(1.225d, NpcID.CALLISTO, NpcID.CALLISTO_6609), - CERBERUS(1.15d, NpcID.CERBERUS, NpcID.CERBERUS_5863, NpcID.CERBERUS_5866), - CHAOS_ELEMENTAL(1.075d, NpcID.CHAOS_ELEMENTAL, NpcID.CHAOS_ELEMENTAL_6505), - CORPOREAL_BEAST(1.55d, NpcID.CORPOREAL_BEAST), - GENERAL_GRAARDOR(1.325d, NpcID.GENERAL_GRAARDOR, NpcID.GENERAL_GRAARDOR_6494), - GIANT_MOLE(1.075d, NpcID.GIANT_MOLE, NpcID.GIANT_MOLE_6499), - KALPHITE_QUEEN(1.05d, NpcID.KALPHITE_QUEEN, NpcID.KALPHITE_QUEEN_963, NpcID.KALPHITE_QUEEN_965, NpcID.KALPHITE_QUEEN_4303, NpcID.KALPHITE_QUEEN_4304, NpcID.KALPHITE_QUEEN_6500, NpcID.KALPHITE_QUEEN_6501), - KING_BLACK_DRAGON(1.075d, NpcID.KING_BLACK_DRAGON, NpcID.KING_BLACK_DRAGON_2642, NpcID.KING_BLACK_DRAGON_6502), - KRIL_TSUROTH(1.375d, NpcID.KRIL_TSUTSAROTH, NpcID.KRIL_TSUTSAROTH_6495), - VENETENATIS(1.4d, NpcID.VENENATIS, NpcID.VENENATIS_6610), - VETION(1.225d, NpcID.VETION, NpcID.VETION_REBORN); + ABYSSAL_SIRE(NpcID.ABYSSAL_SIRE, NpcID.ABYSSAL_SIRE_5887, NpcID.ABYSSAL_SIRE_5888, NpcID.ABYSSAL_SIRE_5889, NpcID.ABYSSAL_SIRE_5890, NpcID.ABYSSAL_SIRE_5891, NpcID.ABYSSAL_SIRE_5908), + CALLISTO(NpcID.CALLISTO, NpcID.CALLISTO_6609), + CERBERUS(NpcID.CERBERUS, NpcID.CERBERUS_5863, NpcID.CERBERUS_5866), + CHAOS_ELEMENTAL(NpcID.CHAOS_ELEMENTAL, NpcID.CHAOS_ELEMENTAL_6505), + CORPOREAL_BEAST(NpcID.CORPOREAL_BEAST), + GENERAL_GRAARDOR(NpcID.GENERAL_GRAARDOR, NpcID.GENERAL_GRAARDOR_6494), + GIANT_MOLE(NpcID.GIANT_MOLE, NpcID.GIANT_MOLE_6499), + KALPHITE_QUEEN(NpcID.KALPHITE_QUEEN, NpcID.KALPHITE_QUEEN_963, NpcID.KALPHITE_QUEEN_965, NpcID.KALPHITE_QUEEN_4303, NpcID.KALPHITE_QUEEN_4304, NpcID.KALPHITE_QUEEN_6500, NpcID.KALPHITE_QUEEN_6501), + KING_BLACK_DRAGON(NpcID.KING_BLACK_DRAGON, NpcID.KING_BLACK_DRAGON_2642, NpcID.KING_BLACK_DRAGON_6502), + KRIL_TSUROTH(NpcID.KRIL_TSUTSAROTH, NpcID.KRIL_TSUTSAROTH_6495), + VENETENATIS(NpcID.VENENATIS, NpcID.VENENATIS_6610), + VETION(NpcID.VETION, NpcID.VETION_REBORN); private final Set ids; - private final double modifier; // Some NPCs have a modifier to the experience a player receives. - Boss(double modifier, Integer... ids) + Boss(Integer... ids) { - this.modifier = modifier; this.ids = Sets.newHashSet(ids); } 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 ad45a84565..562b263a17 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 @@ -32,19 +32,15 @@ import net.runelite.api.Actor; import net.runelite.api.Client; import net.runelite.api.EquipmentInventorySlot; import net.runelite.api.GameState; +import net.runelite.api.Hitsplat; import net.runelite.api.InventoryID; import net.runelite.api.Item; import net.runelite.api.ItemContainer; 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.events.FakeXpDrop; import net.runelite.api.events.GameStateChanged; -import net.runelite.api.events.GameTick; +import net.runelite.api.events.HitsplatApplied; import net.runelite.api.events.NpcDespawned; -import net.runelite.api.events.StatChanged; import net.runelite.api.events.VarbitChanged; import net.runelite.client.callback.ClientThread; import net.runelite.client.eventbus.Subscribe; @@ -54,7 +50,6 @@ import net.runelite.client.plugins.PluginDescriptor; import net.runelite.client.ui.overlay.infobox.InfoBoxManager; import net.runelite.client.ws.PartyService; import net.runelite.client.ws.WSClient; -import org.apache.commons.lang3.ArrayUtils; @PluginDescriptor( name = "Special Attack Counter", @@ -66,10 +61,7 @@ public class SpecialCounterPlugin extends Plugin { private int currentWorld = -1; private int specialPercentage = -1; - private int specialHitpointsExperience = -1; - private int specialHitpointsGained = -1; private boolean specialUsed; - private double modifier = 1d; private SpecialWeapon specialWeapon; private final Set interactedNpcIds = new HashSet<>(); @@ -137,105 +129,57 @@ public class SpecialCounterPlugin extends Plugin this.specialPercentage = specialPercentage; this.specialWeapon = usedSpecialWeapon(); - checkInteracting(); - specialUsed = true; - specialHitpointsExperience = client.getSkillExperience(Skill.HITPOINTS); - specialHitpointsGained = -1; } @Subscribe - public void onStatChanged(StatChanged statChanged) + public void onHitsplatApplied(HitsplatApplied hitsplatApplied) { - if (specialUsed && statChanged.getSkill() == Skill.HITPOINTS) - { - specialHitpointsGained = statChanged.getXp() - specialHitpointsExperience; - } - } - - @Subscribe - public void onFakeXpDrop(FakeXpDrop fakeXpDrop) - { - if (specialUsed && fakeXpDrop.getSkill() == Skill.HITPOINTS) - { - specialHitpointsGained = fakeXpDrop.getXp(); - } - } - - @Subscribe - private void onGameTick(GameTick tick) - { - if (client.getGameState() != GameState.LOGGED_IN) + Actor target = hitsplatApplied.getActor(); + Hitsplat hitsplat = hitsplatApplied.getHitsplat(); + if (hitsplat.getHitsplatType() != Hitsplat.HitsplatType.DAMAGE_ME || !(target instanceof NPC)) { return; } - int interactingId = checkInteracting(); - if (interactingId > -1 && specialUsed) - { - int deltaExperience = specialHitpointsGained; + NPC npc = (NPC) target; + int interactingId = npc.getId(); + // If this is a new NPC reset the counters + if (!interactedNpcIds.contains(interactingId)) + { + removeCounters(); + addInteracting(interactingId); + } + + if (specialUsed) + { specialUsed = false; - if (deltaExperience > 0) + if (specialWeapon != null) { - if (specialWeapon != null) + int hit = getHit(specialWeapon, hitsplat); + + updateCounter(specialWeapon, null, hit); + + if (!party.getMembers().isEmpty()) { - int hit = getHit(specialWeapon, deltaExperience); - - updateCounter(specialWeapon, null, hit); - - if (!party.getMembers().isEmpty()) - { - final SpecialCounterUpdate specialCounterUpdate = new SpecialCounterUpdate(interactingId, specialWeapon, hit); - specialCounterUpdate.setMemberId(party.getLocalMember().getMemberId()); - wsClient.send(specialCounterUpdate); - } + final SpecialCounterUpdate specialCounterUpdate = new SpecialCounterUpdate(interactingId, specialWeapon, hit); + specialCounterUpdate.setMemberId(party.getLocalMember().getMemberId()); + wsClient.send(specialCounterUpdate); } } } } - private int checkInteracting() - { - Player localPlayer = client.getLocalPlayer(); - Actor interacting = localPlayer.getInteracting(); - - if (interacting instanceof NPC) - { - NPC npc = (NPC) interacting; - NPCComposition composition = npc.getComposition(); - int interactingId = npc.getId(); - - if (!ArrayUtils.contains(composition.getActions(), "Attack")) - { - // Skip over non attackable npcs so that eg. talking to bankers doesn't reset - // the counters. - return -1; - } - - if (!interactedNpcIds.contains(interactingId)) - { - removeCounters(); - addInteracting(interactingId); - } - - return interactingId; - } - - return -1; - } - private void addInteracting(int npcId) { - modifier = 1d; interactedNpcIds.add(npcId); // Add alternate forms of bosses final Boss boss = Boss.getBoss(npcId); if (boss != null) { - modifier = boss.getModifier(); interactedNpcIds.addAll(boss.getIds()); } } @@ -356,18 +300,8 @@ public class SpecialCounterPlugin extends Plugin } } - private int getHit(SpecialWeapon specialWeapon, int deltaExperience) + private int getHit(SpecialWeapon specialWeapon, Hitsplat hitsplat) { - double modifierBase = 1d / modifier; - double damageOutput = (deltaExperience * modifierBase) / 1.3333d; - - if (!specialWeapon.isDamage()) - { - return 1; - } - else - { - return (int) Math.round(damageOutput); - } + return specialWeapon.isDamage() ? hitsplat.getAmount() : 1; } } \ No newline at end of file