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 {
258 if (cOwner)
261 owner->SetInFront(target);
263 }
264
265 if (cOwner)
266 {
268 {
271 {
274 }
275 }
278 }
279
281 return true;
282
283
285 {
289 {
290
292 {
296 return true;
297 }
298
299
300 float x, y, z;
302 bool withinRange = owner->IsInDist(target, maxRange);
303 bool withinLOS = owner->IsWithinLOS(x, y, z);
304 bool moveToward = !(withinRange && withinLOS);
305
306
308 i_path = std::make_unique<PathGenerator>(owner);
309 else
311
312
313 float additionalRange = 0;
314 bool predictDestination = !mutualChase && target->
isMoving();
315 if (predictDestination)
316 {
320 else
321 {
324 else
326 }
327 float speed = target->
GetSpeed(moveType) * 0.5f;
328 additionalRange = owner->GetExactDistSq(target) < G3D::square(speed) ? 0 : speed;
329 }
330
331 bool shortenPath;
332
333
334 if (moveToward && !angle)
335 {
336
337 shortenPath = true;
338 }
339 else
340 {
341
342 target->
GetNearPoint(owner, x, y, z, (moveToward ? maxTarget : minTarget) - chaseRange - additionalRange, 0, angle ? target->ToAbsoluteAngle(angle->RelativeAngle) : target->GetAngle(owner));
343 shortenPath = false;
344 }
345
346 bool walk = false;
347 if (cOwner && !cOwner->
IsPet())
348 {
350 {
352 walk = owner->IsWalking();
353 break;
355 walk = true;
356 break;
357 default:
358 break;
359 }
360 }
361
363 }
364 }
365
366 return true;
367}
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:370
@ UNIT_STATE_NOT_MOVE
Definition UnitDefines.h:222
@ UNIT_STATE_NO_COMBAT_MOVEMENT
Definition UnitDefines.h:201
UnitMoveType
Definition UnitDefines.h:352
@ MOVE_FLIGHT
Definition UnitDefines.h:359
@ MOVE_FLIGHT_BACK
Definition UnitDefines.h:360
@ MOVE_RUN
Definition UnitDefines.h:354
@ MOVE_RUN_BACK
Definition UnitDefines.h:355
@ MOVE_WALK
Definition UnitDefines.h:353
bool _mutualChase
Definition TargetedMovementGenerator.h:84
bool PositionOkay(T *owner, Unit *target, Optional< float > maxDistance, Optional< ChaseAngle > angle)
Definition TargetedMovementGenerator.cpp:47
void MovementInform(T *)
Definition TargetedMovementGenerator.cpp:406
bool HasLostTarget(Unit *unit) const
Definition TargetedMovementGenerator.h:67
bool _movingTowards
Definition TargetedMovementGenerator.h:83
void UpdateLeashExtensionTime()
Definition Creature.cpp:3550
CreatureMovementData const & GetMovementTemplate() const
Definition Creature.cpp:2946
bool IsMovementPreventedByCasting() const override
Definition Creature.cpp:3475
bool isValid() const
Definition Reference.h:79
int32 GetCastTime() const
Definition Spell.h:558
float GetSpeed(UnitMoveType mtype) const
Definition Unit.cpp:14601
virtual bool CanFly() const =0
bool IsWithinMeleeRange(Unit const *obj, float dist=0.f) const
Definition Unit.cpp:665
bool isInAccessiblePlaceFor(Creature const *c) const
Definition Unit.cpp:4253
bool HasUnitMovementFlag(uint32 f) const
Definition Unit.h:764
bool isMoving() const
Definition Unit.h:1688
Unit * GetVictim() const
Definition Unit.h:893
Spell * GetFirstCurrentCastingSpell() const
Definition Unit.cpp:4195
bool IsWalking() const
Definition Unit.h:1687
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:2637
CreatureChaseMovementType GetChase() const
Definition CreatureData.h:150
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