581{
583 return false;
584
585 if (!owner || !owner->IsAlive())
586 return false;
587
590
591
592 if (owner->HasUnitState(
UNIT_STATE_NOT_MOVE) || (cOwner && owner->ToCreature()->IsMovementPreventedByCasting()))
593 {
595 owner->StopMoving();
597 return true;
598 }
599
600 bool followingMaster = false;
602 if (oPet)
603 {
605 followingMaster = true;
606 }
607
608 bool forceDest =
609 (followingMaster) ||
611 ;
612
613 bool targetIsMoving = false;
615 bool isFollowingPlayer = target->
IsPlayer();
616
617 if (
PositionOkay(target, isPlayerPet, targetIsMoving, time_diff))
618 {
620 {
624
626 {
628 }
629
631 }
632 }
633 else
634 {
637
638
639 if (targetIsMoving)
640 {
643 return true;
644
646 {
648 targetPosition = predictedPosition;
650 }
651 else
652 {
655 }
656 }
657 else
658 {
662 }
663
665 i_path = std::make_unique<PathGenerator>(owner);
666 else
668
670
671 float x, y, z;
673
674 if (owner->IsHovering())
675 owner->UpdateAllowedPositionZ(x, y, z);
676
677 bool success =
i_path->CalculatePath(x, y, z, forceDest);
679 {
680 if (!owner->IsStopped())
681 owner->StopMoving();
682
683
684 if (cOwner && isFollowingPlayer)
685 {
686 float const distance = owner->GetDistance2d(target);
687 if (distance > 20.f)
688 {
689 float teleX;
690 float teleY;
691 float teleZ;
692
693 target->
GetClosePoint(teleX, teleY, teleZ, owner->GetCombatReach());
694 teleZ = owner->GetMapHeight(teleX, teleY, teleZ);
695 owner->NearTeleportTo(teleX, teleY, teleZ, target->
GetOrientation());
698 }
699 }
700 return true;
701 }
702
704
706 init.MovebyPath(
i_path->GetPath());
709
712 init.SetVelocity(*velocity);
713 init.Launch();
714 }
715
716 return true;
717}
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:520
static Optional< float > GetVelocity(Unit *owner, Unit *target, G3D::Vector3 const &dest, bool playerPet)
Definition TargetedMovementGenerator.cpp:461
static Position const PredictPosition(Unit *target)
Definition TargetedMovementGenerator.cpp:488
@ UNIT_STATE_NOT_MOVE
Definition UnitDefines.h:225
bool PositionOkay(Unit *target, bool isPlayerPet, bool &targetIsMoving, uint32 diff)
Definition TargetedMovementGenerator.cpp:535
Unit * GetTarget() const
Definition TargetedMovementGenerator.h:96
void MovementInform(T *)
Definition TargetedMovementGenerator.cpp:740
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:1178
Pet * ToPet()
Definition Unit.h:730
bool IsGuardian() const
Definition Unit.h:796
ObjectGuid GetOwnerGUID() const
Definition Unit.h:714
bool IsWalking() const
Definition Unit.h:1711
void MovePositionToFirstCollision(Position &pos, float dist, float angle)
Definition Object.cpp:2979
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:2820
bool IsInMap(WorldObject const *obj) const
Definition Object.cpp:1339
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