32 : _timer(0), _speed(speed), _speedSelectionMode(speedSelectionMode), _wanderDistance(distance), _wanderSteps(0)
69 _timer.Reset(overrideTimer);
80 if (!owner->IsAlive())
83 _reference = owner->GetPosition();
87 _wanderSteps =
urand(2, 10);
113 float distance = _wanderDistance > 0.1f ?
frand(0.1f, _wanderDistance) : _wanderDistance;
114 float angle =
frand(0.f,
static_cast<float>(
M_PI * 2));
115 owner->MovePositionToFirstCollision(position, distance, angle);
127 _path = std::make_unique<PathGenerator>(owner);
128 _path->SetPathLengthLimit(30.0f);
141 if (_path->GetPathLength() < 0.1f)
155 switch (_speedSelectionMode)
176 _timer.Reset(splineDuration);
181 _wanderSteps =
urand(2, 10);
185 if constexpr (std::is_base_of_v<Creature, T>)
186 owner->SignalFormationMovement();
192 if (!owner->IsAlive())
200 _duration->Update(diff);
201 if (_duration->Passed())
221 SetRandomLocation(owner);
243 owner->SetWalk(
false);
249 if constexpr (std::is_base_of_v<Creature, T>)
250 if (owner->IsAIEnabled())
MovementWalkRunSpeedSelectionMode
@ MOVEMENTGENERATOR_FLAG_TIMED_PAUSED
@ MOVEMENTGENERATOR_FLAG_INITIALIZATION_PENDING
@ MOVEMENTGENERATOR_FLAG_PAUSED
@ MOVEMENTGENERATOR_FLAG_DEACTIVATED
@ MOVEMENTGENERATOR_FLAG_FINALIZED
@ MOVEMENTGENERATOR_FLAG_TRANSITORY
@ MOVEMENTGENERATOR_FLAG_INTERRUPTED
@ MOVEMENTGENERATOR_FLAG_INFORM_ENABLED
@ MOVEMENTGENERATOR_FLAG_INITIALIZED
@ MOVEMENTGENERATOR_FLAG_SPEED_UPDATE_PENDING
std::optional< T > Optional
Optional helper class to wrap optional values within.
float frand(float min, float max)
uint32 urand(uint32 min, uint32 max)
@ UNIT_STATE_ROAMING_MOVE
@ UNIT_STATE_LOST_CONTROL
float GetWanderDistance() const
CreatureMovementData const & GetMovementTemplate() const
Scripting::v2::ActionResultSetter< MovementStopReason > ScriptResult
void SetWalk(bool enable)
void MovebyPath(std::span< Vector3 const > path, int32 pointId=0)
void SetVelocity(float velocity)
void SetRandomLocation(T *)
RandomMovementGenerator(float distance, Optional< Milliseconds > duration={}, Optional< float > speed={}, MovementWalkRunSpeedSelectionMode speedSelectionMode=MovementWalkRunSpeedSelectionMode::Default, Scripting::v2::ActionResultSetter< MovementStopReason > &&scriptResult={})
Optional< TimeTracker > _duration
void Pause(uint32 timer) override
void DoFinalize(T *, bool, bool)
MovementGeneratorType GetMovementGeneratorType() const override
void Resume(uint32 overrideTimer) override
bool DoUpdate(T *, uint32)
CreatureRandomMovementType GetRandom() const
constexpr float GetPositionX() const
constexpr float GetPositionY() const
constexpr float GetPositionZ() const
MovementGenerator * Create(Unit *object) const override