TrinityCore
Loading...
Searching...
No Matches
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 "Creature.h"
22#include "Corpse.h"
23#include "CreatureAI.h"
24#include "DynamicObject.h"
25#include "GameObject.h"
26#include "Group.h"
27#include "Player.h"
28#include "Spell.h"
29#include "SpellInfo.h"
30#include "UnitAI.h"
31#include "UpdateData.h"
32
33namespace Trinity
34{
35 template<typename ObjectType>
36 struct GridMapTypeMaskForType : std::integral_constant<GridMapTypeMask, GridMapTypeMask(0)> { };
37
38 template<> struct GridMapTypeMaskForType<Corpse> : std::integral_constant<GridMapTypeMask, GRID_MAP_TYPE_MASK_CORPSE> { };
39 template<> struct GridMapTypeMaskForType<Creature> : std::integral_constant<GridMapTypeMask, GRID_MAP_TYPE_MASK_CREATURE> { };
40 template<> struct GridMapTypeMaskForType<DynamicObject> : std::integral_constant<GridMapTypeMask, GRID_MAP_TYPE_MASK_DYNAMICOBJECT> { };
41 template<> struct GridMapTypeMaskForType<GameObject> : std::integral_constant<GridMapTypeMask, GRID_MAP_TYPE_MASK_GAMEOBJECT> { };
42 template<> struct GridMapTypeMaskForType<Player> : std::integral_constant<GridMapTypeMask, GRID_MAP_TYPE_MASK_PLAYER> { };
43
45 {
48 std::set<Unit*> i_visibleNow;
50
51 VisibleNotifier(Player &player) : i_player(player), vis_guids(player.m_clientGUIDs) { }
52 template<class T> void Visit(GridRefManager<T> &m);
53 void SendToSelf(void);
54 };
55
57 {
59
60 explicit VisibleChangesNotifier(WorldObject &object) : i_object(object) { }
61 template<class T> void Visit(GridRefManager<T> &) { }
62 void Visit(PlayerMapType &);
63 void Visit(CreatureMapType &);
65 };
66
68 {
70
71 template<class T> void Visit(GridRefManager<T> &m) { VisibleNotifier::Visit(m); }
72 void Visit(CreatureMapType &);
73 void Visit(PlayerMapType &);
74 };
75
77 {
79 CreatureRelocationNotifier(Creature &c) : i_creature(c) { }
80 template<class T> void Visit(GridRefManager<T> &) { }
81 void Visit(CreatureMapType &);
82 void Visit(PlayerMapType &);
83 };
84
86 {
90 const float i_radius;
91 DelayedUnitRelocation(Cell &c, CellCoord &pair, Map &map, float radius) :
92 i_map(map), cell(c), p(pair), i_radius(radius) { }
93 template<class T> void Visit(GridRefManager<T> &) { }
94 void Visit(CreatureMapType &);
95 void Visit(PlayerMapType &);
96 };
97
99 {
102 explicit AIRelocationNotifier(Unit &unit) : i_unit(unit), isCreature(unit.GetTypeId() == TYPEID_UNIT) { }
103 template<class T> void Visit(GridRefManager<T> &) { }
104 void Visit(CreatureMapType &);
105 };
106
108 {
111 GridUpdater(GridType &grid, uint32 diff) : i_grid(grid), i_timeDiff(diff) { }
112
113 template<class T> void updateObjects(GridRefManager<T> &m)
114 {
115 for (typename GridRefManager<T>::iterator iter = m.begin(); iter != m.end(); ++iter)
116 iter->GetSource()->Update(i_timeDiff);
117 }
118
119 void Visit(PlayerMapType &m) { updateObjects<Player>(m); }
120 void Visit(CreatureMapType &m){ updateObjects<Creature>(m); }
121 void Visit(GameObjectMapType &m) { updateObjects<GameObject>(m); }
122 void Visit(DynamicObjectMapType &m) { updateObjects<DynamicObject>(m); }
123 void Visit(CorpseMapType &m) { updateObjects<Corpse>(m); }
124 };
125
127 {
131 float i_distSq;
135 MessageDistDeliverer(WorldObject const* src, WorldPacket const* msg, float dist, bool own_team_only = false, Player const* skipped = nullptr, bool req3dDist = false)
136 : i_source(src), i_message(msg), i_phaseMask(src->GetPhaseMask()), i_distSq(dist * dist)
137 , team(0)
138 , skipped_receiver(skipped)
139 , required3dDist(req3dDist)
140 {
141 if (own_team_only)
142 if (Player const* player = src->ToPlayer())
143 team = player->GetTeam();
144 }
145
146 void Visit(PlayerMapType &m);
147 void Visit(CreatureMapType &m);
148 void Visit(DynamicObjectMapType &m);
149 template<class SKIP> void Visit(GridRefManager<SKIP> &) { }
150
151 void SendPacket(Player* player)
152 {
153 // never send packet to self
154 if (player == i_source || (team && player->GetTeam() != team) || skipped_receiver == player)
155 return;
156
157 if (!player->HaveAtClient(i_source))
158 return;
159
160 player->SendDirectMessage(i_message);
161 }
162 };
163
165 {
169 float i_distSq;
170
171 MessageDistDelivererToHostile(Unit* src, WorldPacket const* msg, float dist)
172 : i_source(src), i_message(msg), i_phaseMask(src->GetPhaseMask()), i_distSq(dist * dist)
173 {
174 }
175
176 void Visit(PlayerMapType &m);
177 void Visit(CreatureMapType &m);
178 void Visit(DynamicObjectMapType &m);
179 template<class SKIP> void Visit(GridRefManager<SKIP> &) { }
180
181 void SendPacket(Player* player)
182 {
183 // never send packet to self
184 if (player == i_source || !player->HaveAtClient(i_source) || player->IsFriendlyTo(i_source))
185 return;
186
187 player->SendDirectMessage(i_message);
188 }
189 };
190
192 {
194 explicit ObjectUpdater(const uint32 diff) : i_timeDiff(diff) { }
195 template<class T> void Visit(GridRefManager<T> &m);
198 };
199
200 // SEARCHERS & LIST SEARCHERS & WORKERS
201
202 // WorldObject searchers & workers
204 {
205 Continue,
206 Return
207 };
208
209 template<typename Type>
211 {
212 Type& result;
213
214 protected:
215 explicit SearcherFirstObjectResult(Type& ref_) : result(ref_) { }
216
221
222 void Insert(Type object)
223 {
224 result = object;
225 }
226 };
227
228 template<typename Type>
230 {
231 Type& result;
232
233 protected:
234 explicit SearcherLastObjectResult(Type& ref_) : result(ref_) { }
235
240
241 void Insert(Type object)
242 {
243 result = object;
244 }
245 };
246
247 // Generic base class to insert elements into arbitrary containers using push_back
248 template<typename Type>
250 {
251 using InserterType = void(*)(void*, Type&&);
252
253 void* ref;
255
256 protected:
257 template<typename T>
258 explicit SearcherContainerResult(T& ref_) : ref(&ref_)
259 {
260 inserter = [](void* containerRaw, Type&& object)
261 {
262 T* container = reinterpret_cast<T*>(containerRaw);
263 container->insert(container->end(), std::move(object));
264 };
265 }
266
271
272 void Insert(Type object)
273 {
274 inserter(ref, std::move(object));
275 }
276 };
277
278 template<class Check, class Result>
280 {
283 Check& i_check;
284
285 template<typename Container>
286 WorldObjectSearcherBase(uint32 phaseMask, Container& result, Check& check, uint32 mapTypeMask = GRID_MAP_TYPE_MASK_ALL)
287 : Result(result), i_mapTypeMask(mapTypeMask), i_phaseMask(phaseMask), i_check(check) { }
288
289 template<class T>
291 };
292
293 template<class Check>
294 struct WorldObjectSearcher : WorldObjectSearcherBase<Check, SearcherFirstObjectResult<WorldObject*>>
295 {
296 WorldObjectSearcher(WorldObject const* searcher, WorldObject*& result, Check& check, uint32 mapTypeMask = GRID_MAP_TYPE_MASK_ALL)
297 : WorldObjectSearcherBase<Check, SearcherFirstObjectResult<WorldObject*>>(searcher->GetPhaseMask(), result, check, mapTypeMask) { }
298 };
299
300 template<class Check>
301 struct WorldObjectLastSearcher : WorldObjectSearcherBase<Check, SearcherLastObjectResult<WorldObject*>>
302 {
304 : WorldObjectSearcherBase<Check, SearcherLastObjectResult<WorldObject*>>(searcher->GetPhaseMask(), result, check, mapTypeMask) { }
305 };
306
307 template<class Check>
308 struct WorldObjectListSearcher : WorldObjectSearcherBase<Check, SearcherContainerResult<WorldObject*>>
309 {
310 template<typename Container>
311 WorldObjectListSearcher(WorldObject const* searcher, Container& container, Check& check, uint32 mapTypeMask = GRID_MAP_TYPE_MASK_ALL)
312 : WorldObjectSearcherBase<Check, SearcherContainerResult<WorldObject*>>(searcher->GetPhaseMask(), container, check, mapTypeMask) { }
313 };
314
315 template<class Do>
317 {
320 Do const& i_do;
321
322 WorldObjectWorker(WorldObject const* searcher, Do const& _do, uint32 mapTypeMask = GRID_MAP_TYPE_MASK_ALL)
323 : i_mapTypeMask(mapTypeMask), i_phaseMask(searcher->GetPhaseMask()), i_do(_do) { }
324
325 template<class T>
327 {
329 return;
330 for (auto itr = m.begin(); itr != m.end(); ++itr)
331 if (itr->GetSource()->InSamePhase(i_phaseMask))
332 i_do(itr->GetSource());
333 }
334 };
335
336 // Gameobject searchers
337
338 template<class Check, class Result>
340 {
342 Check &i_check;
343
344 template<typename Container>
345 GameObjectSearcherBase(uint32 phaseMask, Container& result, Check& check)
346 : Result(result), i_phaseMask(phaseMask), i_check(check) { }
347
348 void Visit(GameObjectMapType& m);
349
350 template<class NOT_INTERESTED> void Visit(GridRefManager<NOT_INTERESTED> &) { }
351 };
352
353 template<class Check>
354 struct GameObjectSearcher : GameObjectSearcherBase<Check, SearcherFirstObjectResult<GameObject*>>
355 {
356 GameObjectSearcher(WorldObject const* searcher, GameObject*& result, Check& check)
357 : GameObjectSearcherBase<Check, SearcherFirstObjectResult<GameObject*>>(searcher->GetPhaseMask(), result, check) { }
358 };
359
360 // Last accepted by Check GO if any (Check can change requirements at each call)
361 template<class Check>
362 struct GameObjectLastSearcher : GameObjectSearcherBase<Check, SearcherLastObjectResult<GameObject*>>
363 {
364 GameObjectLastSearcher(WorldObject const* searcher, GameObject*& result, Check& check)
365 : GameObjectSearcherBase<Check, SearcherLastObjectResult<GameObject*>>(searcher->GetPhaseMask(), result, check) { }
366 };
367
368 template<class Check>
369 struct GameObjectListSearcher : GameObjectSearcherBase<Check, SearcherContainerResult<GameObject*>>
370 {
371 template<typename Container>
372 GameObjectListSearcher(WorldObject const* searcher, Container& container, Check& check)
373 : GameObjectSearcherBase<Check, SearcherContainerResult<GameObject*>>(searcher->GetPhaseMask(), container, check) { }
374 };
375
376 template<class Functor>
378 {
379 GameObjectWorker(WorldObject const* searcher, Functor& func)
380 : _func(func), _phaseMask(searcher->GetPhaseMask()) { }
381
383 {
384 for (GameObjectMapType::iterator itr = m.begin(); itr != m.end(); ++itr)
385 if (itr->GetSource()->InSamePhase(_phaseMask))
386 _func(itr->GetSource());
387 }
388
389 template<class NOT_INTERESTED> void Visit(GridRefManager<NOT_INTERESTED> &) { }
390
391 private:
392 Functor& _func;
394 };
395
396 // Unit searchers
397
398 template<class Check, class Result>
399 struct UnitSearcherBase : Result
400 {
402 Check& i_check;
403
404 template<typename Container>
405 UnitSearcherBase(uint32 phaseMask, Container& result, Check& check)
406 : Result(result), i_phaseMask(phaseMask), i_check(check) { }
407
410
411 template<class NOT_INTERESTED> void Visit(GridRefManager<NOT_INTERESTED>&) { }
412
413 private:
414 template<class T> void VisitImpl(GridRefManager<T>& m);
415 };
416
417 // First accepted by Check Unit if any
418 template<class Check>
419 struct UnitSearcher : UnitSearcherBase<Check, SearcherFirstObjectResult<Unit*>>
420 {
421 UnitSearcher(WorldObject const* searcher, Unit*& result, Check& check)
422 : UnitSearcherBase<Check, SearcherFirstObjectResult<Unit*>>(searcher->GetPhaseMask(), result, check) { }
423 };
424
425 // Last accepted by Check Unit if any (Check can change requirements at each call)
426 template<class Check>
427 struct UnitLastSearcher : UnitSearcherBase<Check, SearcherLastObjectResult<Unit*>>
428 {
429 UnitLastSearcher(WorldObject const* searcher, Unit*& result, Check& check)
430 : UnitSearcherBase<Check, SearcherLastObjectResult<Unit*>>(searcher->GetPhaseMask(), result, check) { }
431 };
432
433 // All accepted by Check units if any
434 template<class Check>
435 struct UnitListSearcher : UnitSearcherBase<Check, SearcherContainerResult<Unit*>>
436 {
437 template<typename Container>
438 UnitListSearcher(WorldObject const* searcher, Container& container, Check& check)
439 : UnitSearcherBase<Check, SearcherContainerResult<Unit*>>(searcher->GetPhaseMask(), container, check) { }
440 };
441
442 // Creature searchers
443
444 template<class Check, class Result>
445 struct CreatureSearcherBase : Result
446 {
448 Check& i_check;
449
450 template<typename Container>
451 CreatureSearcherBase(uint32 phaseMask, Container& result, Check& check)
452 : Result(result), i_phaseMask(phaseMask), i_check(check) { }
453
454 void Visit(CreatureMapType& m);
455
456 template<class NOT_INTERESTED> void Visit(GridRefManager<NOT_INTERESTED> &) { }
457 };
458
459 template<class Check>
460 struct CreatureSearcher : CreatureSearcherBase<Check, SearcherFirstObjectResult<Creature*>>
461 {
462 CreatureSearcher(WorldObject const* searcher, Creature*& result, Check& check)
463 : CreatureSearcherBase<Check, SearcherFirstObjectResult<Creature*>>(searcher->GetPhaseMask(), result, check) { }
464 };
465
466 // Last accepted by Check Creature if any (Check can change requirements at each call)
467 template<class Check>
468 struct CreatureLastSearcher : CreatureSearcherBase<Check, SearcherLastObjectResult<Creature*>>
469 {
470 CreatureLastSearcher(WorldObject const* searcher, Creature*& result, Check& check)
471 : CreatureSearcherBase<Check, SearcherLastObjectResult<Creature*>>(searcher->GetPhaseMask(), result, check) { }
472 };
473
474 template<class Check>
475 struct CreatureListSearcher : CreatureSearcherBase<Check, SearcherContainerResult<Creature*>>
476 {
477 template<typename Container>
478 CreatureListSearcher(WorldObject const* searcher, Container& container, Check & check)
479 : CreatureSearcherBase<Check, SearcherContainerResult<Creature*>>(searcher->GetPhaseMask(), container, check) { }
480 };
481
482 template<class Do>
484 {
486 Do& i_do;
487
488 CreatureWorker(WorldObject const* searcher, Do& _do)
489 : i_phaseMask(searcher->GetPhaseMask()), i_do(_do) { }
490
492 {
493 for (CreatureMapType::iterator itr=m.begin(); itr != m.end(); ++itr)
494 if (itr->GetSource()->InSamePhase(i_phaseMask))
495 i_do(itr->GetSource());
496 }
497
498 template<class NOT_INTERESTED> void Visit(GridRefManager<NOT_INTERESTED> &) { }
499 };
500
501 // Player searchers
502
503 template<class Check, class Result>
504 struct PlayerSearcherBase : Result
505 {
507 Check& i_check;
508
509 template<typename Container>
510 PlayerSearcherBase(uint32 phaseMask, Container& result, Check& check)
511 : Result(result), i_phaseMask(phaseMask), i_check(check) { }
512
513 void Visit(PlayerMapType& m);
514
515 template<class NOT_INTERESTED> void Visit(GridRefManager<NOT_INTERESTED> &) { }
516 };
517
518 template<class Check>
519 struct PlayerSearcher : PlayerSearcherBase<Check, SearcherFirstObjectResult<Player*>>
520 {
521 PlayerSearcher(WorldObject const* searcher, Player*& result, Check& check)
522 : PlayerSearcherBase<Check, SearcherFirstObjectResult<Player*>>(searcher->GetPhaseMask(), result, check) { }
523 };
524
525 template<class Check>
526 struct PlayerLastSearcher : PlayerSearcherBase<Check, SearcherLastObjectResult<Player*>>
527 {
528 PlayerLastSearcher(WorldObject const* searcher, Player*& result, Check& check)
529 : PlayerSearcherBase<Check, SearcherLastObjectResult<Player*>>(searcher->GetPhaseMask(), result, check) { }
530 };
531
532 template<class Check>
533 struct PlayerListSearcher : PlayerSearcherBase<Check, SearcherContainerResult<Player*>>
534 {
535 template<typename Container>
536 PlayerListSearcher(WorldObject const* searcher, Container& container, Check& check)
537 : PlayerSearcherBase<Check, SearcherContainerResult<Player*>>(searcher->GetPhaseMask(), container, check) { }
538
539 template<typename Container>
540 PlayerListSearcher(uint32 phaseMask, Container& container, Check& check)
541 : PlayerSearcherBase<Check, SearcherContainerResult<Player*>>(phaseMask, container, check) { }
542 };
543
544 template<class Do>
546 {
548 Do& i_do;
549
550 PlayerWorker(WorldObject const* searcher, Do& _do)
551 : i_phaseMask(searcher->GetPhaseMask()), i_do(_do) { }
552
554 {
555 for (PlayerMapType::iterator itr=m.begin(); itr != m.end(); ++itr)
556 if (itr->GetSource()->InSamePhase(i_phaseMask))
557 i_do(itr->GetSource());
558 }
559
560 template<class NOT_INTERESTED> void Visit(GridRefManager<NOT_INTERESTED> &) { }
561 };
562
563 template<class Do>
565 {
567 float i_dist;
568 Do& i_do;
569
570 PlayerDistWorker(WorldObject const* searcher, float _dist, Do& _do)
571 : i_searcher(searcher), i_dist(_dist), i_do(_do) { }
572
574 {
575 for (PlayerMapType::iterator itr=m.begin(); itr != m.end(); ++itr)
576 if (itr->GetSource()->InSamePhase(i_searcher) && itr->GetSource()->IsWithinDist(i_searcher, i_dist))
577 i_do(itr->GetSource());
578 }
579
580 template<class NOT_INTERESTED> void Visit(GridRefManager<NOT_INTERESTED> &) { }
581 };
582
583 // CHECKS && DO classes
584
585 // CHECK modifiers
587 {
588 public:
589 explicit InRangeCheckCustomizer(WorldObject const& obj, float range) : i_obj(obj), i_range(range) { }
590
591 bool Test(WorldObject const* o) const
592 {
593 return i_obj.IsWithinDist(o, i_range);
594 }
595
596 void Update(WorldObject const* /*o*/) { }
597
598 private:
600 float i_range;
601 };
602
604 {
605 public:
606 explicit NearestCheckCustomizer(WorldObject const& obj, float range) : i_obj(obj), i_range(range) { }
607
608 bool Test(WorldObject const* o) const
609 {
611 }
612
613 void Update(WorldObject const* o)
614 {
616 }
617
618 private:
620 float i_range;
621 };
622
623 // WorldObject check classes
624
626 {
627 public:
628 AnyDeadUnitObjectInRangeCheck(WorldObject* searchObj, float range) : i_searchObj(searchObj), i_range(range) { }
629 bool operator()(Player* u);
630 bool operator()(Corpse* u);
631 bool operator()(Creature* u);
632 template<class NOT_INTERESTED> bool operator()(NOT_INTERESTED*) { return false; }
633 protected:
635 float i_range;
636 };
637
639 {
640 public:
641 AnyDeadUnitSpellTargetInRangeCheck(WorldObject* searchObj, float range, SpellInfo const* spellInfo, SpellTargetCheckTypes check)
642 : AnyDeadUnitObjectInRangeCheck(searchObj, range), WorldObjectSpellTargetCheck(searchObj, searchObj, spellInfo, check, nullptr)
643 { }
644 bool operator()(Player* u);
645 bool operator()(Corpse* u);
646 bool operator()(Creature* u);
647 template<class NOT_INTERESTED> bool operator()(NOT_INTERESTED*) { return false; }
648 };
649
650 // WorldObject do classes
651
653 {
654 public:
656 void operator()(Creature* u) const { u->Respawn(); }
657 void operator()(GameObject* u) const { u->Respawn(); }
658 void operator()(WorldObject*) const { }
659 void operator()(Corpse*) const { }
660 };
661
662 // GameObject checks
663
665 {
666 public:
667 GameObjectFocusCheck(WorldObject const* caster, uint32 focusId) : _caster(caster), _focusId(focusId) { }
668
669 bool operator()(GameObject* go) const
670 {
672 return false;
673
674 if (go->GetGOInfo()->spellFocus.focusId != _focusId)
675 return false;
676
677 if (!go->isSpawned())
678 return false;
679
680 float const dist = go->GetGOInfo()->spellFocus.dist;
681 return go->IsWithinDistInMap(_caster, dist);
682 }
683
684 private:
687 };
688
689 // Find the nearest Fishing hole and return true only if source object is in range of hole
691 {
692 public:
693 NearestGameObjectFishingHole(WorldObject const& obj, float range) : i_obj(obj), i_range(range) { }
694
696 {
698 {
700 return true;
701 }
702 return false;
703 }
704
705 private:
707 float i_range;
708
709 // prevent clone
711 };
712
714 {
715 public:
716 NearestGameObjectCheck(WorldObject const& obj) : i_obj(obj), i_range(999.f) { }
717
719 {
721 {
722 i_range = i_obj.GetDistance(go); // use found GO range as new range limit for next check
723 return true;
724 }
725 return false;
726 }
727
728 private:
730 float i_range;
731
732 // prevent clone this object
734 };
735
736 // Success at unit in range, range update for next check (this can be use with GameobjectLastSearcher to find nearest GO)
738 {
739 public:
740 NearestGameObjectEntryInObjectRangeCheck(WorldObject const& obj, uint32 entry, float range, bool spawnedOnly = true) : i_obj(obj), i_entry(entry), i_range(range), i_spawnedOnly(spawnedOnly) { }
741
743 {
744 if ((!i_spawnedOnly || go->isSpawned()) && go->GetEntry() == i_entry && go->GetGUID() != i_obj.GetGUID() && i_obj.IsWithinDistInMap(go, i_range))
745 {
746 i_range = i_obj.GetDistance(go); // use found GO range as new range limit for next check
747 return true;
748 }
749 return false;
750 }
751
752 private:
755 float i_range;
757
758 // prevent clone this object
760 };
761
762 // Success at unit in range, range update for next check (this can be use with GameobjectLastSearcher to find nearest unspawned GO)
764 {
765 public:
766 NearestUnspawnedGameObjectEntryInObjectRangeCheck(WorldObject const& obj, uint32 entry, float range) : i_obj(obj), i_entry(entry), i_range(range) { }
767
769 {
770 if (!go->isSpawned() && go->GetEntry() == i_entry && go->GetGUID() != i_obj.GetGUID() && i_obj.IsWithinDistInMap(go, i_range))
771 {
772 i_range = i_obj.GetDistance(go); // use found GO range as new range limit for next check
773 return true;
774 }
775 return false;
776 }
777
778 private:
781 float i_range;
782
783 // prevent clone this object
785 };
786
787 // Success at unit in range, range update for next check (this can be use with GameobjectLastSearcher to find nearest GO with a certain type)
789 {
790 public:
791 NearestGameObjectTypeInObjectRangeCheck(WorldObject const& obj, GameobjectTypes type, float range) : i_obj(obj), i_type(type), i_range(range) { }
792
794 {
795 if (go->GetGoType() == i_type && i_obj.IsWithinDistInMap(go, i_range))
796 {
797 i_range = i_obj.GetDistance(go); // use found GO range as new range limit for next check
798 return true;
799 }
800 return false;
801 }
802
803 private:
806 float i_range;
807
808 // prevent clone this object
810 };
811
812 // Unit checks
813
815 {
816 public:
817 MostHPMissingInRange(Unit const* obj, float range, uint32 hp) : i_obj(obj), i_range(range), i_hp(hp) { }
818
820 {
821 if (u->IsAlive() && u->IsInCombat() && !i_obj->IsHostileTo(u) && i_obj->IsWithinDistInMap(u, i_range) && u->GetMaxHealth() - u->GetHealth() > i_hp)
822 {
823 i_hp = u->GetMaxHealth() - u->GetHealth();
824 return true;
825 }
826 return false;
827 }
828
829 private:
830 Unit const* i_obj;
831 float i_range;
833 };
834
836 {
837 public:
838 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) { }
839
841 {
842 if (u->IsAlive() && u->IsInCombat() && !i_obj->IsHostileTo(u) && i_obj->IsWithinDistInMap(u, i_range) && i_minHpPct <= u->GetHealthPct() && u->GetHealthPct() <= i_maxHpPct && u->GetHealthPct() < i_hpPct)
843 {
844 i_hpPct = u->GetHealthPct();
845 return true;
846 }
847 return false;
848 }
849
850 private:
851 Unit const* i_obj;
852 float i_range;
854 };
855
857 {
858 public:
859 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) { }
860
862 {
863 if (i_excludeSelf && i_obj->GetGUID() == u->GetGUID())
864 return false;
865 if (u->GetEntry() == i_entry && u->IsAlive() && u->IsInCombat() && !i_obj->IsHostileTo(u) && i_obj->IsWithinDistInMap(u, i_range) && u->HealthBelowPct(i_pct))
866 return true;
867 return false;
868 }
869
870 private:
871 Unit const* i_obj;
873 float i_range;
876 };
877
879 {
880 public:
881 MostHPMissingGroupInRange(Unit const* obj, float range, uint32 hp) : i_obj(obj), i_range(range), i_hp(hp) { }
882
884 {
885 if (i_obj == u)
886 return false;
887
888 Player* player = nullptr;
889 if (u->GetTypeId() == TYPEID_PLAYER)
890 player = u->ToPlayer();
891 else if (u->IsPet() && u->GetOwner())
892 player = u->GetOwner()->ToPlayer();
893
894 if (!player)
895 return false;
896
897 Group* group = player->GetGroup();
898 if (!group || !group->IsMember(i_obj->IsPet() ? i_obj->GetOwnerGUID() : i_obj->GetGUID()))
899 return false;
900
901 if (u->IsAlive() && !i_obj->IsHostileTo(u) && i_obj->IsWithinDistInMap(u, i_range) && u->GetMaxHealth() - u->GetHealth() > i_hp)
902 {
903 i_hp = u->GetMaxHealth() - u->GetHealth();
904 return true;
905 }
906
907 return false;
908 }
909
910 private:
911 Unit const* i_obj;
912 float i_range;
914 };
915
917 {
918 public:
919 FriendlyCCedInRange(Unit const* obj, float range) : i_obj(obj), i_range(range) { }
920
921 bool operator()(Unit* u) const
922 {
923 if (u->IsAlive() && u->IsInCombat() && !i_obj->IsHostileTo(u) && i_obj->IsWithinDistInMap(u, i_range) &&
925 {
926 return true;
927 }
928 return false;
929 }
930
931 private:
932 Unit const* i_obj;
933 float i_range;
934 };
935
937 {
938 public:
939 FriendlyMissingBuffInRange(Unit const* obj, float range, uint32 spellid) : i_obj(obj), i_range(range), i_spell(spellid) { }
940
941 bool operator()(Unit* u) const
942 {
943 if (u->IsAlive() && u->IsInCombat() && !i_obj->IsHostileTo(u) && i_obj->IsWithinDistInMap(u, i_range) && !u->HasAura(i_spell))
944 return true;
945
946 return false;
947 }
948
949 private:
950 Unit const* i_obj;
951 float i_range;
953 };
954
956 {
957 public:
958 AnyUnfriendlyUnitInObjectRangeCheck(WorldObject const* obj, Unit const* funit, float range) : i_obj(obj), i_funit(funit), i_range(range) { }
959
960 bool operator()(Unit* u) const
961 {
963 return true;
964
965 return false;
966 }
967
968 private:
970 Unit const* i_funit;
971 float i_range;
972 };
973
975 {
976 public:
978
980 {
981 if (!u->IsAlive())
982 return false;
983
985 return false;
986
987 if (u->GetTypeId() == TYPEID_UNIT && u->ToCreature()->IsTotem())
988 return false;
989
990 if (!u->isTargetableForAttack(false))
991 return false;
992
994 return false;
995
997 return true;
998 }
999
1000 private:
1002 float i_range;
1003 };
1004
1006 {
1007 public:
1008 AnyFriendlyUnitInObjectRangeCheck(WorldObject const* obj, Unit const* funit, float range, bool playerOnly = false, bool incOwnRadius = true, bool incTargetRadius = true)
1009 : i_obj(obj), i_funit(funit), i_range(range), i_playerOnly(playerOnly), i_incOwnRadius(incOwnRadius), i_incTargetRadius(incTargetRadius) { }
1010
1011 bool operator()(Unit* u) const
1012 {
1013 if (!u->IsAlive())
1014 return false;
1015
1016 float searchRadius = i_range;
1017 if (i_incOwnRadius)
1018 searchRadius += i_obj->GetCombatReach();
1020 searchRadius += u->GetCombatReach();
1021
1022 if (!u->IsInMap(i_obj) || !u->InSamePhase(i_obj) || !u->IsWithinDoubleVerticalCylinder(i_obj, searchRadius, searchRadius))
1023 return false;
1024
1025 if (!i_funit->IsFriendlyTo(u))
1026 return false;
1027
1028 return !i_playerOnly || u->GetTypeId() == TYPEID_PLAYER;
1029 }
1030
1031 private:
1034 float i_range;
1038 };
1039
1041 {
1042 public:
1043 AnyGroupedUnitInObjectRangeCheck(WorldObject const* obj, Unit const* funit, float range, bool raid, bool playerOnly = false, bool incOwnRadius = true, bool incTargetRadius = true)
1044 : _source(obj), _refUnit(funit), _range(range), _raid(raid), _playerOnly(playerOnly), i_incOwnRadius(incOwnRadius), i_incTargetRadius(incTargetRadius) { }
1045
1046 bool operator()(Unit* u) const
1047 {
1048 if (_playerOnly && u->GetTypeId() != TYPEID_PLAYER)
1049 return false;
1050
1051 if (_raid)
1052 {
1053 if (!_refUnit->IsInRaidWith(u))
1054 return false;
1055 }
1056 else if (!_refUnit->IsInPartyWith(u))
1057 return false;
1058
1059 if (_refUnit->IsHostileTo(u))
1060 return false;
1061
1062 if (!u->IsAlive())
1063 return false;
1064
1065 float searchRadius = _range;
1066 if (i_incOwnRadius)
1067 searchRadius += _source->GetCombatReach();
1069 searchRadius += u->GetCombatReach();
1070
1071 return u->IsInMap(_source) && u->InSamePhase(_source) && u->IsWithinDoubleVerticalCylinder(_source, searchRadius, searchRadius);
1072 }
1073
1074 private:
1077 float _range;
1078 bool _raid;
1082 };
1083
1085 {
1086 public:
1087 AnyUnitInObjectRangeCheck(WorldObject const* obj, float range) : i_obj(obj), i_range(range) { }
1088
1089 bool operator()(Unit* u) const
1090 {
1091 if (u->IsAlive() && i_obj->IsWithinDistInMap(u, i_range))
1092 return true;
1093
1094 return false;
1095 }
1096
1097 private:
1099 float i_range;
1100 };
1101
1102 // Success at unit in range, range update for next check (this can be use with UnitLastSearcher to find nearest unit)
1104 {
1105 public:
1106 NearestAttackableUnitInObjectRangeCheck(WorldObject const* obj, Unit const* funit, float range) : i_obj(obj), i_funit(funit), i_range(range) { }
1107
1109 {
1112 {
1113 i_range = i_obj->GetDistance(u); // use found unit range as new range limit for next check
1114 return true;
1115 }
1116
1117 return false;
1118 }
1119
1120 private:
1123 float i_range;
1124
1125 // prevent clone this object
1127 };
1128
1130 {
1131 public:
1132 AnyAoETargetUnitInObjectRangeCheck(WorldObject const* obj, Unit const* funit, float range, SpellInfo const* spellInfo = nullptr, bool incOwnRadius = true, bool incTargetRadius = true)
1133 : i_obj(obj), i_funit(funit), _spellInfo(spellInfo), i_range(range), i_incOwnRadius(incOwnRadius), i_incTargetRadius(incTargetRadius)
1134 {
1135 }
1136
1137 bool operator()(Unit* u) const
1138 {
1139 // Check contains checks for: live, uninteractible, non-attackable flags, flight check and GM check, ignore totems
1140 if (u->GetTypeId() == TYPEID_UNIT && u->IsTotem())
1141 return false;
1142
1144 return false;
1145
1147 return false;
1148
1149 float searchRadius = i_range;
1150 if (i_incOwnRadius)
1151 searchRadius += i_obj->GetCombatReach();
1153 searchRadius += u->GetCombatReach();
1154
1155 return u->IsInMap(i_obj) && u->InSamePhase(i_obj) && u->IsWithinDoubleVerticalCylinder(i_obj, searchRadius, searchRadius);
1156 }
1157
1158 private:
1162 float i_range;
1165 };
1166
1167 // do attack at call of help to friendly crearture
1169 {
1170 public:
1171 CallOfHelpCreatureInRangeDo(Unit* funit, Unit* enemy, float range)
1172 : i_funit(funit), i_enemy(enemy), i_range(range) { }
1173
1174 void operator()(Creature* u) const
1175 {
1176 if (u == i_funit)
1177 return;
1178
1179 if (!u->CanAssistTo(i_funit, i_enemy, false))
1180 return;
1181
1182 // too far
1183 // Don't use combat reach distance, range must be an absolute value, otherwise the chain aggro range will be too big
1184 if (!u->IsWithinDistInMap(i_funit, i_range, true, false, false))
1185 return;
1186
1187 // only if see assisted creature's enemy
1188 if (!u->IsWithinLOSInMap(i_enemy))
1189 return;
1190
1192 }
1193 private:
1196 float i_range;
1197 };
1198
1199 // Creature checks
1200
1202 {
1203 public:
1204 explicit NearestHostileUnitCheck(Creature const* creature, float dist = 0.f, bool playerOnly = false) : me(creature), i_playerOnly(playerOnly)
1205 {
1206 m_range = (dist == 0.f ? 9999.f : dist);
1207 }
1208
1210 {
1211 if (!me->IsWithinDistInMap(u, m_range))
1212 return false;
1213
1214 if (!me->IsValidAttackTarget(u))
1215 return false;
1216
1217 if (i_playerOnly && u->GetTypeId() != TYPEID_PLAYER)
1218 return false;
1219
1220 m_range = me->GetDistance(u); // use found unit range as new range limit for next check
1221 return true;
1222 }
1223
1224 private:
1225 Creature const* me;
1226 float m_range;
1229 };
1230
1232 {
1233 public:
1234 explicit NearestHostileUnitInAttackDistanceCheck(Creature const* creature, float dist = 0.f) : me(creature)
1235 {
1236 m_range = (dist == 0.f ? 9999.f : dist);
1237 m_force = (dist == 0.f ? false : true);
1238 }
1239
1241 {
1242 if (!me->IsWithinDistInMap(u, m_range))
1243 return false;
1244
1245 if (!me->CanSeeOrDetect(u))
1246 return false;
1247
1248 if (m_force)
1249 {
1250 if (!me->IsValidAttackTarget(u))
1251 return false;
1252 }
1253 else if (!me->CanStartAttack(u, false))
1254 return false;
1255
1256 m_range = me->GetDistance(u); // use found unit range as new range limit for next check
1257 return true;
1258 }
1259
1260 private:
1261 Creature const* me;
1262 float m_range;
1265 };
1266
1268 {
1269 public:
1270 explicit NearestHostileUnitInAggroRangeCheck(Creature const* creature, bool useLOS = false, bool ignoreCivilians = false) : _me(creature), _useLOS(useLOS), _ignoreCivilians(ignoreCivilians) { }
1271
1272 bool operator()(Unit* u) const
1273 {
1274 if (!u->IsHostileTo(_me))
1275 return false;
1276
1277 if (!u->IsWithinDistInMap(_me, _me->GetAggroRange(u)))
1278 return false;
1279
1280 if (!_me->IsValidAttackTarget(u))
1281 return false;
1282
1283 if (_useLOS && !u->IsWithinLOSInMap(_me))
1284 return false;
1285
1286 // pets in aggressive do not attack civilians
1287 if (_ignoreCivilians)
1288 if (Creature* c = u->ToCreature())
1289 if (c->IsCivilian())
1290 return false;
1291
1292 return true;
1293 }
1294
1295 private:
1300 };
1301
1303 {
1304 public:
1305 AnyAssistCreatureInRangeCheck(Unit* funit, Unit* enemy, float range)
1306 : i_funit(funit), i_enemy(enemy), i_range(range) { }
1307
1308 bool operator()(Creature* u) const
1309 {
1310 if (u == i_funit)
1311 return false;
1312
1313 if (!u->CanAssistTo(i_funit, i_enemy))
1314 return false;
1315
1316 // too far
1317 // Don't use combat reach distance, range must be an absolute value, otherwise the chain aggro range will be too big
1318 if (!i_funit->IsWithinDistInMap(u, i_range, true, false, false))
1319 return false;
1320
1321 // only if see assisted creature
1322 if (!i_funit->IsWithinLOSInMap(u))
1323 return false;
1324
1325 return true;
1326 }
1327
1328 private:
1331 float i_range;
1332 };
1333
1335 {
1336 public:
1338 : i_obj(obj), i_enemy(enemy), i_range(range) { }
1339
1341 {
1342 if (u == i_obj)
1343 return false;
1344 if (!u->CanAssistTo(i_obj, i_enemy))
1345 return false;
1346
1347 // Don't use combat reach distance, range must be an absolute value, otherwise the chain aggro range will be too big
1348 if (!i_obj->IsWithinDistInMap(u, i_range, true, false, false))
1349 return false;
1350
1351 if (!i_obj->IsWithinLOSInMap(u))
1352 return false;
1353
1354 i_range = i_obj->GetDistance(u); // use found unit range as new range limit for next check
1355 return true;
1356 }
1357
1358 private:
1361 float i_range;
1362
1363 // prevent clone this object
1365 };
1366
1367 // Success at unit in range, range update for next check (this can be use with CreatureLastSearcher to find nearest creature)
1369 {
1370 public:
1372 : i_obj(obj), i_entry(entry), i_alive(alive), i_range(range) { }
1373
1375 {
1376 if (u->getDeathState() != DEAD
1377 && u->GetEntry() == i_entry
1378 && u->IsAlive() == i_alive
1379 && u->GetGUID() != i_obj.GetGUID()
1382 {
1383 i_range = i_obj.GetDistance(u); // use found unit range as new range limit for next check
1384 return true;
1385 }
1386 return false;
1387 }
1388
1389 private:
1393 float i_range;
1394
1395 // prevent clone this object
1397 };
1398
1399 template <typename Customizer = InRangeCheckCustomizer>
1401 {
1402 public:
1403 CreatureWithOptionsInObjectRangeCheck(WorldObject const& obj, Customizer& customizer, FindCreatureOptions const& args)
1404 : i_obj(obj), i_args(args), i_customizer(customizer) { }
1405
1406 bool operator()(Creature const* u) const
1407 {
1408 if (u->getDeathState() == DEAD) // Despawned
1409 return false;
1410
1411 if (u->GetGUID() == i_obj.GetGUID())
1412 return false;
1413
1414 if (!i_customizer.Test(u))
1415 return false;
1416
1418 return false;
1419
1421 return false;
1422
1423 if (i_args.IsAlive.has_value() && u->IsAlive() != i_args.IsAlive)
1424 return false;
1425
1426 if (i_args.IsSummon.has_value() && u->IsSummon() != i_args.IsSummon)
1427 return false;
1428
1429 if (i_args.IsInCombat.has_value() && u->IsInCombat() != i_args.IsInCombat)
1430 return false;
1431
1436 return false;
1437
1439 return false;
1440
1442 return false;
1443
1445 return false;
1446
1447 i_customizer.Update(u);
1448 return true;
1449 }
1450
1451 private:
1454 Customizer& i_customizer;
1455 };
1456
1457 template <typename Customizer = InRangeCheckCustomizer>
1459 {
1460 public:
1461 GameObjectWithOptionsInObjectRangeCheck(WorldObject const& obj, Customizer& customizer, FindGameObjectOptions const& args)
1462 : i_obj(obj), i_args(args), i_customizer(customizer) { }
1463
1464 bool operator()(GameObject const* go) const
1465 {
1466 if (i_args.IsSpawned.has_value() && i_args.IsSpawned != go->isSpawned()) // Despawned
1467 return false;
1468
1469 if (go->GetGUID() == i_obj.GetGUID())
1470 return false;
1471
1472 if (!i_customizer.Test(go))
1473 return false;
1474
1476 return false;
1477
1479 return false;
1480
1481 if (i_args.IsSummon.has_value() && (go->GetSpawnId() == 0) != i_args.IsSummon)
1482 return false;
1483
1484 if ((i_args.OwnerGuid && go->GetOwnerGUID() != i_args.OwnerGuid)
1486 return false;
1487
1489 return false;
1490
1492 return false;
1493
1495 return false;
1496
1497 i_customizer.Update(go);
1498 return true;
1499 }
1500
1501 private:
1504 Customizer& i_customizer;
1505 };
1506
1508 {
1509 public:
1510 AnyPlayerInObjectRangeCheck(WorldObject const* obj, float range, bool reqAlive = true) : _obj(obj), _range(range), _reqAlive(reqAlive) { }
1511
1512 bool operator()(Player* u) const
1513 {
1514 if (_reqAlive && !u->IsAlive())
1515 return false;
1516
1517 if (!_obj->IsWithinDistInMap(u, _range))
1518 return false;
1519
1520 return true;
1521 }
1522
1523 private:
1525 float _range;
1527 };
1528
1530 {
1531 public:
1532 AnyPlayerInPositionRangeCheck(Position const* pos, float range, bool reqAlive = true) : _pos(pos), _range(range), _reqAlive(reqAlive) { }
1534 {
1535 if (_reqAlive && !u->IsAlive())
1536 return false;
1537
1538 if (!u->IsWithinDist3d(_pos, _range))
1539 return false;
1540
1541 return true;
1542 }
1543
1544 private:
1546 float _range;
1548 };
1549
1551 {
1552 public:
1553 NearestPlayerInObjectRangeCheck(WorldObject const* obj, float range) : i_obj(obj), i_range(range) { }
1554
1556 {
1557 if (u->IsAlive() && i_obj->IsWithinDistInMap(u, i_range))
1558 {
1560 return true;
1561 }
1562
1563 return false;
1564 }
1565 private:
1567 float i_range;
1568
1570 };
1571
1573 {
1574 public:
1575 AllFriendlyCreaturesInGrid(Unit const* obj) : unit(obj) { }
1576
1577 bool operator()(Unit* u) const
1578 {
1579 if (u->IsAlive() && u->IsVisible() && u->IsFriendlyTo(unit))
1580 return true;
1581
1582 return false;
1583 }
1584
1585 private:
1586 Unit const* unit;
1587 };
1588
1590 {
1591 public:
1592 AllGameObjectsWithEntryInRange(WorldObject const* object, uint32 entry, float maxRange) : m_pObject(object), m_uiEntry(entry), m_fRange(maxRange) { }
1593
1594 bool operator()(GameObject* go) const
1595 {
1596 if ((!m_uiEntry || go->GetEntry() == m_uiEntry) && m_pObject->IsWithinDist(go, m_fRange, false))
1597 return true;
1598
1599 return false;
1600 }
1601
1602 private:
1606 };
1607
1609 {
1610 public:
1611 AllCreaturesOfEntryInRange(WorldObject const* object, uint32 entry, float maxRange = 0.0f) : m_pObject(object), m_uiEntry(entry), m_fRange(maxRange) { }
1612
1613 bool operator()(Unit* unit) const
1614 {
1615 if (m_uiEntry)
1616 {
1617 if (unit->GetEntry() != m_uiEntry)
1618 return false;
1619 }
1620
1621 if (m_fRange)
1622 {
1623 if (m_fRange > 0.0f && !m_pObject->IsWithinDist(unit, m_fRange, false))
1624 return false;
1625 if (m_fRange < 0.0f && m_pObject->IsWithinDist(unit, m_fRange, false))
1626 return false;
1627 }
1628
1629 return true;
1630 }
1631
1632 private:
1636 };
1637
1639 {
1640 public:
1641 PlayerAtMinimumRangeAway(Unit const* unit, float fMinRange) : unit(unit), fRange(fMinRange) { }
1642
1643 bool operator()(Player* player) const
1644 {
1645 //No threat list check, must be done explicit if expected to be in combat with creature
1646 if (!player->IsGameMaster() && player->IsAlive() && !unit->IsWithinDist(player, fRange, false))
1647 return true;
1648
1649 return false;
1650 }
1651
1652 private:
1653 Unit const* unit;
1654 float fRange;
1655 };
1656
1658 {
1659 public:
1660 GameObjectInRangeCheck(float _x, float _y, float _z, float _range, uint32 _entry = 0) :
1661 x(_x), y(_y), z(_z), range(_range), entry(_entry) { }
1662
1663 bool operator()(GameObject* go) const
1664 {
1665 if (!entry || (go->GetGOInfo() && go->GetGOInfo()->entry == entry))
1666 return go->IsInRange(x, y, z, range);
1667 else return false;
1668 }
1669
1670 private:
1671 float x, y, z, range;
1673 };
1674
1676 {
1677 public:
1678 AllWorldObjectsInRange(WorldObject const* object, float maxRange) : m_pObject(object), m_fRange(maxRange) { }
1679
1680 bool operator()(WorldObject* go) const
1681 {
1682 return m_pObject->IsWithinDist(go, m_fRange, false) && m_pObject->InSamePhase(go);
1683 }
1684
1685 private:
1688 };
1689
1691 {
1692 public:
1693 ObjectTypeIdCheck(TypeID typeId, bool equals) : _typeId(typeId), _equals(equals) { }
1694
1695 bool operator()(WorldObject* object) const
1696 {
1697 return (object->GetTypeId() == _typeId) == _equals;
1698 }
1699
1700 private:
1703 };
1704
1706 {
1707 public:
1709
1710 bool operator()(WorldObject* object) const
1711 {
1712 return object->GetGUID() == _GUID;
1713 }
1714
1715 private:
1717 };
1718
1720 {
1721 public:
1722 HeightDifferenceCheck(WorldObject* go, float diff, bool reverse)
1723 : _baseObject(go), _difference(diff), _reverse(reverse)
1724 {
1725 }
1726
1727 bool operator()(WorldObject* unit) const
1728 {
1729 return (unit->GetPositionZ() - _baseObject->GetPositionZ() > _difference) != _reverse;
1730 }
1731
1732 private:
1736 };
1737
1739 {
1740 public:
1741 UnitAuraCheck(bool present, uint32 spellId, ObjectGuid casterGUID = ObjectGuid::Empty) : _present(present), _spellId(spellId), _casterGUID(casterGUID) { }
1742
1743 bool operator()(Unit* unit) const
1744 {
1745 return unit->HasAura(_spellId, _casterGUID) == _present;
1746 }
1747
1748 bool operator()(WorldObject* object) const
1749 {
1750 return object->ToUnit() && object->ToUnit()->HasAura(_spellId, _casterGUID) == _present;
1751 }
1752
1753 private:
1757 };
1758
1759 // Player checks and do
1760
1761 // Prepare using Builder localized packets with caching and send to player
1762 template<class Builder>
1764 {
1765 public:
1766 explicit LocalizedPacketDo(Builder& builder) : i_builder(builder) { }
1767
1769 {
1770 for (size_t i = 0; i < i_data_cache.size(); ++i)
1771 delete i_data_cache[i];
1772 }
1773
1774 void operator()(Player* p);
1775
1776 private:
1777 Builder& i_builder;
1778 std::vector<WorldPacket*> i_data_cache; // 0 = default, i => i-1 locale index
1779 };
1780
1781 // Prepare using Builder localized packets with caching and send to player
1782 template<class Builder>
1784 {
1785 public:
1786 typedef std::vector<WorldPacket*> WorldPacketList;
1787 explicit LocalizedPacketListDo(Builder& builder) : i_builder(builder) { }
1788
1790 {
1791 for (size_t i = 0; i < i_data_cache.size(); ++i)
1792 for (size_t j = 0; j < i_data_cache[i].size(); ++j)
1793 delete i_data_cache[i][j];
1794 }
1795 void operator()(Player* p);
1796
1797 private:
1798 Builder& i_builder;
1799 std::vector<WorldPacketList> i_data_cache;
1800 // 0 = default, i => i-1 locale index
1801 };
1802}
1803#endif
#define TC_GAME_API
Definition Define.h:114
uint8_t uint8
Definition Define.h:135
uint32_t uint32
Definition Define.h:133
@ GRID_MAP_TYPE_MASK_ALL
Definition GridDefines.h:76
std::unordered_set< ObjectGuid > GuidUnorderedSet
Definition ObjectGuid.h:263
TypeID
Definition ObjectGuid.h:34
@ TYPEID_UNIT
Definition ObjectGuid.h:38
@ TYPEID_PLAYER
Definition ObjectGuid.h:39
GameobjectTypes
@ GAMEOBJECT_TYPE_SPELL_FOCUS
@ GAMEOBJECT_TYPE_FISHINGHOLE
@ CREATURE_TYPE_NON_COMBAT_PET
@ SPELL_ATTR3_ONLY_TARGET_PLAYERS
SpellTargetCheckTypes
Definition SpellInfo.h:78
@ DEAD
Definition Unit.h:214
@ UNIT_STATE_CONFUSED
Definition Unit.h:231
@ UNIT_STATE_STUNNED
Definition Unit.h:223
void Respawn(bool force=false)
float GetAggroRange(Unit const *target) const
bool HasStringId(std::string_view id) const
bool CanAssistTo(Unit const *u, Unit const *enemy, bool checkfaction=true) const
bool CanStartAttack(Unit const *u, bool force) const
bool HasStringId(std::string_view id) const
ObjectGuid GetOwnerGUID() const override
Definition GameObject.h:141
bool IsWithinDistInMap(Player const *player) const
GameObjectTemplate const * GetGOInfo() const
Definition GameObject.h:102
bool isSpawned() const
Definition GameObject.h:155
bool IsInRange(float x, float y, float z, float radius) const
GameobjectTypes GetGoType() const
Definition GameObject.h:176
ObjectGuid::LowType GetSpawnId() const
Definition GameObject.h:112
iterator begin()
Definition Grid.h:46
Definition Group.h:165
bool IsMember(ObjectGuid guid) const
Definition Group.cpp:2505
Definition Map.h:281
static ObjectGuid const Empty
Definition ObjectGuid.h:140
static Creature * ToCreature(Object *o)
Definition Object.h:186
TypeID GetTypeId() const
Definition Object.h:93
uint32 GetEntry() const
Definition Object.h:81
static ObjectGuid GetGUID(Object const *o)
Definition Object.h:78
static Player * ToPlayer(Object *o)
Definition Object.h:180
bool HaveAtClient(Object const *u) const
Definition Player.cpp:22068
uint32 GetTeam() const
Definition Player.h:1832
void SendDirectMessage(WorldPacket const *data) const
Definition Player.cpp:6161
Group * GetGroup()
Definition Player.h:2171
bool IsGameMaster() const
Definition Player.h:998
bool HasAttribute(SpellAttr0 attribute) const
Definition SpellInfo.h:375
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)
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)
CallOfHelpCreatureInRangeDo(Unit *funit, Unit *enemy, float range)
CreatureWithOptionsInObjectRangeCheck(WorldObject const &obj, Customizer &customizer, FindCreatureOptions const &args)
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)
LocalizedPacketDo(Builder &builder)
std::vector< WorldPacket * > i_data_cache
std::vector< WorldPacket * > WorldPacketList
LocalizedPacketListDo(Builder &builder)
std::vector< WorldPacketList > i_data_cache
MostHPMissingGroupInRange(Unit const *obj, float range, uint32 hp)
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
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:769
bool IsCharmed() const
Definition Unit.h:1280
bool isTargetableForAttack(bool checkFakeDeath=true) const
Definition Unit.cpp:8367
float GetHealthPct() const
Definition Unit.h:921
ObjectGuid GetCreatorGUID() const
Definition Unit.h:1243
ObjectGuid GetOwnerGUID() const override
Definition Unit.h:1241
bool IsPet() const
Definition Unit.h:884
uint32 GetMaxHealth() const
Definition Unit.h:914
bool IsAlive() const
Definition Unit.h:1234
float GetCombatReach() const override
Definition Unit.h:839
bool IsInCombatWith(Unit const *who) const
Definition Unit.h:1145
bool HasAura(uint32 spellId, ObjectGuid casterGUID=ObjectGuid::Empty, ObjectGuid itemCasterGUID=ObjectGuid::Empty, uint8 reqEffMask=0) const
Definition Unit.cpp:4535
uint32 GetCreatureType() const
Definition Unit.cpp:8940
bool HealthBelowPct(int32 pct) const
Definition Unit.h:917
bool IsSummon() const
Definition Unit.h:882
uint32 GetHealth() const
Definition Unit.h:913
bool IsVisible() const
Definition Unit.cpp:8508
void EngageWithTarget(Unit *who)
Definition Unit.cpp:8292
bool IsRooted() const
Definition Unit.h:1168
DeathState getDeathState() const
Definition Unit.h:1238
bool HasUnitState(const uint32 f) const
Definition Unit.h:876
bool IsInRaidWith(Unit const *unit) const
Definition Unit.cpp:11892
ObjectGuid GetCharmerGUID() const
Definition Unit.h:1252
bool IsTotem() const
Definition Unit.h:886
bool IsFeared() const
Definition Unit.h:1167
bool IsInPartyWith(Unit const *unit) const
Definition Unit.cpp:11873
bool IsInCombat() const
Definition Unit.h:1144
bool IsWithinDist3d(float x, float y, float z, float dist) const
Definition Object.cpp:1167
bool CheckPrivateObjectOwnerVisibility(WorldObject const *seer) const
Definition Object.cpp:1531
ObjectGuid GetPrivateObjectOwner() const
Definition Object.h:595
bool IsValidAttackTarget(WorldObject const *target, SpellInfo const *bySpell=nullptr) const
Definition Object.cpp:2856
bool IsHostileTo(WorldObject const *target) const
Definition Object.cpp:2796
Unit * GetOwner() const
Definition Object.cpp:2180
bool IsPrivateObject() const
Definition Object.h:594
bool CanSeeOrDetect(WorldObject const *obj, bool implicitDetect=false, bool distanceCheck=false, bool checkAlert=false) const
Definition Object.cpp:1547
bool InSamePhase(uint32 phasemask) const
Definition Object.h:369
bool IsWithinLOSInMap(WorldObject const *obj, LineOfSightChecks checks=LINEOFSIGHT_ALL_CHECKS, VMAP::ModelIgnoreFlags ignoreFlags=VMAP::ModelIgnoreFlags::Nothing) const
Definition Object.cpp:1226
bool IsWithinDistInMap(WorldObject const *obj, float dist2compare, bool is3D=true, bool incOwnRadius=true, bool incTargetRadius=true) const
Definition Object.cpp:1192
float GetDistance(WorldObject const *obj) const
Definition Object.cpp:1123
bool IsWithinDist(WorldObject const *obj, float dist2compare, bool is3D=true) const
Definition Object.cpp:1187
bool IsFriendlyTo(WorldObject const *target) const
Definition Object.cpp:2801
virtual float GetCombatReach() const
Definition Object.h:358
bool IsInMap(WorldObject const *obj) const
Definition Object.cpp:1160
WorldObjectSearcherContinuation
Definition Cell.h:47
Optional< std::string_view > StringId
Definition Object.h:302
Optional< ObjectGuid > CreatorGuid
Definition Object.h:315
Optional< bool > IsSummon
Definition Object.h:306
bool IgnoreNotOwnedPrivateObjects
Definition Object.h:309
bool IgnorePrivateObjects
Definition Object.h:310
Optional< uint32 > AuraSpellId
Definition Object.h:312
Optional< ObjectGuid > PrivateObjectOwnerGuid
Definition Object.h:316
Optional< uint32 > CreatureId
Definition Object.h:301
Optional< bool > IsAlive
Definition Object.h:304
Optional< bool > IsInCombat
Definition Object.h:305
Optional< ObjectGuid > OwnerGuid
Definition Object.h:313
Optional< ObjectGuid > CharmerGuid
Definition Object.h:314
bool IgnoreNotOwnedPrivateObjects
Definition Object.h:328
Optional< ObjectGuid > OwnerGuid
Definition Object.h:331
Optional< std::string_view > StringId
Definition Object.h:322
Optional< GameobjectTypes > GameObjectType
Definition Object.h:333
Optional< uint32 > GameObjectId
Definition Object.h:321
Optional< ObjectGuid > PrivateObjectOwnerGuid
Definition Object.h:332
Optional< bool > IsSummon
Definition Object.h:324
Optional< bool > IsSpawned
Definition Object.h:325
struct GameObjectTemplate::@191::@200 spellFocus
struct GameObjectTemplate::@191::@213 fishinghole
float GetPositionZ() const
Definition Position.h:81
bool IsWithinDoubleVerticalCylinder(Position const *center, float radius, float height) const
Definition Position.cpp:114
void Visit(GridRefManager< T > &)
CreatureLastSearcher(WorldObject const *searcher, Creature *&result, Check &check)
CreatureListSearcher(WorldObject const *searcher, Container &container, Check &check)
void Visit(GridRefManager< T > &)
CreatureSearcherBase(uint32 phaseMask, 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 > &)
void Visit(GridRefManager< T > &)
DelayedUnitRelocation(Cell &c, CellCoord &pair, Map &map, float radius)
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(uint32 phaseMask, Container &result, Check &check)
GameObjectSearcher(WorldObject const *searcher, GameObject *&result, Check &check)
void Visit(GridRefManager< NOT_INTERESTED > &)
GameObjectWorker(WorldObject const *searcher, Functor &func)
void Visit(GameObjectMapType &m)
void Visit(CorpseMapType &m)
void Visit(PlayerMapType &m)
void updateObjects(GridRefManager< T > &m)
void Visit(CreatureMapType &m)
void Visit(DynamicObjectMapType &m)
GridUpdater(GridType &grid, uint32 diff)
void Visit(GameObjectMapType &m)
void Visit(GridRefManager< SKIP > &)
MessageDistDelivererToHostile(Unit *src, WorldPacket const *msg, float dist)
WorldObject const * i_source
WorldPacket const * i_message
void Visit(GridRefManager< SKIP > &)
void SendPacket(Player *player)
MessageDistDeliverer(WorldObject const *src, WorldPacket const *msg, float dist, bool own_team_only=false, Player const *skipped=nullptr, bool req3dDist=false)
void Visit(PlayerMapType &)
void Visit(GridRefManager< T > &m)
void Visit(CorpseMapType &)
ObjectUpdater(const uint32 diff)
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(uint32 phaseMask, Container &container, Check &check)
PlayerListSearcher(WorldObject const *searcher, Container &container, Check &check)
void Visit(GridRefManager< T > &m)
void Visit(PlayerMapType &m)
PlayerSearcherBase(uint32 phaseMask, Container &result, Check &check)
void Visit(GridRefManager< NOT_INTERESTED > &)
PlayerSearcher(WorldObject const *searcher, Player *&result, Check &check)
PlayerWorker(WorldObject const *searcher, Do &_do)
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)
void Visit(PlayerMapType &m)
void Visit(GridRefManager< NOT_INTERESTED > &)
UnitSearcherBase(uint32 phaseMask, Container &result, Check &check)
UnitSearcher(WorldObject const *searcher, Unit *&result, Check &check)
VisibleChangesNotifier(WorldObject &object)
void Visit(GridRefManager< T > &)
GuidUnorderedSet vis_guids
VisibleNotifier(Player &player)
std::set< Unit * > i_visibleNow
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)
WorldObjectSearcherBase(uint32 phaseMask, Container &result, Check &check, uint32 mapTypeMask=GRID_MAP_TYPE_MASK_ALL)
void Visit(GridRefManager< T > &)
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)