67{
69 return false;
70
71 if (!owner || !owner->IsAlive())
72 return false;
73
75
76
78 {
82 cOwner2->SetCannotReachTarget();
83 return true;
84 }
85
86 bool forceDest =
87
89 (owner->CanFly())
90 ;
91
93
96 float const minTarget = (
_range ?
_range->MinTolerance : 0.0f) + chaseRange;
97 float const maxRange =
_range ?
_range->MaxRange + chaseRange : owner->GetMeleeRange(target);
99
101
102
105 {
107
109 {
111 {
115 cOwner2->SetCannotReachTarget();
116 owner->StopMoving();
117 owner->SetInFront(target);
119 return true;
120 }
121 }
122 }
123
124
126 {
130 cOwner2->SetCannotReachTarget();
132 owner->SetInFront(target);
134 }
135
136
138 {
142 {
143
145 {
149 return true;
150 }
151
152
153 float tarX, tarY, tarZ;
155 bool withinRange = owner->IsInDist(target, maxRange);
156 bool withinLOS = owner->IsWithinLOS(tarX, tarY, tarZ);
157 bool moveToward = !(withinRange && withinLOS);
158
159
161 i_path = std::make_unique<PathGenerator>(owner);
162 else
164
165
166 float additionalRange = 0;
167 bool predictDestination = !mutualChase && target->
isMoving();
168 if (predictDestination)
169 {
173 else
174 {
177 else
179 }
180 float speed = target->
GetSpeed(moveType) * 0.5f;
181 additionalRange = owner->GetExactDistSq(target) < G3D::square(speed) ? 0 : speed;
182 }
183
184 float x, y, z;
185 bool shortenPath;
186
187
188 if (moveToward && !angle)
189 {
190
192 shortenPath = true;
193 }
194 else
195 {
196
197 target->
GetNearPoint(owner, x, y, z, (moveToward ? maxTarget : minTarget) - chaseRange - additionalRange, 0, angle ? target->
ToAbsoluteAngle(angle->RelativeAngle) : target->
GetAngle(owner));
198 shortenPath = false;
199 }
200
201 if (owner->IsHovering())
202 owner->UpdateAllowedPositionZ(x, y, z);
203
204 bool success =
i_path->CalculatePath(x, y, z, forceDest);
206 {
207 if (cOwner)
208 {
210 }
211
212 owner->StopMoving();
213 return true;
214 }
215
216 if (shortenPath)
218
219 if (cOwner)
220 {
222 }
223
224 bool walk = false;
225 if (cOwner && !cOwner->
IsPet())
226 {
228 {
229 case CreatureChaseMovementType::CanWalk:
230 walk = owner->IsWalking();
231 break;
232 case CreatureChaseMovementType::AlwaysWalk:
233 walk = true;
234 break;
235 default:
236 break;
237 }
238 }
239
242
244 init.MovebyPath(
i_path->GetPath());
245 init.SetFacing(target);
246 init.SetWalk(walk);
247 init.Launch();
248 }
249 }
250
251 return true;
252}
#define CONTACT_DISTANCE
Definition: ObjectDefines.h:23
@ TYPEID_PLAYER
Definition: ObjectGuid.h:38
@ MOVEMENTFLAG_BACKWARD
Definition: Unit.h:553
@ UNIT_STATE_NOT_MOVE
Definition: Unit.h:371
UnitMoveType
Definition: Unit.h:377
@ MOVE_FLIGHT
Definition: Unit.h:384
@ MOVE_FLIGHT_BACK
Definition: Unit.h:385
@ MOVE_RUN
Definition: Unit.h:379
@ MOVE_RUN_BACK
Definition: Unit.h:380
@ MOVE_WALK
Definition: Unit.h:378
@ PATHFIND_NOPATH
Definition: PathGenerator.h:51
float GetChaseRange(Unit const *owner, Unit const *target)
Definition: TargetedMovementGenerator.cpp:35
static bool IsMutualChase(Unit *owner, Unit *target)
Definition: TargetedMovementGenerator.cpp:27
TO * getTarget() const
Definition: Reference.h:95
bool isValid() const
Definition: Reference.h:79
void Update(int32 diff)
Definition: Timer.h:239
bool Passed() const
Definition: Timer.h:244
void SetCannotReachTarget(ObjectGuid const &target=ObjectGuid::Empty)
Definition: Creature.cpp:3556
CreatureMovementData const & GetMovementTemplate() const
Definition: Creature.cpp:2901
bool IsMovementPreventedByCasting() const override
Definition: Creature.cpp:3534
CreatureChaseMovementType GetChase() const
Definition: CreatureData.h:156
static ObjectGuid GetGUID(Object const *o)
Definition: Object.h:106
void GetNearPoint(WorldObject const *searcher, float &x, float &y, float &z, float searcher_size, float distance2d, float absAngle, float controlZ=0, Position const *startPos=nullptr) const
Definition: Object.cpp:2614
float ToAbsoluteAngle(float relAngle) const
Definition: Position.h:203
float GetPositionZ() const
Definition: Position.h:119
float GetPositionX() const
Definition: Position.h:117
void GetPosition(float &x, float &y) const
Definition: Position.h:122
float GetPositionY() const
Definition: Position.h:118
float GetAngle(const Position *pos) const
Definition: Position.cpp:77
float GetSpeed(UnitMoveType mtype) const
Definition: Unit.cpp:14409
virtual bool CanFly() const =0
bool IsPet() const
Definition: Unit.h:1425
bool isInAccessiblePlaceFor(Creature const *c) const
Definition: Unit.cpp:4145
bool HasUnitMovementFlag(uint32 f) const
Definition: Unit.h:2288
bool isMoving() const
Definition: Unit.h:2394
bool IsWalking() const
Definition: Unit.h:2393
FollowerReference i_target
Definition: TargetedMovementGenerator.h:34
bool _mutualChase
Definition: TargetedMovementGenerator.h:70
bool PositionOkay(T *owner, Unit *target, Optional< float > maxDistance, Optional< ChaseAngle > angle)
Definition: TargetedMovementGenerator.cpp:47
void MovementInform(T *)
Definition: TargetedMovementGenerator.cpp:291
bool HasLostTarget(Unit *unit) const
Definition: TargetedMovementGenerator.h:59
bool _movingTowards
Definition: TargetedMovementGenerator.h:69
Definition: MoveSplineInit.h:71