154{
156 return false;
157
158 if (!owner || !owner->IsAlive())
159 return false;
160
162 {
163 owner->StopMoving();
165 return true;
166 }
167
170
171
173 {
174 owner->StopMoving();
176 if (cOwner)
177 {
178 if (isStoppedBecauseOfCasting)
179 {
180
184 if (spellHasLongCast)
186 }
187 else
189
191 }
192 return true;
193 }
194
195 bool forceDest =
196
198 (owner->CanFly())
199 ;
200
202
204 bool const mutualTarget = target->
GetVictim() == owner;
206 float const meleeRange = owner->GetMeleeRange(target);
207 float const minTarget = (
_range ?
_range->MinTolerance : 0.0f) + chaseRange;
208 float const maxRange =
_range ?
_range->MaxRange + chaseRange : meleeRange;
210
212
213
214 if (angle && !mutualChase &&
_mutualChase && mutualTarget && chaseRange < meleeRange)
215 {
217 mutualChase = true;
218 }
219
220
221
222 if (angle && !mutualChase && !
_mutualChase && mutualTarget && chaseRange < meleeRange && cOwner && cOwner->IsPet())
223 {
225 mutualChase = true;
226 }
227
228
231 {
233
235 {
237 {
239 {
242 if (cOwner)
244 owner->StopMoving();
245 owner->SetInFront(target);
247 return true;
248 }
249 }
250 }
251 }
252
253
255 {
259 owner->SetInFront(target);
260
261 if (cOwner)
263
265 }
266
267 if (cOwner)
268 {
270 {
273 {
276 }
277 }
280 }
281
283 return true;
284
285
287 {
291 {
292
294 {
298 return true;
299 }
300
301
302 float x, y, z;
304 bool withinRange = owner->IsInDist(target, maxRange);
305 bool withinLOS = owner->IsWithinLOS(x, y, z);
306 bool moveToward = !(withinRange && withinLOS);
307
308
310 i_path = std::make_unique<PathGenerator>(owner);
311 else
313
314
315 float additionalRange = 0;
316 bool predictDestination = !mutualChase && target->
isMoving();
317 if (predictDestination)
318 {
322 else
323 {
326 else
328 }
329 float speed = target->
GetSpeed(moveType) * 0.5f;
330 additionalRange = owner->GetExactDistSq(target) < G3D::square(speed) ? 0 : speed;
331 }
332
333 bool shortenPath;
334
335
336 if (moveToward && !angle)
337 {
338
339 shortenPath = true;
340 }
341 else
342 {
343
344 target->
GetNearPoint(owner, x, y, z, (moveToward ? maxTarget : minTarget) - chaseRange - additionalRange, 0, angle ? target->ToAbsoluteAngle(angle->RelativeAngle) : target->GetAngle(owner));
345 shortenPath = false;
346 }
347
348 bool walk = false;
349 if (cOwner && !cOwner->
IsPet())
350 {
352 {
354 walk = owner->IsWalking();
355 break;
357 walk = true;
358 break;
359 default:
360 break;
361 }
362 }
363
365 }
366 }
367
368 return true;
369}
constexpr auto SECOND
Definition Common.h:46
constexpr auto IN_MILLISECONDS
Definition Common.h:53
#define CONTACT_DISTANCE
Definition ObjectDefines.h:23
float GetChaseRange(Unit const *owner, Unit const *target)
Definition TargetedMovementGenerator.cpp:35
static bool IsMutualChase(Unit *owner, Unit *target)
Definition TargetedMovementGenerator.cpp:27
@ MOVEMENTFLAG_BACKWARD
Definition UnitDefines.h:373
@ UNIT_STATE_NOT_MOVE
Definition UnitDefines.h:225
@ UNIT_STATE_NO_COMBAT_MOVEMENT
Definition UnitDefines.h:204
UnitMoveType
Definition UnitDefines.h:355
@ MOVE_FLIGHT
Definition UnitDefines.h:362
@ MOVE_FLIGHT_BACK
Definition UnitDefines.h:363
@ MOVE_RUN
Definition UnitDefines.h:357
@ MOVE_RUN_BACK
Definition UnitDefines.h:358
@ MOVE_WALK
Definition UnitDefines.h:356
bool _mutualChase
Definition TargetedMovementGenerator.h:75
bool PositionOkay(T *owner, Unit *target, Optional< float > maxDistance, Optional< ChaseAngle > angle)
Definition TargetedMovementGenerator.cpp:47
void MovementInform(T *)
Definition TargetedMovementGenerator.cpp:408
bool HasLostTarget(Unit *unit) const
Definition TargetedMovementGenerator.h:58
bool _movingTowards
Definition TargetedMovementGenerator.h:74
void UpdateLeashExtensionTime()
Definition Creature.cpp:3631
CreatureMovementData const & GetMovementTemplate() const
Definition Creature.cpp:3028
bool IsMovementPreventedByCasting() const override
Definition Creature.cpp:3558
bool IsPlayer() const
Definition Object.h:201
Player * ToPlayer()
Definition Object.h:202
bool IsGameMaster() const
Definition Player.h:1174
int32 GetCastTime() const
Definition Spell.h:562
float GetSpeed(UnitMoveType mtype) const
Definition Unit.cpp:11265
virtual bool CanFly() const =0
bool IsWithinMeleeRange(Unit const *obj, float dist=0.f) const
Definition Unit.cpp:782
bool isInAccessiblePlaceFor(Creature const *c) const
Definition Unit.cpp:4375
bool HasUnitMovementFlag(uint32 f) const
Definition Unit.h:774
bool isMoving() const
Definition Unit.h:1708
Unit * GetVictim() const
Definition Unit.h:903
Spell * GetFirstCurrentCastingSpell() const
Definition Unit.cpp:4317
bool IsWalking() const
Definition Unit.h:1707
bool IsInMap(WorldObject const *obj) const
Definition Object.cpp:1335
CreatureChaseMovementType GetChase() const
Definition CreatureData.h:151
void GetPosition(float &x, float &y) const
Definition Position.h:126
void Update(int32 diff)
Definition Timer.h:239
bool Passed() const
Definition Timer.h:244