Make combat idle notifier use interacting changed
To make the notifier more precise make combat idle notifier use interacting changed. Signed-off-by: Tomas Slusny <slusnucky@gmail.com>
This commit is contained in:
@@ -29,17 +29,23 @@ import com.google.common.eventbus.Subscribe;
|
|||||||
import com.google.inject.Provides;
|
import com.google.inject.Provides;
|
||||||
import java.time.Duration;
|
import java.time.Duration;
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import net.runelite.api.Actor;
|
import net.runelite.api.Actor;
|
||||||
|
import net.runelite.api.AnimationID;
|
||||||
import static net.runelite.api.AnimationID.*;
|
import static net.runelite.api.AnimationID.*;
|
||||||
import net.runelite.api.Client;
|
import net.runelite.api.Client;
|
||||||
import net.runelite.api.GameState;
|
import net.runelite.api.GameState;
|
||||||
|
import net.runelite.api.NPC;
|
||||||
|
import net.runelite.api.NPCComposition;
|
||||||
import net.runelite.api.Player;
|
import net.runelite.api.Player;
|
||||||
import net.runelite.api.Skill;
|
import net.runelite.api.Skill;
|
||||||
import net.runelite.api.Varbits;
|
import net.runelite.api.Varbits;
|
||||||
import net.runelite.api.events.AnimationChanged;
|
import net.runelite.api.events.AnimationChanged;
|
||||||
import net.runelite.api.events.GameStateChanged;
|
import net.runelite.api.events.GameStateChanged;
|
||||||
import net.runelite.api.events.GameTick;
|
import net.runelite.api.events.GameTick;
|
||||||
|
import net.runelite.api.events.InteractingChanged;
|
||||||
import net.runelite.client.Notifier;
|
import net.runelite.client.Notifier;
|
||||||
import net.runelite.client.config.ConfigManager;
|
import net.runelite.client.config.ConfigManager;
|
||||||
import net.runelite.client.plugins.Plugin;
|
import net.runelite.client.plugins.Plugin;
|
||||||
@@ -64,10 +70,10 @@ public class IdleNotifierPlugin extends Plugin
|
|||||||
@Inject
|
@Inject
|
||||||
private IdleNotifierConfig config;
|
private IdleNotifierConfig config;
|
||||||
|
|
||||||
private Actor lastOpponent;
|
|
||||||
private Instant lastAnimating;
|
private Instant lastAnimating;
|
||||||
private int lastAnimation = AnimationID.IDLE;
|
private int lastAnimation = AnimationID.IDLE;
|
||||||
private Instant lastInteracting;
|
private Instant lastInteracting;
|
||||||
|
private Actor lastInteract;
|
||||||
private boolean notifyHitpoints = true;
|
private boolean notifyHitpoints = true;
|
||||||
private boolean notifyPrayer = true;
|
private boolean notifyPrayer = true;
|
||||||
private boolean notifyIdleLogout = true;
|
private boolean notifyIdleLogout = true;
|
||||||
@@ -202,6 +208,43 @@ public class IdleNotifierPlugin extends Plugin
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Subscribe
|
||||||
|
public void onInteractingChanged(InteractingChanged event)
|
||||||
|
{
|
||||||
|
final Actor source = event.getSource();
|
||||||
|
if (source != client.getLocalPlayer())
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
final Actor target = event.getTarget();
|
||||||
|
|
||||||
|
// Reset last interact
|
||||||
|
if (target != null)
|
||||||
|
{
|
||||||
|
lastInteract = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
final boolean isNpc = target instanceof NPC;
|
||||||
|
|
||||||
|
// If this is not NPC, do not process as we are not interested in other entities
|
||||||
|
if (!isNpc)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
final NPC npc = (NPC) target;
|
||||||
|
final NPCComposition npcComposition = npc.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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void onGameStateChanged(GameStateChanged gameStateChanged)
|
public void onGameStateChanged(GameStateChanged gameStateChanged)
|
||||||
{
|
{
|
||||||
@@ -326,32 +369,27 @@ public class IdleNotifierPlugin extends Plugin
|
|||||||
|
|
||||||
private boolean checkOutOfCombat(Duration waitDuration, Player local)
|
private boolean checkOutOfCombat(Duration waitDuration, Player local)
|
||||||
{
|
{
|
||||||
Actor opponent = local.getInteracting();
|
if (lastInteract == null)
|
||||||
boolean isPlayer = opponent instanceof Player;
|
|
||||||
|
|
||||||
if (opponent != null
|
|
||||||
&& !isPlayer
|
|
||||||
&& opponent.getCombatLevel() > 0)
|
|
||||||
{
|
{
|
||||||
resetTimers();
|
return false;
|
||||||
lastOpponent = opponent;
|
|
||||||
}
|
|
||||||
else if (opponent == null)
|
|
||||||
{
|
|
||||||
lastOpponent = null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lastOpponent != null && opponent == lastOpponent)
|
final Actor interact = local.getInteracting();
|
||||||
|
|
||||||
|
if (interact == null)
|
||||||
|
{
|
||||||
|
if (lastInteracting != null && Instant.now().compareTo(lastInteracting.plus(waitDuration)) >= 0)
|
||||||
|
{
|
||||||
|
lastInteract = null;
|
||||||
|
lastInteracting = null;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
lastInteracting = Instant.now();
|
lastInteracting = Instant.now();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lastInteracting != null && Instant.now().compareTo(lastInteracting.plus(waitDuration)) >= 0)
|
|
||||||
{
|
|
||||||
lastInteracting = null;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -435,7 +473,10 @@ public class IdleNotifierPlugin extends Plugin
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Reset combat idle timer
|
// Reset combat idle timer
|
||||||
lastOpponent = null;
|
|
||||||
lastInteracting = null;
|
lastInteracting = null;
|
||||||
|
if (client.getGameState() == GameState.LOGIN_SCREEN || local == null || local.getInteracting() != lastInteract)
|
||||||
|
{
|
||||||
|
lastInteract = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user