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_GRIDNOTIFIERSIMPL_H
20 #define MANGOS_GRIDNOTIFIERSIMPL_H
22 #include "GridNotifiers.h"
23 #include "WorldPacket.h"
26 #include "UpdateData.h"
27 #include "CreatureAI.h"
28 #include "SpellAuras.h"
32 MaNGOS::VisibleNotifier::Visit(GridRefManager
<T
> &m
)
34 for(typename GridRefManager
<T
>::iterator iter
= m
.begin(); iter
!= m
.end(); ++iter
)
36 i_player
.UpdateVisibilityOf(iter
->getSource(),i_data
,i_data_updates
,i_visibleNow
);
37 i_clientGUIDs
.erase(iter
->getSource()->GetGUID());
42 MaNGOS::ObjectUpdater::Visit(CreatureMapType
&m
)
44 for(CreatureMapType::iterator iter
=m
.begin(); iter
!= m
.end(); ++iter
)
45 if(!iter
->getSource()->isSpiritService())
46 iter
->getSource()->Update(i_timeDiff
);
50 MaNGOS::PlayerRelocationNotifier::Visit(PlayerMapType
&m
)
52 for(PlayerMapType::iterator iter
=m
.begin(); iter
!= m
.end(); ++iter
)
54 if(&i_player
==iter
->getSource())
57 // visibility for players updated by ObjectAccessor::UpdateVisibilityFor calls in appropriate places
60 if(i_player
.GetTrader()==iter
->getSource())
61 // iteraction distance
62 if(!i_player
.IsWithinDistInMap(iter
->getSource(), 5))
63 i_player
.GetSession()->SendCancelTrade(); // will clode both side trade windows
67 inline void PlayerCreatureRelocationWorker(Player
* pl
, Creature
* c
)
69 // update creature visibility at player/creature move
70 pl
->UpdateVisibilityOf(c
);
72 // Creature AI reaction
73 if(!c
->hasUnitState(UNIT_STAT_SEARCHING
| UNIT_STAT_FLEEING
))
75 if( c
->AI() && c
->AI()->IsVisible(pl
) && !c
->IsInEvadeMode() )
76 c
->AI()->MoveInLineOfSight(pl
);
80 inline void CreatureCreatureRelocationWorker(Creature
* c1
, Creature
* c2
)
82 if(!c1
->hasUnitState(UNIT_STAT_SEARCHING
| UNIT_STAT_FLEEING
))
84 if( c1
->AI() && c1
->AI()->IsVisible(c2
) && !c1
->IsInEvadeMode() )
85 c1
->AI()->MoveInLineOfSight(c2
);
88 if(!c2
->hasUnitState(UNIT_STAT_SEARCHING
| UNIT_STAT_FLEEING
))
90 if( c2
->AI() && c2
->AI()->IsVisible(c1
) && !c2
->IsInEvadeMode() )
91 c2
->AI()->MoveInLineOfSight(c1
);
96 MaNGOS::PlayerRelocationNotifier::Visit(CreatureMapType
&m
)
98 if(!i_player
.isAlive() || i_player
.isInFlight())
101 for(CreatureMapType::iterator iter
=m
.begin(); iter
!= m
.end(); ++iter
)
102 if( iter
->getSource()->isAlive())
103 PlayerCreatureRelocationWorker(&i_player
,iter
->getSource());
108 MaNGOS::CreatureRelocationNotifier::Visit(PlayerMapType
&m
)
110 if(!i_creature
.isAlive())
113 for(PlayerMapType::iterator iter
=m
.begin(); iter
!= m
.end(); ++iter
)
114 if( iter
->getSource()->isAlive() && !iter
->getSource()->isInFlight())
115 PlayerCreatureRelocationWorker(iter
->getSource(), &i_creature
);
120 MaNGOS::CreatureRelocationNotifier::Visit(CreatureMapType
&m
)
122 if(!i_creature
.isAlive())
125 for(CreatureMapType::iterator iter
=m
.begin(); iter
!= m
.end(); ++iter
)
127 Creature
* c
= iter
->getSource();
128 if( c
!= &i_creature
&& c
->isAlive())
129 CreatureCreatureRelocationWorker(c
, &i_creature
);
133 inline void MaNGOS::DynamicObjectUpdater::VisitHelper(Unit
* target
)
135 if(!target
->isAlive() || target
->isInFlight() )
138 if(target
->GetTypeId()==TYPEID_UNIT
&& ((Creature
*)target
)->isTotem())
141 if (!i_dynobject
.IsWithinDistInMap(target
, i_dynobject
.GetRadius()))
144 //Check targets for not_selectable unit flag and remove
145 if (target
->HasFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_NON_ATTACKABLE
| UNIT_FLAG_NOT_SELECTABLE
))
149 if( target
->GetTypeId()==TYPEID_UNIT
&& ((Creature
*)target
)->IsInEvadeMode() )
152 //Check player targets and remove if in GM mode or GM invisibility (for not self casting case)
153 if( target
->GetTypeId()==TYPEID_PLAYER
&& target
!= i_check
&& (((Player
*)target
)->isGameMaster() || ((Player
*)target
)->GetVisibility()==VISIBILITY_OFF
) )
156 if( i_check
->GetTypeId()==TYPEID_PLAYER
)
158 if (i_check
->IsFriendlyTo( target
))
163 if (!i_check
->IsHostileTo( target
))
167 if (i_dynobject
.IsAffecting(target
))
170 SpellEntry
const *spellInfo
= sSpellStore
.LookupEntry(i_dynobject
.GetSpellId());
171 uint32 eff_index
= i_dynobject
.GetEffIndex();
172 // Check target immune to spell or aura
173 if (target
->IsImmunedToSpell(spellInfo
) || target
->IsImmunedToSpellEffect(spellInfo
, eff_index
))
175 // Apply PersistentAreaAura on target
176 PersistentAreaAura
* Aur
= new PersistentAreaAura(spellInfo
, eff_index
, NULL
, target
, i_dynobject
.GetCaster());
177 target
->AddAura(Aur
);
178 i_dynobject
.AddAffected(target
);
183 MaNGOS::DynamicObjectUpdater::Visit(CreatureMapType
&m
)
185 for(CreatureMapType::iterator itr
=m
.begin(); itr
!= m
.end(); ++itr
)
186 VisitHelper(itr
->getSource());
191 MaNGOS::DynamicObjectUpdater::Visit(PlayerMapType
&m
)
193 for(PlayerMapType::iterator itr
=m
.begin(); itr
!= m
.end(); ++itr
)
194 VisitHelper(itr
->getSource());
197 // SEARCHERS & LIST SEARCHERS & WORKERS
199 // WorldObject searchers & workers
201 template<class Check
>
202 void MaNGOS::WorldObjectSearcher
<Check
>::Visit(GameObjectMapType
&m
)
208 for(GameObjectMapType::iterator itr
=m
.begin(); itr
!= m
.end(); ++itr
)
210 if(i_check(itr
->getSource()))
212 i_object
= itr
->getSource();
218 template<class Check
>
219 void MaNGOS::WorldObjectSearcher
<Check
>::Visit(PlayerMapType
&m
)
225 for(PlayerMapType::iterator itr
=m
.begin(); itr
!= m
.end(); ++itr
)
227 if(i_check(itr
->getSource()))
229 i_object
= itr
->getSource();
235 template<class Check
>
236 void MaNGOS::WorldObjectSearcher
<Check
>::Visit(CreatureMapType
&m
)
242 for(CreatureMapType::iterator itr
=m
.begin(); itr
!= m
.end(); ++itr
)
244 if(i_check(itr
->getSource()))
246 i_object
= itr
->getSource();
252 template<class Check
>
253 void MaNGOS::WorldObjectSearcher
<Check
>::Visit(CorpseMapType
&m
)
259 for(CorpseMapType::iterator itr
=m
.begin(); itr
!= m
.end(); ++itr
)
261 if(i_check(itr
->getSource()))
263 i_object
= itr
->getSource();
269 template<class Check
>
270 void MaNGOS::WorldObjectSearcher
<Check
>::Visit(DynamicObjectMapType
&m
)
276 for(DynamicObjectMapType::iterator itr
=m
.begin(); itr
!= m
.end(); ++itr
)
278 if(i_check(itr
->getSource()))
280 i_object
= itr
->getSource();
286 template<class Check
>
287 void MaNGOS::WorldObjectListSearcher
<Check
>::Visit(PlayerMapType
&m
)
289 for(PlayerMapType::iterator itr
=m
.begin(); itr
!= m
.end(); ++itr
)
290 if(i_check(itr
->getSource()))
291 i_objects
.push_back(itr
->getSource());
294 template<class Check
>
295 void MaNGOS::WorldObjectListSearcher
<Check
>::Visit(CreatureMapType
&m
)
297 for(CreatureMapType::iterator itr
=m
.begin(); itr
!= m
.end(); ++itr
)
298 if(i_check(itr
->getSource()))
299 i_objects
.push_back(itr
->getSource());
302 template<class Check
>
303 void MaNGOS::WorldObjectListSearcher
<Check
>::Visit(CorpseMapType
&m
)
305 for(CorpseMapType::iterator itr
=m
.begin(); itr
!= m
.end(); ++itr
)
306 if(i_check(itr
->getSource()))
307 i_objects
.push_back(itr
->getSource());
310 template<class Check
>
311 void MaNGOS::WorldObjectListSearcher
<Check
>::Visit(GameObjectMapType
&m
)
313 for(GameObjectMapType::iterator itr
=m
.begin(); itr
!= m
.end(); ++itr
)
314 if(i_check(itr
->getSource()))
315 i_objects
.push_back(itr
->getSource());
318 template<class Check
>
319 void MaNGOS::WorldObjectListSearcher
<Check
>::Visit(DynamicObjectMapType
&m
)
321 for(DynamicObjectMapType::iterator itr
=m
.begin(); itr
!= m
.end(); ++itr
)
322 if(i_check(itr
->getSource()))
323 i_objects
.push_back(itr
->getSource());
326 // Gameobject searchers
328 template<class Check
>
329 void MaNGOS::GameObjectSearcher
<Check
>::Visit(GameObjectMapType
&m
)
335 for(GameObjectMapType::iterator itr
=m
.begin(); itr
!= m
.end(); ++itr
)
337 if(i_check(itr
->getSource()))
339 i_object
= itr
->getSource();
345 template<class Check
>
346 void MaNGOS::GameObjectLastSearcher
<Check
>::Visit(GameObjectMapType
&m
)
348 for(GameObjectMapType::iterator itr
=m
.begin(); itr
!= m
.end(); ++itr
)
350 if(i_check(itr
->getSource()))
351 i_object
= itr
->getSource();
355 template<class Check
>
356 void MaNGOS::GameObjectListSearcher
<Check
>::Visit(GameObjectMapType
&m
)
358 for(GameObjectMapType::iterator itr
=m
.begin(); itr
!= m
.end(); ++itr
)
359 if(i_check(itr
->getSource()))
360 i_objects
.push_back(itr
->getSource());
365 template<class Check
>
366 void MaNGOS::UnitSearcher
<Check
>::Visit(CreatureMapType
&m
)
372 for(CreatureMapType::iterator itr
=m
.begin(); itr
!= m
.end(); ++itr
)
374 if(i_check(itr
->getSource()))
376 i_object
= itr
->getSource();
382 template<class Check
>
383 void MaNGOS::UnitSearcher
<Check
>::Visit(PlayerMapType
&m
)
389 for(PlayerMapType::iterator itr
=m
.begin(); itr
!= m
.end(); ++itr
)
391 if(i_check(itr
->getSource()))
393 i_object
= itr
->getSource();
399 template<class Check
>
400 void MaNGOS::UnitLastSearcher
<Check
>::Visit(CreatureMapType
&m
)
402 for(CreatureMapType::iterator itr
=m
.begin(); itr
!= m
.end(); ++itr
)
404 if(i_check(itr
->getSource()))
405 i_object
= itr
->getSource();
409 template<class Check
>
410 void MaNGOS::UnitLastSearcher
<Check
>::Visit(PlayerMapType
&m
)
412 for(PlayerMapType::iterator itr
=m
.begin(); itr
!= m
.end(); ++itr
)
414 if(i_check(itr
->getSource()))
415 i_object
= itr
->getSource();
419 template<class Check
>
420 void MaNGOS::UnitListSearcher
<Check
>::Visit(PlayerMapType
&m
)
422 for(PlayerMapType::iterator itr
=m
.begin(); itr
!= m
.end(); ++itr
)
423 if(i_check(itr
->getSource()))
424 i_objects
.push_back(itr
->getSource());
427 template<class Check
>
428 void MaNGOS::UnitListSearcher
<Check
>::Visit(CreatureMapType
&m
)
430 for(CreatureMapType::iterator itr
=m
.begin(); itr
!= m
.end(); ++itr
)
431 if(i_check(itr
->getSource()))
432 i_objects
.push_back(itr
->getSource());
435 // Creature searchers
437 template<class Check
>
438 void MaNGOS::CreatureSearcher
<Check
>::Visit(CreatureMapType
&m
)
444 for(CreatureMapType::iterator itr
=m
.begin(); itr
!= m
.end(); ++itr
)
446 if(i_check(itr
->getSource()))
448 i_object
= itr
->getSource();
454 template<class Check
>
455 void MaNGOS::CreatureLastSearcher
<Check
>::Visit(CreatureMapType
&m
)
457 for(CreatureMapType::iterator itr
=m
.begin(); itr
!= m
.end(); ++itr
)
459 if(i_check(itr
->getSource()))
460 i_object
= itr
->getSource();
464 template<class Check
>
465 void MaNGOS::CreatureListSearcher
<Check
>::Visit(CreatureMapType
&m
)
467 for(CreatureMapType::iterator itr
=m
.begin(); itr
!= m
.end(); ++itr
)
468 if(i_check(itr
->getSource()))
469 i_objects
.push_back(itr
->getSource());
472 template<class Check
>
473 void MaNGOS::PlayerSearcher
<Check
>::Visit(PlayerMapType
&m
)
479 for(PlayerMapType::iterator itr
=m
.begin(); itr
!= m
.end(); ++itr
)
481 if(i_check(itr
->getSource()))
483 i_object
= itr
->getSource();
489 #endif // MANGOS_GRIDNOTIFIERSIMPL_H