NpcInfo

An implementation of the npc info packet. This class is responsible for bringing together all the bits of the npc info protocol, including copying all the pre-built buffers that were made beforehand.

Types

Link copied to clipboard
object Companion

Functions

Link copied to clipboard
fun allocateWorld(worldId: Int)

Allocates a new NPC info tracking object for the respective worldId, keeping track of everyone that's within this new world entity.

Link copied to clipboard
fun <T : MutableCollection<Int>> appendHighResolutionIndices(worldId: Int, collection: T, throwExceptionIfNoWorld: Boolean = true): T

Appends the high resolution indices of the given worldId to the provided collection. This can be used to determine which NPCs the player is currently seeing in the client. Servers often rely on this metric to determine things such as aggression/hunt.

Link copied to clipboard
fun clearEntities(worldId: Int)

Clears all the entities for the provided worldId. This function is only intended to be used together with the net.rsprot.protocol.game.outgoing.worldentity.ClearEntities packet. This packet should only be called before NpcInfoProtocol.update has been called, otherwise problems may arise.

Link copied to clipboard

Clears the specified NPC's avatar as specific-visible.

Link copied to clipboard
fun destroyWorld(worldId: Int)

Destroys NPC info tracking for the specified worldId. This is intended to be used when one of the world entities leaves the render distance.

Link copied to clipboard

Gets the high resolution indices of the given worldId in a new arraylist of integers. The list is initialized to an initial capacity equal to the high resolution npc index count.

Link copied to clipboard

Gets the high resolution indices of the given worldId in a new arraylist of integers, or null if the provided world does not exist. The list is initialized to an initial capacity equal to the high resolution npc index count.

Link copied to clipboard
open override fun isDestroyed(): Boolean

Whether this reference pooled object is destroyed. A destroyed object will not be returned back to the pool and instead will be left off for the garbage collector to clean up in due time. This condition is only hit when there was some error thrown during the processing of a given info object. In order to mitigate potential future problems that might continue to stem from re-using this object, we discard it altogether.

Link copied to clipboard
open override fun onAlloc(index: Int, oldSchoolClientType: OldSchoolClientType, newInstance: Boolean)

Invoked whenever a previously pooled object is re-allocated. This function will be responsible for restoring state to be equivalent to newly instantiated object.

Link copied to clipboard
open override fun onDealloc()

Invoked whenever a pooled object is no longer in use. This function is primarily used to clear out any sensitive information or potential memory leaks regarding byte buffers. This function should not fully reset objects, particularly primitives, as there is a chance a given pooled object never gets re-utilized and the garbage collector ends up picking it up. In such cases, it is more beneficial to do the resetting of properties during the onAlloc, to ensure no work is 'wasted'.

Link copied to clipboard

This function allocates a new clean world details object, as on reconnect, all existing npc info state is lost. This function should be called on the old npc info object whenever a reconnect occurs.

Link copied to clipboard

Resets the view distance back to a default value of 15 tile radius.

Link copied to clipboard
fun setPriorityCaps(worldId: Int, lowPriorityCap: Int, normalPrioritySoftCap: Int)

Sets the priority threshold caps for how many NPCs can render at once in either of the priority groups.

Link copied to clipboard
fun setSpecific(avatar: NpcAvatar)

Marks the specified NPC's avatar as specific-visible, meaning the NPC will render to this player if other conditions are met. Anyone that hasn't marked it as specific will be unable to see that NPC.

Link copied to clipboard

Sets the view distance, meaning how far the player can see NPCs.

Link copied to clipboard
fun toNpcInfoPacket(worldId: Int): OutgoingGameMessage

Turns this npc info structure into a respective npc info packet, depending on the current known view distance.

Link copied to clipboard
fun toPacket(worldId: Int): OutgoingGameMessage

Turns this npc info structure into a respective npc info packet, depending on the current known view distance.

Link copied to clipboard
fun updateBuildArea(worldId: Int, buildArea: BuildArea)
fun updateBuildArea(worldId: Int, zoneX: Int, zoneZ: Int, widthInZones: Int = BuildArea.DEFAULT_BUILD_AREA_SIZE, heightInZones: Int = BuildArea.DEFAULT_BUILD_AREA_SIZE)

Updates the build area of a given world to the specified one. This will ensure that no NPCs outside of this box will be added to high resolution view.

Link copied to clipboard
fun updateCoord(worldId: Int, level: Int, x: Int, z: Int)

Updates the coordinate of the local player, as this is necessary to know how far NPCs nearby are to the player, which allows us to remove NPCs that have gone too far out, and add NPCs that are within certain distance.