Merge pull request #3412 from deathbeam/idle-notifer-combat-attack
Idle notifier fix combat notifications, reset notifications on interaction
This commit is contained in:
@@ -29,17 +29,23 @@ import com.google.common.eventbus.Subscribe;
|
||||
import com.google.inject.Provides;
|
||||
import java.time.Duration;
|
||||
import java.time.Instant;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import javax.inject.Inject;
|
||||
import net.runelite.api.Actor;
|
||||
import net.runelite.api.AnimationID;
|
||||
import static net.runelite.api.AnimationID.*;
|
||||
import net.runelite.api.Client;
|
||||
import net.runelite.api.GameState;
|
||||
import net.runelite.api.NPC;
|
||||
import net.runelite.api.NPCComposition;
|
||||
import net.runelite.api.Player;
|
||||
import net.runelite.api.Skill;
|
||||
import net.runelite.api.Varbits;
|
||||
import net.runelite.api.events.AnimationChanged;
|
||||
import net.runelite.api.events.GameStateChanged;
|
||||
import net.runelite.api.events.GameTick;
|
||||
import net.runelite.api.events.InteractingChanged;
|
||||
import net.runelite.client.Notifier;
|
||||
import net.runelite.client.config.ConfigManager;
|
||||
import net.runelite.client.plugins.Plugin;
|
||||
@@ -64,10 +70,10 @@ public class IdleNotifierPlugin extends Plugin
|
||||
@Inject
|
||||
private IdleNotifierConfig config;
|
||||
|
||||
private Actor lastOpponent;
|
||||
private Instant lastAnimating;
|
||||
private int lastAnimation = AnimationID.IDLE;
|
||||
private Instant lastInteracting;
|
||||
private boolean notifyIdle = false;
|
||||
private Actor lastInteract;
|
||||
private boolean notifyHitpoints = true;
|
||||
private boolean notifyPrayer = true;
|
||||
private boolean notifyIdleLogout = true;
|
||||
@@ -192,8 +198,50 @@ public class IdleNotifierPlugin extends Plugin
|
||||
/* Prayer */
|
||||
case USING_GILDED_ALTAR:
|
||||
resetTimers();
|
||||
notifyIdle = true;
|
||||
lastAnimation = animation;
|
||||
break;
|
||||
case IDLE:
|
||||
break;
|
||||
default:
|
||||
// On unknown animation simply assume the animation is invalid and dont throw notification
|
||||
lastAnimation = IDLE;
|
||||
}
|
||||
}
|
||||
|
||||
@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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -206,6 +254,9 @@ public class IdleNotifierPlugin extends Plugin
|
||||
|
||||
switch (state)
|
||||
{
|
||||
case LOGIN_SCREEN:
|
||||
resetTimers();
|
||||
break;
|
||||
case LOGGING_IN:
|
||||
case HOPPING:
|
||||
case CONNECTION_LOST:
|
||||
@@ -216,7 +267,9 @@ public class IdleNotifierPlugin extends Plugin
|
||||
{
|
||||
sixHourWarningTime = Instant.now().plus(SIX_HOUR_LOGOUT_WARNING_AFTER_DURATION);
|
||||
ready = false;
|
||||
resetTimers();
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -227,8 +280,9 @@ public class IdleNotifierPlugin extends Plugin
|
||||
final Player local = client.getLocalPlayer();
|
||||
final Duration waitDuration = Duration.ofMillis(config.getIdleNotificationDelay());
|
||||
|
||||
if (client.getGameState() != GameState.LOGGED_IN || local == null)
|
||||
if (client.getGameState() != GameState.LOGGED_IN || local == null || client.getMouseIdleTicks() < 10)
|
||||
{
|
||||
resetTimers();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -315,32 +369,27 @@ public class IdleNotifierPlugin extends Plugin
|
||||
|
||||
private boolean checkOutOfCombat(Duration waitDuration, Player local)
|
||||
{
|
||||
Actor opponent = local.getInteracting();
|
||||
boolean isPlayer = opponent instanceof Player;
|
||||
|
||||
if (opponent != null
|
||||
&& !isPlayer
|
||||
&& opponent.getCombatLevel() > 0)
|
||||
if (lastInteract == null)
|
||||
{
|
||||
resetTimers();
|
||||
lastOpponent = opponent;
|
||||
}
|
||||
else if (opponent == null)
|
||||
{
|
||||
lastOpponent = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
if (lastInteracting != null && Instant.now().compareTo(lastInteracting.plus(waitDuration)) >= 0)
|
||||
{
|
||||
lastInteracting = null;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -388,34 +437,46 @@ public class IdleNotifierPlugin extends Plugin
|
||||
|
||||
private boolean checkAnimationIdle(Duration waitDuration, Player local)
|
||||
{
|
||||
if (notifyIdle)
|
||||
if (lastAnimation == IDLE)
|
||||
{
|
||||
if (lastAnimating != null)
|
||||
return false;
|
||||
}
|
||||
|
||||
final int animation = local.getAnimation();
|
||||
|
||||
if (animation == IDLE)
|
||||
{
|
||||
if (lastAnimating != null && Instant.now().compareTo(lastAnimating.plus(waitDuration)) >= 0)
|
||||
{
|
||||
if (Instant.now().compareTo(lastAnimating.plus(waitDuration)) >= 0)
|
||||
{
|
||||
notifyIdle = false;
|
||||
lastAnimating = null;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else if (local.getAnimation() == IDLE)
|
||||
{
|
||||
lastAnimating = Instant.now();
|
||||
lastAnimation = IDLE;
|
||||
lastAnimating = null;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
lastAnimating = Instant.now();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private void resetTimers()
|
||||
{
|
||||
final Player local = client.getLocalPlayer();
|
||||
|
||||
// Reset animation idle timer
|
||||
notifyIdle = false;
|
||||
lastAnimating = null;
|
||||
if (client.getGameState() == GameState.LOGIN_SCREEN || local == null || local.getAnimation() != lastAnimation)
|
||||
{
|
||||
lastAnimation = IDLE;
|
||||
}
|
||||
|
||||
// Reset combat idle timer
|
||||
lastOpponent = null;
|
||||
lastInteracting = null;
|
||||
if (client.getGameState() == GameState.LOGIN_SCREEN || local == null || local.getInteracting() != lastInteract)
|
||||
{
|
||||
lastInteract = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user