142{
144 return false;
145
146 if (!owner || !owner->IsAlive())
147 return false;
148
150 {
151 owner->StopMoving();
153 return true;
154 }
155
158
159
161 {
162 owner->StopMoving();
164 if (cOwner)
165 {
166 if (isStoppedBecauseOfCasting)
167 {
168
172 if (spellHasLongCast)
174 }
175 else
177
179 }
180 return true;
181 }
182
183 bool forceDest =
184
186 (owner->CanFly())
187 ;
188
190
192 bool const mutualTarget = target->
GetVictim() == owner;
194 float const meleeRange = owner->GetMeleeRange(target);
195 float const minTarget = (
_range ?
_range->MinTolerance : 0.0f) + chaseRange;
196 float const maxRange =
_range ?
_range->MaxRange + chaseRange : meleeRange;
198
200
201
202 if (angle && !mutualChase &&
_mutualChase && mutualTarget && chaseRange < meleeRange)
203 {
205 mutualChase = true;
206 }
207
208
209
210 if (angle && !mutualChase && !
_mutualChase && mutualTarget && chaseRange < meleeRange && cOwner && cOwner->IsPet())
211 {
213 mutualChase = true;
214 }
215
216
219 {
221
223 {
225 {
227 {
230 if (cOwner)
232 owner->StopMoving();
233 owner->SetInFront(target);
235 return true;
236 }
237 }
238 }
239 }
240
241
243 {
246 if (cOwner)
249 owner->SetInFront(target);
251 }
252
253 if (cOwner)
254 {
256 {
259 {
262 }
263 }
266 }
267
269 return true;
270
271
273 {
277 {
278
280 {
284 return true;
285 }
286
287
288 float x, y, z;
290 bool withinRange = owner->IsInDist(target, maxRange);
291 bool withinLOS = owner->IsWithinLOS(x, y, z);
292 bool moveToward = !(withinRange && withinLOS);
293
294
296 i_path = std::make_unique<PathGenerator>(owner);
297 else
299
300
301 float additionalRange = 0;
302 bool predictDestination = !mutualChase && target->
isMoving();
303 if (predictDestination)
304 {
308 else
309 {
312 else
314 }
315 float speed = target->
GetSpeed(moveType) * 0.5f;
316 additionalRange = owner->GetExactDistSq(target) < G3D::square(speed) ? 0 : speed;
317 }
318
319 bool shortenPath;
320
321
322 if (moveToward && !angle)
323 {
324
325 shortenPath = true;
326 }
327 else
328 {
329
330 target->
GetNearPoint(owner, x, y, z, (moveToward ? maxTarget : minTarget) - chaseRange - additionalRange, 0, angle ? target->ToAbsoluteAngle(angle->RelativeAngle) : target->GetAngle(owner));
331 shortenPath = false;
332 }
333
334 bool walk = false;
335 if (cOwner && !cOwner->
IsPet())
336 {
338 {
340 walk = owner->IsWalking();
341 break;
343 walk = true;
344 break;
345 default:
346 break;
347 }
348 }
349
351 }
352 }
353
354 return true;
355}
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:394
bool HasLostTarget(Unit *unit) const
Definition TargetedMovementGenerator.h:67
bool _movingTowards
Definition TargetedMovementGenerator.h:83
void UpdateLeashExtensionTime()
Definition Creature.cpp:3607
CreatureMovementData const & GetMovementTemplate() const
Definition Creature.cpp:2998
bool IsMovementPreventedByCasting() const override
Definition Creature.cpp:3532
bool isValid() const
Definition Reference.h:79
int32 GetCastTime() const
Definition Spell.h:558
float GetSpeed(UnitMoveType mtype) const
Definition Unit.cpp:14513
virtual bool CanFly() const =0
bool IsPet() const
Definition Unit.h:780
bool IsWithinMeleeRange(Unit const *obj, float dist=0.f) const
Definition Unit.cpp:665
bool isInAccessiblePlaceFor(Creature const *c) const
Definition Unit.cpp:4262
bool HasUnitMovementFlag(uint32 f) const
Definition Unit.h:759
bool isMoving() const
Definition Unit.h:1663
Unit * GetVictim() const
Definition Unit.h:886
Spell * GetFirstCurrentCastingSpell() const
Definition Unit.cpp:4204
bool IsWalking() const
Definition Unit.h:1662
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:2644
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