mirror of
https://github.com/mod-playerbots/azerothcore-wotlk.git
synced 2026-01-13 09:17:18 +00:00
fix(Core/Movement): Improved fleeing movement generator. (#11896)
* fix(Core/Movement): Improved fleeing movement generator. Fixes #11850 * Update.
This commit is contained in:
@@ -26,6 +26,7 @@
|
||||
|
||||
#define MIN_QUIET_DISTANCE 28.0f
|
||||
#define MAX_QUIET_DISTANCE 43.0f
|
||||
#define MIN_PATH_LENGTH 2.0f
|
||||
|
||||
template<class T>
|
||||
void FleeingMovementGenerator<T>::DoInitialize(T* owner)
|
||||
@@ -144,6 +145,20 @@ void FleeingMovementGenerator<T>::SetTargetLocation(T* owner)
|
||||
return;
|
||||
}
|
||||
|
||||
// Same position - recheck
|
||||
if (_path->getPathLength() < MIN_PATH_LENGTH)
|
||||
{
|
||||
if (_fleeTargetGUID)
|
||||
{
|
||||
++_shortPathsCount;
|
||||
}
|
||||
|
||||
_timer.Reset(100);
|
||||
return;
|
||||
}
|
||||
|
||||
_shortPathsCount = 0;
|
||||
|
||||
Movement::MoveSplineInit init(owner);
|
||||
init.MovebyPath(_path->GetPath());
|
||||
init.SetWalk(false);
|
||||
@@ -154,8 +169,13 @@ void FleeingMovementGenerator<T>::SetTargetLocation(T* owner)
|
||||
template<class T>
|
||||
void FleeingMovementGenerator<T>::GetPoint(T* owner, Position& position)
|
||||
{
|
||||
float casterDistance, casterAngle;
|
||||
if (Unit* fleeTarget = ObjectAccessor::GetUnit(*owner, _fleeTargetGUID))
|
||||
float casterDistance = 0.f;
|
||||
float casterAngle = 0.f;
|
||||
Unit* fleeTarget = nullptr;
|
||||
if (_shortPathsCount < 5)
|
||||
fleeTarget = ObjectAccessor::GetUnit(*owner, _fleeTargetGUID);
|
||||
|
||||
if (fleeTarget)
|
||||
{
|
||||
casterDistance = fleeTarget->GetDistance(owner);
|
||||
if (casterDistance > 0.2f)
|
||||
@@ -173,7 +193,8 @@ void FleeingMovementGenerator<T>::GetPoint(T* owner, Position& position)
|
||||
casterAngle = frand(0.0f, 2.0f * float(M_PI));
|
||||
}
|
||||
|
||||
float distance, angle;
|
||||
float distance = 0.f;
|
||||
float angle = 0.f;
|
||||
if (casterDistance < MIN_QUIET_DISTANCE)
|
||||
{
|
||||
distance = frand(0.4f, 1.3f) * (MIN_QUIET_DISTANCE - casterDistance);
|
||||
|
||||
@@ -24,7 +24,7 @@ template<class T>
|
||||
class FleeingMovementGenerator : public MovementGeneratorMedium< T, FleeingMovementGenerator<T> >
|
||||
{
|
||||
public:
|
||||
explicit FleeingMovementGenerator(ObjectGuid fleeTargetGUID) : _path(nullptr), _fleeTargetGUID(fleeTargetGUID), _timer(0), _interrupt(false) {}
|
||||
explicit FleeingMovementGenerator(ObjectGuid fleeTargetGUID) : _path(nullptr), _fleeTargetGUID(fleeTargetGUID), _timer(0), _interrupt(false), _shortPathsCount(0) { }
|
||||
|
||||
MovementGeneratorType GetMovementGeneratorType() override { return FLEEING_MOTION_TYPE; }
|
||||
|
||||
@@ -41,6 +41,7 @@ class FleeingMovementGenerator : public MovementGeneratorMedium< T, FleeingMovem
|
||||
ObjectGuid _fleeTargetGUID;
|
||||
TimeTracker _timer;
|
||||
bool _interrupt;
|
||||
uint8 _shortPathsCount;
|
||||
};
|
||||
|
||||
class TimedFleeingMovementGenerator : public FleeingMovementGenerator<Creature>
|
||||
|
||||
Reference in New Issue
Block a user