OregonCore  revision be9e804-git
Your Favourite TBC server
GridNotifiers.h
Go to the documentation of this file.
1 /*
2  * This file is part of the OregonCore 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 <https://www.gnu.org/licenses/>.
16  */
17 
18 #ifndef OREGON_GRIDNOTIFIERS_H
19 #define OREGON_GRIDNOTIFIERS_H
20 
21 #include "ObjectGridLoader.h"
22 #include "ByteBuffer.h"
23 #include "UpdateData.h"
24 #include <iostream>
25 
26 #include "Corpse.h"
27 #include "Object.h"
28 #include "DynamicObject.h"
29 #include "GameObject.h"
30 #include "Player.h"
31 #include "Unit.h"
32 #include "CreatureAI.h"
33 
34 class Player;
35 //class Map;
36 
37 namespace Oregon
38 {
40 {
43  std::set<Unit*> i_visibleNow;
45 
46  VisibleNotifier(Player& player) : i_player(player), vis_guids(player.m_clientGUIDs) {}
47  template<class T> void Visit(GridRefManager<T>& m);
48  void SendToSelf(void);
49 };
50 
52 {
54 
55  explicit VisibleChangesNotifier(WorldObject& object) : i_object(object) {}
56  template<class T> void Visit(GridRefManager<T>&) {}
57  void Visit(PlayerMapType&);
58  void Visit(CreatureMapType&);
60 };
61 
63 {
65 
66  template<class T> void Visit(GridRefManager<T> &m) { VisibleNotifier::Visit(m); }
67  void Visit(CreatureMapType&);
68  void Visit(PlayerMapType&);
69 };
70 
72 {
74  const float i_radius;
76  i_creature(c), i_radius(radius) {}
77  template<class T> void Visit(GridRefManager<T>&) {}
78  void Visit(CreatureMapType&);
79  void Visit(PlayerMapType&);
80 };
81 
83 {
87  const float i_radius;
88  DelayedUnitRelocation(Cell& c, CellCoord& pair, Map& map, float radius) :
89  i_map(map), cell(c), p(pair), i_radius(radius) {}
90  template<class T> void Visit(GridRefManager<T>&) {}
91  void Visit(CreatureMapType&);
92  void Visit(PlayerMapType&);
93 };
94 
96 {
98  bool isCreature;
99  explicit AIRelocationNotifier(Unit& unit) : i_unit(unit), isCreature(unit.GetTypeId() == TYPEID_UNIT) {}
100  template<class T> void Visit(GridRefManager<T>&) {}
101  void Visit(CreatureMapType&);
102 };
103 
105 {
108  GridUpdater(GridType& grid, uint32 diff) : i_grid(grid), i_timeDiff(diff) {}
109 
110  template<class T> void updateObjects(GridRefManager<T>& m)
111  {
112  for (typename GridRefManager<T>::iterator iter = m.begin(); iter != m.end(); ++iter)
113  iter->GetSource()->Update(i_timeDiff);
114  }
115 
117  {
118  updateObjects<Player>(m);
119  }
121  {
122  updateObjects<Creature>(m);
123  }
125  {
126  updateObjects<GameObject>(m);
127  }
129  {
130  updateObjects<DynamicObject>(m);
131  }
133  {
134  updateObjects<Corpse>(m);
135  }
136 };
137 
139 {
143  float i_distSq;
145  MessageDistDeliverer(WorldObject* src, WorldPacket* msg, float dist, bool own_team_only = false)
146  : i_source(src), i_message(msg), i_phaseMask(src->GetPhaseMask()), i_distSq(dist* dist)
147  , team((own_team_only && src->GetTypeId() == TYPEID_PLAYER) ? ((Player*)src)->GetTeam() : 0)
148  {
149  }
150  void Visit(PlayerMapType& m);
151  void Visit(CreatureMapType& m);
152  void Visit(DynamicObjectMapType& m);
153  template<class SKIP> void Visit(GridRefManager<SKIP>&) {}
154 
155  void SendPacket(Player* plr)
156  {
157  // never send packet to self
158  if (plr == i_source || (team && plr->GetTeam() != team))
159  return;
160 
161  if (!plr->HaveAtClient(i_source))
162  return;
163 
164  if (WorldSession* session = plr->GetSession())
165  session->SendPacket(i_message);
166  }
167 };
168 
170 {
172  explicit ObjectUpdater(const uint32& diff) : i_timeDiff(diff) {}
173  template<class T> void Visit(GridRefManager<T>& m);
176  void Visit(CreatureMapType&);
177 };
178 
180 {
183  DynamicObjectUpdater(DynamicObject& dynobject, Unit* caster) : i_dynobject(dynobject)
184  {
185  i_check = caster;
186  Unit* owner = i_check->GetOwner();
187  if (owner)
188  i_check = owner;
189  }
190 
191  template<class T> void Visit(GridRefManager<T>&) {}
192  void Visit(CreatureMapType&);
193  void Visit(PlayerMapType&);
194 
195  void VisitHelper(Unit* target);
196 };
197 
198 // SEARCHERS & LIST SEARCHERS & WORKERS
199 
200 // WorldObject searchers & workers
201 
202 template<class Check>
204 {
207  Check& i_check;
208 
209  WorldObjectSearcher(WorldObject const* searcher, WorldObject*& result, Check& check) : i_phaseMask(searcher->GetPhaseMask()), i_object(result), i_check(check) {}
210 
211  void Visit(GameObjectMapType& m);
212  void Visit(PlayerMapType& m);
213  void Visit(CreatureMapType& m);
214  void Visit(CorpseMapType& m);
215  void Visit(DynamicObjectMapType& m);
216 
217  template<class NOT_INTERESTED> void Visit(GridRefManager<NOT_INTERESTED>&) {}
218 };
219 
220 template<class Check>
222 {
224  std::list<WorldObject*>& i_objects;
225  Check& i_check;
226 
227  WorldObjectListSearcher(WorldObject const* searcher, std::list<WorldObject*>& objects, Check& check) : i_phaseMask(searcher->GetPhaseMask()), i_objects(objects), i_check(check) {}
228 
229  void Visit(PlayerMapType& m);
230  void Visit(CreatureMapType& m);
231  void Visit(CorpseMapType& m);
232  void Visit(GameObjectMapType& m);
233  void Visit(DynamicObjectMapType& m);
234 
235  template<class NOT_INTERESTED> void Visit(GridRefManager<NOT_INTERESTED>&) {}
236 };
237 
238 template<class Do>
240 {
242  Do const& i_do;
243 
244  explicit WorldObjectWorker(WorldObject const* searcher, Do const& _do) : i_phaseMask(searcher->GetPhaseMask()), i_do(_do) {}
245 
247  {
248  for (GameObjectMapType::iterator itr = m.begin(); itr != m.end(); ++itr)
249  if (itr->GetSource()->InSamePhase(i_phaseMask))
250  i_do(itr->GetSource());
251  }
252 
254  {
255  for (PlayerMapType::iterator itr = m.begin(); itr != m.end(); ++itr)
256  if (itr->GetSource()->InSamePhase(i_phaseMask))
257  i_do(itr->GetSource());
258  }
260  {
261  for (CreatureMapType::iterator itr = m.begin(); itr != m.end(); ++itr)
262  if (itr->GetSource()->InSamePhase(i_phaseMask))
263  i_do(itr->GetSource());
264  }
265 
267  {
268  for (CorpseMapType::iterator itr = m.begin(); itr != m.end(); ++itr)
269  if (itr->GetSource()->InSamePhase(i_phaseMask))
270  i_do(itr->GetSource());
271  }
272 
274  {
275  for (DynamicObjectMapType::iterator itr = m.begin(); itr != m.end(); ++itr)
276  if (itr->GetSource()->InSamePhase(i_phaseMask))
277  i_do(itr->GetSource());
278  }
279 
280  template<class NOT_INTERESTED> void Visit(GridRefManager<NOT_INTERESTED>&) {}
281 };
282 
283 // Gameobject searchers
284 
285 template<class Check>
287 {
290  Check& i_check;
291 
292  GameObjectSearcher(WorldObject const* searcher, GameObject*& result, Check& check) : i_phaseMask(searcher->GetPhaseMask()), i_object(result), i_check(check) {}
293 
294  void Visit(GameObjectMapType& m);
295 
296  template<class NOT_INTERESTED> void Visit(GridRefManager<NOT_INTERESTED>&) {}
297 };
298 
299 // Last accepted by Check GO if any (Check can change requirements at each call)
300 template<class Check>
302 {
305  Check& i_check;
306 
307  GameObjectLastSearcher(WorldObject const* searcher, GameObject*& result, Check& check) : i_phaseMask(searcher->GetPhaseMask()), i_object(result), i_check(check) {}
308 
309  void Visit(GameObjectMapType& m);
310 
311  template<class NOT_INTERESTED> void Visit(GridRefManager<NOT_INTERESTED>&) {}
312 };
313 
314 template<class Check>
316 {
318  std::list<GameObject*>& i_objects;
319  Check& i_check;
320 
321  GameObjectListSearcher(WorldObject const* searcher, std::list<GameObject*>& objects, Check& check) : i_phaseMask(searcher->GetPhaseMask()), i_objects(objects), i_check(check) {}
322 
323  void Visit(GameObjectMapType& m);
324 
325  template<class NOT_INTERESTED> void Visit(GridRefManager<NOT_INTERESTED>&) {}
326 };
327 
328 // Unit searchers
329 
330 // First accepted by Check Unit if any
331 template<class Check>
333 {
336  Check& i_check;
337 
338  UnitSearcher(WorldObject const* searcher, Unit*& result, Check& check) : i_phaseMask(searcher->GetPhaseMask()), i_object(result), i_check(check) {}
339 
340  void Visit(CreatureMapType& m);
341  void Visit(PlayerMapType& m);
342 
343  template<class NOT_INTERESTED> void Visit(GridRefManager<NOT_INTERESTED>&) {}
344 };
345 
346 // Last accepted by Check Unit if any (Check can change requirements at each call)
347 template<class Check>
349 {
352  Check& i_check;
353 
354  UnitLastSearcher(WorldObject const* searcher, Unit*& result, Check& check) : i_phaseMask(searcher->GetPhaseMask()), i_object(result), i_check(check) {}
355 
356  void Visit(CreatureMapType& m);
357  void Visit(PlayerMapType& m);
358 
359  template<class NOT_INTERESTED> void Visit(GridRefManager<NOT_INTERESTED>&) {}
360 };
361 
362 // All accepted by Check units if any
363 template<class Check>
365 {
367  std::list<Unit*>& i_objects;
368  Check& i_check;
369 
370  UnitListSearcher(WorldObject const* searcher, std::list<Unit*>& objects, Check& check) : i_phaseMask(searcher->GetPhaseMask()), i_objects(objects), i_check(check) {}
371 
372  void Visit(PlayerMapType& m);
373  void Visit(CreatureMapType& m);
374 
375  template<class NOT_INTERESTED> void Visit(GridRefManager<NOT_INTERESTED>&) {}
376 };
377 
378 // Creature searchers
379 
380 template<class Check>
382 {
385  Check& i_check;
386 
387  CreatureSearcher(WorldObject const* searcher, Creature*& result, Check& check) : i_phaseMask(searcher->GetPhaseMask()), i_object(result), i_check(check) {}
388 
389  void Visit(CreatureMapType& m);
390 
391  template<class NOT_INTERESTED> void Visit(GridRefManager<NOT_INTERESTED>&) {}
392 };
393 
394 // Last accepted by Check Creature if any (Check can change requirements at each call)
395 template<class Check>
397 {
400  Check& i_check;
401 
402  CreatureLastSearcher(WorldObject const* searcher, Creature*& result, Check& check) : i_phaseMask(searcher->GetPhaseMask()), i_object(result), i_check(check) {}
403 
404  void Visit(CreatureMapType& m);
405 
406  template<class NOT_INTERESTED> void Visit(GridRefManager<NOT_INTERESTED>&) {}
407 };
408 
409 template<class Check>
411 {
413  std::list<Creature*>& i_objects;
414  Check& i_check;
415 
416  CreatureListSearcher(WorldObject const* searcher, std::list<Creature*>& objects, Check& check) : i_phaseMask(searcher->GetPhaseMask()), i_objects(objects), i_check(check) {}
417 
418  void Visit(CreatureMapType& m);
419 
420  template<class NOT_INTERESTED> void Visit(GridRefManager<NOT_INTERESTED>&) {}
421 };
422 
423 template<class Do>
425 {
427  Do& i_do;
428 
429  CreatureWorker(WorldObject const* searcher, Do& _do)
430  : i_phaseMask(searcher->GetPhaseMask()), i_do(_do) {}
431 
433  {
434  for (CreatureMapType::iterator itr = m.begin(); itr != m.end(); ++itr)
435  i_do(itr->GetSource());
436  }
437 
438  template<class NOT_INTERESTED> void Visit(GridRefManager<NOT_INTERESTED>&) {}
439 };
440 
441 // Player searchers
442 
443 template<class Check>
445 {
448  Check& i_check;
449 
450  PlayerSearcher(WorldObject const* searcher, Player*& result, Check& check) : i_phaseMask(searcher->GetPhaseMask()), i_object(result), i_check(check) {}
451 
452  void Visit(PlayerMapType& m);
453 
454  template<class NOT_INTERESTED> void Visit(GridRefManager<NOT_INTERESTED>&) {}
455 };
456 
457 template<class Check>
459 {
461  std::list<Player*>& i_objects;
462  Check& i_check;
463 
464  PlayerListSearcher(WorldObject const* searcher, std::list<Player*>& objects, Check& check)
465  : i_phaseMask(searcher->GetPhaseMask()), i_objects(objects), i_check(check) {}
466 
467  void Visit(PlayerMapType& m);
468 
469  template<class NOT_INTERESTED> void Visit(GridRefManager<NOT_INTERESTED>&) {}
470 };
471 
472 template<class Do>
474 {
476  Do& i_do;
477 
478  explicit PlayerWorker(WorldObject const* searcher, Do& _do) : i_phaseMask(searcher->GetPhaseMask()), i_do(_do) {}
479 
481  {
482  for (PlayerMapType::iterator itr = m.begin(); itr != m.end(); ++itr)
483  i_do(itr->GetSource());
484  }
485 
486  template<class NOT_INTERESTED> void Visit(GridRefManager<NOT_INTERESTED>&) {}
487 };
488 
489 template<class Do>
491 {
493  float i_dist;
494  Do& i_do;
495 
496  PlayerDistWorker(WorldObject const* searcher, float _dist, Do& _do)
497  : i_searcher(searcher), i_dist(_dist), i_do(_do) {}
498 
500  {
501  for (PlayerMapType::iterator itr = m.begin(); itr != m.end(); ++itr)
502  if (itr->GetSource()->InSamePhase(i_searcher) && itr->GetSource()->IsWithinDist(i_searcher, i_dist))
503  i_do(itr->GetSource());
504  }
505 
506  template<class NOT_INTERESTED> void Visit(GridRefManager<NOT_INTERESTED>&) {}
507 };
508 
509 // CHECKS && DO classes
510 
511 // WorldObject check classes
513 {
514  public:
515  CannibalizeObjectCheck(Unit* funit, float range) : i_funit(funit), i_range(range) {}
517  {
518  if (i_funit->IsFriendlyTo(u) || u->IsAlive() || u->IsInFlight())
519  return false;
520 
521  return i_funit->IsWithinDistInMap(u, i_range);
522  }
523  bool operator()(Corpse* u);
525  {
526  if (i_funit->IsFriendlyTo(u) || u->IsAlive() || u->IsInFlight() ||
528  return false;
529 
530  return i_funit->IsWithinDistInMap(u, i_range);
531  }
532  template<class NOT_INTERESTED> bool operator()(NOT_INTERESTED*)
533  {
534  return false;
535  }
536  private:
537  Unit* const i_funit;
538  float i_range;
539 };
540 
541 // WorldObject do classes
542 
544 {
545  public:
547  void operator()(Creature* u) const
548  {
549  u->Respawn();
550  }
551  void operator()(GameObject* u) const
552  {
553  u->Respawn();
554  }
555  void operator()(WorldObject*) const {}
556  void operator()(Corpse*) const {}
557 };
558 
559 // GameObject checks
560 
562 {
563  public:
564  GameObjectFocusCheck(Unit const* unit, uint32 focusId) : i_unit(unit), i_focusId(focusId) {}
565  bool operator()(GameObject* go) const
566  {
568  return false;
569 
570  if (go->GetGOInfo()->spellFocus.focusId != i_focusId)
571  return false;
572 
573  float dist = go->GetGOInfo()->spellFocus.dist / 2.f;
574 
575  return go->IsWithinDistInMap(i_unit, dist);
576  }
577  private:
578  Unit const* i_unit;
580 };
581 
582 // Find the nearest Fishing hole and return true only if source object is in range of hole
584 {
585  public:
586  NearestGameObjectFishingHole(WorldObject const& obj, float range) : i_obj(obj), i_range(range) {}
588  {
589  if (go->GetGOInfo()->type == GAMEOBJECT_TYPE_FISHINGHOLE && go->isSpawned() && i_obj.IsWithinDistInMap(go, i_range) && i_obj.IsWithinDistInMap(go, go->GetGOInfo()->fishinghole.radius))
590  {
591  i_range = i_obj.GetDistance(go);
592  return true;
593  }
594  return false;
595  }
596  float GetLastRange() const
597  {
598  return i_range;
599  }
600  private:
602  float i_range;
603 
604  // prevent clone
606 };
607 
608 // Success at unit in range, range update for next check (this can be use with GameobjectLastSearcher to find nearest GO with a certain type)
610 {
611  public:
612  NearestGameObjectTypeInObjectRangeCheck(WorldObject const& obj, GameobjectTypes type, float range) : i_obj(obj), i_type(type), i_range(range) {}
614  {
615  if (go->GetGoType() == i_type && i_obj.IsWithinDistInMap(go, i_range))
616  {
617  i_range = i_obj.GetDistance(go); // use found GO range as new range limit for next check
618  return true;
619  }
620  return false;
621  }
622 
623  float GetLastRange() const { return i_range; }
624 
625  private:
628  float i_range;
629 
630  // prevent clone this object
632 };
633 
634 
635 // Success at unit in range, range update for next check (this can be use with GameobjectLastSearcher to find nearest GO)
637 {
638  public:
639  NearestGameObjectEntryInObjectRangeCheck(WorldObject const& obj, uint32 entry, float range) : i_obj(obj), i_entry(entry), i_range(range) {}
641  {
642  if (go->GetEntry() == i_entry && i_obj.IsWithinDistInMap(go, i_range))
643  {
644  i_range = i_obj.GetDistance(go); // use found GO range as new range limit for next check
645  return true;
646  }
647  return false;
648  }
649  float GetLastRange() const
650  {
651  return i_range;
652  }
653  private:
656  float i_range;
657 
658  // prevent clone this object
660 };
661 
663 {
664  public:
665  GameObjectWithDbGUIDCheck(WorldObject const&, uint32 db_guid) : i_db_guid(db_guid) {}
666  bool operator()(GameObject const* go) const
667  {
668  return go->GetDBTableGUIDLow() == i_db_guid;
669  }
670  private:
672 };
673 
674 // Unit checks
675 
677 {
678  public:
679  MostHPMissingInRange(Unit const* obj, float range, uint32 hp) : i_obj(obj), i_range(range), i_hp(hp) {}
680  bool operator()(Unit* u)
681  {
682  if (u->IsAlive() && u->IsInCombat() && !i_obj->IsHostileTo(u) && i_obj->IsWithinDistInMap(u, i_range) && u->GetMaxHealth() - u->GetHealth() > i_hp)
683  {
684  i_hp = u->GetMaxHealth() - u->GetHealth();
685  return true;
686  }
687  return false;
688  }
689  private:
690  Unit const* i_obj;
691  float i_range;
693 };
694 
696 {
697  public:
698  FriendlyCCedInRange(Unit const* obj, float range) : i_obj(obj), i_range(range) {}
699  bool operator()(Unit* u)
700  {
701  if (u->IsAlive() && u->IsInCombat() && !i_obj->IsHostileTo(u) && i_obj->IsWithinDistInMap(u, i_range) &&
703  return true;
704  return false;
705  }
706  private:
707  Unit const* i_obj;
708  float i_range;
709 };
710 
712 {
713  public:
714  FriendlyMissingBuffInRange(Unit const* obj, float range, uint32 spellid) : i_obj(obj), i_range(range), i_spell(spellid) {}
715  bool operator()(Unit* u)
716  {
717  if (u->IsAlive() && u->IsInCombat() && i_obj->IsFriendlyTo(u) && i_obj->IsWithinDistInMap(u, i_range) &&
718  !(u->HasAura(i_spell, 0) || u->HasAura(i_spell, 1) || u->HasAura(i_spell, 2)))
719  return true;
720  return false;
721  }
722  private:
723  Unit const* i_obj;
724  float i_range;
726 };
727 
729 {
730  public:
731  AnyUnfriendlyUnitInObjectRangeCheck(WorldObject const* obj, Unit const* funit, float range) : i_obj(obj), i_funit(funit), i_range(range) {}
732  bool operator()(Unit* u)
733  {
734  if (u->IsAlive() && i_obj->IsWithinDistInMap(u, i_range) && !i_funit->IsFriendlyTo(u))
735  return true;
736  else
737  return false;
738  }
739  private:
741  Unit const* i_funit;
742  float i_range;
743 };
744 
746 {
747  public:
748  AnyUnfriendlyNoTotemUnitInObjectRangeCheck(WorldObject const* obj, Unit const* funit, float range) : i_obj(obj), i_funit(funit), i_range(range) {}
749  bool operator()(Unit* u)
750  {
751  if (!u->IsAlive())
752  return false;
753 
755  return false;
756 
757  if (u->GetTypeId() == TYPEID_UNIT && u->IsTotem())
758  return false;
759 
760  if (!u->isTargetableForAttack(false))
761  return false;
762 
763  return i_obj->IsWithinDistInMap(u, i_range) && !i_funit->IsFriendlyTo(u);
764  }
765  private:
767  Unit const* i_funit;
768  float i_range;
769 };
770 
772 {
773  public:
774  CreatureWithDbGUIDCheck(WorldObject const*, uint32 lowguid) : i_lowguid(lowguid) {}
776  {
777  return u->GetDBTableGUIDLow() == i_lowguid;
778  }
779  private:
781 };
782 
784 {
785  public:
786  AnyFriendlyUnitInObjectRangeCheck(WorldObject const* obj, Unit const* funit, float range, bool playerOnly = false) : i_obj(obj), i_funit(funit), i_range(range), i_playerOnly(playerOnly) {}
787  bool operator()(Unit* u)
788  {
789  if (u->IsAlive() && i_obj->IsWithinDistInMap(u, i_range) && !u->InSamePhase(i_obj) && i_funit->IsFriendlyTo(u) && (!i_playerOnly || u->GetTypeId() == TYPEID_PLAYER))
790  return true;
791  else
792  return false;
793  }
794  private:
796  Unit const* i_funit;
797  float i_range;
799 };
800 
802 {
803  public:
804  AnyUnitInObjectRangeCheck(WorldObject const* obj, float range) : i_obj(obj), i_range(range) {}
805  bool operator()(Unit* u)
806  {
807  if (u->IsAlive() && i_obj->IsWithinDistInMap(u, i_range))
808  return true;
809 
810  return false;
811  }
812  private:
814  float i_range;
815 };
816 
817 // Success at unit in range, range update for next check (this can be use with UnitLastSearcher to find nearest unit)
819 {
820  public:
821  NearestAttackableUnitInObjectRangeCheck(WorldObject const* obj, Unit const* funit, float range) : i_obj(obj), i_funit(funit), i_range(range) {}
822  bool operator()(Unit* u)
823  {
824  if (u->isTargetableForAttack() && i_obj->IsWithinDistInMap(u, i_range) &&
825  (i_funit->IsInCombatWith(u) || i_funit->IsHostileTo(u)) && i_obj->CanSeeOrDetect(u))
826  {
827  i_range = i_obj->GetDistance(u); // use found unit range as new range limit for next check
828  return true;
829  }
830 
831  return false;
832  }
833  private:
835  Unit const* i_funit;
836  float i_range;
837 
838  // prevent clone this object
840 };
841 
843 {
844  public:
845  AnyAoETargetUnitInObjectRangeCheck(WorldObject const* obj, Unit const* funit, float range)
846  : i_obj(obj), i_funit(funit), i_range(range)
847  {
848  Unit const* check = i_funit;
849  Unit const* owner = i_funit->GetOwner();
850  if (owner)
851  check = owner;
852  i_targetForPlayer = (check->GetTypeId() == TYPEID_PLAYER);
853  }
854  bool operator()(Unit* u)
855  {
856  // Check contains checks for: live, non-selectable, non-attackable flags, flight check and GM check, ignore totems
857  if (u->GetTypeId() == TYPEID_UNIT && u->IsTotem())
858  return false;
859 
860  if (!i_funit->IsValidAttackTarget(u))
861  return false;
862 
863  return u->IsInMap(i_obj) && u->InSamePhase(i_obj) && i_obj->IsWithinDistInMap(u, i_range);
864  }
865  private:
868  Unit const* i_funit;
869  float i_range;
870 };
871 
872 // do attack at call of help to friendly crearture
874 {
875  public:
876  CallOfHelpCreatureInRangeDo(Unit* funit, Unit* enemy, float range)
877  : i_funit(funit), i_enemy(enemy), i_range(range)
878  {}
880  {
881  if (u == i_funit)
882  return;
883 
884  if (!u->CanAssistTo(i_funit, i_enemy, false))
885  return;
886 
887  // too far
888  if (!u->IsWithinDistInMap(i_funit, i_range))
889  return;
890 
891  // only if see assisted creature
892  if (!u->IsWithinLOSInMap(i_enemy))
893  return;
894 
895  if (u->AI())
896  u->AI()->AttackStart(i_enemy);
897  }
898  private:
899  Unit* const i_funit;
900  Unit* const i_enemy;
901  float i_range;
902 };
903 
905 {
906  bool operator()(Unit* u)
907  {
908  return !u->IsAlive();
909  }
910 };
911 
912 // Creature checks
913 
915  {
916  public:
917  explicit NearestHostileUnitCheck(Creature const* creature, float dist = 0, bool playerOnly = false) : me(creature), i_playerOnly(playerOnly)
918  {
919  m_range = (dist == 0 ? 9999 : dist);
920  }
921  bool operator()(Unit* u)
922  {
923  if (!me->IsWithinDistInMap(u, m_range))
924  return false;
925 
926  if (!me->IsValidAttackTarget(u))
927  return false;
928 
929  if (i_playerOnly && u->GetTypeId() != TYPEID_PLAYER)
930  return false;
931 
932  m_range = me->GetDistance(u); // use found unit range as new range limit for next check
933  return true;
934  }
935 
936  private:
937  Creature const *me;
938  float m_range;
941  };
942 
944 {
945  public:
946  explicit NearestHostileUnitInAttackDistanceCheck(Creature const* creature, float dist = 0.f) : me(creature)
947  {
948  m_range = (dist == 0.f ? 9999.f : dist);
949  m_force = (dist == 0.f ? false : true);
950  }
951  bool operator()(Unit* u)
952  {
953  if (!me->IsWithinDistInMap(u, m_range))
954  return false;
955 
956  if (!me->CanSeeOrDetect(u))
957  return false;
958 
959  if (m_force)
960  {
961  if (!me->IsValidAttackTarget(u))
962  return false;
963  }
964  else if (!me->canStartAttack(u, false))
965  return false;
966 
967  m_range = me->GetDistance(u); // use found unit range as new range limit for next check
968  return true;
969  }
970  float GetLastRange() const
971  {
972  return m_range;
973  }
974  private:
975  Creature const* me;
976  float m_range;
977  bool m_force;
979 };
980 
982 {
983 public:
984  explicit NearestHostileUnitInAggroRangeCheck(Creature const* creature, bool useLOS = false) : _me(creature), _useLOS(useLOS)
985  {
986  }
987  bool operator()(Unit* u)
988  {
989  if (!u->IsHostileTo(_me))
990  return false;
991 
992  if (!u->IsWithinDistInMap(_me, _me->GetAggroRange(u)))
993  return false;
994 
995  if (!_me->IsValidAttackTarget(u))
996  return false;
997 
998  if (_useLOS && !u->IsWithinLOSInMap(_me))
999  return false;
1000 
1001  return true;
1002  }
1003 
1004 private:
1005  Creature const* _me;
1006  bool _useLOS;
1008 };
1009 
1011 {
1012  public:
1013  AnyAssistCreatureInRangeCheck(Unit* funit, Unit* enemy, float range)
1014  : i_funit(funit), i_enemy(enemy), i_range(range)
1015  {
1016  }
1018  {
1019  if (u == i_funit)
1020  return false;
1021 
1022  if (!u->CanAssistTo(i_funit, i_enemy))
1023  return false;
1024 
1025  // too far
1026  if (!i_funit->IsWithinDistInMap(u, i_range))
1027  return false;
1028 
1029  // only if see assisted creature
1030  if (!i_funit->IsWithinLOSInMap(u))
1031  return false;
1032 
1033  return true;
1034  }
1035  private:
1036  Unit* const i_funit;
1037  Unit* const i_enemy;
1038  float i_range;
1039 };
1040 
1042 {
1043  public:
1045  : i_obj(obj), i_enemy(enemy), i_range(range) {}
1046 
1048  {
1049  if (u->GetFaction() == i_obj->GetFaction() && !u->IsInCombat() && !u->GetCharmerOrOwnerGUID() && u->IsHostileTo(i_enemy) && u->IsAlive() && i_obj->IsWithinDistInMap(u, i_range) && i_obj->IsWithinLOSInMap(u))
1050  {
1051  i_range = i_obj->GetDistance(u); // use found unit range as new range limit for next check
1052  return true;
1053  }
1054  return false;
1055  }
1056  float GetLastRange() const
1057  {
1058  return i_range;
1059  }
1060  private:
1061  Creature* const i_obj;
1062  Unit* const i_enemy;
1063  float i_range;
1064 
1065  // prevent clone this object
1067 };
1068 
1069 // Success at unit in range, range update for next check (this can be use with CreatureLastSearcher to find nearest creature)
1071 {
1072  public:
1073  NearestCreatureEntryWithLiveStateInObjectRangeCheck(WorldObject const& obj, uint32 entry, bool alive, float range)
1074  : i_obj(obj), i_entry(entry), i_alive(alive), i_range(range) {}
1075 
1077  {
1078  if (u->GetEntry() == i_entry && u->IsAlive() == i_alive && i_obj.IsWithinDistInMap(u, i_range))
1079  {
1080  i_range = i_obj.GetDistance(u); // use found unit range as new range limit for next check
1081  return true;
1082  }
1083  return false;
1084  }
1085  float GetLastRange() const
1086  {
1087  return i_range;
1088  }
1089  private:
1092  bool i_alive;
1093  float i_range;
1094 
1095  // prevent clone this object
1097 };
1098 
1100 {
1101  public:
1102  AnyPlayerInObjectRangeCheck(WorldObject const* obj, float range, bool reqAlive = true) : i_obj(obj), i_range(range), _reqAlive(reqAlive) {}
1104  {
1105  if (_reqAlive && !u->IsAlive())
1106  return false;
1107 
1108  if (!i_obj->IsWithinDistInMap(u, i_range))
1109  return false;
1110 
1111  return true;
1112  }
1113  private:
1115  float i_range;
1117 };
1118 
1120 {
1121 public:
1123  : i_obj(obj), i_range(range) {}
1124 
1126  {
1127  if (i_obj.IsWithinDistInMap(u, i_range))
1128  {
1129  i_range = i_obj.GetDistance(u); // use found unit range as new range limit for next check
1130  return true;
1131  }
1132  return false;
1133  }
1134  float GetLastRange() const { return i_range; }
1135 private:
1137  float i_range;
1138 
1139  // prevent clone this object
1141 };
1142 
1144 {
1145 public:
1146  AllWorldObjectsInRange(const WorldObject* pObject, float fMaxRange) : m_pObject(pObject), m_fRange(fMaxRange) {}
1147  bool operator() (WorldObject* pGo)
1148  {
1149  return m_pObject->IsWithinDistInMap(pGo, m_fRange, false) && m_pObject->InSamePhase(pGo);
1150  }
1151 private:
1153  float m_fRange;
1154 };
1155 
1157 {
1158  public:
1159  AllFriendlyCreaturesInGrid(Unit const* obj) : pUnit(obj) {}
1160  bool operator() (Unit* u)
1161  {
1162  if (u->IsAlive() && u->IsVisible() && u->IsFriendlyTo(pUnit))
1163  return true;
1164 
1165  return false;
1166  }
1167  private:
1168  Unit const* pUnit;
1169 };
1170 
1172 {
1173  public:
1174  AllGameObjectsWithEntryInRange(const WorldObject* pObject, uint32 uiEntry, float fMaxRange) : m_pObject(pObject), m_uiEntry(uiEntry), m_fRange(fMaxRange) {}
1175  bool operator() (GameObject* pGo)
1176  {
1177  if ((!m_uiEntry || pGo->GetEntry() == m_uiEntry) && m_pObject->IsWithinDist(pGo, m_fRange, false))
1178  return true;
1179 
1180  return false;
1181  }
1182  private:
1185  float m_fRange;
1186 };
1187 
1189 {
1190  public:
1191  AllCreaturesOfEntryInRange(const WorldObject* pObject, uint32 uiEntry, float fMaxRange) : m_pObject(pObject), m_uiEntry(uiEntry), m_fRange(fMaxRange) {}
1192  bool operator() (Unit* pUnit)
1193  {
1194  if ((!m_uiEntry || pUnit->GetEntry() == m_uiEntry) && m_pObject->IsWithinDist(pUnit, m_fRange, false))
1195  return true;
1196 
1197  return false;
1198  }
1199 
1200  private:
1203  float m_fRange;
1204 };
1205 
1207 {
1208  public:
1209  PlayerAtMinimumRangeAway(Unit const* unit, float fMinRange) : pUnit(unit), fRange(fMinRange) {}
1210  bool operator() (Player* pPlayer)
1211  {
1212  //No threat list check, must be done explicit if expected to be in combat with creature
1213  if (!pPlayer->IsGameMaster() && pPlayer->IsAlive() && !pUnit->IsWithinDist(pPlayer, fRange, false))
1214  return true;
1215 
1216  return false;
1217  }
1218 
1219  private:
1220  Unit const* pUnit;
1221  float fRange;
1222 };
1223 
1225 {
1226  public:
1227  ObjectTypeIdCheck(TypeID typeId, bool equals) : _typeId(typeId), _equals(equals) {}
1228  bool operator()(WorldObject* object)
1229  {
1230  return (object->GetTypeId() == _typeId) == _equals;
1231  }
1232 
1233  private:
1235  bool _equals;
1236 };
1237 
1238 // Player checks and do
1239 
1240 // Prepare using Builder localized packets with caching and send to player
1241 template<class Builder>
1243 {
1244  public:
1245  explicit LocalizedPacketDo(Builder& builder) : i_builder(builder) {}
1246 
1248  {
1249  for (uint32 i = 0; i < i_data_cache.size(); ++i)
1250  delete i_data_cache[i];
1251  }
1252  void operator()(Player* p);
1253 
1254  private:
1255  Builder& i_builder;
1256  std::vector<WorldPacket*> i_data_cache; // 0 = default, i => i-1 locale index
1257 };
1258 
1259 // Prepare using Builder localized packets with caching and send to player
1260 template<class Builder>
1262 {
1263  public:
1264  typedef std::vector<WorldPacket*> WorldPacketList;
1265  explicit LocalizedPacketListDo(Builder& builder) : i_builder(builder) {}
1266 
1268  {
1269  for (size_t i = 0; i < i_data_cache.size(); ++i)
1270  for (int j = 0; j < i_data_cache[i].size(); ++j)
1271  delete i_data_cache[i][j];
1272  }
1273  void operator()(Player* p);
1274 
1275  private:
1276  Builder& i_builder;
1277  std::vector<WorldPacketList> i_data_cache;
1278  // 0 = default, i => i-1 locale index
1279 };
1280 }
1281 #endif
1282 
uint32 GetCreatureTypeMask() const
Definition: Unit.h:1149
GameobjectTypes
UnitListSearcher(WorldObject const *searcher, std::list< Unit * > &objects, Check &check)
uint32 const CREATURE_TYPEMASK_HUMANOID_OR_UNDEAD
GameObjectListSearcher(WorldObject const *searcher, std::list< GameObject * > &objects, Check &check)
PlayerDistWorker(WorldObject const *searcher, float _dist, Do &_do)
std::list< Player * > & i_objects
void Visit(GridRefManager< NOT_INTERESTED > &)
GameObjectWithDbGUIDCheck(WorldObject const &, uint32 db_guid)
Definition: Corpse.h:48
void Visit(GridRefManager< NOT_INTERESTED > &)
std::list< GameObject * > & i_objects
NearestAttackableUnitInObjectRangeCheck(WorldObject const *obj, Unit const *funit, float range)
void Visit(GridRefManager< T > &)
Definition: GridNotifiers.h:90
GameObjectSearcher(WorldObject const *searcher, GameObject *&result, Check &check)
AnyUnitInObjectRangeCheck(WorldObject const *obj, float range)
ObjectUpdater(const uint32 &diff)
uint32 GetMaxHealth() const
Definition: Unit.h:1075
NearestHostileUnitInAttackDistanceCheck(Creature const *creature, float dist=0.f)
WorldObjectListSearcher(WorldObject const *searcher, std::list< WorldObject * > &objects, Check &check)
uint32 GetFaction() const
Definition: Unit.h:1116
void Visit(GameObjectMapType &m)
uint32 GetDBTableGUIDLow() const
Definition: Creature.h:484
void Visit(CreatureMapType &m)
AllCreaturesOfEntryInRange(const WorldObject *pObject, uint32 uiEntry, float fMaxRange)
void Visit(CorpseMapType &)
void Visit(GridRefManager< NOT_INTERESTED > &)
AnyUnfriendlyUnitInObjectRangeCheck(WorldObject const *obj, Unit const *funit, float range)
NearestGameObjectTypeInObjectRangeCheck(WorldObject const &obj, GameobjectTypes type, float range)
GameObjectLastSearcher(WorldObject const *searcher, GameObject *&result, Check &check)
void Visit(CorpseMapType &m)
void Visit(GridRefManager< NOT_INTERESTED > &)
CallOfHelpCreatureInRangeDo(Unit *funit, Unit *enemy, float range)
NearestPlayerInObjectRangeCheck(WorldObject const &obj, float range)
void Visit(GridRefManager< NOT_INTERESTED > &)
const WorldObject * m_pObject
void Visit(GridRefManager< NOT_INTERESTED > &)
bool IsInCombat() const
Definition: Unit.h:1243
AllFriendlyCreaturesInGrid(Unit const *obj)
void Visit(GridRefManager< NOT_INTERESTED > &)
MostHPMissingInRange(Unit const *obj, float range, uint32 hp)
NearestCreatureEntryWithLiveStateInObjectRangeCheck(WorldObject const &obj, uint32 entry, bool alive, float range)
void operator()(Creature *u) const
bool operator()(WorldObject *object)
void Visit(GameObjectMapType &m)
AnyFriendlyUnitInObjectRangeCheck(WorldObject const *obj, Unit const *funit, float range, bool playerOnly=false)
void Visit(GridRefManager< SKIP > &)
bool IsInFlight() const
Definition: Unit.h:1239
bool IsWithinLOSInMap(const WorldObject *obj) const
Definition: Object.cpp:1252
FriendlyMissingBuffInRange(Unit const *obj, float range, uint32 spellid)
AnyAoETargetUnitInObjectRangeCheck(WorldObject const *obj, Unit const *funit, float range)
void updateObjects(GridRefManager< T > &m)
LocalizedPacketListDo(Builder &builder)
Definition: Grid.h:45
bool IsGameMaster() const
Definition: Player.h:1010
void Visit(GridRefManager< T > &)
bool operator()(GameObject const *go) const
void Visit(GridRefManager< NOT_INTERESTED > &)
void operator()(WorldObject *) const
void Respawn()
Definition: GameObject.cpp:859
void Visit(PlayerMapType &)
AllGameObjectsWithEntryInRange(const WorldObject *pObject, uint32 uiEntry, float fMaxRange)
uint32 GetCreatureType() const
Definition: Unit.cpp:10721
PlayerListSearcher(WorldObject const *searcher, std::list< Player * > &objects, Check &check)
void Visit(PlayerMapType &m)
std::set< Unit * > i_visibleNow
Definition: GridNotifiers.h:43
bool operator()(NOT_INTERESTED *)
UnitSearcher(WorldObject const *searcher, Unit *&result, Check &check)
void Visit(GridRefManager< NOT_INTERESTED > &)
void Visit(CreatureMapType &m)
void Visit(DynamicObjectMapType &m)
WorldObject const * i_searcher
bool CanAssistTo(const Unit *u, const Unit *enemy, bool checkfaction=true) const
Definition: Creature.cpp:1977
DelayedUnitRelocation(Cell &c, CellCoord &pair, Map &map, float radius)
Definition: GridNotifiers.h:88
bool IsWithinDistInMap(WorldObject const *obj, float dist2compare, bool is3D=true) const
Definition: Object.h:750
uint64 GetCharmerOrOwnerGUID() const
Definition: Unit.h:1387
void Visit(GridRefManager< T > &)
VisibleNotifier(Player &player)
Definition: GridNotifiers.h:46
NearestHostileUnitInAggroRangeCheck(Creature const *creature, bool useLOS=false)
std::vector< WorldPacket * > i_data_cache
void Visit(GridRefManager< T > &)
Definition: GridNotifiers.h:56
uint8 GetTypeId() const
Definition: Object.h:192
CreatureRelocationNotifier(Creature &c, float radius)
Definition: GridNotifiers.h:75
void Visit(PlayerMapType &m)
void operator()(GameObject *u) const
std::list< Unit * > & i_objects
void Visit(GridRefManager< NOT_INTERESTED > &)
MessageDistDeliverer(WorldObject *src, WorldPacket *msg, float dist, bool own_team_only=false)
VisibleChangesNotifier(WorldObject &object)
Definition: GridNotifiers.h:55
std::list< WorldObject * > & i_objects
void Visit(PlayerMapType &m)
LocalizedPacketDo(Builder &builder)
bool IsAlive() const
Definition: Unit.h:1336
WorldObjectSearcher(WorldObject const *searcher, WorldObject *&result, Check &check)
void Visit(GridRefManager< NOT_INTERESTED > &)
DynamicObjectUpdater(DynamicObject &dynobject, Unit *caster)
void Visit(GridRefManager< NOT_INTERESTED > &)
CreatureAI * AI() const
Definition: Creature.h:525
void Visit(GridRefManager< NOT_INTERESTED > &)
void Visit(GridRefManager< T > &)
Definition: GridNotifiers.h:77
NearestHostileUnitCheck(Creature const *creature, float dist=0, bool playerOnly=false)
ObjectTypeIdCheck(TypeID typeId, bool equals)
bool IsFriendlyTo(Unit const *unit) const
Definition: Unit.cpp:7374
void Visit(GridRefManager< NOT_INTERESTED > &)
void Visit(GridRefManager< NOT_INTERESTED > &)
bool isFrozen() const
Definition: Unit.cpp:11437
bool IsInMap(const WorldObject *obj) const
Definition: Object.h:721
struct GameObjectInfo::@59::@82 fishinghole
bool IsVisible() const
Definition: Unit.h:1691
Player::ClientGUIDs vis_guids
Definition: GridNotifiers.h:44
iterator end()
std::vector< WorldPacketList > i_data_cache
Definition: Map.h:266
PlayerRelocationNotifier(Player &player)
Definition: GridNotifiers.h:64
AnyAssistCreatureInRangeCheck(Unit *funit, Unit *enemy, float range)
void SendPacket(Player *plr)
void Visit(GridRefManager< T > &m)
Definition: GridNotifiers.h:66
void Visit(GridRefManager< NOT_INTERESTED > &)
WorldObjectWorker(WorldObject const *searcher, Do const &_do)
CreatureListSearcher(WorldObject const *searcher, std::list< Creature * > &objects, Check &check)
TypeID
Definition: ObjectGuid.h:24
AnyPlayerInObjectRangeCheck(WorldObject const *obj, float range, bool reqAlive=true)
bool operator()(GameObject *go) const
struct GameObjectInfo::@59::@68 spellFocus
Definition: Cell.h:46
void Respawn(bool force=false)
Definition: Creature.cpp:1646
NearestGameObjectEntryInObjectRangeCheck(WorldObject const &obj, uint32 entry, float range)
CreatureWorker(WorldObject const *searcher, Do &_do)
UnitLastSearcher(WorldObject const *searcher, Unit *&result, Check &check)
bool isSpawned() const
Definition: GameObject.h:716
bool HaveAtClient(WorldObject const *u) const
Definition: Player.cpp:18689
bool IsFeared() const
Definition: Unit.h:1272
GameobjectTypes GetGoType() const
Definition: GameObject.h:737
void Visit(PlayerMapType &m)
CreatureLastSearcher(WorldObject const *searcher, Creature *&result, Check &check)
PlayerAtMinimumRangeAway(Unit const *unit, float fMinRange)
bool IsTotem() const
Definition: Unit.h:1050
PlayerSearcher(WorldObject const *searcher, Player *&result, Check &check)
Unit * GetOwner() const
Definition: Unit.cpp:7660
CreatureWithDbGUIDCheck(WorldObject const *, uint32 lowguid)
GameObjectInfo const * GetGOInfo() const
Definition: GameObject.h:609
AnyUnfriendlyNoTotemUnitInObjectRangeCheck(WorldObject const *obj, Unit const *funit, float range)
iterator begin()
GridUpdater(GridType &grid, uint32 diff)
bool IsHostileTo(Unit const *unit) const
Definition: Unit.cpp:7369
PlayerWorker(WorldObject const *searcher, Do &_do)
uint32 GetTeam() const
Definition: Player.h:2066
bool HasUnitState(const uint32 f) const
Definition: Unit.h:1030
std::set< uint64 > ClientGUIDs
Definition: Player.h:2458
uint32 GetEntry() const
Definition: Object.h:186
FriendlyCCedInRange(Unit const *obj, float range)
void Visit(GridRefManager< NOT_INTERESTED > &)
WorldSession * GetSession() const
Definition: Player.h:1947
uint32 GetDBTableGUIDLow() const
Definition: GameObject.h:624
AllWorldObjectsInRange(const WorldObject *pObject, float fMaxRange)
std::vector< WorldPacket * > WorldPacketList
NearestGameObjectFishingHole(WorldObject const &obj, float range)
std::list< Creature * > & i_objects
CannibalizeObjectCheck(Unit *funit, float range)
bool isCharmed() const
Definition: Unit.h:1434
ACE_UINT32 uint32
Definition: Define.h:71
bool InSamePhase(uint32 phasemask) const
Definition: Object.h:671
uint32 GetHealth() const
Definition: Unit.h:1074
void Visit(CreatureMapType &m)
void Visit(DynamicObjectMapType &m)
Definition: Unit.h:908
Definition: Player.h:923
virtual void AttackStart(Unit *)
Definition: UnitAI.cpp:25
bool isTargetableForAttack(bool checkFakeDeath=true) const
Definition: Unit.cpp:9530
void Visit(GridRefManager< T > &m)
CreatureSearcher(WorldObject const *searcher, Creature *&result, Check &check)
NearestAssistCreatureInCreatureRangeCheck(Creature *obj, Unit *enemy, float range)
GameObjectFocusCheck(Unit const *unit, uint32 focusId)
void Visit(CorpseMapType &m)
bool HasAura(uint32 spellId, uint8 effIndex=0) const
Definition: Unit.h:1262
void operator()(Corpse *) const