Class DeathWatch

java.lang.Object
privbot.mechanics.DeathWatch

public final class DeathWatch extends Object
Detects the local player's death and respawn by POLLING, one observe(java.lang.Integer, java.lang.Integer, net.runelite.api.coords.WorldPoint, int) call per game tick. Pure: the caller reads hitpoints, animation and tile and feeds them in; nothing here touches a client. Not thread-safe: feed it from one thread.

What it proves: DEAD when hitpoints read 0 or the animation is a death animation (default 836, the OSRS death animation, or the set the constructor was given). Hitpoints reading 0 always catch a death, on every server. The animation is only a faster cue, and its id differs per server: Elorin's player animations are the OSRS id + 19000 (19836), so pass new DeathWatch(Set.of(836, 19836)) to also catch the animation there. After a death, RESPAWNED is answered once, on the first tick where hitpoints are above 0 and either the tile differs from where the player died or hitpoints have been above 0 for 3 distinct ticks in a row; after that the watch is ALIVE again. A death animation that is still showing keeps the watch DEAD.

Unreadable looks like: null hitpoints answer UNKNOWN, never ALIVE, and break the run of "hitpoints above 0" ticks. A null tile never counts as a change. Never subscribe to the animation event for the local player's death (a client does not see its own death through it on some servers); poll.

  • Field Details

    • DEFAULT_DEATH_ANIMATION

      public static final int DEFAULT_DEATH_ANIMATION
      The OSRS death animation (836). Elorin's is 19836 (OSRS id + 19000); hitpoints 0 catch a death anyway.
      See Also:
  • Constructor Details

    • DeathWatch

      public DeathWatch()
      A watch with the default death animation {836}.
    • DeathWatch

      public DeathWatch(Set<Integer> deathAnimations)
      Parameters:
      deathAnimations - the animation ids that mean "dying" on this server; null or empty means the default
  • Method Details

    • observe

      public DeathWatch.State observe(Integer hp, Integer animation, net.runelite.api.coords.WorldPoint tile, int tick)
      Feeds one tick.
      Parameters:
      hp - current hitpoints, or null when unreadable
      animation - the local player's animation id, or null / -1 for none
      tile - the local player's tile, or null when unreadable
      tick - the game tick number (any increasing number)
      Returns:
      what this tick says
    • diedAtTick

      public int diedAtTick()
      Returns:
      the tick the latest death was first seen, or -1 when none has been seen
    • diedAt

      public net.runelite.api.coords.WorldPoint diedAt()
      Returns:
      the tile the latest death was first seen on, or null when none (or the tile was unreadable)
    • reset

      public void reset()
      Forgets any death in progress (Stop, disconnect).