feat: fire PLAYER_STARTED_MOVING and PLAYER_STOPPED_MOVING events

Track horizontal movement flag transitions (forward/backward/strafe)
and fire events when the player starts or stops moving. Used by
Healbot, cast-while-moving addons, and nameplate addons that track
player movement state for positioning optimization.
This commit is contained in:
Kelsi 2026-03-21 06:38:48 -07:00
parent d36172fc90
commit de903e363c

View file

@ -11173,6 +11173,13 @@ void GameHandler::sendMovement(Opcode opcode) {
} }
} }
// Track movement state transition for PLAYER_STARTED/STOPPED_MOVING events
const uint32_t kMoveMask = static_cast<uint32_t>(MovementFlags::FORWARD) |
static_cast<uint32_t>(MovementFlags::BACKWARD) |
static_cast<uint32_t>(MovementFlags::STRAFE_LEFT) |
static_cast<uint32_t>(MovementFlags::STRAFE_RIGHT);
const bool wasMoving = (movementInfo.flags & kMoveMask) != 0;
// Cancel any timed (non-channeled) cast the moment the player starts moving. // Cancel any timed (non-channeled) cast the moment the player starts moving.
// Channeled spells end via MSG_CHANNEL_UPDATE / SMSG_CHANNEL_NOTIFY from the server. // Channeled spells end via MSG_CHANNEL_UPDATE / SMSG_CHANNEL_NOTIFY from the server.
// Turning (MSG_MOVE_START_TURN_*) is allowed while casting. // Turning (MSG_MOVE_START_TURN_*) is allowed while casting.
@ -11277,6 +11284,15 @@ void GameHandler::sendMovement(Opcode opcode) {
break; break;
} }
// Fire PLAYER_STARTED/STOPPED_MOVING on movement state transitions
{
const bool isMoving = (movementInfo.flags & kMoveMask) != 0;
if (isMoving && !wasMoving && addonEventCallback_)
addonEventCallback_("PLAYER_STARTED_MOVING", {});
else if (!isMoving && wasMoving && addonEventCallback_)
addonEventCallback_("PLAYER_STOPPED_MOVING", {});
}
if (opcode == Opcode::MSG_MOVE_SET_FACING) { if (opcode == Opcode::MSG_MOVE_SET_FACING) {
lastFacingSendTimeMs_ = movementInfo.time; lastFacingSendTimeMs_ = movementInfo.time;
lastFacingSentOrientation_ = movementInfo.orientation; lastFacingSentOrientation_ = movementInfo.orientation;