67{
69 return false;
70
71 if (!owner || !owner->IsAlive())
72 return false;
73
75
76
78 {
81 if (cOwner)
82 {
85 }
86 return true;
87 }
88
89 bool forceDest =
90
92 (owner->CanFly())
93 ;
94
96
98 bool const mutualTarget = target->
GetVictim() == owner;
100 float const meleeRange = owner->GetMeleeRange(target);
101 float const minTarget = (
_range ?
_range->MinTolerance : 0.0f) + chaseRange;
102 float const maxRange =
_range ?
_range->MaxRange + chaseRange : meleeRange;
104
106
107
108 if (angle && !mutualChase &&
_mutualChase && mutualTarget && chaseRange < meleeRange)
109 {
111 mutualChase = true;
112 }
113
114
115
116 if (angle && !mutualChase && !
_mutualChase && mutualTarget && chaseRange < meleeRange && cOwner && cOwner->IsPet())
117 {
119 mutualChase = true;
120 }
121
122
125 {
127
129 {
131 {
134 if (cOwner)
136 owner->StopMoving();
137 owner->SetInFront(target);
139 return true;
140 }
141 }
142 }
143
144
146 {
149 if (cOwner)
152 owner->SetInFront(target);
154 }
155
156 if (cOwner)
157 {
159 {
162 {
165 }
166 }
169 }
170
171
173 {
177 {
178
180 {
184 return true;
185 }
186
187
188 float x, y, z;
190 bool withinRange = owner->IsInDist(target, maxRange);
191 bool withinLOS = owner->IsWithinLOS(x, y, z);
192 bool moveToward = !(withinRange && withinLOS);
193
194
196 i_path = std::make_unique<PathGenerator>(owner);
197 else
199
200
201 float additionalRange = 0;
202 bool predictDestination = !mutualChase && target->
isMoving();
203 if (predictDestination)
204 {
208 else
209 {
212 else
214 }
215 float speed = target->
GetSpeed(moveType) * 0.5f;
216 additionalRange = owner->GetExactDistSq(target) < G3D::square(speed) ? 0 : speed;
217 }
218
219 bool shortenPath;
220
221
222 if (moveToward && !angle)
223 {
224
225 shortenPath = true;
226 }
227 else
228 {
229
230 target->
GetNearPoint(owner, x, y, z, (moveToward ? maxTarget : minTarget) - chaseRange - additionalRange, 0, angle ? target->ToAbsoluteAngle(angle->RelativeAngle) : target->GetAngle(owner));
231 shortenPath = false;
232 }
233
234 if (owner->IsHovering())
235 owner->UpdateAllowedPositionZ(x, y, z);
236
237 bool success =
i_path->CalculatePath(x, y, z, forceDest);
239 {
240 if (cOwner)
241 {
243 }
244
245 owner->StopMoving();
246 return true;
247 }
248
249 if (shortenPath)
250 i_path->ShortenPathUntilDist(G3D::Vector3(x, y, z), maxTarget);
251
252 if (cOwner)
253 {
255 }
256
257 bool walk = false;
258 if (cOwner && !cOwner->
IsPet())
259 {
261 {
263 walk = owner->IsWalking();
264 break;
266 walk = true;
267 break;
268 default:
269 break;
270 }
271 }
272
275
277 init.MovebyPath(
i_path->GetPath());
278 init.SetFacing(target);
279 init.SetWalk(walk);
280 init.Launch();
281 }
282 }
283
284 return true;
285}
#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:325
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:3681
void UpdateLeashExtensionTime()
Definition Creature.cpp:3734
CreatureMovementData const & GetMovementTemplate() const
Definition Creature.cpp:3001
bool IsMovementPreventedByCasting() const override
Definition Creature.cpp:3659
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
FollowerReference i_target
Definition TargetedMovementGenerator.h:34
float GetSpeed(UnitMoveType mtype) const
Definition Unit.cpp:14475
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:4226
bool HasUnitMovementFlag(uint32 f) const
Definition Unit.h:729
bool isMoving() const
Definition Unit.h:1619
Unit * GetVictim() const
Definition Unit.h:846
bool IsWalking() const
Definition Unit.h:1618
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:2639
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