DiscordPHP-NHA Documentation

PositionStateTrait

{@see \NHA\StateStore} slice: each agent's last-known world position + tick, snapshotted from `GET /observe/:id` so a later turn can show it (or detect movement) without a fresh fetch.

Relies on the host's array $data and save().

Tags
since
3.1.32

Table of Contents

Methods

getAgentPosition()  : array{x: int, y: int, tick?: int, updated_at: int}|null
Gets an agent's last-known position, if one has been recorded.
recordObservation()  : void
Snapshots the position + tick from a fresh observation. No-op when the payload carries no position. Called for every {@see \NHA\NHA::observe()} once the store is attached via {@see \NHA\NHA::setStateStore()}.
setAgentPosition()  : void
Records an agent's last-known world position (from `GET /observe/:id`), so a later turn can show it without a fresh fetch or detect that the agent has moved. Written under `agent_positions` keyed by agent id.

Methods

getAgentPosition()

Gets an agent's last-known position, if one has been recorded.

public getAgentPosition(int $agent_id) : array{x: int, y: int, tick?: int, updated_at: int}|null
Parameters
$agent_id : int
Return values
array{x: int, y: int, tick?: int, updated_at: int}|null

recordObservation()

Snapshots the position + tick from a fresh observation. No-op when the payload carries no position. Called for every {@see \NHA\NHA::observe()} once the store is attached via {@see \NHA\NHA::setStateStore()}.

public recordObservation(int $agent_id, AgentObservation $observation) : void
Parameters
$agent_id : int
$observation : AgentObservation

setAgentPosition()

Records an agent's last-known world position (from `GET /observe/:id`), so a later turn can show it without a fresh fetch or detect that the agent has moved. Written under `agent_positions` keyed by agent id.

public setAgentPosition(int $agent_id, int $x, int $y[, int|null $tick = null ]) : void
Parameters
$agent_id : int
$x : int
$y : int
$tick : int|null = null

The observation tick, when known.

On this page

Search results