563{
565 return false;
566
567 if (!owner || !owner->IsAlive())
568 return false;
569
572
573
574 if (owner->HasUnitState(
UNIT_STATE_NOT_MOVE) || (cOwner && owner->ToCreature()->IsMovementPreventedByCasting()))
575 {
577 owner->StopMoving();
579 return true;
580 }
581
582 bool followingMaster = false;
584 if (oPet)
585 {
587 followingMaster = true;
588 }
589
590 bool forceDest =
591 (followingMaster) ||
593 ;
594
595 bool targetIsMoving = false;
597 bool isFollowingPlayer = target->
IsPlayer();
598
599 if (
PositionOkay(target, isPlayerPet, targetIsMoving, time_diff))
600 {
602 {
606
608 {
610 }
611
613 }
614 }
615 else
616 {
619
620
621 if (targetIsMoving)
622 {
625 return true;
626
628 {
630 targetPosition = predictedPosition;
632 }
633 else
634 {
637 }
638 }
639 else
640 {
644 }
645
647 i_path = std::make_unique<PathGenerator>(owner);
648 else
650
652
653 float x, y, z;
655
656 if (owner->IsHovering())
657 owner->UpdateAllowedPositionZ(x, y, z);
658
659 bool success =
i_path->CalculatePath(x, y, z, forceDest);
661 {
662 if (!owner->IsStopped())
663 owner->StopMoving();
664
665
666 if (cOwner && isFollowingPlayer)
667 {
668 float const distance = owner->GetDistance2d(target);
669 if (distance > 20.f)
670 {
671 float teleX;
672 float teleY;
673 float teleZ;
674
675 target->
GetClosePoint(teleX, teleY, teleZ, owner->GetCombatReach());
676 teleZ = owner->GetMapHeight(teleX, teleY, teleZ);
677 owner->NearTeleportTo(teleX, teleY, teleZ, target->
GetOrientation());
680 }
681 }
682 return true;
683 }
684
686
688 init.MovebyPath(
i_path->GetPath());
691
694 init.SetVelocity(*velocity);
695 init.Launch();
696 }
697
698 return true;
699}
std::optional< T > Optional
Optional helper class to wrap optional values within.
Definition Optional.h:24
@ PATHFIND_NOPATH
Definition PathGenerator.h:50
static bool IsValidPredictedPosition(Unit *target, Position const &predicted)
Definition TargetedMovementGenerator.cpp:502
static Optional< float > GetVelocity(Unit *owner, Unit *target, G3D::Vector3 const &dest, bool playerPet)
Definition TargetedMovementGenerator.cpp:443
static Position const PredictPosition(Unit *target)
Definition TargetedMovementGenerator.cpp:470
@ UNIT_STATE_NOT_MOVE
Definition UnitDefines.h:225
bool PositionOkay(Unit *target, bool isPlayerPet, bool &targetIsMoving, uint32 diff)
Definition TargetedMovementGenerator.cpp:517
Unit * GetTarget() const
Definition TargetedMovementGenerator.h:96
void MovementInform(T *)
Definition TargetedMovementGenerator.cpp:722
Optional< Position > _lastPredictedPosition
Definition TargetedMovementGenerator.h:113
Definition MoveSplineInit.h:63
bool IsPlayer() const
Definition Object.h:201
Player * ToPlayer()
Definition Object.h:202
Creature * ToCreature()
Definition Object.h:206
static ObjectGuid GetGUID(Object const *o)
Definition Object.h:114
bool IsGameMaster() const
Definition Player.h:1174
Pet * ToPet()
Definition Unit.h:729
bool IsGuardian() const
Definition Unit.h:795
ObjectGuid GetOwnerGUID() const
Definition Unit.h:713
bool IsWalking() const
Definition Unit.h:1707
void MovePositionToFirstCollision(Position &pos, float dist, float angle)
Definition Object.cpp:2925
bool GetClosePoint(float &x, float &y, float &z, float size, float distance2d=0, float angle=0, WorldObject const *forWho=nullptr, bool force=false) const
Definition Object.cpp:2766
bool IsInMap(WorldObject const *obj) const
Definition Object.cpp:1335
float RelativeAngle
Definition MotionMaster.h:126
float ToAbsoluteAngle(float relAngle) const
Definition Position.h:207
float GetOrientation() const
Definition Position.h:124
void GetPosition(float &x, float &y) const
Definition Position.h:126
void Reset(int32 interval)
Definition Timer.h:249