554{
556 return false;
557
558 if (!owner || !owner->IsAlive())
559 return false;
560
563
564
565 if (owner->HasUnitState(
UNIT_STATE_NOT_MOVE) || (cOwner && owner->ToCreature()->IsMovementPreventedByCasting()))
566 {
570 return true;
571 }
572
573 bool followingMaster = false;
575 if (oPet)
576 {
578 followingMaster = true;
579 }
580
581 bool forceDest =
582 (followingMaster) ||
584 ;
585
586 bool targetIsMoving = false;
588 bool isFollowingPlayer = target->
IsPlayer();
589
590 if (
PositionOkay(target, isPlayerPet, targetIsMoving, time_diff))
591 {
593 {
597
599 {
601 }
602
604 }
605 }
606 else
607 {
610
611
612 if (targetIsMoving)
613 {
616 return true;
617
619 {
621 targetPosition = predictedPosition;
623 }
624 else
625 {
628 }
629 }
630 else
631 {
635 }
636
638 i_path = std::make_unique<PathGenerator>(owner);
639 else
641
643
644 float x, y, z;
646
647 if (owner->IsHovering())
648 owner->UpdateAllowedPositionZ(x, y, z);
649
650 bool success =
i_path->CalculatePath(x, y, z, forceDest);
652 {
653 if (!owner->IsStopped())
654 owner->StopMoving();
655
656
657 if (cOwner && isFollowingPlayer)
658 {
659 float distance = owner->GetDistance(target);
660 if (distance > 20.f)
661 {
662 float teleX;
663 float teleY;
664 float teleZ;
665
666 target->
GetClosePoint(teleX, teleY, teleZ, owner->GetCombatReach());
667 owner->NearTeleportTo(teleX, teleY, teleZ, target->
GetOrientation());
670 }
671 }
672 return true;
673 }
674
676
678 init.MovebyPath(
i_path->GetPath());
681
684 init.SetVelocity(*velocity);
685 init.Launch();
686 }
687
688 return true;
689}
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:493
static Optional< float > GetVelocity(Unit *owner, Unit *target, G3D::Vector3 const &dest, bool playerPet)
Definition TargetedMovementGenerator.cpp:433
static Position const PredictPosition(Unit *target)
Definition TargetedMovementGenerator.cpp:461
@ UNIT_STATE_NOT_MOVE
Definition UnitDefines.h:222
bool PositionOkay(Unit *target, bool isPlayerPet, bool &targetIsMoving, uint32 diff)
Definition TargetedMovementGenerator.cpp:508
void MovementInform(T *)
Definition TargetedMovementGenerator.cpp:712
Optional< Position > _lastPredictedPosition
Definition TargetedMovementGenerator.h:122
Definition MoveSplineInit.h:63
bool IsPlayer() const
Definition Object.h:200
Creature * ToCreature()
Definition Object.h:205
static ObjectGuid GetGUID(Object const *o)
Definition Object.h:113
TO * getTarget() const
Definition Reference.h:95
bool isValid() const
Definition Reference.h:79
FollowerReference i_target
Definition TargetedMovementGenerator.h:34
Pet * ToPet()
Definition Unit.h:719
void StopMoving()
Definition Unit.cpp:16879
bool IsGuardian() const
Definition Unit.h:785
ObjectGuid GetOwnerGUID() const
Definition Unit.h:703
bool IsWalking() const
Definition Unit.h:1687
void MovePositionToFirstCollision(Position &pos, float dist, float angle)
Definition Object.cpp:2869
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:2710
float RelativeAngle
Definition MotionMaster.h:125
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