Skip to content

Commit

Permalink
idle notifier: Re-check NPC interaction on transform
Browse files Browse the repository at this point in the history
NPCs which begin combat with a menu option that is not "Attack" are
missed during combat detection. This commit uses NpcChanged to detect
when an NPC that we are interacting with transforms and gains an Attack
option while still being interacted with. This notably fixes the
interaction check at Kraken as combat is initiated via a "Disturb"
option on a Whirlpool which transforms into the Kraken.

Co-authored-by: Jordan Atwood <[email protected]>
  • Loading branch information
LlemonDuck and Nightfirecat committed Dec 13, 2022
1 parent cfeffa5 commit 82fe3f3
Showing 1 changed file with 37 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
import net.runelite.api.events.GraphicChanged;
import net.runelite.api.events.HitsplatApplied;
import net.runelite.api.events.InteractingChanged;
import net.runelite.api.events.NpcChanged;
import net.runelite.client.Notifier;
import net.runelite.client.config.ConfigManager;
import net.runelite.client.eventbus.Subscribe;
Expand Down Expand Up @@ -337,34 +338,27 @@ public void onInteractingChanged(InteractingChanged event)
lastInteracting = Instant.now();
}

final boolean isNpc = target instanceof NPC;

// If this is not NPC, do not process as we are not interested in other entities
if (!isNpc)
if (!(target instanceof NPC))
{
return;
}

final NPC npc = (NPC) target;
final NPCComposition npcComposition = npc.getComposition();
final List<String> npcMenuActions = Arrays.asList(npcComposition.getActions());
checkNpcInteraction((NPC) target);
}

if (npcMenuActions.contains("Attack"))
{
// Player is most likely in combat with attack-able NPC
resetTimers();
lastInteract = target;
lastInteracting = Instant.now();
lastInteractWasCombat = true;
}
else if (target.getName() != null && target.getName().contains(FISHING_SPOT))
// this event is needed to handle some rare npcs where "Attack" is not used to initiate combat
// for example, kraken starts the fight with "Disturb" then changes into another form with "Attack"
@Subscribe
public void onNpcChanged(NpcChanged event)
{
NPC npc = event.getNpc();
if (client.getLocalPlayer().getInteracting() != npc)
{
// Player is fishing
resetTimers();
lastInteract = target;
lastInteracting = Instant.now();
lastInteractWasCombat = false;
return;
}

checkNpcInteraction(npc);
}

@Subscribe
Expand Down Expand Up @@ -507,6 +501,29 @@ public void onGameTick(GameTick event)
}
}

private void checkNpcInteraction(final NPC target)
{
final NPCComposition npcComposition = target.getComposition();
final List<String> npcMenuActions = Arrays.asList(npcComposition.getActions());

if (npcMenuActions.contains("Attack"))
{
// Player is most likely in combat with attack-able NPC
resetTimers();
lastInteract = target;
lastInteracting = Instant.now();
lastInteractWasCombat = true;
}
else if (target.getName() != null && target.getName().contains(FISHING_SPOT))
{
// Player is fishing
resetTimers();
lastInteract = target;
lastInteracting = Instant.now();
lastInteractWasCombat = false;
}
}

private boolean checkFullSpecEnergy()
{
int currentSpecEnergy = client.getVarpValue(VarPlayer.SPECIAL_ATTACK_PERCENT);
Expand Down

0 comments on commit 82fe3f3

Please sign in to comment.