[7915] Implement more stricted checks and limitations at loading creature addon data.
[getmangos.git] / src / game / GridNotifiers.h
blob18de7f857d66e1ff435a7213d8bce238cdf03032
1 /*
2 * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 #ifndef MANGOS_GRIDNOTIFIERS_H
20 #define MANGOS_GRIDNOTIFIERS_H
22 #include "ObjectGridLoader.h"
23 #include "ByteBuffer.h"
24 #include "UpdateData.h"
25 #include <iostream>
27 #include "Corpse.h"
28 #include "Object.h"
29 #include "DynamicObject.h"
30 #include "GameObject.h"
31 #include "Player.h"
32 #include "Unit.h"
34 class Player;
35 //class Map;
37 namespace MaNGOS
40 struct MANGOS_DLL_DECL PlayerNotifier
42 explicit PlayerNotifier(Player &pl) : i_player(pl) {}
43 void Visit(PlayerMapType &);
44 template<class SKIP> void Visit(GridRefManager<SKIP> &) {}
45 Player &i_player;
48 struct MANGOS_DLL_DECL VisibleNotifier
50 Player &i_player;
51 UpdateData i_data;
52 UpdateDataMapType i_data_updates;
53 Player::ClientGUIDs i_clientGUIDs;
54 std::set<WorldObject*> i_visibleNow;
56 explicit VisibleNotifier(Player &player) : i_player(player),i_clientGUIDs(player.m_clientGUIDs) {}
57 template<class T> void Visit(GridRefManager<T> &m);
58 void Visit(PlayerMapType &);
59 void Notify(void);
62 struct MANGOS_DLL_DECL VisibleChangesNotifier
64 WorldObject &i_object;
66 explicit VisibleChangesNotifier(WorldObject &object) : i_object(object) {}
67 template<class T> void Visit(GridRefManager<T> &) {}
68 void Visit(PlayerMapType &);
71 struct MANGOS_DLL_DECL GridUpdater
73 GridType &i_grid;
74 uint32 i_timeDiff;
75 GridUpdater(GridType &grid, uint32 diff) : i_grid(grid), i_timeDiff(diff) {}
77 template<class T> void updateObjects(GridRefManager<T> &m)
79 for(typename GridRefManager<T>::iterator iter = m.begin(); iter != m.end(); ++iter)
80 iter->getSource()->Update(i_timeDiff);
83 void Visit(PlayerMapType &m) { updateObjects<Player>(m); }
84 void Visit(CreatureMapType &m){ updateObjects<Creature>(m); }
85 void Visit(GameObjectMapType &m) { updateObjects<GameObject>(m); }
86 void Visit(DynamicObjectMapType &m) { updateObjects<DynamicObject>(m); }
87 void Visit(CorpseMapType &m) { updateObjects<Corpse>(m); }
90 struct MANGOS_DLL_DECL MessageDeliverer
92 Player &i_player;
93 WorldPacket *i_message;
94 bool i_toSelf;
95 MessageDeliverer(Player &pl, WorldPacket *msg, bool to_self) : i_player(pl), i_message(msg), i_toSelf(to_self) {}
96 void Visit(PlayerMapType &m);
97 template<class SKIP> void Visit(GridRefManager<SKIP> &) {}
100 struct MANGOS_DLL_DECL ObjectMessageDeliverer
102 uint32 i_phaseMask;
103 WorldPacket *i_message;
104 explicit ObjectMessageDeliverer(WorldObject& obj, WorldPacket *msg)
105 : i_phaseMask(obj.GetPhaseMask()), i_message(msg) {}
106 void Visit(PlayerMapType &m);
107 template<class SKIP> void Visit(GridRefManager<SKIP> &) {}
110 struct MANGOS_DLL_DECL MessageDistDeliverer
112 Player &i_player;
113 WorldPacket *i_message;
114 bool i_toSelf;
115 bool i_ownTeamOnly;
116 float i_dist;
118 MessageDistDeliverer(Player &pl, WorldPacket *msg, float dist, bool to_self, bool ownTeamOnly)
119 : i_player(pl), i_message(msg), i_toSelf(to_self), i_ownTeamOnly(ownTeamOnly), i_dist(dist) {}
120 void Visit(PlayerMapType &m);
121 template<class SKIP> void Visit(GridRefManager<SKIP> &) {}
124 struct MANGOS_DLL_DECL ObjectMessageDistDeliverer
126 WorldObject &i_object;
127 WorldPacket *i_message;
128 float i_dist;
129 ObjectMessageDistDeliverer(WorldObject &obj, WorldPacket *msg, float dist) : i_object(obj), i_message(msg), i_dist(dist) {}
130 void Visit(PlayerMapType &m);
131 template<class SKIP> void Visit(GridRefManager<SKIP> &) {}
134 struct MANGOS_DLL_DECL ObjectUpdater
136 uint32 i_timeDiff;
137 explicit ObjectUpdater(const uint32 &diff) : i_timeDiff(diff) {}
138 template<class T> void Visit(GridRefManager<T> &m);
139 void Visit(PlayerMapType &) {}
140 void Visit(CorpseMapType &) {}
141 void Visit(CreatureMapType &);
144 template<class T>
145 struct MANGOS_DLL_DECL ObjectAccessorNotifier
147 T *& i_object;
149 uint64 i_id;
150 ObjectAccessorNotifier(T * &obj, uint64 id) : i_object(obj), i_id(id)
152 i_object = NULL;
155 void Visit(GridRefManager<T> &m )
157 if( i_object == NULL )
159 GridRefManager<T> *iter = m.find(i_id);
160 if( iter != m.end() )
162 assert( iter->second != NULL );
163 i_object = iter->second;
168 template<class NOT_INTERESTED> void Visit(GridRefManager<NOT_INTERESTED> &) {}
171 struct MANGOS_DLL_DECL PlayerRelocationNotifier
173 Player &i_player;
174 PlayerRelocationNotifier(Player &pl) : i_player(pl) {}
175 template<class T> void Visit(GridRefManager<T> &) {}
176 void Visit(PlayerMapType &);
177 void Visit(CreatureMapType &);
180 struct MANGOS_DLL_DECL CreatureRelocationNotifier
182 Creature &i_creature;
183 CreatureRelocationNotifier(Creature &c) : i_creature(c) {}
184 template<class T> void Visit(GridRefManager<T> &) {}
185 #ifdef WIN32
186 template<> void Visit(PlayerMapType &);
187 #endif
190 struct MANGOS_DLL_DECL DynamicObjectUpdater
192 DynamicObject &i_dynobject;
193 Unit* i_check;
194 DynamicObjectUpdater(DynamicObject &dynobject, Unit* caster) : i_dynobject(dynobject)
196 i_check = caster;
197 Unit* owner = i_check->GetOwner();
198 if(owner)
199 i_check = owner;
202 template<class T> inline void Visit(GridRefManager<T> &) {}
203 #ifdef WIN32
204 template<> inline void Visit<Player>(PlayerMapType &);
205 template<> inline void Visit<Creature>(CreatureMapType &);
206 #endif
208 void VisitHelper(Unit* target);
211 // SEARCHERS & LIST SEARCHERS & WORKERS
213 // WorldObject searchers & workers
215 template<class Check>
216 struct MANGOS_DLL_DECL WorldObjectSearcher
218 uint32 i_phaseMask;
219 WorldObject* &i_object;
220 Check &i_check;
222 WorldObjectSearcher(WorldObject const* searcher, WorldObject* & result, Check& check)
223 : i_phaseMask(searcher->GetPhaseMask()), i_object(result),i_check(check) {}
225 void Visit(GameObjectMapType &m);
226 void Visit(PlayerMapType &m);
227 void Visit(CreatureMapType &m);
228 void Visit(CorpseMapType &m);
229 void Visit(DynamicObjectMapType &m);
231 template<class NOT_INTERESTED> void Visit(GridRefManager<NOT_INTERESTED> &) {}
234 template<class Check>
235 struct MANGOS_DLL_DECL WorldObjectListSearcher
237 uint32 i_phaseMask;
238 std::list<WorldObject*> &i_objects;
239 Check& i_check;
241 WorldObjectListSearcher(WorldObject const* searcher, std::list<WorldObject*> &objects, Check & check)
242 : i_phaseMask(searcher->GetPhaseMask()), i_objects(objects),i_check(check) {}
244 void Visit(PlayerMapType &m);
245 void Visit(CreatureMapType &m);
246 void Visit(CorpseMapType &m);
247 void Visit(GameObjectMapType &m);
248 void Visit(DynamicObjectMapType &m);
250 template<class NOT_INTERESTED> void Visit(GridRefManager<NOT_INTERESTED> &) {}
253 template<class Do>
254 struct MANGOS_DLL_DECL WorldObjectWorker
256 uint32 i_phaseMask;
257 Do const& i_do;
259 WorldObjectWorker(WorldObject const* searcher, Do const& _do)
260 : i_phaseMask(searcher->GetPhaseMask()), i_do(_do) {}
262 void Visit(GameObjectMapType &m)
264 for(GameObjectMapType::iterator itr=m.begin(); itr != m.end(); ++itr)
265 if(itr->getSource()->InSamePhase(i_phaseMask))
266 i_do(itr->getSource());
269 void Visit(PlayerMapType &m)
271 for(PlayerMapType::iterator itr=m.begin(); itr != m.end(); ++itr)
272 if(itr->getSource()->InSamePhase(i_phaseMask))
273 i_do(itr->getSource());
275 void Visit(CreatureMapType &m)
277 for(CreatureMapType::iterator itr=m.begin(); itr != m.end(); ++itr)
278 if(itr->getSource()->InSamePhase(i_phaseMask))
279 i_do(itr->getSource());
282 void Visit(CorpseMapType &m)
284 for(CorpseMapType::iterator itr=m.begin(); itr != m.end(); ++itr)
285 if(itr->getSource()->InSamePhase(i_phaseMask))
286 i_do(itr->getSource());
289 void Visit(DynamicObjectMapType &m)
291 for(DynamicObjectMapType::iterator itr=m.begin(); itr != m.end(); ++itr)
292 if(itr->getSource()->InSamePhase(i_phaseMask))
293 i_do(itr->getSource());
296 template<class NOT_INTERESTED> void Visit(GridRefManager<NOT_INTERESTED> &) {}
299 // Gameobject searchers
301 template<class Check>
302 struct MANGOS_DLL_DECL GameObjectSearcher
304 uint32 i_phaseMask;
305 GameObject* &i_object;
306 Check &i_check;
308 GameObjectSearcher(WorldObject const* searcher, GameObject* & result, Check& check)
309 : i_phaseMask(searcher->GetPhaseMask()), i_object(result),i_check(check) {}
311 void Visit(GameObjectMapType &m);
313 template<class NOT_INTERESTED> void Visit(GridRefManager<NOT_INTERESTED> &) {}
316 // Last accepted by Check GO if any (Check can change requirements at each call)
317 template<class Check>
318 struct MANGOS_DLL_DECL GameObjectLastSearcher
320 uint32 i_phaseMask;
321 GameObject* &i_object;
322 Check& i_check;
324 GameObjectLastSearcher(WorldObject const* searcher, GameObject* & result, Check& check)
325 : i_phaseMask(searcher->GetPhaseMask()), i_object(result), i_check(check) {}
327 void Visit(GameObjectMapType &m);
329 template<class NOT_INTERESTED> void Visit(GridRefManager<NOT_INTERESTED> &) {}
332 template<class Check>
333 struct MANGOS_DLL_DECL GameObjectListSearcher
335 uint32 i_phaseMask;
336 std::list<GameObject*> &i_objects;
337 Check& i_check;
339 GameObjectListSearcher(WorldObject const* searcher, std::list<GameObject*> &objects, Check & check)
340 : i_phaseMask(searcher->GetPhaseMask()), i_objects(objects), i_check(check) {}
342 void Visit(GameObjectMapType &m);
344 template<class NOT_INTERESTED> void Visit(GridRefManager<NOT_INTERESTED> &) {}
347 // Unit searchers
349 // First accepted by Check Unit if any
350 template<class Check>
351 struct MANGOS_DLL_DECL UnitSearcher
353 uint32 i_phaseMask;
354 Unit* &i_object;
355 Check & i_check;
357 UnitSearcher(WorldObject const* searcher, Unit* & result, Check & check)
358 : i_phaseMask(searcher->GetPhaseMask()), i_object(result),i_check(check) {}
360 void Visit(CreatureMapType &m);
361 void Visit(PlayerMapType &m);
363 template<class NOT_INTERESTED> void Visit(GridRefManager<NOT_INTERESTED> &) {}
366 // Last accepted by Check Unit if any (Check can change requirements at each call)
367 template<class Check>
368 struct MANGOS_DLL_DECL UnitLastSearcher
370 uint32 i_phaseMask;
371 Unit* &i_object;
372 Check & i_check;
374 UnitLastSearcher(WorldObject const* searcher, Unit* & result, Check & check)
375 : i_phaseMask(searcher->GetPhaseMask()), i_object(result),i_check(check) {}
377 void Visit(CreatureMapType &m);
378 void Visit(PlayerMapType &m);
380 template<class NOT_INTERESTED> void Visit(GridRefManager<NOT_INTERESTED> &) {}
383 // All accepted by Check units if any
384 template<class Check>
385 struct MANGOS_DLL_DECL UnitListSearcher
387 uint32 i_phaseMask;
388 std::list<Unit*> &i_objects;
389 Check& i_check;
391 UnitListSearcher(WorldObject const* searcher, std::list<Unit*> &objects, Check & check)
392 : i_phaseMask(searcher->GetPhaseMask()), i_objects(objects),i_check(check) {}
394 void Visit(PlayerMapType &m);
395 void Visit(CreatureMapType &m);
397 template<class NOT_INTERESTED> void Visit(GridRefManager<NOT_INTERESTED> &) {}
400 // Creature searchers
402 template<class Check>
403 struct MANGOS_DLL_DECL CreatureSearcher
405 uint32 i_phaseMask;
406 Creature* &i_object;
407 Check & i_check;
409 CreatureSearcher(WorldObject const* searcher, Creature* & result, Check & check)
410 : i_phaseMask(searcher->GetPhaseMask()), i_object(result),i_check(check) {}
412 void Visit(CreatureMapType &m);
414 template<class NOT_INTERESTED> void Visit(GridRefManager<NOT_INTERESTED> &) {}
417 // Last accepted by Check Creature if any (Check can change requirements at each call)
418 template<class Check>
419 struct MANGOS_DLL_DECL CreatureLastSearcher
421 uint32 i_phaseMask;
422 Creature* &i_object;
423 Check & i_check;
425 CreatureLastSearcher(WorldObject const* searcher, Creature* & result, Check & check)
426 : i_phaseMask(searcher->GetPhaseMask()), i_object(result),i_check(check) {}
428 void Visit(CreatureMapType &m);
430 template<class NOT_INTERESTED> void Visit(GridRefManager<NOT_INTERESTED> &) {}
433 template<class Check>
434 struct MANGOS_DLL_DECL CreatureListSearcher
436 uint32 i_phaseMask;
437 std::list<Creature*> &i_objects;
438 Check& i_check;
440 CreatureListSearcher(WorldObject const* searcher, std::list<Creature*> &objects, Check & check)
441 : i_phaseMask(searcher->GetPhaseMask()), i_objects(objects),i_check(check) {}
443 void Visit(CreatureMapType &m);
445 template<class NOT_INTERESTED> void Visit(GridRefManager<NOT_INTERESTED> &) {}
448 template<class Do>
449 struct MANGOS_DLL_DECL CreatureWorker
451 uint32 i_phaseMask;
452 Do& i_do;
454 CreatureWorker(WorldObject const* searcher, Do& _do)
455 : i_phaseMask(searcher->GetPhaseMask()), i_do(_do) {}
457 void Visit(CreatureMapType &m)
459 for(CreatureMapType::iterator itr=m.begin(); itr != m.end(); ++itr)
460 if(itr->getSource()->InSamePhase(i_phaseMask))
461 i_do(itr->getSource());
464 template<class NOT_INTERESTED> void Visit(GridRefManager<NOT_INTERESTED> &) {}
467 // Player searchers
469 template<class Check>
470 struct MANGOS_DLL_DECL PlayerSearcher
472 uint32 i_phaseMask;
473 Player* &i_object;
474 Check & i_check;
476 PlayerSearcher(WorldObject const* searcher, Player* & result, Check & check)
477 : i_phaseMask(searcher->GetPhaseMask()), i_object(result),i_check(check) {}
479 void Visit(PlayerMapType &m);
481 template<class NOT_INTERESTED> void Visit(GridRefManager<NOT_INTERESTED> &) {}
484 template<class Do>
485 struct MANGOS_DLL_DECL PlayerWorker
487 uint32 i_phaseMask;
488 Do& i_do;
490 PlayerWorker(WorldObject const* searcher, Do& _do)
491 : i_phaseMask(searcher->GetPhaseMask()), i_do(_do) {}
493 void Visit(PlayerMapType &m)
495 for(PlayerMapType::iterator itr=m.begin(); itr != m.end(); ++itr)
496 if(itr->getSource()->InSamePhase(i_phaseMask))
497 i_do(itr->getSource());
500 template<class NOT_INTERESTED> void Visit(GridRefManager<NOT_INTERESTED> &) {}
503 template<class Do>
504 struct MANGOS_DLL_DECL PlayerDistWorker
506 WorldObject const* i_searcher;
507 float i_dist;
508 Do& i_do;
510 PlayerDistWorker(WorldObject const* searcher, float _dist, Do& _do)
511 : i_searcher(searcher), i_dist(_dist), i_do(_do) {}
513 void Visit(PlayerMapType &m)
515 for(PlayerMapType::iterator itr=m.begin(); itr != m.end(); ++itr)
516 if (itr->getSource()->InSamePhase(i_searcher) && itr->getSource()->IsWithinDist(i_searcher,i_dist))
517 i_do(itr->getSource());
520 template<class NOT_INTERESTED> void Visit(GridRefManager<NOT_INTERESTED> &) {}
523 // CHECKS && DO classes
525 // WorldObject check classes
526 class RaiseDeadObjectCheck
528 public:
529 RaiseDeadObjectCheck(Unit* funit, float range) : i_funit(funit), i_range(range) {}
530 bool operator()(Creature* u)
532 if (i_funit->GetTypeId()!=TYPEID_PLAYER || !((Player*)i_funit)->isHonorOrXPTarget(u) ||
533 u->getDeathState() != CORPSE || u->isDeadByDefault() || u->isInFlight() ||
534 ( u->GetCreatureTypeMask() & (1 << (CREATURE_TYPE_HUMANOID-1)) )==0 ||
535 (u->GetDisplayId() != u->GetNativeDisplayId()))
536 return false;
538 return i_funit->IsWithinDistInMap(u, i_range);
540 template<class NOT_INTERESTED> bool operator()(NOT_INTERESTED*) { return false; }
541 private:
542 Unit* const i_funit;
543 float i_range;
546 class ExplodeCorpseObjectCheck
548 public:
549 ExplodeCorpseObjectCheck(Unit* funit, float range) : i_funit(funit), i_range(range) {}
550 bool operator()(Player* u)
552 if (u->getDeathState()!=CORPSE || u->isInFlight() ||
553 u->HasAuraType(SPELL_AURA_GHOST) || (u->GetDisplayId() != u->GetNativeDisplayId()))
554 return false;
556 return i_funit->IsWithinDistInMap(u, i_range);
558 bool operator()(Creature* u)
560 if (u->getDeathState()!=CORPSE || u->isInFlight() || u->isDeadByDefault() ||
561 (u->GetDisplayId() != u->GetNativeDisplayId()) ||
562 (u->GetCreatureTypeMask() & CREATURE_TYPEMASK_MECHANICAL_OR_ELEMENTAL)!=0)
563 return false;
565 return i_funit->IsWithinDistInMap(u, i_range);
567 template<class NOT_INTERESTED> bool operator()(NOT_INTERESTED*) { return false; }
568 private:
569 Unit* const i_funit;
570 float i_range;
573 class CannibalizeObjectCheck
575 public:
576 CannibalizeObjectCheck(Unit* funit, float range) : i_funit(funit), i_range(range) {}
577 bool operator()(Player* u)
579 if( i_funit->IsFriendlyTo(u) || u->isAlive() || u->isInFlight() )
580 return false;
582 return i_funit->IsWithinDistInMap(u, i_range);
584 bool operator()(Corpse* u);
585 bool operator()(Creature* u)
587 if (i_funit->IsFriendlyTo(u) || u->isAlive() || u->isInFlight() ||
588 (u->GetCreatureTypeMask() & CREATURE_TYPEMASK_HUMANOID_OR_UNDEAD)==0)
589 return false;
591 return i_funit->IsWithinDistInMap(u, i_range);
593 template<class NOT_INTERESTED> bool operator()(NOT_INTERESTED*) { return false; }
594 private:
595 Unit* const i_funit;
596 float i_range;
599 // WorldObject do classes
601 class RespawnDo
603 public:
604 RespawnDo() {}
605 void operator()(Creature* u) const { u->Respawn(); }
606 void operator()(GameObject* u) const { u->Respawn(); }
607 void operator()(WorldObject*) const {}
608 void operator()(Corpse*) const {}
611 // GameObject checks
613 class GameObjectFocusCheck
615 public:
616 GameObjectFocusCheck(Unit const* unit,uint32 focusId) : i_unit(unit), i_focusId(focusId) {}
617 bool operator()(GameObject* go) const
619 if(go->GetGOInfo()->type != GAMEOBJECT_TYPE_SPELL_FOCUS)
620 return false;
622 if(go->GetGOInfo()->spellFocus.focusId != i_focusId)
623 return false;
625 float dist = go->GetGOInfo()->spellFocus.dist;
627 return go->IsWithinDistInMap(i_unit, dist);
629 private:
630 Unit const* i_unit;
631 uint32 i_focusId;
634 // Find the nearest Fishing hole and return true only if source object is in range of hole
635 class NearestGameObjectFishingHole
637 public:
638 NearestGameObjectFishingHole(WorldObject const& obj, float range) : i_obj(obj), i_range(range) {}
639 bool operator()(GameObject* go)
641 if(go->GetGOInfo()->type == GAMEOBJECT_TYPE_FISHINGHOLE && go->isSpawned() && i_obj.IsWithinDistInMap(go, i_range) && i_obj.IsWithinDistInMap(go, go->GetGOInfo()->fishinghole.radius))
643 i_range = i_obj.GetDistance(go);
644 return true;
646 return false;
648 float GetLastRange() const { return i_range; }
649 private:
650 WorldObject const& i_obj;
651 float i_range;
653 // prevent clone
654 NearestGameObjectFishingHole(NearestGameObjectFishingHole const&);
657 // Success at unit in range, range update for next check (this can be use with GameobjectLastSearcher to find nearest GO)
658 class NearestGameObjectEntryInObjectRangeCheck
660 public:
661 NearestGameObjectEntryInObjectRangeCheck(WorldObject const& obj,uint32 entry, float range) : i_obj(obj), i_entry(entry), i_range(range) {}
662 bool operator()(GameObject* go)
664 if(go->GetEntry() == i_entry && i_obj.IsWithinDistInMap(go, i_range))
666 i_range = i_obj.GetDistance(go); // use found GO range as new range limit for next check
667 return true;
669 return false;
671 float GetLastRange() const { return i_range; }
672 private:
673 WorldObject const& i_obj;
674 uint32 i_entry;
675 float i_range;
677 // prevent clone this object
678 NearestGameObjectEntryInObjectRangeCheck(NearestGameObjectEntryInObjectRangeCheck const&);
681 class GameObjectWithDbGUIDCheck
683 public:
684 GameObjectWithDbGUIDCheck(WorldObject const& obj,uint32 db_guid) : i_obj(obj), i_db_guid(db_guid) {}
685 bool operator()(GameObject const* go) const
687 return go->GetDBTableGUIDLow() == i_db_guid;
689 private:
690 WorldObject const& i_obj;
691 uint32 i_db_guid;
694 // Unit checks
696 class MostHPMissingInRange
698 public:
699 MostHPMissingInRange(Unit const* obj, float range, uint32 hp) : i_obj(obj), i_range(range), i_hp(hp) {}
700 bool operator()(Unit* u)
702 if(u->isAlive() && u->isInCombat() && !i_obj->IsHostileTo(u) && i_obj->IsWithinDistInMap(u, i_range) && u->GetMaxHealth() - u->GetHealth() > i_hp)
704 i_hp = u->GetMaxHealth() - u->GetHealth();
705 return true;
707 return false;
709 private:
710 Unit const* i_obj;
711 float i_range;
712 uint32 i_hp;
715 class FriendlyCCedInRange
717 public:
718 FriendlyCCedInRange(Unit const* obj, float range) : i_obj(obj), i_range(range) {}
719 bool operator()(Unit* u)
721 if(u->isAlive() && u->isInCombat() && !i_obj->IsHostileTo(u) && i_obj->IsWithinDistInMap(u, i_range) &&
722 (u->isFeared() || u->isCharmed() || u->isFrozen() || u->hasUnitState(UNIT_STAT_STUNNED) || u->hasUnitState(UNIT_STAT_CONFUSED)))
724 return true;
726 return false;
728 private:
729 Unit const* i_obj;
730 float i_range;
733 class FriendlyMissingBuffInRange
735 public:
736 FriendlyMissingBuffInRange(Unit const* obj, float range, uint32 spellid) : i_obj(obj), i_range(range), i_spell(spellid) {}
737 bool operator()(Unit* u)
739 if(u->isAlive() && u->isInCombat() && !i_obj->IsHostileTo(u) && i_obj->IsWithinDistInMap(u, i_range) &&
740 !(u->HasAura(i_spell, 0) || u->HasAura(i_spell, 1) || u->HasAura(i_spell, 2)))
742 return true;
744 return false;
746 private:
747 Unit const* i_obj;
748 float i_range;
749 uint32 i_spell;
752 class AnyUnfriendlyUnitInObjectRangeCheck
754 public:
755 AnyUnfriendlyUnitInObjectRangeCheck(WorldObject const* obj, Unit const* funit, float range) : i_obj(obj), i_funit(funit), i_range(range) {}
756 bool operator()(Unit* u)
758 if(u->isAlive() && i_obj->IsWithinDistInMap(u, i_range) && !i_funit->IsFriendlyTo(u))
759 return true;
760 else
761 return false;
763 private:
764 WorldObject const* i_obj;
765 Unit const* i_funit;
766 float i_range;
769 class AnyFriendlyUnitInObjectRangeCheck
771 public:
772 AnyFriendlyUnitInObjectRangeCheck(WorldObject const* obj, Unit const* funit, float range) : i_obj(obj), i_funit(funit), i_range(range) {}
773 bool operator()(Unit* u)
775 if(u->isAlive() && i_obj->IsWithinDistInMap(u, i_range) && i_funit->IsFriendlyTo(u))
776 return true;
777 else
778 return false;
780 private:
781 WorldObject const* i_obj;
782 Unit const* i_funit;
783 float i_range;
786 class AnyUnitInObjectRangeCheck
788 public:
789 AnyUnitInObjectRangeCheck(WorldObject const* obj, float range) : i_obj(obj), i_range(range) {}
790 bool operator()(Unit* u)
792 if(u->isAlive() && i_obj->IsWithinDistInMap(u, i_range))
793 return true;
795 return false;
797 private:
798 WorldObject const* i_obj;
799 float i_range;
802 // Success at unit in range, range update for next check (this can be use with UnitLastSearcher to find nearest unit)
803 class NearestAttackableUnitInObjectRangeCheck
805 public:
806 NearestAttackableUnitInObjectRangeCheck(WorldObject const* obj, Unit const* funit, float range) : i_obj(obj), i_funit(funit), i_range(range) {}
807 bool operator()(Unit* u)
809 if( u->isTargetableForAttack() && i_obj->IsWithinDistInMap(u, i_range) &&
810 !i_funit->IsFriendlyTo(u) && u->isVisibleForOrDetect(i_funit,false) )
812 i_range = i_obj->GetDistance(u); // use found unit range as new range limit for next check
813 return true;
816 return false;
818 private:
819 WorldObject const* i_obj;
820 Unit const* i_funit;
821 float i_range;
823 // prevent clone this object
824 NearestAttackableUnitInObjectRangeCheck(NearestAttackableUnitInObjectRangeCheck const&);
827 class AnyAoETargetUnitInObjectRangeCheck
829 public:
830 AnyAoETargetUnitInObjectRangeCheck(WorldObject const* obj, Unit const* funit, float range)
831 : i_obj(obj), i_funit(funit), i_range(range)
833 Unit const* check = i_funit;
834 Unit const* owner = i_funit->GetOwner();
835 if(owner)
836 check = owner;
837 i_targetForPlayer = ( check->GetTypeId()==TYPEID_PLAYER );
839 bool operator()(Unit* u)
841 // Check contains checks for: live, non-selectable, non-attackable flags, flight check and GM check, ignore totems
842 if (!u->isTargetableForAttack())
843 return false;
844 if(u->GetTypeId()==TYPEID_UNIT && ((Creature*)u)->isTotem())
845 return false;
847 if(( i_targetForPlayer ? !i_funit->IsFriendlyTo(u) : i_funit->IsHostileTo(u) )&& i_obj->IsWithinDistInMap(u, i_range))
848 return true;
850 return false;
852 private:
853 bool i_targetForPlayer;
854 WorldObject const* i_obj;
855 Unit const* i_funit;
856 float i_range;
859 struct AnyDeadUnitCheck
861 bool operator()(Unit* u) { return !u->isAlive(); }
864 struct AnyStealthedCheck
866 bool operator()(Unit* u) { return u->GetVisibility()==VISIBILITY_GROUP_STEALTH; }
869 // Creature checks
871 class InAttackDistanceFromAnyHostileCreatureCheck
873 public:
874 explicit InAttackDistanceFromAnyHostileCreatureCheck(Unit* funit) : i_funit(funit) {}
875 bool operator()(Creature* u)
877 if(u->isAlive() && u->IsHostileTo(i_funit) && i_funit->IsWithinDistInMap(u, u->GetAttackDistance(i_funit)))
878 return true;
880 return false;
882 private:
883 Unit* const i_funit;
886 class AnyAssistCreatureInRangeCheck
888 public:
889 AnyAssistCreatureInRangeCheck(Unit* funit, Unit* enemy, float range)
890 : i_funit(funit), i_enemy(enemy), i_range(range)
893 bool operator()(Creature* u)
895 if(u == i_funit)
896 return false;
898 if ( !u->CanAssistTo(i_funit, i_enemy) )
899 return false;
901 // too far
902 if( !i_funit->IsWithinDistInMap(u, i_range) )
903 return false;
905 // only if see assisted creature
906 if( !i_funit->IsWithinLOSInMap(u) )
907 return false;
909 return true;
911 private:
912 Unit* const i_funit;
913 Unit* const i_enemy;
914 float i_range;
917 class NearestAssistCreatureInCreatureRangeCheck
919 public:
920 NearestAssistCreatureInCreatureRangeCheck(Creature* obj, Unit* enemy, float range)
921 : i_obj(obj), i_enemy(enemy), i_range(range) {}
923 bool operator()(Creature* u)
925 if(u == i_obj)
926 return false;
927 if(!u->CanAssistTo(i_obj,i_enemy))
928 return false;
930 if(!i_obj->IsWithinDistInMap(u, i_range))
931 return false;
933 if(!i_obj->IsWithinLOSInMap(u))
934 return false;
936 i_range = i_obj->GetDistance(u); // use found unit range as new range limit for next check
937 return true;
939 float GetLastRange() const { return i_range; }
940 private:
941 Creature* const i_obj;
942 Unit* const i_enemy;
943 float i_range;
945 // prevent clone this object
946 NearestAssistCreatureInCreatureRangeCheck(NearestAssistCreatureInCreatureRangeCheck const&);
949 // Success at unit in range, range update for next check (this can be use with CreatureLastSearcher to find nearest creature)
950 class NearestCreatureEntryWithLiveStateInObjectRangeCheck
952 public:
953 NearestCreatureEntryWithLiveStateInObjectRangeCheck(WorldObject const& obj,uint32 entry, bool alive, float range)
954 : i_obj(obj), i_entry(entry), i_alive(alive), i_range(range) {}
956 bool operator()(Creature* u)
958 if(u->GetEntry() == i_entry && u->isAlive()==i_alive && i_obj.IsWithinDistInMap(u, i_range))
960 i_range = i_obj.GetDistance(u); // use found unit range as new range limit for next check
961 return true;
963 return false;
965 float GetLastRange() const { return i_range; }
966 private:
967 WorldObject const& i_obj;
968 uint32 i_entry;
969 bool i_alive;
970 float i_range;
972 // prevent clone this object
973 NearestCreatureEntryWithLiveStateInObjectRangeCheck(NearestCreatureEntryWithLiveStateInObjectRangeCheck const&);
976 class AnyPlayerInObjectRangeCheck
978 public:
979 AnyPlayerInObjectRangeCheck(WorldObject const* obj, float range) : i_obj(obj), i_range(range) {}
980 bool operator()(Player* u)
982 if(u->isAlive() && i_obj->IsWithinDistInMap(u, i_range))
983 return true;
985 return false;
987 private:
988 WorldObject const* i_obj;
989 float i_range;
992 // Player checks and do
994 // Prepare using Builder localized packets with caching and send to player
995 template<class Builder>
996 class LocalizedPacketDo
998 public:
999 explicit LocalizedPacketDo(Builder& builder) : i_builder(builder) {}
1001 ~LocalizedPacketDo()
1003 for(size_t i = 0; i < i_data_cache.size(); ++i)
1004 delete i_data_cache[i];
1006 void operator()( Player* p );
1008 private:
1009 Builder& i_builder;
1010 std::vector<WorldPacket*> i_data_cache; // 0 = default, i => i-1 locale index
1013 // Prepare using Builder localized packets with caching and send to player
1014 template<class Builder>
1015 class LocalizedPacketListDo
1017 public:
1018 typedef std::vector<WorldPacket*> WorldPacketList;
1019 explicit LocalizedPacketListDo(Builder& builder) : i_builder(builder) {}
1021 ~LocalizedPacketListDo()
1023 for(size_t i = 0; i < i_data_cache.size(); ++i)
1024 for(int j = 0; j < i_data_cache[i].size(); ++j)
1025 delete i_data_cache[i][j];
1027 void operator()( Player* p );
1029 private:
1030 Builder& i_builder;
1031 std::vector<WorldPacketList> i_data_cache;
1032 // 0 = default, i => i-1 locale index
1035 #ifndef WIN32
1036 template<> void PlayerRelocationNotifier::Visit<Creature>(CreatureMapType &);
1037 template<> void PlayerRelocationNotifier::Visit<Player>(PlayerMapType &);
1038 template<> void CreatureRelocationNotifier::Visit<Player>(PlayerMapType &);
1039 template<> void CreatureRelocationNotifier::Visit<Creature>(CreatureMapType &);
1040 template<> inline void DynamicObjectUpdater::Visit<Creature>(CreatureMapType &);
1041 template<> inline void DynamicObjectUpdater::Visit<Player>(PlayerMapType &);
1042 #endif
1044 #endif