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 {
260 case CreatureChaseMovementType::CanWalk:
261 walk = owner->IsWalking();
262 break;
263 case CreatureChaseMovementType::AlwaysWalk:
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}
@ PATHFIND_NOPATH
Definition: PathGenerator.h:51
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:345
@ UNIT_STATE_NOT_MOVE
Definition: UnitDefines.h:197
UnitMoveType
Definition: UnitDefines.h:327
@ MOVE_FLIGHT
Definition: UnitDefines.h:334
@ MOVE_FLIGHT_BACK
Definition: UnitDefines.h:335
@ MOVE_RUN
Definition: UnitDefines.h:329
@ MOVE_RUN_BACK
Definition: UnitDefines.h:330
@ MOVE_WALK
Definition: UnitDefines.h:328
#define CONTACT_DISTANCE
Definition: ObjectDefines.h:23
TO * getTarget() const
Definition: Reference.h:95
bool isValid() const
Definition: Reference.h:79
void Update(int32 diff)
Definition: Timer.h:239
bool Passed() const
Definition: Timer.h:244
void SetCannotReachTarget(ObjectGuid const &target=ObjectGuid::Empty)
Definition: Creature.cpp:3647
void UpdateLeashExtensionTime()
Definition: Creature.cpp:3700
CreatureMovementData const & GetMovementTemplate() const
Definition: Creature.cpp:2975
bool IsMovementPreventedByCasting() const override
Definition: Creature.cpp:3625
CreatureChaseMovementType GetChase() const
Definition: CreatureData.h:153
static ObjectGuid GetGUID(Object const *o)
Definition: Object.h:109
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:2626
float ToAbsoluteAngle(float relAngle) const
Definition: Position.h:203
void GetPosition(float &x, float &y) const
Definition: Position.h:122
float GetAngle(const Position *pos) const
Definition: Position.cpp:77
float GetSpeed(UnitMoveType mtype) const
Definition: Unit.cpp:14378
virtual bool CanFly() const =0
bool IsPet() const
Definition: Unit.h:710
bool isInAccessiblePlaceFor(Creature const *c) const
Definition: Unit.cpp:4175
bool HasUnitMovementFlag(uint32 f) const
Definition: Unit.h:1613
bool isMoving() const
Definition: Unit.h:1696
Unit * GetVictim() const
Definition: Unit.h:789
bool IsWalking() const
Definition: Unit.h:1695
FollowerReference i_target
Definition: TargetedMovementGenerator.h:34
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
Definition: MoveSplineInit.h:71