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 (owner->movespline->Finalized())
157 {
160 {
162 if (cOwner)
164 }
165 }
168
169
171 {
175 {
176
178 {
182 return true;
183 }
184
185
186 float x, y, z;
188 bool withinRange = owner->IsInDist(target, maxRange);
189 bool withinLOS = owner->IsWithinLOS(x, y, z);
190 bool moveToward = !(withinRange && withinLOS);
191
192
194 i_path = std::make_unique<PathGenerator>(owner);
195 else
197
198
199 float additionalRange = 0;
200 bool predictDestination = !mutualChase && target->
isMoving();
201 if (predictDestination)
202 {
206 else
207 {
210 else
212 }
213 float speed = target->
GetSpeed(moveType) * 0.5f;
214 additionalRange = owner->GetExactDistSq(target) < G3D::square(speed) ? 0 : speed;
215 }
216
217 bool shortenPath;
218
219
220 if (moveToward && !angle)
221 {
222
223 shortenPath = true;
224 }
225 else
226 {
227
228 target->
GetNearPoint(owner, x, y, z, (moveToward ? maxTarget : minTarget) - chaseRange - additionalRange, 0, angle ? target->ToAbsoluteAngle(angle->RelativeAngle) : target->GetAngle(owner));
229 shortenPath = false;
230 }
231
232 if (owner->IsHovering())
233 owner->UpdateAllowedPositionZ(x, y, z);
234
235 bool success =
i_path->CalculatePath(x, y, z, forceDest);
237 {
238 if (cOwner)
239 {
241 }
242
243 owner->StopMoving();
244 return true;
245 }
246
247 if (shortenPath)
248 i_path->ShortenPathUntilDist(G3D::Vector3(x, y, z), maxTarget);
249
250 if (cOwner)
251 {
253 }
254
255 bool walk = false;
256 if (cOwner && !cOwner->
IsPet())
257 {
259 {
261 walk = owner->IsWalking();
262 break;
264 walk = true;
265 break;
266 default:
267 break;
268 }
269 }
270
273
275 init.MovebyPath(
i_path->GetPath());
276 init.SetFacing(target);
277 init.SetWalk(walk);
278 init.Launch();
279 }
280 }
281
282 return true;
283}
#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:322
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:3677
void UpdateLeashExtensionTime()
Definition Creature.cpp:3730
CreatureMovementData const & GetMovementTemplate() const
Definition Creature.cpp:2997
bool IsMovementPreventedByCasting() const override
Definition Creature.cpp:3655
Definition MoveSplineInit.h:71
static ObjectGuid GetGUID(Object const *o)
Definition Object.h:112
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:14476
virtual bool CanFly() const =0
bool IsPet() const
Definition Unit.h:763
bool isInAccessiblePlaceFor(Creature const *c) const
Definition Unit.cpp:4225
bool HasUnitMovementFlag(uint32 f) const
Definition Unit.h:745
bool isMoving() const
Definition Unit.h:1628
Unit * GetVictim() const
Definition Unit.h:862
bool IsWalking() const
Definition Unit.h:1627
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