Class Npc
java.lang.Object
com.botwithus.bot.api.entities.Npc
- All Implemented Interfaces:
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 Summary
Modifier and TypeMethodDescriptionintintintChebyshev distance to the local player tile, orMAX_VALUEif the player isn't loaded.intintAlias foranimationId().intAlias forfollowingIndex().intAlias forhp().intCurrent health as a percentage of max health,0when max health is unknown.intAlias formaxHp().Right-click options.Currently-active spot anim ids (graphics) playing on this NPC.getType()Cached NpcType for this NPC's base typeId.booleanTrue if any option matchesoption(case-insensitive).inthp()voidinteract(int optionIndex) Queue an action against this NPC by 1-based option index.voidinteract(int optionIndex, int unusedSubOption) Two-arg variant kept for pre-rewrite scripts.booleanQueue an action by option text (e.g.booleanisAlive()booleanbooleanisDead()Same as!isAlive().booleanbooleanTrue when this NPC is following another entity (followingIndex()!= -1).booleanisHidden()The snapshot only carries visible NPCs; this stub always returnsfalse.booleanisMoving()intmaxHp()name()Which way this NPC is facing (wire v21): its rendered facing, interpolated while it turns.intplane()Plane / height level (0-3).raw()The underlying snapshot record.intintFirst active spot anim (graphic) id playing on this NPC, or-1if none.intstanceId()inttileX()Absolute world tile X.inttileY()Absolute world tile Y.toString()inttypeId()Methods inherited from interface EntityContext
distanceTo, distanceTo
-
Method Details
-
raw
The underlying snapshot record. -
serverIndex
public int serverIndex() -
typeId
public int typeId() -
name
-
combatLevel
public int combatLevel() -
tileX
public int tileX()Description copied from interface:EntityContextAbsolute world tile X.- Specified by:
tileXin interfaceEntityContext
-
tileY
public int tileY()Description copied from interface:EntityContextAbsolute world tile Y.- Specified by:
tileYin interfaceEntityContext
-
plane
public int plane()Description copied from interface:EntityContextPlane / height level (0-3).- Specified by:
planein interfaceEntityContext
-
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 forhp(). -
getMaxHealth
public int getMaxHealth()Alias formaxHp(). -
getHealthPercent
public int getHealthPercent()Current health as a percentage of max health,0when max health is unknown. -
isHidden
public boolean isHidden()The snapshot only carries visible NPCs; this stub always returnsfalse. -
distanceToPlayer
public int distanceToPlayer()Chebyshev distance to the local player tile, orMAX_VALUEif the player isn't loaded. -
getAnimation
public int getAnimation()Alias foranimationId(). -
getSpotAnims
Currently-active spot anim ids (graphics) playing on this NPC. The post-rewrite snapshot surfaces only the first concurrent spot anim viaspotAnimId(), so this list is at most one-long — for every newly-started anim, subscribe toSpotAnimEvent. -
isFollowing
public boolean isFollowing()True when this NPC is following another entity (followingIndex()!= -1). -
getFollowingIndex
public int getFollowingIndex()Alias forfollowingIndex(). -
interact
public void interact(int optionIndex, int unusedSubOption) Two-arg variant kept for pre-rewrite scripts.unusedSubOptionis ignored — the option index encodes everything the action queue needs. Delegates tointeract(int). -
spotAnimId
public int spotAnimId()First active spot anim (graphic) id playing on this NPC, or-1if none. Only the first concurrent spot anim is surfaced here — subscribe toSpotAnimEventfor every newly-started one. -
orientation
Which way this NPC is facing (wire v21): its rendered facing, interpolated while it turns. UseOrientation.compass()orOrientation.degrees()to read it, andOrientation.isSameFacingAs(Orientation)to compare two, neverequals; the client can read an angle back one unit short. Unknown when the producer could not read one. -
getType
Cached NpcType for this NPC's base typeId. May benullif the lookup fails. -
getOptions
-
hasOption
True if any option matchesoption(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- foroptionIndexoutside [1, 6]
-
interact
Queue an action by option text (e.g. "Attack", "Talk-to"). Returnsfalsewhen the option isn't on this NPC's menu (no action queued). -
toString
-