speccounter: fix some bugs and edge cases
1) fix plugin to correctly identify blocked hits as a spec being used 2) fix when hitsplats appear on the same tick as uninteracting with the target npc 3) fix when hitsplats appear in between the spec and its hitsplat on other targets 4) fix specs not registering when not having to path to monsters due to the spec varbit changing prior to the interact event firing
This commit is contained in:
@@ -28,6 +28,7 @@ import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import javax.inject.Inject;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.runelite.api.Actor;
|
||||
import net.runelite.api.Client;
|
||||
import net.runelite.api.EquipmentInventorySlot;
|
||||
@@ -40,6 +41,7 @@ import net.runelite.api.NPC;
|
||||
import net.runelite.api.VarPlayer;
|
||||
import net.runelite.api.events.GameStateChanged;
|
||||
import net.runelite.api.events.HitsplatApplied;
|
||||
import net.runelite.api.events.InteractingChanged;
|
||||
import net.runelite.api.events.NpcDespawned;
|
||||
import net.runelite.api.events.VarbitChanged;
|
||||
import net.runelite.client.callback.ClientThread;
|
||||
@@ -57,11 +59,13 @@ import net.runelite.client.ws.WSClient;
|
||||
tags = {"combat", "npcs", "overlay"},
|
||||
enabledByDefault = false
|
||||
)
|
||||
@Slf4j
|
||||
public class SpecialCounterPlugin extends Plugin
|
||||
{
|
||||
private int currentWorld = -1;
|
||||
private int specialPercentage = -1;
|
||||
private NPC specedNPC;
|
||||
private int currentWorld;
|
||||
private int specialPercentage;
|
||||
private Actor lastSpecTarget;
|
||||
private int lastSpecTick;
|
||||
|
||||
private SpecialWeapon specialWeapon;
|
||||
private final Set<Integer> interactedNpcIds = new HashSet<>();
|
||||
@@ -89,6 +93,11 @@ public class SpecialCounterPlugin extends Plugin
|
||||
protected void startUp()
|
||||
{
|
||||
wsClient.registerMessage(SpecialCounterUpdate.class);
|
||||
currentWorld = -1;
|
||||
specialPercentage = -1;
|
||||
lastSpecTarget = null;
|
||||
lastSpecTick = -1;
|
||||
interactedNpcIds.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -115,6 +124,20 @@ public class SpecialCounterPlugin extends Plugin
|
||||
}
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onInteractingChanged(InteractingChanged interactingChanged)
|
||||
{
|
||||
Actor source = interactingChanged.getSource();
|
||||
Actor target = interactingChanged.getTarget();
|
||||
if (lastSpecTick != client.getTickCount() || source != client.getLocalPlayer() || target == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
log.debug("Updating last spec target to {} (was {})", target.getName(), lastSpecTarget);
|
||||
lastSpecTarget = target;
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onVarbitChanged(VarbitChanged event)
|
||||
{
|
||||
@@ -129,11 +152,13 @@ public class SpecialCounterPlugin extends Plugin
|
||||
this.specialPercentage = specialPercentage;
|
||||
this.specialWeapon = usedSpecialWeapon();
|
||||
|
||||
Actor interacting = client.getLocalPlayer().getInteracting();
|
||||
if (interacting instanceof NPC)
|
||||
{
|
||||
specedNPC = (NPC) interacting;
|
||||
}
|
||||
log.debug("Special attack used - percent: {} weapon: {}", specialPercentage, specialWeapon);
|
||||
|
||||
// spec was used; since the varbit change event fires before the interact change event,
|
||||
// this will be specing on the target of interact changed *if* it fires this tick,
|
||||
// otherwise it is what we are currently interacting with
|
||||
lastSpecTarget = client.getLocalPlayer().getInteracting();
|
||||
lastSpecTick = client.getTickCount();
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
@@ -141,7 +166,25 @@ public class SpecialCounterPlugin extends Plugin
|
||||
{
|
||||
Actor target = hitsplatApplied.getActor();
|
||||
Hitsplat hitsplat = hitsplatApplied.getHitsplat();
|
||||
if (hitsplat.getHitsplatType() != Hitsplat.HitsplatType.DAMAGE_ME || !(target instanceof NPC))
|
||||
Hitsplat.HitsplatType hitsplatType = hitsplat.getHitsplatType();
|
||||
// Ignore all hitsplats other than mine
|
||||
if ((hitsplatType != Hitsplat.HitsplatType.DAMAGE_ME && hitsplatType != Hitsplat.HitsplatType.BLOCK_ME) || target == client.getLocalPlayer())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
log.debug("Hitsplat target: {} spec target: {}", target, lastSpecTarget);
|
||||
|
||||
// If waiting for a spec, ignore hitsplats not on the actor we specced
|
||||
if (lastSpecTarget != null && lastSpecTarget != target)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
boolean wasSpec = lastSpecTarget != null;
|
||||
lastSpecTarget = null;
|
||||
|
||||
if (!(target instanceof NPC))
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -156,22 +199,17 @@ public class SpecialCounterPlugin extends Plugin
|
||||
addInteracting(interactingId);
|
||||
}
|
||||
|
||||
if (specedNPC == hitsplatApplied.getActor())
|
||||
if (wasSpec && specialWeapon != null && hitsplat.getAmount() > 0)
|
||||
{
|
||||
specedNPC = null;
|
||||
int hit = getHit(specialWeapon, hitsplat);
|
||||
|
||||
if (specialWeapon != null)
|
||||
updateCounter(specialWeapon, null, hit);
|
||||
|
||||
if (!party.getMembers().isEmpty())
|
||||
{
|
||||
int hit = getHit(specialWeapon, hitsplat);
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -193,10 +231,9 @@ public class SpecialCounterPlugin extends Plugin
|
||||
{
|
||||
NPC actor = npcDespawned.getNpc();
|
||||
|
||||
// if the NPC despawns before the hitsplat is shown
|
||||
if (specedNPC == actor)
|
||||
if (lastSpecTarget == actor)
|
||||
{
|
||||
specedNPC = null;
|
||||
lastSpecTarget = null;
|
||||
}
|
||||
|
||||
if (actor.isDead() && interactedNpcIds.contains(actor.getId()))
|
||||
|
||||
Reference in New Issue
Block a user