32 : _timer(0), _speed(speed), _speedSelectionMode(speedSelectionMode), _wanderDistance(distance), _wanderSteps(0)
68 _timer.Reset(overrideTimer);
79 if (!owner->IsAlive())
82 _reference = owner->GetPosition();
85 _wanderSteps =
urand(2, 10);
97 return DoInitialize(owner);
112 float distance = _wanderDistance > 0.1f ?
frand(0.1f, _wanderDistance) : _wanderDistance;
113 float angle =
frand(0.f,
static_cast<float>(
M_PI * 2));
114 owner->MovePositionToFirstCollision(position, distance, angle);
126 _path = std::make_unique<PathGenerator>(owner);
127 _path->SetPathLengthLimit(30.0f);
140 if (_path->GetPathLength() < 0.1f)
154 switch (_speedSelectionMode)
175 _timer.Reset(splineDuration);
180 _wanderSteps =
urand(2, 10);
184 if constexpr (std::is_base_of_v<Creature, T>)
185 owner->SignalFormationMovement();
191 if (!owner->IsAlive())
199 _duration->Update(diff);
200 if (_duration->Passed())
220 SetRandomLocation(owner);
242 owner->SetWalk(
false);
248 if constexpr (std::is_base_of_v<Creature, T>)
249 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