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"
29 #include "DynamicObject.h"
30 #include "GameObject.h"
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
> &) {}
48 struct MANGOS_DLL_DECL VisibleNotifier
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
&);
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
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
93 WorldPacket
*i_message
;
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
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
113 WorldPacket
*i_message
;
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
;
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
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
&);
145 struct MANGOS_DLL_DECL ObjectAccessorNotifier
150 ObjectAccessorNotifier(T
* &obj
, uint64 id
) : i_object(obj
), i_id(id
)
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
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
> &) {}
186 template<> void Visit(PlayerMapType
&);
190 struct MANGOS_DLL_DECL DynamicObjectUpdater
192 DynamicObject
&i_dynobject
;
194 DynamicObjectUpdater(DynamicObject
&dynobject
, Unit
* caster
) : i_dynobject(dynobject
)
197 Unit
* owner
= i_check
->GetOwner();
202 template<class T
> inline void Visit(GridRefManager
<T
> &) {}
204 template<> inline void Visit
<Player
>(PlayerMapType
&);
205 template<> inline void Visit
<Creature
>(CreatureMapType
&);
208 void VisitHelper(Unit
* target
);
211 // SEARCHERS & LIST SEARCHERS & WORKERS
213 // WorldObject searchers & workers
215 template<class Check
>
216 struct MANGOS_DLL_DECL WorldObjectSearcher
219 WorldObject
* &i_object
;
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
238 std::list
<WorldObject
*> &i_objects
;
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
> &) {}
254 struct MANGOS_DLL_DECL WorldObjectWorker
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
305 GameObject
* &i_object
;
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
321 GameObject
* &i_object
;
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
336 std::list
<GameObject
*> &i_objects
;
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
> &) {}
349 // First accepted by Check Unit if any
350 template<class Check
>
351 struct MANGOS_DLL_DECL UnitSearcher
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
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
388 std::list
<Unit
*> &i_objects
;
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
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
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
437 std::list
<Creature
*> &i_objects
;
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
> &) {}
450 template<class Check
>
451 struct MANGOS_DLL_DECL PlayerSearcher
457 PlayerSearcher(WorldObject
const* searcher
, Player
* & result
, Check
& check
)
458 : i_phaseMask(searcher
->GetPhaseMask()), i_object(result
),i_check(check
) {}
460 void Visit(PlayerMapType
&m
);
462 template<class NOT_INTERESTED
> void Visit(GridRefManager
<NOT_INTERESTED
> &) {}
466 struct MANGOS_DLL_DECL PlayerWorker
471 PlayerWorker(WorldObject
const* searcher
, Do
& _do
)
472 : i_phaseMask(searcher
->GetPhaseMask()), i_do(_do
) {}
474 void Visit(PlayerMapType
&m
)
476 for(PlayerMapType::iterator itr
=m
.begin(); itr
!= m
.end(); ++itr
)
477 if(itr
->getSource()->InSamePhase(i_phaseMask
))
478 i_do(itr
->getSource());
481 template<class NOT_INTERESTED
> void Visit(GridRefManager
<NOT_INTERESTED
> &) {}
485 struct MANGOS_DLL_DECL PlayerDistWorker
487 WorldObject
const* i_searcher
;
491 PlayerDistWorker(WorldObject
const* searcher
, float _dist
, Do
& _do
)
492 : i_searcher(searcher
), i_dist(_dist
), i_do(_do
) {}
494 void Visit(PlayerMapType
&m
)
496 for(PlayerMapType::iterator itr
=m
.begin(); itr
!= m
.end(); ++itr
)
497 if (itr
->getSource()->InSamePhase(i_searcher
) && itr
->getSource()->IsWithinDist(i_searcher
,i_dist
))
498 i_do(itr
->getSource());
501 template<class NOT_INTERESTED
> void Visit(GridRefManager
<NOT_INTERESTED
> &) {}
504 // CHECKS && DO classes
506 // WorldObject check classes
507 class RaiseDeadObjectCheck
510 RaiseDeadObjectCheck(Unit
* funit
, float range
) : i_funit(funit
), i_range(range
) {}
511 bool operator()(Creature
* u
)
513 if (i_funit
->GetTypeId()!=TYPEID_PLAYER
|| !((Player
*)i_funit
)->isHonorOrXPTarget(u
) ||
514 u
->getDeathState() != CORPSE
|| u
->isDeadByDefault() || u
->isInFlight() ||
515 ( u
->GetCreatureTypeMask() & (1 << (CREATURE_TYPE_HUMANOID
-1)) )==0 ||
516 (u
->GetDisplayId() != u
->GetNativeDisplayId()))
519 return i_funit
->IsWithinDistInMap(u
, i_range
);
521 template<class NOT_INTERESTED
> bool operator()(NOT_INTERESTED
*) { return false; }
527 class ExplodeCorpseObjectCheck
530 ExplodeCorpseObjectCheck(Unit
* funit
, float range
) : i_funit(funit
), i_range(range
) {}
531 bool operator()(Player
* u
)
533 if (u
->getDeathState()!=CORPSE
|| u
->isInFlight() ||
534 u
->HasAuraType(SPELL_AURA_GHOST
) || (u
->GetDisplayId() != u
->GetNativeDisplayId()))
537 return i_funit
->IsWithinDistInMap(u
, i_range
);
539 bool operator()(Creature
* u
)
541 if (u
->getDeathState()!=CORPSE
|| u
->isInFlight() || u
->isDeadByDefault() ||
542 (u
->GetDisplayId() != u
->GetNativeDisplayId()) ||
543 (u
->GetCreatureTypeMask() & CREATURE_TYPEMASK_MECHANICAL_OR_ELEMENTAL
)!=0)
546 return i_funit
->IsWithinDistInMap(u
, i_range
);
548 template<class NOT_INTERESTED
> bool operator()(NOT_INTERESTED
*) { return false; }
554 class CannibalizeObjectCheck
557 CannibalizeObjectCheck(Unit
* funit
, float range
) : i_funit(funit
), i_range(range
) {}
558 bool operator()(Player
* u
)
560 if( i_funit
->IsFriendlyTo(u
) || u
->isAlive() || u
->isInFlight() )
563 return i_funit
->IsWithinDistInMap(u
, i_range
);
565 bool operator()(Corpse
* u
);
566 bool operator()(Creature
* u
)
568 if (i_funit
->IsFriendlyTo(u
) || u
->isAlive() || u
->isInFlight() ||
569 (u
->GetCreatureTypeMask() & CREATURE_TYPEMASK_HUMANOID_OR_UNDEAD
)==0)
572 return i_funit
->IsWithinDistInMap(u
, i_range
);
574 template<class NOT_INTERESTED
> bool operator()(NOT_INTERESTED
*) { return false; }
580 // WorldObject do classes
586 void operator()(Creature
* u
) const { u
->Respawn(); }
587 void operator()(GameObject
* u
) const { u
->Respawn(); }
588 void operator()(WorldObject
*) const {}
589 void operator()(Corpse
*) const {}
594 class GameObjectFocusCheck
597 GameObjectFocusCheck(Unit
const* unit
,uint32 focusId
) : i_unit(unit
), i_focusId(focusId
) {}
598 bool operator()(GameObject
* go
) const
600 if(go
->GetGOInfo()->type
!= GAMEOBJECT_TYPE_SPELL_FOCUS
)
603 if(go
->GetGOInfo()->spellFocus
.focusId
!= i_focusId
)
606 float dist
= go
->GetGOInfo()->spellFocus
.dist
;
608 return go
->IsWithinDistInMap(i_unit
, dist
);
615 // Find the nearest Fishing hole and return true only if source object is in range of hole
616 class NearestGameObjectFishingHole
619 NearestGameObjectFishingHole(WorldObject
const& obj
, float range
) : i_obj(obj
), i_range(range
) {}
620 bool operator()(GameObject
* go
)
622 if(go
->GetGOInfo()->type
== GAMEOBJECT_TYPE_FISHINGHOLE
&& go
->isSpawned() && i_obj
.IsWithinDistInMap(go
, i_range
) && i_obj
.IsWithinDistInMap(go
, go
->GetGOInfo()->fishinghole
.radius
))
624 i_range
= i_obj
.GetDistance(go
);
629 float GetLastRange() const { return i_range
; }
631 WorldObject
const& i_obj
;
635 NearestGameObjectFishingHole(NearestGameObjectFishingHole
const&);
638 // Success at unit in range, range update for next check (this can be use with GameobjectLastSearcher to find nearest GO)
639 class NearestGameObjectEntryInObjectRangeCheck
642 NearestGameObjectEntryInObjectRangeCheck(WorldObject
const& obj
,uint32 entry
, float range
) : i_obj(obj
), i_entry(entry
), i_range(range
) {}
643 bool operator()(GameObject
* go
)
645 if(go
->GetEntry() == i_entry
&& i_obj
.IsWithinDistInMap(go
, i_range
))
647 i_range
= i_obj
.GetDistance(go
); // use found GO range as new range limit for next check
652 float GetLastRange() const { return i_range
; }
654 WorldObject
const& i_obj
;
658 // prevent clone this object
659 NearestGameObjectEntryInObjectRangeCheck(NearestGameObjectEntryInObjectRangeCheck
const&);
662 class GameObjectWithDbGUIDCheck
665 GameObjectWithDbGUIDCheck(WorldObject
const& obj
,uint32 db_guid
) : i_obj(obj
), i_db_guid(db_guid
) {}
666 bool operator()(GameObject
const* go
) const
668 return go
->GetDBTableGUIDLow() == i_db_guid
;
671 WorldObject
const& i_obj
;
677 class MostHPMissingInRange
680 MostHPMissingInRange(Unit
const* obj
, float range
, uint32 hp
) : i_obj(obj
), i_range(range
), i_hp(hp
) {}
681 bool operator()(Unit
* u
)
683 if(u
->isAlive() && u
->isInCombat() && !i_obj
->IsHostileTo(u
) && i_obj
->IsWithinDistInMap(u
, i_range
) && u
->GetMaxHealth() - u
->GetHealth() > i_hp
)
685 i_hp
= u
->GetMaxHealth() - u
->GetHealth();
696 class FriendlyCCedInRange
699 FriendlyCCedInRange(Unit
const* obj
, float range
) : i_obj(obj
), i_range(range
) {}
700 bool operator()(Unit
* u
)
702 if(u
->isAlive() && u
->isInCombat() && !i_obj
->IsHostileTo(u
) && i_obj
->IsWithinDistInMap(u
, i_range
) &&
703 (u
->isFeared() || u
->isCharmed() || u
->isFrozen() || u
->hasUnitState(UNIT_STAT_STUNNED
) || u
->hasUnitState(UNIT_STAT_CONFUSED
)))
714 class FriendlyMissingBuffInRange
717 FriendlyMissingBuffInRange(Unit
const* obj
, float range
, uint32 spellid
) : i_obj(obj
), i_range(range
), i_spell(spellid
) {}
718 bool operator()(Unit
* u
)
720 if(u
->isAlive() && u
->isInCombat() && !i_obj
->IsHostileTo(u
) && i_obj
->IsWithinDistInMap(u
, i_range
) &&
721 !(u
->HasAura(i_spell
, 0) || u
->HasAura(i_spell
, 1) || u
->HasAura(i_spell
, 2)))
733 class AnyUnfriendlyUnitInObjectRangeCheck
736 AnyUnfriendlyUnitInObjectRangeCheck(WorldObject
const* obj
, Unit
const* funit
, float range
) : i_obj(obj
), i_funit(funit
), i_range(range
) {}
737 bool operator()(Unit
* u
)
739 if(u
->isAlive() && i_obj
->IsWithinDistInMap(u
, i_range
) && !i_funit
->IsFriendlyTo(u
))
745 WorldObject
const* i_obj
;
750 class AnyFriendlyUnitInObjectRangeCheck
753 AnyFriendlyUnitInObjectRangeCheck(WorldObject
const* obj
, Unit
const* funit
, float range
) : i_obj(obj
), i_funit(funit
), i_range(range
) {}
754 bool operator()(Unit
* u
)
756 if(u
->isAlive() && i_obj
->IsWithinDistInMap(u
, i_range
) && i_funit
->IsFriendlyTo(u
))
762 WorldObject
const* i_obj
;
767 class AnyUnitInObjectRangeCheck
770 AnyUnitInObjectRangeCheck(WorldObject
const* obj
, float range
) : i_obj(obj
), i_range(range
) {}
771 bool operator()(Unit
* u
)
773 if(u
->isAlive() && i_obj
->IsWithinDistInMap(u
, i_range
))
779 WorldObject
const* i_obj
;
783 // Success at unit in range, range update for next check (this can be use with UnitLastSearcher to find nearest unit)
784 class NearestAttackableUnitInObjectRangeCheck
787 NearestAttackableUnitInObjectRangeCheck(WorldObject
const* obj
, Unit
const* funit
, float range
) : i_obj(obj
), i_funit(funit
), i_range(range
) {}
788 bool operator()(Unit
* u
)
790 if( u
->isTargetableForAttack() && i_obj
->IsWithinDistInMap(u
, i_range
) &&
791 !i_funit
->IsFriendlyTo(u
) && u
->isVisibleForOrDetect(i_funit
,false) )
793 i_range
= i_obj
->GetDistance(u
); // use found unit range as new range limit for next check
800 WorldObject
const* i_obj
;
804 // prevent clone this object
805 NearestAttackableUnitInObjectRangeCheck(NearestAttackableUnitInObjectRangeCheck
const&);
808 class AnyAoETargetUnitInObjectRangeCheck
811 AnyAoETargetUnitInObjectRangeCheck(WorldObject
const* obj
, Unit
const* funit
, float range
)
812 : i_obj(obj
), i_funit(funit
), i_range(range
)
814 Unit
const* check
= i_funit
;
815 Unit
const* owner
= i_funit
->GetOwner();
818 i_targetForPlayer
= ( check
->GetTypeId()==TYPEID_PLAYER
);
820 bool operator()(Unit
* u
)
822 // Check contains checks for: live, non-selectable, non-attackable flags, flight check and GM check, ignore totems
823 if (!u
->isTargetableForAttack())
825 if(u
->GetTypeId()==TYPEID_UNIT
&& ((Creature
*)u
)->isTotem())
828 if(( i_targetForPlayer
? !i_funit
->IsFriendlyTo(u
) : i_funit
->IsHostileTo(u
) )&& i_obj
->IsWithinDistInMap(u
, i_range
))
834 bool i_targetForPlayer
;
835 WorldObject
const* i_obj
;
840 struct AnyDeadUnitCheck
842 bool operator()(Unit
* u
) { return !u
->isAlive(); }
845 struct AnyStealthedCheck
847 bool operator()(Unit
* u
) { return u
->GetVisibility()==VISIBILITY_GROUP_STEALTH
; }
852 class InAttackDistanceFromAnyHostileCreatureCheck
855 explicit InAttackDistanceFromAnyHostileCreatureCheck(Unit
* funit
) : i_funit(funit
) {}
856 bool operator()(Creature
* u
)
858 if(u
->isAlive() && u
->IsHostileTo(i_funit
) && i_funit
->IsWithinDistInMap(u
, u
->GetAttackDistance(i_funit
)))
867 class AnyAssistCreatureInRangeCheck
870 AnyAssistCreatureInRangeCheck(Unit
* funit
, Unit
* enemy
, float range
)
871 : i_funit(funit
), i_enemy(enemy
), i_range(range
)
874 bool operator()(Creature
* u
)
879 if ( !u
->CanAssistTo(i_funit
, i_enemy
) )
883 if( !i_funit
->IsWithinDistInMap(u
, i_range
) )
886 // only if see assisted creature
887 if( !i_funit
->IsWithinLOSInMap(u
) )
898 // Success at unit in range, range update for next check (this can be use with CreatureLastSearcher to find nearest creature)
899 class NearestCreatureEntryWithLiveStateInObjectRangeCheck
902 NearestCreatureEntryWithLiveStateInObjectRangeCheck(WorldObject
const& obj
,uint32 entry
, bool alive
, float range
)
903 : i_obj(obj
), i_entry(entry
), i_alive(alive
), i_range(range
) {}
905 bool operator()(Creature
* u
)
907 if(u
->GetEntry() == i_entry
&& u
->isAlive()==i_alive
&& i_obj
.IsWithinDistInMap(u
, i_range
))
909 i_range
= i_obj
.GetDistance(u
); // use found unit range as new range limit for next check
914 float GetLastRange() const { return i_range
; }
916 WorldObject
const& i_obj
;
921 // prevent clone this object
922 NearestCreatureEntryWithLiveStateInObjectRangeCheck(NearestCreatureEntryWithLiveStateInObjectRangeCheck
const&);
925 class AnyPlayerInObjectRangeCheck
928 AnyPlayerInObjectRangeCheck(WorldObject
const* obj
, float range
) : i_obj(obj
), i_range(range
) {}
929 bool operator()(Player
* u
)
931 if(u
->isAlive() && i_obj
->IsWithinDistInMap(u
, i_range
))
937 WorldObject
const* i_obj
;
941 // Player checks and do
943 // Prepare using Builder localized packets with caching and send to player
944 template<class Builder
>
945 class LocalizedPacketDo
948 explicit LocalizedPacketDo(Builder
& builder
) : i_builder(builder
) {}
952 for(size_t i
= 0; i
< i_data_cache
.size(); ++i
)
953 delete i_data_cache
[i
];
955 void operator()( Player
* p
);
959 std::vector
<WorldPacket
*> i_data_cache
; // 0 = default, i => i-1 locale index
962 // Prepare using Builder localized packets with caching and send to player
963 template<class Builder
>
964 class LocalizedPacketListDo
967 typedef std::vector
<WorldPacket
*> WorldPacketList
;
968 explicit LocalizedPacketListDo(Builder
& builder
) : i_builder(builder
) {}
970 ~LocalizedPacketListDo()
972 for(size_t i
= 0; i
< i_data_cache
.size(); ++i
)
973 for(int j
= 0; j
< i_data_cache
[i
].size(); ++j
)
974 delete i_data_cache
[i
][j
];
976 void operator()( Player
* p
);
980 std::vector
<WorldPacketList
> i_data_cache
;
981 // 0 = default, i => i-1 locale index
985 template<> void PlayerRelocationNotifier::Visit
<Creature
>(CreatureMapType
&);
986 template<> void PlayerRelocationNotifier::Visit
<Player
>(PlayerMapType
&);
987 template<> void CreatureRelocationNotifier::Visit
<Player
>(PlayerMapType
&);
988 template<> void CreatureRelocationNotifier::Visit
<Creature
>(CreatureMapType
&);
989 template<> inline void DynamicObjectUpdater::Visit
<Creature
>(CreatureMapType
&);
990 template<> inline void DynamicObjectUpdater::Visit
<Player
>(PlayerMapType
&);