Class Npc

java.lang.Object
com.botwithus.bot.api.entities.Npc
All Implemented Interfaces:
EntityContext

public final class Npc extends Object implements EntityContext
Rich wrapper around a snapshot Npc record plus the cached NpcType definition. Carries the snapshot fields for cheap access (position, animation, hp) and resolves the definition lazily for name / options / interaction.

Obtained via Npcs.query(). Don't construct directly — the facade owns the definition cache that makes repeat lookups cheap.

Name collision note: the snapshot type com.botwithus.bot.api.snapshot.Npc shares the simple name Npc with this wrapper, so the snapshot type is fully qualified at the field declaration below and reflected mechanically on the constructor parameter and raw() accessor (Java has no import aliasing, and the enclosing class shadows any import of the snapshot type).

  • Method Details

    • raw

      public Npc raw()
      The underlying snapshot record.
    • serverIndex

      public int serverIndex()
    • typeId

      public int typeId()
    • name

      public String name()
    • combatLevel

      public int combatLevel()
    • tileX

      public int tileX()
      Description copied from interface: EntityContext
      Absolute world tile X.
      Specified by:
      tileX in interface EntityContext
    • tileY

      public int tileY()
      Description copied from interface: EntityContext
      Absolute world tile Y.
      Specified by:
      tileY in interface EntityContext
    • plane

      public int plane()
      Description copied from interface: EntityContext
      Plane / height level (0-3).
      Specified by:
      plane in interface EntityContext
    • isMoving

      public boolean isMoving()
    • followingIndex

      public int followingIndex()
    • animationId

      public int animationId()
    • stanceId

      public int stanceId()
    • hp

      public int hp()
    • maxHp

      public int maxHp()
    • isAlive

      public boolean isAlive()
    • isDead

      public boolean isDead()
      Same as !isAlive().
    • getHealth

      public int getHealth()
      Alias for hp().
    • getMaxHealth

      public int getMaxHealth()
      Alias for maxHp().
    • getHealthPercent

      public int getHealthPercent()
      Current health as a percentage of max health, 0 when max health is unknown.
    • isHidden

      public boolean isHidden()
      The snapshot only carries visible NPCs; this stub always returns false.
    • distanceToPlayer

      public int distanceToPlayer()
      Chebyshev distance to the local player tile, or MAX_VALUE if the player isn't loaded.
    • getAnimation

      public int getAnimation()
      Alias for animationId().
    • getSpotAnims

      public List<Integer> getSpotAnims()
      Currently-active spot anim ids (graphics) playing on this NPC. The post-rewrite snapshot surfaces only the first concurrent spot anim via spotAnimId(), so this list is at most one-long — for every newly-started anim, subscribe to SpotAnimEvent.
    • isFollowing

      public boolean isFollowing()
      True when this NPC is following another entity (followingIndex() != -1).
    • getFollowingIndex

      public int getFollowingIndex()
      Alias for followingIndex().
    • interact

      public void interact(int optionIndex, int unusedSubOption)
      Two-arg variant kept for pre-rewrite scripts. unusedSubOption is ignored — the option index encodes everything the action queue needs. Delegates to interact(int).
    • spotAnimId

      public int spotAnimId()
      First active spot anim (graphic) id playing on this NPC, or -1 if none. Only the first concurrent spot anim is surfaced here — subscribe to SpotAnimEvent for every newly-started one.
    • orientation

      public Orientation orientation()
      Which way this NPC is facing (wire v21): its rendered facing, interpolated while it turns. Use Orientation.compass() or Orientation.degrees() to read it, and Orientation.isSameFacingAs(Orientation) to compare two, never equals; the client can read an angle back one unit short. Unknown when the producer could not read one.
    • getType

      public NpcType getType()
      Cached NpcType for this NPC's base typeId. May be null if the lookup fails.
    • getOptions

      public List<String> getOptions()
      Right-click options. Empty list if the definition isn't available.
    • hasOption

      public boolean hasOption(String option)
      True if any option matches option (case-insensitive).
    • isDefinitionVisible

      public boolean isDefinitionVisible()
    • isClickable

      public boolean isClickable()
    • interact

      public void interact(int optionIndex)
      Queue an action against this NPC by 1-based option index. Index 1 is the default left-click action (e.g. "Attack"); 2-6 are the right-click sub-options shown on the menu.
      Throws:
      IllegalArgumentException - for optionIndex outside [1, 6]
    • interact

      public boolean interact(String option)
      Queue an action by option text (e.g. "Attack", "Talk-to"). Returns false when the option isn't on this NPC's menu (no action queued).
    • toString

      public String toString()
      Overrides:
      toString in class Object