TrinityCore
GridNotifiers.h
Go to the documentation of this file.
1/*
2 * This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2 of the License, or (at your
7 * option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#ifndef TRINITY_GRIDNOTIFIERS_H
19#define TRINITY_GRIDNOTIFIERS_H
20
21#include "AreaTrigger.h"
22#include "Creature.h"
23#include "Corpse.h"
24#include "Conversation.h"
25#include "DynamicObject.h"
26#include "GameObject.h"
27#include "Player.h"
28#include "SceneObject.h"
29#include "Spell.h"
30#include "SpellInfo.h"
31#include "UnitAI.h"
32#include "UpdateData.h"
33
34namespace Trinity
35{
36 template<typename ObjectType>
37 struct GridMapTypeMaskForType : std::integral_constant<GridMapTypeMask, GridMapTypeMask(0)> { };
38
39 template<> struct GridMapTypeMaskForType<Corpse> : std::integral_constant<GridMapTypeMask, GRID_MAP_TYPE_MASK_CORPSE> { };
40 template<> struct GridMapTypeMaskForType<Creature> : std::integral_constant<GridMapTypeMask, GRID_MAP_TYPE_MASK_CREATURE> { };
41 template<> struct GridMapTypeMaskForType<DynamicObject> : std::integral_constant<GridMapTypeMask, GRID_MAP_TYPE_MASK_DYNAMICOBJECT> { };
42 template<> struct GridMapTypeMaskForType<GameObject> : std::integral_constant<GridMapTypeMask, GRID_MAP_TYPE_MASK_GAMEOBJECT> { };
43 template<> struct GridMapTypeMaskForType<Player> : std::integral_constant<GridMapTypeMask, GRID_MAP_TYPE_MASK_PLAYER> { };
44 template<> struct GridMapTypeMaskForType<AreaTrigger> : std::integral_constant<GridMapTypeMask, GRID_MAP_TYPE_MASK_AREATRIGGER> { };
45 template<> struct GridMapTypeMaskForType<SceneObject> : std::integral_constant<GridMapTypeMask, GRID_MAP_TYPE_MASK_SCENEOBJECT> { };
46 template<> struct GridMapTypeMaskForType<Conversation> : std::integral_constant<GridMapTypeMask, GRID_MAP_TYPE_MASK_CONVERSATION> { };
47
49 {
52 std::set<WorldObject*> i_visibleNow;
54
55 VisibleNotifier(Player &player) : i_player(player), i_data(player.GetMapId()), vis_guids(player.m_clientGUIDs) { }
56 template<class T> void Visit(GridRefManager<T> &m);
57 void SendToSelf(void);
58 };
59
61 {
63
65 template<class T> void Visit(GridRefManager<T> &) { }
66 void Visit(PlayerMapType &);
67 void Visit(CreatureMapType &);
69 };
70
72 {
74
75 template<class T> void Visit(GridRefManager<T> &m) { VisibleNotifier::Visit(m); }
76 void Visit(CreatureMapType &);
77 void Visit(PlayerMapType &);
78 };
79
81 {
83 CreatureRelocationNotifier(Creature &c) : i_creature(c) { }
84 template<class T> void Visit(GridRefManager<T> &) { }
85 void Visit(CreatureMapType &);
86 void Visit(PlayerMapType &);
87 };
88
90 {
94 const float i_radius;
95 DelayedUnitRelocation(Cell &c, CellCoord &pair, Map &map, float radius) :
96 i_map(map), cell(c), p(pair), i_radius(radius) { }
97 template<class T> void Visit(GridRefManager<T> &) { }
98 void Visit(CreatureMapType &);
99 void Visit(PlayerMapType &);
100 };
101
103 {
106 explicit AIRelocationNotifier(Unit &unit) : i_unit(unit), isCreature(unit.GetTypeId() == TYPEID_UNIT) { }
107 template<class T> void Visit(GridRefManager<T> &) { }
108 void Visit(CreatureMapType &);
109 };
110
112 {
115 GridUpdater(GridType &grid, uint32 diff) : i_grid(grid), i_timeDiff(diff) { }
116
117 template<class T> void updateObjects(GridRefManager<T> &m)
118 {
119 for (typename GridRefManager<T>::iterator iter = m.begin(); iter != m.end(); ++iter)
120 iter->GetSource()->Update(i_timeDiff);
121 }
122
123 void Visit(PlayerMapType &m) { updateObjects<Player>(m); }
124 void Visit(CreatureMapType &m){ updateObjects<Creature>(m); }
125 void Visit(GameObjectMapType &m) { updateObjects<GameObject>(m); }
126 void Visit(DynamicObjectMapType &m) { updateObjects<DynamicObject>(m); }
127 void Visit(CorpseMapType &m) { updateObjects<Corpse>(m); }
128 void Visit(AreaTriggerMapType &m) { updateObjects<AreaTrigger>(m); }
129 void Visit(SceneObjectMapType &m) { updateObjects<SceneObject>(m); }
130 void Visit(ConversationMapType &m) { updateObjects<Conversation>(m); }
131 };
132
134 {
136
137 PacketSenderRef(WorldPacket const* message) : Data(message) { }
138
139 void operator()(Player const* player) const
140 {
141 player->SendDirectMessage(Data);
142 }
143 };
144
145 template<typename Packet>
147 {
148 Packet Data;
149
150 void operator()(Player const* player) const
151 {
152 player->SendDirectMessage(Data.GetRawPacket());
153 }
154 };
155
156 template<typename PacketSender>
158 {
160 PacketSender& i_packetSender;
162 float i_distSq;
166 MessageDistDeliverer(WorldObject const* src, PacketSender& packetSender, float dist, bool own_team_only = false, Player const* skipped = nullptr, bool req3dDist = false)
167 : i_source(src), i_packetSender(packetSender), i_phaseShift(&src->GetPhaseShift()), i_distSq(dist * dist)
169 , skipped_receiver(skipped)
170 , required3dDist(req3dDist)
171 {
172 if (own_team_only)
173 if (Player const* player = src->ToPlayer())
174 team = player->GetEffectiveTeam();
175 }
176
177 void Visit(PlayerMapType &m) const;
178 void Visit(CreatureMapType &m) const;
179 void Visit(DynamicObjectMapType &m) const;
180 template<class SKIP> void Visit(GridRefManager<SKIP> &) const { }
181
182 void SendPacket(Player const* player) const
183 {
184 // never send packet to self
185 if (player == i_source || (team && player->GetEffectiveTeam() != team) || skipped_receiver == player)
186 return;
187
188 if (!player->HaveAtClient(i_source))
189 return;
190
191 i_packetSender(player);
192 }
193 };
194
195 template<typename PacketSender>
197 {
199 PacketSender& i_packetSender;
201 float i_distSq;
202
203 MessageDistDelivererToHostile(Unit* src, PacketSender& packetSender, float dist)
204 : i_source(src), i_packetSender(packetSender), i_phaseShift(&src->GetPhaseShift()), i_distSq(dist * dist)
205 {
206 }
207
208 void Visit(PlayerMapType &m) const;
209 void Visit(CreatureMapType &m) const;
210 void Visit(DynamicObjectMapType &m) const;
211 template<class SKIP> void Visit(GridRefManager<SKIP> &) const { }
212
213 void SendPacket(Player const* player) const
214 {
215 // never send packet to self
216 if (player == i_source || !player->HaveAtClient(i_source) || player->IsFriendlyTo(i_source))
217 return;
218
219 i_packetSender(player);
220 }
221 };
222
224 {
226 explicit ObjectUpdater(const uint32 diff) : i_timeDiff(diff) { }
227 template<class T> void Visit(GridRefManager<T> &m);
230 };
231
232 // SEARCHERS & LIST SEARCHERS & WORKERS
233
234 // WorldObject searchers & workers
236 {
237 Continue,
238 Return
239 };
240
241 template<typename Type>
243 {
245
246 protected:
247 explicit SearcherFirstObjectResult(Type& ref_) : result(ref_) { }
248
250 {
252 }
253
254 void Insert(Type object)
255 {
256 result = object;
257 }
258 };
259
260 template<typename Type>
262 {
264
265 protected:
266 explicit SearcherLastObjectResult(Type& ref_) : result(ref_) { }
267
269 {
271 }
272
273 void Insert(Type object)
274 {
275 result = object;
276 }
277 };
278
279 // Generic base class to insert elements into arbitrary containers using push_back
280 template<typename Type>
282 {
283 using InserterType = void(*)(void*, Type&&);
284
285 void* ref;
287
288 protected:
289 template<typename T>
290 explicit SearcherContainerResult(T& ref_) : ref(&ref_)
291 {
292 inserter = [](void* containerRaw, Type&& object)
293 {
294 T* container = reinterpret_cast<T*>(containerRaw);
295 container->insert(container->end(), std::move(object));
296 };
297 }
298
300 {
302 }
303
304 void Insert(Type object)
305 {
306 inserter(ref, std::move(object));
307 }
308 };
309
310 template<class Check, class Result>
312 {
315 Check& i_check;
316
317 template<typename Container>
318 WorldObjectSearcherBase(PhaseShift const* phaseShift, Container& result, Check& check, uint32 mapTypeMask = GRID_MAP_TYPE_MASK_ALL)
319 : Result(result), i_mapTypeMask(mapTypeMask), i_phaseShift(phaseShift), i_check(check) { }
320
321 template<class T>
323 };
324
325 template<class Check>
326 struct WorldObjectSearcher : WorldObjectSearcherBase<Check, SearcherFirstObjectResult<WorldObject*>>
327 {
328 WorldObjectSearcher(WorldObject const* searcher, WorldObject*& result, Check& check, uint32 mapTypeMask = GRID_MAP_TYPE_MASK_ALL)
329 : WorldObjectSearcherBase<Check, SearcherFirstObjectResult<WorldObject*>>(&searcher->GetPhaseShift(), result, check, mapTypeMask) { }
330 };
331
332 template<class Check>
333 struct WorldObjectLastSearcher : WorldObjectSearcherBase<Check, SearcherLastObjectResult<WorldObject*>>
334 {
336 : WorldObjectSearcherBase<Check, SearcherLastObjectResult<WorldObject*>>(&searcher->GetPhaseShift(), result, check, mapTypeMask) { }
337 };
338
339 template<class Check>
340 struct WorldObjectListSearcher : WorldObjectSearcherBase<Check, SearcherContainerResult<WorldObject*>>
341 {
342 template<typename Container>
343 WorldObjectListSearcher(WorldObject const* searcher, Container& container, Check& check, uint32 mapTypeMask = GRID_MAP_TYPE_MASK_ALL)
344 : WorldObjectSearcherBase<Check, SearcherContainerResult<WorldObject*>>(&searcher->GetPhaseShift(), container, check, mapTypeMask) { }
345 };
346
347 template<class Do>
349 {
352 Do const& i_do;
353
354 WorldObjectWorker(WorldObject const* searcher, Do const& _do, uint32 mapTypeMask = GRID_MAP_TYPE_MASK_ALL)
355 : i_mapTypeMask(mapTypeMask), i_phaseShift(&searcher->GetPhaseShift()), i_do(_do) { }
356
357 template<class T>
359 {
361 return;
362 for (auto itr = m.begin(); itr != m.end(); ++itr)
363 if (itr->GetSource()->InSamePhase(*i_phaseShift))
364 i_do(itr->GetSource());
365 }
366 };
367
368 // Gameobject searchers
369
370 template<class Check, class Result>
372 {
374 Check &i_check;
375
376 template<typename Container>
377 GameObjectSearcherBase(PhaseShift const* phaseShift, Container& result, Check& check)
378 : Result(result), i_phaseShift(phaseShift), i_check(check) { }
379
380 void Visit(GameObjectMapType& m);
381
382 template<class NOT_INTERESTED> void Visit(GridRefManager<NOT_INTERESTED> &) { }
383 };
384
385 template<class Check>
386 struct GameObjectSearcher : GameObjectSearcherBase<Check, SearcherFirstObjectResult<GameObject*>>
387 {
388 GameObjectSearcher(WorldObject const* searcher, GameObject*& result, Check& check)
389 : GameObjectSearcherBase<Check, SearcherFirstObjectResult<GameObject*>>(&searcher->GetPhaseShift(), result, check) { }
390 };
391
392 // Last accepted by Check GO if any (Check can change requirements at each call)
393 template<class Check>
394 struct GameObjectLastSearcher : GameObjectSearcherBase<Check, SearcherLastObjectResult<GameObject*>>
395 {
396 GameObjectLastSearcher(WorldObject const* searcher, GameObject*& result, Check& check)
397 : GameObjectSearcherBase<Check, SearcherLastObjectResult<GameObject*>>(&searcher->GetPhaseShift(), result, check) { }
398 };
399
400 template<class Check>
401 struct GameObjectListSearcher : GameObjectSearcherBase<Check, SearcherContainerResult<GameObject*>>
402 {
403 template<typename Container>
404 GameObjectListSearcher(WorldObject const* searcher, Container& container, Check& check)
405 : GameObjectSearcherBase<Check, SearcherContainerResult<GameObject*>>(&searcher->GetPhaseShift(), container, check) { }
406 };
407
408 template<class Functor>
410 {
411 GameObjectWorker(WorldObject const* searcher, Functor& func)
412 : _func(func), _phaseShift(&searcher->GetPhaseShift()) { }
413
415 {
416 for (GameObjectMapType::iterator itr = m.begin(); itr != m.end(); ++itr)
417 if (itr->GetSource()->InSamePhase(*_phaseShift))
418 _func(itr->GetSource());
419 }
420
421 template<class NOT_INTERESTED> void Visit(GridRefManager<NOT_INTERESTED> &) { }
422
423 private:
424 Functor& _func;
426 };
427
428 // Unit searchers
429
430 template<class Check, class Result>
431 struct UnitSearcherBase : Result
432 {
434 Check& i_check;
435
436 template<typename Container>
437 UnitSearcherBase(PhaseShift const* phaseShift, Container& result, Check& check)
438 : Result(result), i_phaseShift(phaseShift), i_check(check) { }
439
442
443 template<class NOT_INTERESTED> void Visit(GridRefManager<NOT_INTERESTED>&) { }
444
445 private:
446 template<class T> void VisitImpl(GridRefManager<T>& m);
447 };
448
449 // First accepted by Check Unit if any
450 template<class Check>
451 struct UnitSearcher : UnitSearcherBase<Check, SearcherFirstObjectResult<Unit*>>
452 {
453 UnitSearcher(WorldObject const* searcher, Unit*& result, Check& check)
454 : UnitSearcherBase<Check, SearcherFirstObjectResult<Unit*>>(&searcher->GetPhaseShift(), result, check) { }
455 };
456
457 // Last accepted by Check Unit if any (Check can change requirements at each call)
458 template<class Check>
459 struct UnitLastSearcher : UnitSearcherBase<Check, SearcherLastObjectResult<Unit*>>
460 {
461 UnitLastSearcher(WorldObject const* searcher, Unit*& result, Check& check)
462 : UnitSearcherBase<Check, SearcherLastObjectResult<Unit*>>(&searcher->GetPhaseShift(), result, check) { }
463 };
464
465 // All accepted by Check units if any
466 template<class Check>
467 struct UnitListSearcher : UnitSearcherBase<Check, SearcherContainerResult<Unit*>>
468 {
469 template<typename Container>
470 UnitListSearcher(WorldObject const* searcher, Container& container, Check& check)
471 : UnitSearcherBase<Check, SearcherContainerResult<Unit*>>(&searcher->GetPhaseShift(), container, check) { }
472 };
473
474 // Creature searchers
475
476 template<class Check, class Result>
477 struct CreatureSearcherBase : Result
478 {
480 Check& i_check;
481
482 template<typename Container>
483 CreatureSearcherBase(PhaseShift const* phaseShift, Container& result, Check& check)
484 : Result(result), i_phaseShift(phaseShift), i_check(check) { }
485
486 void Visit(CreatureMapType& m);
487
488 template<class NOT_INTERESTED> void Visit(GridRefManager<NOT_INTERESTED> &) { }
489 };
490
491 template<class Check>
492 struct CreatureSearcher : CreatureSearcherBase<Check, SearcherFirstObjectResult<Creature*>>
493 {
494 CreatureSearcher(WorldObject const* searcher, Creature*& result, Check& check)
495 : CreatureSearcherBase<Check, SearcherFirstObjectResult<Creature*>>(&searcher->GetPhaseShift(), result, check) { }
496 };
497
498 // Last accepted by Check Creature if any (Check can change requirements at each call)
499 template<class Check>
500 struct CreatureLastSearcher : CreatureSearcherBase<Check, SearcherLastObjectResult<Creature*>>
501 {
502 CreatureLastSearcher(WorldObject const* searcher, Creature*& result, Check& check)
503 : CreatureSearcherBase<Check, SearcherLastObjectResult<Creature*>>(&searcher->GetPhaseShift(), result, check) { }
504 };
505
506 template<class Check>
507 struct CreatureListSearcher : CreatureSearcherBase<Check, SearcherContainerResult<Creature*>>
508 {
509 template<typename Container>
510 CreatureListSearcher(WorldObject const* searcher, Container& container, Check & check)
511 : CreatureSearcherBase<Check, SearcherContainerResult<Creature*>>(&searcher->GetPhaseShift(), container, check) { }
512 };
513
514 template<class Do>
516 {
518 Do& i_do;
519
520 CreatureWorker(WorldObject const* searcher, Do& _do)
521 : i_phaseShift(&searcher->GetPhaseShift()), i_do(_do) { }
522
524 {
525 for (CreatureMapType::iterator itr=m.begin(); itr != m.end(); ++itr)
526 if (itr->GetSource()->InSamePhase(*i_phaseShift))
527 i_do(itr->GetSource());
528 }
529
530 template<class NOT_INTERESTED> void Visit(GridRefManager<NOT_INTERESTED> &) { }
531 };
532
533 // Player searchers
534
535 template<class Check, class Result>
536 struct PlayerSearcherBase : Result
537 {
539 Check& i_check;
540
541 template<typename Container>
542 PlayerSearcherBase(PhaseShift const* phaseShift, Container& result, Check& check)
543 : Result(result), i_phaseShift(phaseShift), i_check(check) { }
544
545 void Visit(PlayerMapType& m);
546
547 template<class NOT_INTERESTED> void Visit(GridRefManager<NOT_INTERESTED> &) { }
548 };
549
550 template<class Check>
551 struct PlayerSearcher : PlayerSearcherBase<Check, SearcherFirstObjectResult<Player*>>
552 {
553 PlayerSearcher(WorldObject const* searcher, Player*& result, Check& check)
554 : PlayerSearcherBase<Check, SearcherFirstObjectResult<Player*>>(&searcher->GetPhaseShift(), result, check) { }
555 };
556
557 template<class Check>
558 struct PlayerLastSearcher : PlayerSearcherBase<Check, SearcherLastObjectResult<Player*>>
559 {
560 PlayerLastSearcher(WorldObject const* searcher, Player*& result, Check& check)
561 : PlayerSearcherBase<Check, SearcherLastObjectResult<Player*>>(&searcher->GetPhaseShift(), result, check) { }
562 };
563
564 template<class Check>
565 struct PlayerListSearcher : PlayerSearcherBase<Check, SearcherContainerResult<Player*>>
566 {
567 template<typename Container>
568 PlayerListSearcher(WorldObject const* searcher, Container& container, Check& check)
569 : PlayerSearcherBase<Check, SearcherContainerResult<Player*>>(&searcher->GetPhaseShift(), container, check) { }
570
571 template<typename Container>
572 PlayerListSearcher(PhaseShift const& phaseShift, Container& container, Check& check)
573 : PlayerSearcherBase<Check, SearcherContainerResult<Player*>>(phaseShift, container, check) { }
574 };
575
576 template<class Do>
578 {
580 Do& i_do;
581
582 PlayerWorker(WorldObject const* searcher, Do& _do)
583 : i_phaseShift(&searcher->GetPhaseShift()), i_do(_do) { }
584
586 {
587 for (PlayerMapType::iterator itr=m.begin(); itr != m.end(); ++itr)
588 if (itr->GetSource()->InSamePhase(*i_phaseShift))
589 i_do(itr->GetSource());
590 }
591
592 template<class NOT_INTERESTED> void Visit(GridRefManager<NOT_INTERESTED> &) { }
593 };
594
595 template<class Do>
597 {
599 float i_dist;
600 Do& i_do;
601
602 PlayerDistWorker(WorldObject const* searcher, float _dist, Do& _do)
603 : i_searcher(searcher), i_dist(_dist), i_do(_do) { }
604
606 {
607 for (PlayerMapType::iterator itr=m.begin(); itr != m.end(); ++itr)
608 if (itr->GetSource()->InSamePhase(i_searcher) && itr->GetSource()->IsWithinDist(i_searcher, i_dist))
609 i_do(itr->GetSource());
610 }
611
612 template<class NOT_INTERESTED> void Visit(GridRefManager<NOT_INTERESTED> &) { }
613 };
614
615 // CHECKS && DO classes
616
617 // CHECK modifiers
619 {
620 public:
621 explicit InRangeCheckCustomizer(WorldObject const& obj, float range) : i_obj(obj), i_range(range) { }
622
623 bool Test(WorldObject const* o) const
624 {
625 return i_obj.IsWithinDist(o, i_range);
626 }
627
628 void Update(WorldObject const* /*o*/) { }
629
630 private:
632 float i_range;
633 };
634
636 {
637 public:
638 explicit NearestCheckCustomizer(WorldObject const& obj, float range) : i_obj(obj), i_range(range) { }
639
640 bool Test(WorldObject const* o) const
641 {
642 return i_obj.IsWithinDist(o, i_range);
643 }
644
645 void Update(WorldObject const* o)
646 {
648 }
649
650 private:
652 float i_range;
653 };
654
655 // WorldObject check classes
656
658 {
659 public:
660 AnyDeadUnitObjectInRangeCheck(WorldObject* searchObj, float range) : i_searchObj(searchObj), i_range(range) { }
661 bool operator()(Player* u);
662 bool operator()(Corpse* u);
663 bool operator()(Creature* u);
664 template<class NOT_INTERESTED> bool operator()(NOT_INTERESTED*) { return false; }
665 protected:
667 float i_range;
668 };
669
671 {
672 public:
674 : AnyDeadUnitObjectInRangeCheck(searchObj, range), WorldObjectSpellTargetCheck(searchObj, searchObj, spellInfo, check, nullptr, objectType)
675 { }
676 bool operator()(Player* u);
677 bool operator()(Corpse* u);
678 bool operator()(Creature* u);
679 template<class NOT_INTERESTED> bool operator()(NOT_INTERESTED*) { return false; }
680 };
681
682 // WorldObject do classes
683
685 {
686 public:
688 void operator()(Creature* u) const { u->Respawn(); }
689 void operator()(GameObject* u) const { u->Respawn(); }
690 void operator()(WorldObject*) const { }
691 void operator()(Corpse*) const { }
692 };
693
694 // GameObject checks
695
697 {
698 public:
699 GameObjectFocusCheck(WorldObject const* caster, uint32 focusId) : _caster(caster), _focusId(focusId) { }
700
701 bool operator()(GameObject* go) const
702 {
703 if (go->GetGOInfo()->GetSpellFocusType() != _focusId)
704 return false;
705
706 if (!go->isSpawned())
707 return false;
708
709 float const dist = go->GetGOInfo()->GetSpellFocusRadius();
710 return go->IsWithinDist(_caster, dist);
711 }
712
713 private:
716 };
717
718 // Find the nearest Fishing hole and return true only if source object is in range of hole
720 {
721 public:
722 NearestGameObjectFishingHole(WorldObject const& obj, float range) : i_obj(obj), i_range(range) { }
723
725 {
727 {
729 return true;
730 }
731 return false;
732 }
733
734 private:
736 float i_range;
737
738 // prevent clone
740 };
741
743 {
744 public:
745 NearestGameObjectCheck(WorldObject const& obj) : i_obj(obj), i_range(999.f) { }
746
748 {
749 if (i_obj.IsWithinDist(go, i_range))
750 {
751 i_range = i_obj.GetDistance(go); // use found GO range as new range limit for next check
752 return true;
753 }
754 return false;
755 }
756
757 private:
759 float i_range;
760
761 // prevent clone this object
763 };
764
765 // Success at unit in range, range update for next check (this can be use with GameobjectLastSearcher to find nearest GO)
767 {
768 public:
769 NearestGameObjectEntryInObjectRangeCheck(WorldObject const& obj, uint32 entry, float range, bool spawnedOnly = true) : i_obj(obj), i_entry(entry), i_range(range), i_spawnedOnly(spawnedOnly) { }
770
772 {
773 if ((!i_spawnedOnly || go->isSpawned()) && go->GetEntry() == i_entry && go->GetGUID() != i_obj.GetGUID() && i_obj.IsWithinDist(go, i_range))
774 {
775 i_range = i_obj.GetDistance(go); // use found GO range as new range limit for next check
776 return true;
777 }
778 return false;
779 }
780
781 private:
784 float i_range;
786
787 // prevent clone this object
789 };
790
791 // Success at unit in range, range update for next check (this can be use with GameobjectLastSearcher to find nearest unspawned GO)
793 {
794 public:
795 NearestUnspawnedGameObjectEntryInObjectRangeCheck(WorldObject const& obj, uint32 entry, float range) : i_obj(obj), i_entry(entry), i_range(range) { }
796
798 {
799 if (!go->isSpawned() && go->GetEntry() == i_entry && go->GetGUID() != i_obj.GetGUID() && i_obj.IsWithinDist(go, i_range))
800 {
801 i_range = i_obj.GetDistance(go); // use found GO range as new range limit for next check
802 return true;
803 }
804 return false;
805 }
806
807 private:
810 float i_range;
811
812 // prevent clone this object
814 };
815
816 // Success at unit in range, range update for next check (this can be use with GameobjectLastSearcher to find nearest GO with a certain type)
818 {
819 public:
820 NearestGameObjectTypeInObjectRangeCheck(WorldObject const& obj, GameobjectTypes type, float range) : i_obj(obj), i_type(type), i_range(range) { }
821
823 {
824 if (go->GetGoType() == i_type && i_obj.IsWithinDist(go, i_range))
825 {
826 i_range = i_obj.GetDistance(go); // use found GO range as new range limit for next check
827 return true;
828 }
829 return false;
830 }
831
832 private:
835 float i_range;
836
837 // prevent clone this object
839 };
840
841 // Unit checks
842
844 {
845 public:
846 MostHPMissingInRange(Unit const* obj, float range, uint32 hp) : i_obj(obj), i_range(range), i_hp(hp) { }
847
849 {
850 if (u->IsAlive() && u->IsInCombat() && !i_obj->IsHostileTo(u) && i_obj->IsWithinDist(u, i_range) && u->GetMaxHealth() - u->GetHealth() > i_hp)
851 {
852 i_hp = u->GetMaxHealth() - u->GetHealth();
853 return true;
854 }
855 return false;
856 }
857
858 private:
859 Unit const* i_obj;
860 float i_range;
862 };
863
865 {
866 public:
867 MostHPPercentMissingInRange(Unit const* obj, float range, uint32 minHpPct, uint32 maxHpPct) : i_obj(obj), i_range(range), i_minHpPct(minHpPct), i_maxHpPct(maxHpPct), i_hpPct(101.f) { }
868
870 {
871 if (u->IsAlive() && u->IsInCombat() && !i_obj->IsHostileTo(u) && i_obj->IsWithinDist(u, i_range) && i_minHpPct <= u->GetHealthPct() && u->GetHealthPct() <= i_maxHpPct && u->GetHealthPct() < i_hpPct)
872 {
873 i_hpPct = u->GetHealthPct();
874 return true;
875 }
876 return false;
877 }
878
879 private:
880 Unit const* i_obj;
881 float i_range;
883 };
884
886 {
887 public:
888 FriendlyBelowHpPctEntryInRange(Unit const* obj, uint32 entry, float range, uint8 pct, bool excludeSelf) : i_obj(obj), i_entry(entry), i_range(range), i_pct(pct), i_excludeSelf(excludeSelf) { }
889
891 {
892 if (i_excludeSelf && i_obj->GetGUID() == u->GetGUID())
893 return false;
894 if (u->GetEntry() == i_entry && u->IsAlive() && u->IsInCombat() && !i_obj->IsHostileTo(u) && i_obj->IsWithinDist(u, i_range) && u->HealthBelowPct(i_pct))
895 return true;
896 return false;
897 }
898
899 private:
900 Unit const* i_obj;
902 float i_range;
905 };
906
908 {
909 public:
910 FriendlyCCedInRange(Unit const* obj, float range) : i_obj(obj), i_range(range) { }
911
912 bool operator()(Unit* u) const
913 {
914 if (u->IsAlive() && u->IsInCombat() && !i_obj->IsHostileTo(u) && i_obj->IsWithinDist(u, i_range) &&
916 {
917 return true;
918 }
919 return false;
920 }
921
922 private:
923 Unit const* i_obj;
924 float i_range;
925 };
926
928 {
929 public:
930 FriendlyMissingBuffInRange(Unit const* obj, float range, uint32 spellid) : i_obj(obj), i_range(range), i_spell(spellid) { }
931
932 bool operator()(Unit* u) const
933 {
934 if (u->IsAlive() && u->IsInCombat() && !i_obj->IsHostileTo(u) && i_obj->IsWithinDist(u, i_range) && !u->HasAura(i_spell))
935 return true;
936
937 return false;
938 }
939
940 private:
941 Unit const* i_obj;
942 float i_range;
944 };
945
947 {
948 public:
949 AnyUnfriendlyUnitInObjectRangeCheck(WorldObject const* obj, Unit const* funit, float range) : i_obj(obj), i_funit(funit), i_range(range) { }
950
951 bool operator()(Unit* u) const
952 {
953 if (u->IsAlive() && i_obj->IsWithinDist(u, i_range) && !i_funit->IsFriendlyTo(u))
954 return true;
955
956 return false;
957 }
958
959 private:
961 Unit const* i_funit;
962 float i_range;
963 };
964
966 {
967 public:
969
971 {
972 if (!u->IsAlive())
973 return false;
974
976 return false;
977
978 if (u->GetTypeId() == TYPEID_UNIT && u->ToCreature()->IsTotem())
979 return false;
980
981 if (!u->isTargetableForAttack(false))
982 return false;
983
985 return false;
986
988 return true;
989 }
990
991 private:
993 float i_range;
994 };
995
997 {
998 public:
999 AnyFriendlyUnitInObjectRangeCheck(WorldObject const* obj, Unit const* funit, float range, bool playerOnly = false, bool incOwnRadius = true, bool incTargetRadius = true)
1000 : i_obj(obj), i_funit(funit), i_range(range), i_playerOnly(playerOnly), i_incOwnRadius(incOwnRadius), i_incTargetRadius(incTargetRadius) { }
1001
1002 bool operator()(Unit* u) const
1003 {
1004 if (!u->IsAlive())
1005 return false;
1006
1007 float searchRadius = i_range;
1008 if (i_incOwnRadius)
1009 searchRadius += i_obj->GetCombatReach();
1011 searchRadius += u->GetCombatReach();
1012
1013 if (!u->IsInMap(i_obj) || !u->InSamePhase(i_obj) || !u->IsWithinDoubleVerticalCylinder(i_obj, searchRadius, searchRadius))
1014 return false;
1015
1016 if (!i_funit->IsFriendlyTo(u))
1017 return false;
1018
1019 return !i_playerOnly || u->GetTypeId() == TYPEID_PLAYER;
1020 }
1021
1022 private:
1025 float i_range;
1029 };
1030
1032 {
1033 public:
1034 AnyGroupedUnitInObjectRangeCheck(WorldObject const* obj, Unit const* funit, float range, bool raid, bool playerOnly = false, bool incOwnRadius = true, bool incTargetRadius = true)
1035 : _source(obj), _refUnit(funit), _range(range), _raid(raid), _playerOnly(playerOnly), i_incOwnRadius(incOwnRadius), i_incTargetRadius(incTargetRadius) { }
1036
1037 bool operator()(Unit* u) const
1038 {
1039 if (_playerOnly && u->GetTypeId() != TYPEID_PLAYER)
1040 return false;
1041
1042 if (_raid)
1043 {
1044 if (!_refUnit->IsInRaidWith(u))
1045 return false;
1046 }
1047 else if (!_refUnit->IsInPartyWith(u))
1048 return false;
1049
1050 if (_refUnit->IsHostileTo(u))
1051 return false;
1052
1053 if (!u->IsAlive())
1054 return false;
1055
1056 float searchRadius = _range;
1057 if (i_incOwnRadius)
1058 searchRadius += _source->GetCombatReach();
1060 searchRadius += u->GetCombatReach();
1061
1062 return u->IsInMap(_source) && u->InSamePhase(_source) && u->IsWithinDoubleVerticalCylinder(_source, searchRadius, searchRadius);
1063 }
1064
1065 private:
1068 float _range;
1069 bool _raid;
1073 };
1074
1076 {
1077 public:
1078 AnyUnitInObjectRangeCheck(WorldObject const* obj, float range, bool check3D = true) : i_obj(obj), i_range(range), i_check3D(check3D) { }
1079
1080 bool operator()(Unit* u) const
1081 {
1082 if (u->IsAlive() && i_obj->IsWithinDist(u, i_range, i_check3D))
1083 return true;
1084
1085 return false;
1086 }
1087
1088 private:
1090 float i_range;
1092 };
1093
1094 // Success at unit in range, range update for next check (this can be use with UnitLastSearcher to find nearest unit)
1096 {
1097 public:
1098 NearestAttackableUnitInObjectRangeCheck(WorldObject const* obj, Unit const* funit, float range) : i_obj(obj), i_funit(funit), i_range(range) { }
1099
1101 {
1104 {
1105 i_range = i_obj->GetDistance(u); // use found unit range as new range limit for next check
1106 return true;
1107 }
1108
1109 return false;
1110 }
1111
1112 private:
1115 float i_range;
1116
1117 // prevent clone this object
1119 };
1120
1122 {
1123 public:
1124 AnyAoETargetUnitInObjectRangeCheck(WorldObject const* obj, Unit const* funit, float range, SpellInfo const* spellInfo = nullptr, bool incOwnRadius = true, bool incTargetRadius = true)
1125 : i_obj(obj), i_funit(funit), _spellInfo(spellInfo), i_range(range), i_incOwnRadius(incOwnRadius), i_incTargetRadius(incTargetRadius)
1126 {
1127 }
1128
1129 bool operator()(Unit* u) const
1130 {
1131 // Check contains checks for: live, uninteractible, non-attackable flags, flight check and GM check, ignore totems
1132 if (u->GetTypeId() == TYPEID_UNIT && u->IsTotem())
1133 return false;
1134
1135 if (_spellInfo)
1136 {
1137 if (!u->IsPlayer())
1138 {
1140 return false;
1141
1143 return false;
1144 }
1146 return false;
1147 }
1148
1150 return false;
1151
1152 float searchRadius = i_range;
1153 if (i_incOwnRadius)
1154 searchRadius += i_obj->GetCombatReach();
1156 searchRadius += u->GetCombatReach();
1157
1158 return u->IsInMap(i_obj) && u->InSamePhase(i_obj) && u->IsWithinDoubleVerticalCylinder(i_obj, searchRadius, searchRadius);
1159 }
1160
1161 private:
1165 float i_range;
1168 };
1169
1170 // do attack at call of help to friendly crearture
1172 {
1173 public:
1174 CallOfHelpCreatureInRangeDo(Unit* funit, Unit* enemy, float range)
1175 : i_funit(funit), i_enemy(enemy), i_range(range) { }
1176
1177 void operator()(Creature* u) const
1178 {
1179 if (u == i_funit)
1180 return;
1181
1182 if (!u->CanAssistTo(i_funit, i_enemy, false))
1183 return;
1184
1185 // too far
1186 // Don't use combat reach distance, range must be an absolute value, otherwise the chain aggro range will be too big
1187 if (!u->IsWithinDist(i_funit, i_range, true, false, false))
1188 return;
1189
1190 // only if see assisted creature's enemy
1191 if (!u->IsWithinLOSInMap(i_enemy))
1192 return;
1193
1195 }
1196 private:
1199 float i_range;
1200 };
1201
1203 {
1204 bool operator()(Unit* u) const
1205 {
1206 return !u->IsAlive();
1207 }
1208 };
1209
1210 // Creature checks
1211
1213 {
1214 public:
1215 explicit NearestHostileUnitCheck(Creature const* creature, float dist = 0.f, bool playerOnly = false) : me(creature), i_playerOnly(playerOnly)
1216 {
1217 m_range = (dist == 0.f ? 9999.f : dist);
1218 }
1219
1221 {
1222 if (!me->IsWithinDist(u, m_range))
1223 return false;
1224
1225 if (!me->IsValidAttackTarget(u))
1226 return false;
1227
1228 if (i_playerOnly && u->GetTypeId() != TYPEID_PLAYER)
1229 return false;
1230
1231 m_range = me->GetDistance(u); // use found unit range as new range limit for next check
1232 return true;
1233 }
1234
1235 private:
1236 Creature const* me;
1237 float m_range;
1240 };
1241
1243 {
1244 public:
1245 explicit NearestHostileUnitInAttackDistanceCheck(Creature const* creature, float dist = 0.f) : me(creature)
1246 {
1247 m_range = (dist == 0.f ? 9999.f : dist);
1248 m_force = (dist == 0.f ? false : true);
1249 }
1250
1252 {
1253 if (!me->IsWithinDist(u, m_range))
1254 return false;
1255
1256 if (!me->CanSeeOrDetect(u))
1257 return false;
1258
1259 if (m_force)
1260 {
1261 if (!me->IsValidAttackTarget(u))
1262 return false;
1263 }
1264 else if (!me->CanStartAttack(u, false))
1265 return false;
1266
1267 m_range = me->GetDistance(u); // use found unit range as new range limit for next check
1268 return true;
1269 }
1270
1271 private:
1272 Creature const* me;
1273 float m_range;
1276 };
1277
1279 {
1280 public:
1281 explicit NearestHostileUnitInAggroRangeCheck(Creature const* creature, bool useLOS = false, bool ignoreCivilians = false) : _me(creature), _useLOS(useLOS), _ignoreCivilians(ignoreCivilians) { }
1282
1283 bool operator()(Unit* u) const
1284 {
1285 if (!u->IsHostileTo(_me))
1286 return false;
1287
1288 if (!u->IsWithinDist(_me, _me->GetAggroRange(u)))
1289 return false;
1290
1291 if (!_me->IsValidAttackTarget(u))
1292 return false;
1293
1294 if (_useLOS && !u->IsWithinLOSInMap(_me))
1295 return false;
1296
1297 // pets in aggressive do not attack civilians
1298 if (_ignoreCivilians)
1299 if (Creature* c = u->ToCreature())
1300 if (c->IsCivilian())
1301 return false;
1302
1303 return true;
1304 }
1305
1306 private:
1311 };
1312
1314 {
1315 public:
1316 AnyAssistCreatureInRangeCheck(Unit* funit, Unit* enemy, float range)
1317 : i_funit(funit), i_enemy(enemy), i_range(range) { }
1318
1319 bool operator()(Creature* u) const
1320 {
1321 if (u == i_funit)
1322 return false;
1323
1324 if (!u->CanAssistTo(i_funit, i_enemy))
1325 return false;
1326
1327 // too far
1328 // Don't use combat reach distance, range must be an absolute value, otherwise the chain aggro range will be too big
1329 if (!i_funit->IsWithinDist(u, i_range, true, false, false))
1330 return false;
1331
1332 // only if see assisted creature
1333 if (!i_funit->IsWithinLOSInMap(u))
1334 return false;
1335
1336 return true;
1337 }
1338
1339 private:
1342 float i_range;
1343 };
1344
1346 {
1347 public:
1349 : i_obj(obj), i_enemy(enemy), i_range(range) { }
1350
1352 {
1353 if (u == i_obj)
1354 return false;
1355 if (!u->CanAssistTo(i_obj, i_enemy))
1356 return false;
1357
1358 // Don't use combat reach distance, range must be an absolute value, otherwise the chain aggro range will be too big
1359 if (!i_obj->IsWithinDist(u, i_range, true, false, false))
1360 return false;
1361
1362 if (!i_obj->IsWithinLOSInMap(u))
1363 return false;
1364
1365 i_range = i_obj->GetDistance(u); // use found unit range as new range limit for next check
1366 return true;
1367 }
1368
1369 private:
1372 float i_range;
1373
1374 // prevent clone this object
1376 };
1377
1378 // Success at unit in range, range update for next check (this can be use with CreatureLastSearcher to find nearest creature)
1380 {
1381 public:
1383 : i_obj(obj), i_entry(entry), i_alive(alive), i_range(range) { }
1384
1386 {
1387 if (u->getDeathState() != DEAD
1388 && u->GetEntry() == i_entry
1389 && u->IsAlive() == i_alive
1390 && u->GetGUID() != i_obj.GetGUID()
1393 {
1394 i_range = i_obj.GetDistance(u); // use found unit range as new range limit for next check
1395 return true;
1396 }
1397 return false;
1398 }
1399
1400 private:
1404 float i_range;
1405
1406 // prevent clone this object
1408 };
1409
1410 template <typename Customizer = InRangeCheckCustomizer>
1412 {
1413 public:
1414 CreatureWithOptionsInObjectRangeCheck(WorldObject const& obj, Customizer& customizer, FindCreatureOptions const& args)
1415 : i_obj(obj), i_args(args), i_customizer(customizer) { }
1416
1417 bool operator()(Creature const* u) const
1418 {
1419 if (u->getDeathState() == DEAD) // Despawned
1420 return false;
1421
1422 if (u->GetGUID() == i_obj.GetGUID())
1423 return false;
1424
1425 if (!i_customizer.Test(u))
1426 return false;
1427
1429 return false;
1430
1432 return false;
1433
1434 if (i_args.IsAlive.has_value() && u->IsAlive() != i_args.IsAlive)
1435 return false;
1436
1437 if (i_args.IsSummon.has_value() && u->IsSummon() != i_args.IsSummon)
1438 return false;
1439
1440 if (i_args.IsInCombat.has_value() && u->IsInCombat() != i_args.IsInCombat)
1441 return false;
1442
1448 return false;
1449
1451 return false;
1452
1454 return false;
1455
1457 return false;
1458
1459 i_customizer.Update(u);
1460 return true;
1461 }
1462
1463 private:
1466 Customizer& i_customizer;
1467 };
1468
1469 template <typename Customizer = InRangeCheckCustomizer>
1471 {
1472 public:
1473 GameObjectWithOptionsInObjectRangeCheck(WorldObject const& obj, Customizer& customizer, FindGameObjectOptions const& args)
1474 : i_obj(obj), i_args(args), i_customizer(customizer) { }
1475
1476 bool operator()(GameObject const* go) const
1477 {
1478 if (i_args.IsSpawned.has_value() && i_args.IsSpawned != go->isSpawned()) // Despawned
1479 return false;
1480
1481 if (go->GetGUID() == i_obj.GetGUID())
1482 return false;
1483
1484 if (!i_customizer.Test(go))
1485 return false;
1486
1488 return false;
1489
1491 return false;
1492
1493 if (i_args.IsSummon.has_value() && (go->GetSpawnId() == 0) != i_args.IsSummon)
1494 return false;
1495
1496 if ((i_args.OwnerGuid && go->GetOwnerGUID() != i_args.OwnerGuid)
1498 return false;
1499
1501 return false;
1502
1504 return false;
1505
1507 return false;
1508
1509 i_customizer.Update(go);
1510 return true;
1511 }
1512
1513 private:
1516 Customizer& i_customizer;
1517 };
1518
1520 {
1521 public:
1522 AnyPlayerInObjectRangeCheck(WorldObject const* obj, float range, bool reqAlive = true) : _obj(obj), _range(range), _reqAlive(reqAlive) { }
1523
1524 bool operator()(Player* u) const
1525 {
1526 if (_reqAlive && !u->IsAlive())
1527 return false;
1528
1529 if (!_obj->IsWithinDist(u, _range))
1530 return false;
1531
1532 return true;
1533 }
1534
1535 private:
1537 float _range;
1539 };
1540
1542 {
1543 public:
1544 AnyPlayerInPositionRangeCheck(Position const* pos, float range, bool reqAlive = true) : _pos(pos), _range(range), _reqAlive(reqAlive) { }
1546 {
1547 if (_reqAlive && !u->IsAlive())
1548 return false;
1549
1550 if (!u->IsWithinDist3d(_pos, _range))
1551 return false;
1552
1553 return true;
1554 }
1555
1556 private:
1558 float _range;
1560 };
1561
1563 {
1564 public:
1565 NearestPlayerInObjectRangeCheck(WorldObject const* obj, float range) : i_obj(obj), i_range(range) { }
1566
1568 {
1569 if (u->IsAlive() && i_obj->IsWithinDist(u, i_range))
1570 {
1572 return true;
1573 }
1574
1575 return false;
1576 }
1577 private:
1579 float i_range;
1580
1582 };
1583
1585 {
1586 public:
1587 AllFriendlyCreaturesInGrid(Unit const* obj) : unit(obj) { }
1588
1589 bool operator()(Unit* u) const
1590 {
1591 if (u->IsAlive() && u->IsVisible() && u->IsFriendlyTo(unit))
1592 return true;
1593
1594 return false;
1595 }
1596
1597 private:
1598 Unit const* unit;
1599 };
1600
1602 {
1603 public:
1604 AllGameObjectsWithEntryInRange(WorldObject const* object, uint32 entry, float maxRange) : m_pObject(object), m_uiEntry(entry), m_fRange(maxRange) { }
1605
1606 bool operator()(GameObject* go) const
1607 {
1608 if ((!m_uiEntry || go->GetEntry() == m_uiEntry) && m_pObject->IsWithinDist(go, m_fRange, false))
1609 return true;
1610
1611 return false;
1612 }
1613
1614 private:
1618 };
1619
1621 {
1622 public:
1623 AllCreaturesOfEntryInRange(WorldObject const* object, uint32 entry, float maxRange = 0.0f) : m_pObject(object), m_uiEntry(entry), m_fRange(maxRange) { }
1624
1625 bool operator()(Unit* unit) const
1626 {
1627 if (m_uiEntry)
1628 {
1629 if (unit->GetEntry() != m_uiEntry)
1630 return false;
1631 }
1632
1633 if (m_fRange)
1634 {
1635 if (m_fRange > 0.0f && !m_pObject->IsWithinDist(unit, m_fRange, false))
1636 return false;
1637 if (m_fRange < 0.0f && m_pObject->IsWithinDist(unit, m_fRange, false))
1638 return false;
1639 }
1640
1641 return true;
1642 }
1643
1644 private:
1648 };
1649
1651 {
1652 public:
1653 PlayerAtMinimumRangeAway(Unit const* unit, float fMinRange) : unit(unit), fRange(fMinRange) { }
1654
1655 bool operator()(Player* player) const
1656 {
1657 //No threat list check, must be done explicit if expected to be in combat with creature
1658 if (!player->IsGameMaster() && player->IsAlive() && !unit->IsWithinDist(player, fRange, false))
1659 return true;
1660
1661 return false;
1662 }
1663
1664 private:
1665 Unit const* unit;
1666 float fRange;
1667 };
1668
1670 {
1671 public:
1672 GameObjectInRangeCheck(float _x, float _y, float _z, float _range, uint32 _entry = 0) :
1673 x(_x), y(_y), z(_z), range(_range), entry(_entry) { }
1674
1675 bool operator()(GameObject* go) const
1676 {
1677 if (!entry || (go->GetGOInfo() && go->GetGOInfo()->entry == entry))
1678 return go->IsInRange(x, y, z, range);
1679 else return false;
1680 }
1681
1682 private:
1683 float x, y, z, range;
1685 };
1686
1688 {
1689 public:
1690 AllWorldObjectsInRange(WorldObject const* object, float maxRange) : m_pObject(object), m_fRange(maxRange) { }
1691
1692 bool operator()(WorldObject* go) const
1693 {
1694 return m_pObject->IsWithinDist(go, m_fRange, false) && m_pObject->InSamePhase(go);
1695 }
1696
1697 private:
1700 };
1701
1703 {
1704 public:
1705 ObjectTypeIdCheck(TypeID typeId, bool equals) : _typeId(typeId), _equals(equals) { }
1706
1707 bool operator()(WorldObject* object) const
1708 {
1709 return (object->GetTypeId() == _typeId) == _equals;
1710 }
1711
1712 private:
1715 };
1716
1718 {
1719 public:
1721
1722 bool operator()(WorldObject* object) const
1723 {
1724 return object->GetGUID() == _GUID;
1725 }
1726
1727 private:
1729 };
1730
1732 {
1733 public:
1734 HeightDifferenceCheck(WorldObject* go, float diff, bool reverse)
1735 : _baseObject(go), _difference(diff), _reverse(reverse)
1736 {
1737 }
1738
1739 bool operator()(WorldObject* unit) const
1740 {
1741 return (unit->GetPositionZ() - _baseObject->GetPositionZ() > _difference) != _reverse;
1742 }
1743
1744 private:
1748 };
1749
1751 {
1752 public:
1753 UnitAuraCheck(bool present, uint32 spellId, ObjectGuid casterGUID = ObjectGuid::Empty) : _present(present), _spellId(spellId), _casterGUID(casterGUID) { }
1754
1755 bool operator()(Unit* unit) const
1756 {
1757 return unit->HasAura(_spellId, _casterGUID) == _present;
1758 }
1759
1760 bool operator()(WorldObject* object) const
1761 {
1762 return object->ToUnit() && object->ToUnit()->HasAura(_spellId, _casterGUID) == _present;
1763 }
1764
1765 private:
1769 };
1770
1772 {
1773 public:
1775
1776 bool operator()(WorldObject* object) const
1777 {
1778 return object->GetEntry() == _entry && (!object->IsPrivateObject() || object->GetPrivateObjectOwner() == _ownerGUID);
1779 }
1780
1781 private:
1784 };
1785
1786 // Player checks and do
1787
1788 // Prepare using Builder localized packets with caching and send to player
1789 template<typename Localizer>
1791 {
1792 using LocalizedAction = std::remove_pointer_t<decltype(std::declval<Localizer>()(LocaleConstant{}))>;
1793
1794 public:
1795 explicit LocalizedDo(Localizer& localizer) : _localizer(localizer) { }
1796
1797 void operator()(Player const* p);
1798
1799 private:
1800 Localizer& _localizer;
1801 std::vector<std::unique_ptr<LocalizedAction>> _localizedCache; // 0 = default, i => i-1 locale index
1802 };
1803}
1804#endif
LocaleConstant
Definition: Common.h:48
#define TC_GAME_API
Definition: Define.h:123
uint8_t uint8
Definition: Define.h:144
uint64_t uint64
Definition: Define.h:141
uint32_t uint32
Definition: Define.h:142
@ GRID_MAP_TYPE_MASK_ALL
Definition: GridDefines.h:89
std::unordered_set< ObjectGuid > GuidUnorderedSet
Definition: ObjectGuid.h:396
TypeID
Definition: ObjectGuid.h:34
@ TYPEID_UNIT
Definition: ObjectGuid.h:40
@ TYPEID_PLAYER
Definition: ObjectGuid.h:41
GameobjectTypes
@ GAMEOBJECT_TYPE_FISHINGHOLE
@ SPELL_ATTR5_NOT_ON_PLAYER_CONTROLLED_NPC
@ SPELL_ATTR5_NOT_ON_PLAYER
@ CREATURE_TYPE_NON_COMBAT_PET
@ SPELL_ATTR3_ONLY_ON_PLAYER
Team
@ TEAM_OTHER
SpellTargetCheckTypes
Definition: SpellInfo.h:81
SpellTargetObjectTypes
Definition: SpellInfo.h:65
@ DEAD
Definition: Unit.h:249
@ UNIT_STATE_CONFUSED
Definition: Unit.h:266
@ UNIT_STATE_STUNNED
Definition: Unit.h:258
Definition: Corpse.h:53
void Respawn(bool force=false)
Definition: Creature.cpp:2303
float GetAggroRange(Unit const *target) const
Definition: Creature.cpp:3322
bool HasStringId(std::string_view id) const
Definition: Creature.cpp:3165
bool CanAssistTo(Unit const *u, Unit const *enemy, bool checkfaction=true) const
Definition: Creature.cpp:2585
bool CanStartAttack(Unit const *u, bool force) const
Definition: Creature.cpp:2099
bool HasStringId(std::string_view id) const
ObjectGuid GetOwnerGUID() const override
Definition: GameObject.h:242
GameObjectTemplate const * GetGOInfo() const
Definition: GameObject.h:202
bool isSpawned() const
Definition: GameObject.h:256
bool IsInRange(float x, float y, float z, float radius) const
GameobjectTypes GetGoType() const
Definition: GameObject.h:279
ObjectGuid::LowType GetSpawnId() const
Definition: GameObject.h:212
void Respawn()
iterator end()
iterator begin()
Definition: Grid.h:46
Definition: Map.h:189
static ObjectGuid const Empty
Definition: ObjectGuid.h:274
static Creature * ToCreature(Object *o)
Definition: Object.h:219
bool IsPlayer() const
Definition: Object.h:212
TypeID GetTypeId() const
Definition: Object.h:173
uint32 GetEntry() const
Definition: Object.h:161
static ObjectGuid GetGUID(Object const *o)
Definition: Object.h:159
static Player * ToPlayer(Object *o)
Definition: Object.h:213
bool HaveAtClient(Object const *u) const
Definition: Player.cpp:23726
void SendDirectMessage(WorldPacket const *data) const
Definition: Player.cpp:6324
bool IsGameMaster() const
Definition: Player.h:1178
Team GetEffectiveTeam() const
Definition: Player.h:2239
bool HasAttribute(SpellAttr0 attribute) const
Definition: SpellInfo.h:449
bool operator()(Unit *unit) const
AllCreaturesOfEntryInRange(WorldObject const *object, uint32 entry, float maxRange=0.0f)
bool operator()(GameObject *go) const
AllGameObjectsWithEntryInRange(WorldObject const *object, uint32 entry, float maxRange)
bool operator()(WorldObject *go) const
AllWorldObjectsInRange(WorldObject const *object, float maxRange)
AnyAoETargetUnitInObjectRangeCheck(WorldObject const *obj, Unit const *funit, float range, SpellInfo const *spellInfo=nullptr, bool incOwnRadius=true, bool incTargetRadius=true)
AnyAssistCreatureInRangeCheck(Unit *funit, Unit *enemy, float range)
WorldObject const *const i_searchObj
AnyDeadUnitObjectInRangeCheck(WorldObject *searchObj, float range)
AnyDeadUnitSpellTargetInRangeCheck(WorldObject *searchObj, float range, SpellInfo const *spellInfo, SpellTargetCheckTypes check, SpellTargetObjectTypes objectType)
AnyFriendlyUnitInObjectRangeCheck(WorldObject const *obj, Unit const *funit, float range, bool playerOnly=false, bool incOwnRadius=true, bool incTargetRadius=true)
AnyGroupedUnitInObjectRangeCheck(WorldObject const *obj, Unit const *funit, float range, bool raid, bool playerOnly=false, bool incOwnRadius=true, bool incTargetRadius=true)
AnyPlayerInObjectRangeCheck(WorldObject const *obj, float range, bool reqAlive=true)
AnyPlayerInPositionRangeCheck(Position const *pos, float range, bool reqAlive=true)
AnyUnfriendlyUnitInObjectRangeCheck(WorldObject const *obj, Unit const *funit, float range)
AnyUnitInObjectRangeCheck(WorldObject const *obj, float range, bool check3D=true)
void operator()(Creature *u) const
CallOfHelpCreatureInRangeDo(Unit *funit, Unit *enemy, float range)
CreatureWithOptionsInObjectRangeCheck(WorldObject const &obj, Customizer &customizer, FindCreatureOptions const &args)
bool operator()(Creature const *u) const
FriendlyBelowHpPctEntryInRange(Unit const *obj, uint32 entry, float range, uint8 pct, bool excludeSelf)
FriendlyCCedInRange(Unit const *obj, float range)
bool operator()(Unit *u) const
FriendlyMissingBuffInRange(Unit const *obj, float range, uint32 spellid)
bool operator()(GameObject *go) const
GameObjectFocusCheck(WorldObject const *caster, uint32 focusId)
WorldObject const * _caster
GameObjectInRangeCheck(float _x, float _y, float _z, float _range, uint32 _entry=0)
bool operator()(GameObject *go) const
bool operator()(GameObject const *go) const
GameObjectWithOptionsInObjectRangeCheck(WorldObject const &obj, Customizer &customizer, FindGameObjectOptions const &args)
bool operator()(WorldObject *unit) const
HeightDifferenceCheck(WorldObject *go, float diff, bool reverse)
bool Test(WorldObject const *o) const
void Update(WorldObject const *)
InRangeCheckCustomizer(WorldObject const &obj, float range)
void operator()(Player const *p)
LocalizedDo(Localizer &localizer)
std::remove_pointer_t< decltype(std::declval< Localizer >()(LocaleConstant{}))> LocalizedAction
std::vector< std::unique_ptr< LocalizedAction > > _localizedCache
MostHPMissingInRange(Unit const *obj, float range, uint32 hp)
MostHPPercentMissingInRange(Unit const *obj, float range, uint32 minHpPct, uint32 maxHpPct)
NearestAssistCreatureInCreatureRangeCheck(NearestAssistCreatureInCreatureRangeCheck const &)=delete
NearestAssistCreatureInCreatureRangeCheck(Creature *obj, Unit *enemy, float range)
NearestAttackableNoTotemUnitInObjectRangeCheck(WorldObject const *obj, float range)
NearestAttackableUnitInObjectRangeCheck(WorldObject const *obj, Unit const *funit, float range)
NearestAttackableUnitInObjectRangeCheck(NearestAttackableUnitInObjectRangeCheck const &)=delete
NearestCheckCustomizer(WorldObject const &obj, float range)
bool Test(WorldObject const *o) const
void Update(WorldObject const *o)
NearestCreatureEntryWithLiveStateInObjectRangeCheck(WorldObject const &obj, uint32 entry, bool alive, float range)
NearestCreatureEntryWithLiveStateInObjectRangeCheck(NearestCreatureEntryWithLiveStateInObjectRangeCheck const &)=delete
NearestGameObjectCheck(WorldObject const &obj)
bool operator()(GameObject *go)
NearestGameObjectCheck(NearestGameObjectCheck const &)=delete
NearestGameObjectEntryInObjectRangeCheck(NearestGameObjectEntryInObjectRangeCheck const &)=delete
NearestGameObjectEntryInObjectRangeCheck(WorldObject const &obj, uint32 entry, float range, bool spawnedOnly=true)
NearestGameObjectFishingHole(NearestGameObjectFishingHole const &)=delete
NearestGameObjectFishingHole(WorldObject const &obj, float range)
NearestGameObjectTypeInObjectRangeCheck(NearestGameObjectTypeInObjectRangeCheck const &)=delete
NearestGameObjectTypeInObjectRangeCheck(WorldObject const &obj, GameobjectTypes type, float range)
NearestHostileUnitCheck(NearestHostileUnitCheck const &)=delete
NearestHostileUnitCheck(Creature const *creature, float dist=0.f, bool playerOnly=false)
NearestHostileUnitInAggroRangeCheck(NearestHostileUnitInAggroRangeCheck const &)=delete
NearestHostileUnitInAggroRangeCheck(Creature const *creature, bool useLOS=false, bool ignoreCivilians=false)
NearestHostileUnitInAttackDistanceCheck(Creature const *creature, float dist=0.f)
NearestHostileUnitInAttackDistanceCheck(NearestHostileUnitInAttackDistanceCheck const &)=delete
NearestPlayerInObjectRangeCheck(NearestPlayerInObjectRangeCheck const &)=delete
NearestPlayerInObjectRangeCheck(WorldObject const *obj, float range)
NearestUnspawnedGameObjectEntryInObjectRangeCheck(NearestUnspawnedGameObjectEntryInObjectRangeCheck const &)=delete
NearestUnspawnedGameObjectEntryInObjectRangeCheck(WorldObject const &obj, uint32 entry, float range)
bool operator()(WorldObject *object) const
ObjectEntryAndPrivateOwnerIfExistsCheck(ObjectGuid ownerGUID, uint32 entry)
bool operator()(WorldObject *object) const
ObjectGUIDCheck(ObjectGuid GUID)
ObjectTypeIdCheck(TypeID typeId, bool equals)
bool operator()(WorldObject *object) const
bool operator()(Player *player) const
PlayerAtMinimumRangeAway(Unit const *unit, float fMinRange)
void operator()(WorldObject *) const
void operator()(GameObject *u) const
void operator()(Corpse *) const
void operator()(Creature *u) const
WorldObjectSearcherContinuation ShouldContinue() const
void(*)(void *, Type &&) InserterType
WorldObjectSearcherContinuation ShouldContinue() const
WorldObjectSearcherContinuation ShouldContinue() const
UnitAuraCheck(bool present, uint32 spellId, ObjectGuid casterGUID=ObjectGuid::Empty)
bool operator()(WorldObject *object) const
bool operator()(Unit *unit) const
Definition: Unit.h:627
bool IsCharmed() const
Definition: Unit.h:1215
bool isTargetableForAttack(bool checkFakeDeath=true) const
Definition: Unit.cpp:8168
float GetHealthPct() const
Definition: Unit.h:784
ObjectGuid GetDemonCreatorGUID() const
Definition: Unit.h:1182
ObjectGuid GetOwnerGUID() const override
Definition: Unit.h:1170
bool IsAlive() const
Definition: Unit.h:1164
float GetCombatReach() const override
Definition: Unit.h:694
bool IsInCombatWith(Unit const *who) const
Definition: Unit.h:1044
ObjectGuid GetCreatorGUID() const override
Definition: Unit.h:1172
uint32 GetCreatureType() const
Definition: Unit.cpp:8880
bool HealthBelowPct(int32 pct) const
Definition: Unit.h:780
uint64 GetMaxHealth() const
Definition: Unit.h:777
uint64 GetHealth() const
Definition: Unit.h:776
bool IsSummon() const
Definition: Unit.h:738
bool IsVisible() const
Definition: Unit.cpp:8346
void EngageWithTarget(Unit *who)
Definition: Unit.cpp:8077
bool HasRootAura() const
Definition: Unit.h:1076
DeathState getDeathState() const
Definition: Unit.h:1167
bool HasUnitState(const uint32 f) const
Definition: Unit.h:732
bool IsInRaidWith(Unit const *unit) const
Definition: Unit.cpp:11546
bool HasAura(uint32 spellId, ObjectGuid casterGUID=ObjectGuid::Empty, ObjectGuid itemCasterGUID=ObjectGuid::Empty, uint32 reqEffMask=0) const
Definition: Unit.cpp:4664
bool IsControlledByPlayer() const
Definition: Unit.h:1193
ObjectGuid GetCharmerGUID() const
Definition: Unit.h:1187
bool IsTotem() const
Definition: Unit.h:742
bool IsFeared() const
Definition: Unit.h:1075
bool IsInPartyWith(Unit const *unit) const
Definition: Unit.cpp:11527
bool IsInCombat() const
Definition: Unit.h:1043
bool InSamePhase(PhaseShift const &phaseShift) const
Definition: Object.h:527
bool IsWithinDist3d(float x, float y, float z, float dist) const
Definition: Object.cpp:1122
bool CheckPrivateObjectOwnerVisibility(WorldObject const *seer) const
Definition: Object.cpp:1486
ObjectGuid GetPrivateObjectOwner() const
Definition: Object.h:785
bool IsValidAttackTarget(WorldObject const *target, SpellInfo const *bySpell=nullptr) const
Definition: Object.cpp:2991
bool IsHostileTo(WorldObject const *target) const
Definition: Object.cpp:2860
bool IsPrivateObject() const
Definition: Object.h:784
bool CanSeeOrDetect(WorldObject const *obj, bool implicitDetect=false, bool distanceCheck=false, bool checkAlert=false) const
Definition: Object.cpp:1514
bool IsWithinLOSInMap(WorldObject const *obj, LineOfSightChecks checks=LINEOFSIGHT_ALL_CHECKS, VMAP::ModelIgnoreFlags ignoreFlags=VMAP::ModelIgnoreFlags::Nothing) const
Definition: Object.cpp:1181
float GetDistance(WorldObject const *obj) const
Definition: Object.cpp:1078
bool IsWithinDist(WorldObject const *obj, float dist2compare, bool is3D=true, bool incOwnRadius=true, bool incTargetRadius=true) const
Definition: Object.cpp:1142
bool IsFriendlyTo(WorldObject const *target) const
Definition: Object.cpp:2865
virtual float GetCombatReach() const
Definition: Object.h:514
bool IsInMap(WorldObject const *obj) const
Definition: Object.cpp:1115
WorldObjectSearcherContinuation
Definition: Cell.h:47
Optional< std::string_view > StringId
Definition: Object.h:457
Optional< ObjectGuid > CreatorGuid
Definition: Object.h:470
Optional< bool > IsSummon
Definition: Object.h:461
bool IgnoreNotOwnedPrivateObjects
Definition: Object.h:464
bool IgnorePrivateObjects
Definition: Object.h:465
Optional< uint32 > AuraSpellId
Definition: Object.h:467
Optional< ObjectGuid > PrivateObjectOwnerGuid
Definition: Object.h:472
Optional< uint32 > CreatureId
Definition: Object.h:456
Optional< ObjectGuid > DemonCreatorGuid
Definition: Object.h:471
Optional< bool > IsAlive
Definition: Object.h:459
Optional< bool > IsInCombat
Definition: Object.h:460
Optional< ObjectGuid > OwnerGuid
Definition: Object.h:468
Optional< ObjectGuid > CharmerGuid
Definition: Object.h:469
bool IgnoreNotOwnedPrivateObjects
Definition: Object.h:484
Optional< ObjectGuid > OwnerGuid
Definition: Object.h:487
Optional< std::string_view > StringId
Definition: Object.h:478
Optional< GameobjectTypes > GameObjectType
Definition: Object.h:489
Optional< uint32 > GameObjectId
Definition: Object.h:477
Optional< ObjectGuid > PrivateObjectOwnerGuid
Definition: Object.h:488
bool IgnorePrivateObjects
Definition: Object.h:485
Optional< bool > IsSummon
Definition: Object.h:480
Optional< bool > IsSpawned
Definition: Object.h:481
uint32 GetSpellFocusRadius() const
struct GameObjectTemplate::@213::@240 fishingHole
uint32 GetSpellFocusType() const
bool IsWithinDoubleVerticalCylinder(Position const *center, float radius, float height) const
Definition: Position.cpp:93
constexpr float GetPositionZ() const
Definition: Position.h:78
void Visit(GridRefManager< T > &)
bool operator()(Unit *u) const
CreatureLastSearcher(WorldObject const *searcher, Creature *&result, Check &check)
CreatureListSearcher(WorldObject const *searcher, Container &container, Check &check)
void Visit(GridRefManager< T > &)
Definition: GridNotifiers.h:84
PhaseShift const * i_phaseShift
CreatureSearcherBase(PhaseShift const *phaseShift, Container &result, Check &check)
void Visit(GridRefManager< NOT_INTERESTED > &)
void Visit(CreatureMapType &m)
CreatureSearcher(WorldObject const *searcher, Creature *&result, Check &check)
CreatureWorker(WorldObject const *searcher, Do &_do)
void Visit(CreatureMapType &m)
void Visit(GridRefManager< NOT_INTERESTED > &)
PhaseShift const * i_phaseShift
void Visit(GridRefManager< T > &)
Definition: GridNotifiers.h:97
DelayedUnitRelocation(Cell &c, CellCoord &pair, Map &map, float radius)
Definition: GridNotifiers.h:95
GameObjectLastSearcher(WorldObject const *searcher, GameObject *&result, Check &check)
GameObjectListSearcher(WorldObject const *searcher, Container &container, Check &check)
void Visit(GameObjectMapType &m)
void Visit(GridRefManager< NOT_INTERESTED > &)
GameObjectSearcherBase(PhaseShift const *phaseShift, Container &result, Check &check)
PhaseShift const * i_phaseShift
GameObjectSearcher(WorldObject const *searcher, GameObject *&result, Check &check)
void Visit(GridRefManager< NOT_INTERESTED > &)
GameObjectWorker(WorldObject const *searcher, Functor &func)
PhaseShift const * _phaseShift
void Visit(GameObjectMapType &m)
void Visit(CorpseMapType &m)
void Visit(PlayerMapType &m)
void Visit(SceneObjectMapType &m)
void updateObjects(GridRefManager< T > &m)
void Visit(CreatureMapType &m)
void Visit(DynamicObjectMapType &m)
void Visit(AreaTriggerMapType &m)
GridUpdater(GridType &grid, uint32 diff)
void Visit(ConversationMapType &m)
void Visit(GameObjectMapType &m)
MessageDistDelivererToHostile(Unit *src, PacketSender &packetSender, float dist)
void Visit(PlayerMapType &m) const
void Visit(GridRefManager< SKIP > &) const
void SendPacket(Player const *player) const
void Visit(GridRefManager< SKIP > &) const
void SendPacket(Player const *player) const
MessageDistDeliverer(WorldObject const *src, PacketSender &packetSender, float dist, bool own_team_only=false, Player const *skipped=nullptr, bool req3dDist=false)
WorldObject const * i_source
PhaseShift const * i_phaseShift
void Visit(PlayerMapType &m) const
void Visit(PlayerMapType &)
void Visit(GridRefManager< T > &m)
void Visit(CorpseMapType &)
ObjectUpdater(const uint32 diff)
void operator()(Player const *player) const
WorldPacket const * Data
void operator()(Player const *player) const
PacketSenderRef(WorldPacket const *message)
WorldObject const * i_searcher
PlayerDistWorker(WorldObject const *searcher, float _dist, Do &_do)
void Visit(PlayerMapType &m)
void Visit(GridRefManager< NOT_INTERESTED > &)
PlayerLastSearcher(WorldObject const *searcher, Player *&result, Check &check)
PlayerListSearcher(PhaseShift const &phaseShift, Container &container, Check &check)
PlayerListSearcher(WorldObject const *searcher, Container &container, Check &check)
void Visit(GridRefManager< T > &m)
Definition: GridNotifiers.h:75
PlayerRelocationNotifier(Player &player)
Definition: GridNotifiers.h:73
PhaseShift const * i_phaseShift
void Visit(PlayerMapType &m)
void Visit(GridRefManager< NOT_INTERESTED > &)
PlayerSearcherBase(PhaseShift const *phaseShift, Container &result, Check &check)
PlayerSearcher(WorldObject const *searcher, Player *&result, Check &check)
PlayerWorker(WorldObject const *searcher, Do &_do)
PhaseShift const * i_phaseShift
void Visit(GridRefManager< NOT_INTERESTED > &)
void Visit(PlayerMapType &m)
UnitLastSearcher(WorldObject const *searcher, Unit *&result, Check &check)
UnitListSearcher(WorldObject const *searcher, Container &container, Check &check)
void VisitImpl(GridRefManager< T > &m)
void Visit(CreatureMapType &m)
PhaseShift const * i_phaseShift
UnitSearcherBase(PhaseShift const *phaseShift, Container &result, Check &check)
void Visit(PlayerMapType &m)
void Visit(GridRefManager< NOT_INTERESTED > &)
UnitSearcher(WorldObject const *searcher, Unit *&result, Check &check)
IteratorPair< WorldObject ** > i_objects
Definition: GridNotifiers.h:62
void Visit(GridRefManager< T > &)
Definition: GridNotifiers.h:65
VisibleChangesNotifier(IteratorPair< WorldObject ** > objects)
Definition: GridNotifiers.h:64
GuidUnorderedSet vis_guids
Definition: GridNotifiers.h:53
VisibleNotifier(Player &player)
Definition: GridNotifiers.h:55
void Visit(GridRefManager< T > &m)
std::set< WorldObject * > i_visibleNow
Definition: GridNotifiers.h:52
WorldObjectLastSearcher(WorldObject const *searcher, WorldObject *&result, Check &check, uint32 mapTypeMask=GRID_MAP_TYPE_MASK_ALL)
WorldObjectListSearcher(WorldObject const *searcher, Container &container, Check &check, uint32 mapTypeMask=GRID_MAP_TYPE_MASK_ALL)
void Visit(GridRefManager< T > &)
WorldObjectSearcherBase(PhaseShift const *phaseShift, Container &result, Check &check, uint32 mapTypeMask=GRID_MAP_TYPE_MASK_ALL)
WorldObjectSearcher(WorldObject const *searcher, WorldObject *&result, Check &check, uint32 mapTypeMask=GRID_MAP_TYPE_MASK_ALL)
void Visit(GridRefManager< T > &m)
WorldObjectWorker(WorldObject const *searcher, Do const &_do, uint32 mapTypeMask=GRID_MAP_TYPE_MASK_ALL)
PhaseShift const * i_phaseShift