NpcAvatar

The npc avatar class represents an NPC as shown by the client. This class contains all the properties necessary to put a NPC into high resolution.

Npc direction table:

| Id | Client Angle |  Direction |
|:--:|:------------:|:----------:|
| 0 | 768 | North-West |
| 1 | 1024 | North |
| 2 | 1280 | North-East |
| 3 | 512 | West |
| 4 | 1536 | East |
| 5 | 256 | South-West |
| 6 | 0 | South |
| 7 | 1792 | South-East |

Parameters

index

the index of the npc in the world

id

the id of the npc in the world, limited to range of 0..16383

level

the height level of the npc

x

the absolute x coordinate of the npc

z

the absolute z coordinate of the npc

spawnCycle

the game cycle on which the npc spawned into the world; for static NPCs, this would always be zero. This is only used by the C++ clients.

direction

the direction that the npc will face on spawn (see table above)

Properties

Link copied to clipboard

Extended info repository, commonly referred to as "masks", will track everything relevant inside itself. Setting properties such as a spotanim would be done through this. The extendedInfo is also responsible for caching the non-temporary blocks, such as appearance and move speed.

Functions

Link copied to clipboard
fun crawl(deltaX: Int, deltaZ: Int)

Marks the NPC as moved with the crawl movement type. If more than one crawl/walks are sent in one cycle, it will instead be treated as run. If more than two crawl/walks are sent in one cycle, it will be treated as a teleport.

Link copied to clipboard
fun level(): Int

The current height level of this avatar.

Link copied to clipboard
open override fun postUpdate()

Handles any changes to be done to the avatar post its update. This will clean up any extended info blocks and update the last coordinate to match up with the current (set earlier in the cycle).

Link copied to clipboard
fun setId(id: Int)

Sets the id of the avatar - any new observers of this NPC will receive the new id. This should be used in tandem with the transformation extended info block.

Link copied to clipboard
fun setInaccessible(inaccessible: Boolean)

Sets this avatar inaccessible, meaning no player can observe this NPC, but they are still in the world. This is how NPCs in the 'dead' state will be handled.

Link copied to clipboard
fun teleport(level: Int, x: Int, z: Int, jump: Boolean)

A helper function to teleport the NPC to a new coordinate. This will furthermore mark the movement type as teleport, meaning no matter what other coordinate changes are applied, as teleport has the highest priority, teleportation will be how it is rendered on the client's end.

Link copied to clipboard
open override fun toString(): String
Link copied to clipboard
fun updateDirection(direction: Int)

Updates the spawn direction of the NPC.

Link copied to clipboard
fun walk(deltaX: Int, deltaZ: Int)

Marks the NPC as moved with the walk movement type. If more than one crawl/walks are sent in one cycle, it will instead be treated as run. If more than two crawl/walks are sent in one cycle, it will be treated as a teleport.

Link copied to clipboard
fun x(): Int

The current absolute x coordinate of this avatar.

Link copied to clipboard
fun z(): Int

The current absolute z coordinate of this avatar.