142{
  144        return false;
  145 
  146    if (!owner || !owner->IsAlive())
  147        return false;
  148 
  150    {
  151        owner->StopMoving();
  153        return true;
  154    }
  155 
  158 
  159    
  161    {
  162        owner->StopMoving();
  164        if (cOwner)
  165        {
  166            if (isStoppedBecauseOfCasting)
  167            {
  168                
  172                if (spellHasLongCast)
  174            }
  175            else
  177 
  179        }
  180        return true;
  181    }
  182 
  183    bool forceDest =
  184        
  186        (owner->CanFly())
  187        ; 
  188 
  190 
  192    bool const mutualTarget = target->
GetVictim() == owner;
 
  194    float const meleeRange = owner->GetMeleeRange(target);
  195    float const minTarget = (
_range ? 
_range->MinTolerance : 0.0f) + chaseRange;
 
  196    float const maxRange = 
_range ? 
_range->MaxRange + chaseRange : meleeRange; 
 
  198 
  200 
  201    
  202    if (angle && !mutualChase && 
_mutualChase && mutualTarget && chaseRange < meleeRange)
 
  203    {
  205        mutualChase = true;
  206    }
  207 
  208    
  209    
  210    if (angle && !mutualChase && !
_mutualChase && mutualTarget && chaseRange < meleeRange && cOwner && cOwner->IsPet())
 
  211    {
  213        mutualChase = true;
  214    }
  215 
  216    
  219    {
  221 
  223        {
  225            {
  228                if (cOwner)
  230                owner->StopMoving();
  231                owner->SetInFront(target);
  233                return true;
  234            }
  235        }
  236    }
  237 
  238    
  240    {
  243        if (cOwner)
  246        owner->SetInFront(target);
  248    }
  249 
  250    if (cOwner)
  251    {
  253        { 
  256            {
  259            }
  260        }
  263    }
  264 
  265    
  267    {
  271        {
  272            
  274            {
  278                return true;
  279            }
  280 
  281            
  282            float x, y, z;
  284            bool withinRange = owner->IsInDist(target, maxRange);
  285            bool withinLOS = owner->IsWithinLOS(x, y, z);
  286            bool moveToward = !(withinRange && withinLOS);
  287 
  288            
  290                i_path = std::make_unique<PathGenerator>(owner);
 
  291            else
  293 
  294            
  295            float additionalRange = 0;
  296            bool predictDestination = !mutualChase && target->
isMoving();
 
  297            if (predictDestination)
  298            {
  302                else
  303                {
  306                    else
  308                }
  309                float speed = target->
GetSpeed(moveType) * 0.5f;
 
  310                additionalRange = owner->GetExactDistSq(target) < G3D::square(speed) ? 0 : speed;
  311            }
  312 
  313            bool shortenPath;
  314 
  315            
  316            if (moveToward && !angle)
  317            {
  318                
  319                shortenPath = true;
  320            }
  321            else
  322            {
  323                
  324                target->
GetNearPoint(owner, x, y, z, (moveToward ? maxTarget : minTarget) - chaseRange - additionalRange, 0, angle ? target->ToAbsoluteAngle(angle->RelativeAngle) : target->GetAngle(owner));
 
  325                shortenPath = false;
  326            }
  327 
  328            bool walk = false;
  329            if (cOwner && !cOwner->
IsPet())
 
  330            {
  332                {
  334                        walk = owner->IsWalking();
  335                        break;
  337                        walk = true;
  338                        break;
  339                    default:
  340                        break;
  341                }
  342            }
  343 
  345        }
  346    }
  347 
  348    return true;
  349}
constexpr auto SECOND
Definition Common.h:46
constexpr auto IN_MILLISECONDS
Definition Common.h:53
#define CONTACT_DISTANCE
Definition ObjectDefines.h:23
float GetChaseRange(Unit const *owner, Unit const *target)
Definition TargetedMovementGenerator.cpp:35
static bool IsMutualChase(Unit *owner, Unit *target)
Definition TargetedMovementGenerator.cpp:27
@ MOVEMENTFLAG_BACKWARD
Definition UnitDefines.h:370
@ UNIT_STATE_NOT_MOVE
Definition UnitDefines.h:222
@ UNIT_STATE_NO_COMBAT_MOVEMENT
Definition UnitDefines.h:201
UnitMoveType
Definition UnitDefines.h:352
@ MOVE_FLIGHT
Definition UnitDefines.h:359
@ MOVE_FLIGHT_BACK
Definition UnitDefines.h:360
@ MOVE_RUN
Definition UnitDefines.h:354
@ MOVE_RUN_BACK
Definition UnitDefines.h:355
@ MOVE_WALK
Definition UnitDefines.h:353
bool _mutualChase
Definition TargetedMovementGenerator.h:84
bool PositionOkay(T *owner, Unit *target, Optional< float > maxDistance, Optional< ChaseAngle > angle)
Definition TargetedMovementGenerator.cpp:47
void MovementInform(T *)
Definition TargetedMovementGenerator.cpp:388
bool HasLostTarget(Unit *unit) const
Definition TargetedMovementGenerator.h:67
bool _movingTowards
Definition TargetedMovementGenerator.h:83
void UpdateLeashExtensionTime()
Definition Creature.cpp:3607
CreatureMovementData const & GetMovementTemplate() const
Definition Creature.cpp:2998
bool IsMovementPreventedByCasting() const override
Definition Creature.cpp:3532
bool isValid() const
Definition Reference.h:79
int32 GetCastTime() const
Definition Spell.h:558
float GetSpeed(UnitMoveType mtype) const
Definition Unit.cpp:14508
virtual bool CanFly() const =0
bool IsPet() const
Definition Unit.h:780
bool IsWithinMeleeRange(Unit const *obj, float dist=0.f) const
Definition Unit.cpp:665
bool isInAccessiblePlaceFor(Creature const *c) const
Definition Unit.cpp:4261
bool HasUnitMovementFlag(uint32 f) const
Definition Unit.h:759
bool isMoving() const
Definition Unit.h:1663
Unit * GetVictim() const
Definition Unit.h:886
Spell * GetFirstCurrentCastingSpell() const
Definition Unit.cpp:4203
bool IsWalking() const
Definition Unit.h:1662
void GetNearPoint(WorldObject const *searcher, float &x, float &y, float &z, float searcher_size, float distance2d, float absAngle, float controlZ=0, Position const *startPos=nullptr) const
Definition Object.cpp:2640
CreatureChaseMovementType GetChase() const
Definition CreatureData.h:150
void GetPosition(float &x, float &y) const
Definition Position.h:126
void Update(int32 diff)
Definition Timer.h:239
bool Passed() const
Definition Timer.h:244