NpcSim

Methods
14
Fields
None

Methods

MethodReturnsDescription
setProfile(number, "melee" | "ranged" | "magic", number, number)()Simulate NPCs of type npcId: style is "melee", "ranged" or "magic" (any other raises an error); range the attack range in tiles (igno…
setFlags(number, boolean, boolean)()Collision flags for npcId: blocksEntities false for NPCs that neither block nor are blocked (Jal-Nib); fullBlock true for NPCs that b…
setAttackAnims(number, {number})()The animation ids that mark an attack by npcId, for attack timing. Like setFlags, they apply on top of the type's profile: its `setProf…
clearProfiles()()Forgets every setProfile, setFlags and setAttackAnims, and the latest rollout.
useCacheProfiles(boolean)()Simulate every NPC type the client has loaded that can fight (combat level above 0), not only those given a setProfile: attack speed and…
rollout(number, {WorldPoint}?)booleanSimulates ticks ticks from now (at most 200) and keeps the result for the queries below. The player follows path when given, else its o…
tileAt(NPC, number)WorldPoint?Where npc stands at tick (its south-west tile); nil when lost, not simulated, or past the latest rollout. The first of several when the…
tilesAt(NPC, number){WorldPoint}Every tile npc may stand on at tick; empty where tileAt is nil.
attacksAt(number){NPC}The NPCs that attack you (certainly or possibly) on tick. An attack on another NPC does not count, here or in isCertain and `firstAttac…
isCertain(NPC, number)booleanWhether npc's attack on you on tick is certain (false when none or only possible).
firstAttack(NPC)number?The first tick npc may attack you in the latest rollout; nil when it does not.
canAttack(NPC, WorldPoint)booleanWhether npc, from where it stands now, could attack a player on tile. False for an NPC without a profile.
isSafespot(WorldPoint)booleanWhether standing on tile (walking there first) is safe from every simulated NPC: within 32 ticks you arrive, none can attack you there an…
safespots(number, number?){WorldPoint}Safe tiles within radius (at most 30) of the player, nearest first. With attackRange, only tiles the player can hit a stalled NPC from:…

Method details

setProfile

setProfile: (number, "melee" | "ranged" | "magic", number, number) -> ()

Simulate NPCs of type npcId: style is "melee", "ranged" or "magic" (any other raises an error); range the attack range in tiles (ignored for melee); attackSpeedTicks ticks between attacks. A range or attackSpeedTicks below 1 counts as 1. Replaces the game's NPC data for the type; its setFlags and setAttackAnims still apply on top.

setFlags

setFlags: (number, boolean, boolean) -> ()

Collision flags for npcId: blocksEntities false for NPCs that neither block nor are blocked (Jal-Nib); fullBlock true for NPCs that block players and projectiles, which here means they block lines of sight through their tiles. They apply on top of the type's profile: its setProfile, else the game's NPC data's when useCacheProfiles is on, else the default one (melee, 4 ticks).

setAttackAnims

setAttackAnims: (number, {number}) -> ()

The animation ids that mark an attack by npcId, for attack timing. Like setFlags, they apply on top of the type's profile: its setProfile, else the game's NPC data's when useCacheProfiles is on, else the default one (melee, 4 ticks).

clearProfiles

clearProfiles: () -> ()

Forgets every setProfile, setFlags and setAttackAnims, and the latest rollout.

useCacheProfiles

useCacheProfiles: (boolean) -> ()

Simulate every NPC type the client has loaded that can fight (combat level above 0), not only those given a setProfile: attack speed and style come from the game's own NPC data. Ranged and magic NPCs get range 10 (the data holds no range). A setProfile you set replaces the data's; setFlags and setAttackAnims apply on top of either. Types that cannot fight (pets, shopkeepers) only block. Off by default.

rollout

rollout: (number, {WorldPoint}?) -> boolean

Simulates ticks ticks from now (at most 200) and keeps the result for the queries below. The player follows path when given, else its own walk: path is every tile it steps onto, in order (one a tick walking, two running), and tiles outside the loaded scene are dropped. False with no scene.

tileAt

tileAt: (NPC, number) -> WorldPoint?

Where npc stands at tick (its south-west tile); nil when lost, not simulated, or past the latest rollout. The first of several when the tick is uncertain.

tilesAt

tilesAt: (NPC, number) -> {WorldPoint}

Every tile npc may stand on at tick; empty where tileAt is nil.

attacksAt

attacksAt: (number) -> {NPC}

The NPCs that attack you (certainly or possibly) on tick. An attack on another NPC does not count, here or in isCertain and firstAttack.

isCertain

isCertain: (NPC, number) -> boolean

Whether npc's attack on you on tick is certain (false when none or only possible).

firstAttack

firstAttack: (NPC) -> number?

The first tick npc may attack you in the latest rollout; nil when it does not.

canAttack

canAttack: (NPC, WorldPoint) -> boolean

Whether npc, from where it stands now, could attack a player on tile. False for an NPC without a profile.

isSafespot

isSafespot: (WorldPoint) -> boolean

Whether standing on tile (walking there first) is safe from every simulated NPC: within 32 ticks you arrive, none can attack you there and all have stopped moving. False when an attack is possible on the way or there, the tile is unreachable, an NPC gets lost, or 32 ticks are not enough to tell.

safespots

safespots: (number, number?) -> {WorldPoint}

Safe tiles within radius (at most 30) of the player, nearest first. With attackRange, only tiles the player can hit a stalled NPC from: 1 is melee reach, more is that range with line of sight.