Core/Movement: improved RandomMovementGenerator wait handling to get closer to retail behaivior (#24093)

* according to observations Blizzard is letting creatures do 2 up to 10 spline movements right after each other before waiting for a couple seconds

(cherry picked from commit 78c1216bcf)
This commit is contained in:
Ovah
2020-01-22 22:19:42 +01:00
committed by Shauren
parent ce8c83ef6f
commit cdeb752941
2 changed files with 19 additions and 8 deletions

View File

@@ -25,7 +25,7 @@
#include "Random.h"
template<class T>
RandomMovementGenerator<T>::RandomMovementGenerator(float distance) : _timer(0), _reference(), _wanderDistance(distance)
RandomMovementGenerator<T>::RandomMovementGenerator(float distance) : _timer(0), _reference(), _wanderDistance(distance), _wanderSteps(0)
{
this->Mode = MOTION_MODE_DEFAULT;
this->Priority = MOTION_PRIORITY_NORMAL;
@@ -83,9 +83,12 @@ void RandomMovementGenerator<Creature>::DoInitialize(Creature* owner)
_reference = owner->GetPosition();
owner->StopMoving();
if (!_wanderDistance)
if (_wanderDistance == 0.f)
_wanderDistance = owner->GetRespawnRadius();
// Retail seems to let a creature walk 2 up to 10 splines before triggering a pause
_wanderSteps = urand(2, 10);
_timer.Reset(0);
_path = nullptr;
}
@@ -119,8 +122,8 @@ void RandomMovementGenerator<Creature>::SetRandomLocation(Creature* owner)
}
Position position(_reference);
float distance = frand(0.f, 1.f) * _wanderDistance;
float angle = frand(0.f, 1.f) * float(M_PI) * 2.f;
float distance = frand(0.f, _wanderDistance);
float angle = frand(0.f, float(M_PI * 2));
owner->MovePositionToFirstCollision(position, distance, angle);
// Check if the destination is in LOS
@@ -131,8 +134,6 @@ void RandomMovementGenerator<Creature>::SetRandomLocation(Creature* owner)
return;
}
uint32 resetTimer = roll_chance_i(50) ? urand(5000, 10000) : urand(1000, 2000);
if (!_path)
{
_path = std::make_unique<PathGenerator>(owner);
@@ -168,8 +169,17 @@ void RandomMovementGenerator<Creature>::SetRandomLocation(Creature* owner)
Movement::MoveSplineInit init(owner);
init.MovebyPath(_path->GetPath());
init.SetWalk(walk);
time_t traveltime = init.Launch();
_timer.Reset(traveltime + resetTimer);
int32 splineDuration = init.Launch();
--_wanderSteps;
if (_wanderSteps) // Creature has yet to do steps before pausing
_timer.Reset(splineDuration);
else
{
// Creature has made all its steps, time for a little break
_timer.Reset(splineDuration + urand(4, 10) * IN_MILLISECONDS); // Retails seems to use rounded numbers so we do as well
_wanderSteps = urand(2, 10);
}
// Call for creature group update
owner->SignalFormationMovement(position);

View File

@@ -50,6 +50,7 @@ class RandomMovementGenerator : public MovementGeneratorMedium<T, RandomMovement
TimeTracker _timer;
Position _reference;
float _wanderDistance;
uint8 _wanderSteps;
};
#endif