605{
607 return false;
608
609 if (!owner || !owner->IsAlive())
610 return false;
611
614
615
616 if (owner->HasUnitState(
UNIT_STATE_NOT_MOVE) || (cOwner && owner->ToCreature()->IsMovementPreventedByCasting()))
617 {
619 owner->StopMoving();
621 return true;
622 }
623
624 bool followingMaster = false;
626 if (oPet)
627 {
629 followingMaster = true;
630 }
631
632 bool forceDest =
633 (followingMaster) ||
635 ;
636
637 bool targetIsMoving = false;
639 bool isFollowingPlayer = target->
IsPlayer();
640
641 if (
PositionOkay(target, isPlayerPet, targetIsMoving, time_diff))
642 {
644 {
648
650 {
652 }
653
655 }
656 }
657 else
658 {
661
662
663 if (targetIsMoving)
664 {
667 return true;
668
670 {
672 targetPosition = predictedPosition;
674 }
675 else
676 {
679 }
680 }
681 else
682 {
686 }
687
689 i_path = std::make_unique<PathGenerator>(owner);
690 else
692
694
695 float x, y, z;
697
698 if (owner->IsHovering())
699 owner->UpdateAllowedPositionZ(x, y, z);
700
701 bool success =
i_path->CalculatePath(x, y, z, forceDest);
703 {
704 if (!owner->IsStopped())
705 owner->StopMoving();
706
707
708 if (cOwner && isFollowingPlayer)
709 {
710 float const distance = owner->GetDistance2d(target);
711 if (distance > 20.f)
712 {
713 float teleX;
714 float teleY;
715 float teleZ;
716
717 target->
GetClosePoint(teleX, teleY, teleZ, owner->GetCombatReach());
718 teleZ = owner->GetMapHeight(teleX, teleY, teleZ);
719 owner->NearTeleportTo(teleX, teleY, teleZ, target->
GetOrientation());
722 }
723 }
724 return true;
725 }
726
728
730 init.MovebyPath(
i_path->GetPath());
733
736 init.SetVelocity(*velocity);
737 init.Launch();
738 }
739
740 return true;
741}
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:544
static Optional< float > GetVelocity(Unit *owner, Unit *target, G3D::Vector3 const &dest, bool playerPet)
Definition TargetedMovementGenerator.cpp:485
static Position const PredictPosition(Unit *target)
Definition TargetedMovementGenerator.cpp:512
@ UNIT_STATE_NOT_MOVE
Definition UnitDefines.h:225
bool PositionOkay(Unit *target, bool isPlayerPet, bool &targetIsMoving, uint32 diff)
Definition TargetedMovementGenerator.cpp:559
Unit * GetTarget() const
Definition TargetedMovementGenerator.h:97
void MovementInform(T *)
Definition TargetedMovementGenerator.cpp:764
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:730
ObjectGuid GetOwnerGUID() const override
Definition Unit.h:714
bool IsGuardian() const
Definition Unit.h:796
bool IsWalking() const
Definition Unit.h:1714
void MovePositionToFirstCollision(Position &pos, float dist, float angle)
Definition Object.cpp:2984
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:2825
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