67{
69 return false;
70
71 if (!owner || !owner->IsAlive())
72 return false;
73
76
77
79 {
80 owner->StopMoving();
82 if (cOwner)
83 {
84 if (isStoppedBecauseOfCasting)
85 {
86
90 if (spellHasLongCast)
92 }
93 else
95
97 }
98 return true;
99 }
100
101 bool forceDest =
102
104 (owner->CanFly())
105 ;
106
108
110 bool const mutualTarget = target->
GetVictim() == owner;
112 float const meleeRange = owner->GetMeleeRange(target);
113 float const minTarget = (
_range ?
_range->MinTolerance : 0.0f) + chaseRange;
114 float const maxRange =
_range ?
_range->MaxRange + chaseRange : meleeRange;
116
118
119
120 if (angle && !mutualChase &&
_mutualChase && mutualTarget && chaseRange < meleeRange)
121 {
123 mutualChase = true;
124 }
125
126
127
128 if (angle && !mutualChase && !
_mutualChase && mutualTarget && chaseRange < meleeRange && cOwner && cOwner->IsPet())
129 {
131 mutualChase = true;
132 }
133
134
137 {
139
141 {
143 {
146 if (cOwner)
148 owner->StopMoving();
149 owner->SetInFront(target);
151 return true;
152 }
153 }
154 }
155
156
158 {
161 if (cOwner)
164 owner->SetInFront(target);
166 }
167
168 if (cOwner)
169 {
171 {
174 {
177 }
178 }
181 }
182
183
185 {
189 {
190
192 {
196 return true;
197 }
198
199
200 float x, y, z;
202 bool withinRange = owner->IsInDist(target, maxRange);
203 bool withinLOS = owner->IsWithinLOS(x, y, z);
204 bool moveToward = !(withinRange && withinLOS);
205
206
208 i_path = std::make_unique<PathGenerator>(owner);
209 else
211
212
213 float additionalRange = 0;
214 bool predictDestination = !mutualChase && target->
isMoving();
215 if (predictDestination)
216 {
220 else
221 {
224 else
226 }
227 float speed = target->
GetSpeed(moveType) * 0.5f;
228 additionalRange = owner->GetExactDistSq(target) < G3D::square(speed) ? 0 : speed;
229 }
230
231 bool shortenPath;
232
233
234 if (moveToward && !angle)
235 {
236
237 shortenPath = true;
238 }
239 else
240 {
241
242 target->
GetNearPoint(owner, x, y, z, (moveToward ? maxTarget : minTarget) - chaseRange - additionalRange, 0, angle ? target->ToAbsoluteAngle(angle->RelativeAngle) : target->GetAngle(owner));
243 shortenPath = false;
244 }
245
246 if (owner->IsHovering())
247 owner->UpdateAllowedPositionZ(x, y, z);
248
249 bool success =
i_path->CalculatePath(x, y, z, forceDest);
251 {
252 if (cOwner)
253 {
255 }
256
257 owner->StopMoving();
258 return true;
259 }
260
261 if (shortenPath)
262 i_path->ShortenPathUntilDist(G3D::Vector3(x, y, z), maxTarget);
263
264 if (cOwner)
265 {
267 }
268
269 bool walk = false;
270 if (cOwner && !cOwner->
IsPet())
271 {
273 {
275 walk = owner->IsWalking();
276 break;
278 walk = true;
279 break;
280 default:
281 break;
282 }
283 }
284
287
289 init.MovebyPath(
i_path->GetPath());
290 init.SetFacing(target);
291 init.SetWalk(walk);
292 init.Launch();
293 }
294 }
295
296 return true;
297}
constexpr auto SECOND
Definition Common.h:46
constexpr auto IN_MILLISECONDS
Definition Common.h:53
#define CONTACT_DISTANCE
Definition ObjectDefines.h:23
@ PATHFIND_NOPATH
Definition PathGenerator.h:50
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:366
@ UNIT_STATE_NOT_MOVE
Definition UnitDefines.h:218
UnitMoveType
Definition UnitDefines.h:348
@ MOVE_FLIGHT
Definition UnitDefines.h:355
@ MOVE_FLIGHT_BACK
Definition UnitDefines.h:356
@ MOVE_RUN
Definition UnitDefines.h:350
@ MOVE_RUN_BACK
Definition UnitDefines.h:351
@ MOVE_WALK
Definition UnitDefines.h:349
bool _mutualChase
Definition TargetedMovementGenerator.h:71
bool PositionOkay(T *owner, Unit *target, Optional< float > maxDistance, Optional< ChaseAngle > angle)
Definition TargetedMovementGenerator.cpp:47
void MovementInform(T *)
Definition TargetedMovementGenerator.cpp:337
bool HasLostTarget(Unit *unit) const
Definition TargetedMovementGenerator.h:59
bool _movingTowards
Definition TargetedMovementGenerator.h:70
void SetCannotReachTarget(ObjectGuid const &target=ObjectGuid::Empty)
Definition Creature.cpp:3675
void UpdateLeashExtensionTime()
Definition Creature.cpp:3728
CreatureMovementData const & GetMovementTemplate() const
Definition Creature.cpp:2995
bool IsMovementPreventedByCasting() const override
Definition Creature.cpp:3653
Definition MoveSplineInit.h:71
static ObjectGuid GetGUID(Object const *o)
Definition Object.h:113
TO * getTarget() const
Definition Reference.h:95
bool isValid() const
Definition Reference.h:79
int32 GetCastTime() const
Definition Spell.h:550
FollowerReference i_target
Definition TargetedMovementGenerator.h:34
float GetSpeed(UnitMoveType mtype) const
Definition Unit.cpp:14516
virtual bool CanFly() const =0
bool IsPet() const
Definition Unit.h:747
bool IsWithinMeleeRange(Unit const *obj, float dist=0.f) const
Definition Unit.cpp:665
bool isInAccessiblePlaceFor(Creature const *c) const
Definition Unit.cpp:4249
bool HasUnitMovementFlag(uint32 f) const
Definition Unit.h:729
bool isMoving() const
Definition Unit.h:1622
Unit * GetVictim() const
Definition Unit.h:848
Spell * GetFirstCurrentCastingSpell() const
Definition Unit.cpp:4191
bool IsWalking() const
Definition Unit.h:1621
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:2635
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