Class Threats

java.lang.Object
privbot.hooks.Threats

public final class Threats extends Object
ctx.threats: a detached, per-tick copy of the fight around the local player (NPCs, projectiles, graphics, hitpoints and chosen prayers), the same on every server.

The snapshot is plain immutable data. Feed it to the pure planners in privbot.mechanics (PrayerPlanner, ShotTracker, CueTimeline) instead of reading the client more than once a tick.

What a result proves. A present ThreatSnapshot was read in one client-thread batch: the player's tile and the NPC, projectile and graphics lists were read, so empty lists mean "none in range on the player's plane". Things on other planes are excluded.

NPC tiles. NpcView.tile() is the south-west corner of the footprint on every server. Stock RuneLite reports that from getWorldLocation(). Supported clients (Elorin, Impact and the other proxy-backed clients) report the drawn centre there, which also slides while the NPC walks, so the server tile (Client.base + Actor.pathX/pathY[0]) is read instead; if an NPC's server tile cannot be read, its drawn centre is moved back by size / 2 (by 2, the 5x5 case, when the size is unknown too).

ThreatSnapshot.player() follows the same rule for the local player: on a supported client it is the player's server tile, or the drawn tile when that cannot be read.

Unreadable. Not logged in, no local player or tile, an unreadable projectile list (the reason contains "projectiles"), or any exception from a client read each give Observed.unreadable(String). Smaller gaps do not discard the snapshot: unreadable hitpoints or prayer points are null in it, a requested prayer that cannot be read is listed in ThreatSnapshot.unreadablePrayers() (never counted as off), an NPC size that cannot be read is 0, an NPC overhead that cannot be read is null (a read that shows none is NpcView.NO_OVERHEAD), and a projectile whose target cannot be read, or that is aimed at a tile rather than an actor, has ShotView.targetsUs() null (unknown, not "not us").

Thread. Call from the runner worker or a node; it marshals its own read through GameThread.ensure(java.util.function.Supplier). Do not wrap it in another client-thread read.

  • Method Details

    • snapshot

      public Observed<ThreatSnapshot> snapshot(ThreatQuery query)
      Reads the fight once.
      Parameters:
      query - what to include (radius, NPC filter, prayers to check)
      Returns:
      the snapshot, or UNREADABLE with the reason (see the class comment); never null