612{
614 return false;
615
616 if (!owner || !owner->IsAlive())
617 return false;
618
621
622
623 if (owner->HasUnitState(
UNIT_STATE_NOT_MOVE) || (cOwner && owner->ToCreature()->IsMovementPreventedByCasting()))
624 {
626 owner->StopMoving();
628 return true;
629 }
630
631 bool followingMaster = false;
633 if (oPet)
634 {
636 followingMaster = true;
637 }
638
639 bool forceDest =
640 (followingMaster) ||
642 ;
643
644 bool targetIsMoving = false;
646 bool isFollowingPlayer = target->
IsPlayer();
647
648 if (
PositionOkay(target, isPlayerPet, targetIsMoving, time_diff))
649 {
651 {
655
657 {
659 }
660
662 }
663 }
664 else
665 {
668
669
670 if (targetIsMoving)
671 {
674 return true;
675
677 {
679 targetPosition = predictedPosition;
681 }
682 else
683 {
686 }
687 }
688 else
689 {
693 }
694
696 i_path = std::make_unique<PathGenerator>(owner);
697 else
699
701
702 float x, y, z;
704
705 if (owner->IsHovering())
706 owner->UpdateAllowedPositionZ(x, y, z);
707
708 bool success =
i_path->CalculatePath(x, y, z, forceDest);
710 {
711 if (!owner->IsStopped())
712 owner->StopMoving();
713
714
715 if (cOwner && isFollowingPlayer)
716 {
717 float const distance = owner->GetDistance2d(target);
718 if (distance > 20.f)
719 {
720 float teleX;
721 float teleY;
722 float teleZ;
723
724 target->
GetClosePoint(teleX, teleY, teleZ, owner->GetCombatReach());
725 teleZ = owner->GetMapHeight(teleX, teleY, teleZ);
726 owner->NearTeleportTo(teleX, teleY, teleZ, target->
GetOrientation());
729 }
730 }
731 return true;
732 }
733
735
737 init.MovebyPath(
i_path->GetPath());
740
743 init.SetVelocity(*velocity);
744 init.Launch();
745 }
746
747 return true;
748}
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:551
static Optional< float > GetVelocity(Unit *owner, Unit *target, G3D::Vector3 const &dest, bool playerPet)
Definition TargetedMovementGenerator.cpp:488
static Position const PredictPosition(Unit *target)
Definition TargetedMovementGenerator.cpp:519
@ UNIT_STATE_NOT_MOVE
Definition UnitDefines.h:225
bool PositionOkay(Unit *target, bool isPlayerPet, bool &targetIsMoving, uint32 diff)
Definition TargetedMovementGenerator.cpp:566
Unit * GetTarget() const
Definition TargetedMovementGenerator.h:97
void MovementInform(T *)
Definition TargetedMovementGenerator.cpp:771
Optional< Position > _lastPredictedPosition
Definition TargetedMovementGenerator.h:114
Definition MoveSplineInit.h:63
bool IsPlayer() const
Definition Object.h:207
Player * ToPlayer()
Definition Object.h:208
Creature * ToCreature()
Definition Object.h:212
static ObjectGuid GetGUID(Object const *o)
Definition Object.h:120
bool IsGameMaster() const
Definition Player.h:1178
Pet * ToPet()
Definition Unit.h:735
ObjectGuid GetOwnerGUID() const override
Definition Unit.h:719
bool IsGuardian() const
Definition Unit.h:801
bool IsWalking() const
Definition Unit.h:1727
void MovePositionToFirstCollision(Position &pos, float dist, float angle)
Definition Object.cpp:2991
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:2832
bool IsInMap(WorldObject const *obj) const
Definition Object.cpp:1344
float RelativeAngle
Definition MotionMaster.h:127
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