TrinityCore
Loading...
Searching...
No Matches
GridNotifiers.cpp
Go to the documentation of this file.
1/*
2 * This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2 of the License, or (at your
7 * option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#include "GridNotifiers.h"
19#include "GridNotifiersImpl.h"
20#include "WorldPacket.h"
21#include "WorldSession.h"
22#include "UpdateData.h"
23#include "Transport.h"
24#include "ObjectAccessor.h"
25#include "CellImpl.h"
26
27using namespace Trinity;
28
30{
31 // at this moment i_clientGUIDs have guids that not iterate at grid level checks
32 // but exist one case when this possible and object not out of range: transports
33 if (Transport* transport = i_player.GetTransport())
34 {
35 for (Transport::PassengerSet::const_iterator itr = transport->GetPassengers().begin(); itr != transport->GetPassengers().end(); ++itr)
36 {
37 if (vis_guids.find((*itr)->GetGUID()) != vis_guids.end())
38 {
39 vis_guids.erase((*itr)->GetGUID());
40
41 switch ((*itr)->GetTypeId())
42 {
44 i_player.UpdateVisibilityOf((*itr)->ToGameObject(), i_data, i_visibleNow);
45 break;
46 case TYPEID_PLAYER:
47 i_player.UpdateVisibilityOf((*itr)->ToPlayer(), i_data, i_visibleNow);
48 if (!(*itr)->isNeedNotify(NOTIFY_VISIBILITY_CHANGED))
49 (*itr)->ToPlayer()->UpdateVisibilityOf(&i_player);
50 break;
51 case TYPEID_UNIT:
52 i_player.UpdateVisibilityOf((*itr)->ToCreature(), i_data, i_visibleNow);
53 break;
55 i_player.UpdateVisibilityOf((*itr)->ToDynObject(), i_data, i_visibleNow);
56 break;
57 default:
58 break;
59 }
60 }
61 }
62 }
63
64 for (auto it = vis_guids.begin(); it != vis_guids.end(); ++it)
65 {
66 i_player.m_clientGUIDs.erase(*it);
68
69 if (it->IsPlayer())
70 {
72 if (player && !player->isNeedNotify(NOTIFY_VISIBILITY_CHANGED))
74 }
75 }
76
77 if (!i_data.HasData())
78 return;
79
80 WorldPacket packet;
81 i_data.BuildPacket(&packet);
83
84 for (std::set<Unit*>::const_iterator it = i_visibleNow.begin(); it != i_visibleNow.end(); ++it)
86}
87
89{
90 for (PlayerMapType::iterator iter = m.begin(); iter != m.end(); ++iter)
91 {
92 if (iter->GetSource() == &i_object)
93 continue;
94
95 iter->GetSource()->UpdateVisibilityOf(&i_object);
96
97 if (iter->GetSource()->HasSharedVision())
98 {
99 for (SharedVisionList::const_iterator i = iter->GetSource()->GetSharedVisionList().begin();
100 i != iter->GetSource()->GetSharedVisionList().end(); ++i)
101 {
102 if ((*i)->m_seer == iter->GetSource())
103 (*i)->UpdateVisibilityOf(&i_object);
104 }
105 }
106 }
107}
108
110{
111 for (CreatureMapType::iterator iter = m.begin(); iter != m.end(); ++iter)
112 if (iter->GetSource()->HasSharedVision())
113 for (SharedVisionList::const_iterator i = iter->GetSource()->GetSharedVisionList().begin();
114 i != iter->GetSource()->GetSharedVisionList().end(); ++i)
115 if ((*i)->m_seer == iter->GetSource())
116 (*i)->UpdateVisibilityOf(&i_object);
117}
118
120{
121 for (DynamicObjectMapType::iterator iter = m.begin(); iter != m.end(); ++iter)
122 if (Unit* caster = iter->GetSource()->GetCaster())
123 if (Player* player = caster->ToPlayer())
124 if (player->m_seer == iter->GetSource())
125 player->UpdateVisibilityOf(&i_object);
126}
127
129{
130 if (!u->IsAlive() || !c->IsAlive() || c == u || u->IsInFlight())
131 return;
132
134 {
135 if (c->IsAIEnabled() && c->CanSeeOrDetect(u, false, true))
136 c->AI()->MoveInLineOfSight_Safe(u);
137 else
138 if (u->GetTypeId() == TYPEID_PLAYER && u->HasStealthAura() && c->IsAIEnabled() && c->CanSeeOrDetect(u, false, true, true))
139 c->AI()->TriggerAlert(u);
140 }
141}
142
144{
145 for (PlayerMapType::iterator iter = m.begin(); iter != m.end(); ++iter)
146 {
147 Player* player = iter->GetSource();
148
149 vis_guids.erase(player->GetGUID());
150
152
154 continue;
155
157 }
158}
159
161{
162 bool relocated_for_ai = (&i_player == i_player.m_seer);
163
164 for (CreatureMapType::iterator iter=m.begin(); iter != m.end(); ++iter)
165 {
166 Creature* c = iter->GetSource();
167
168 vis_guids.erase(c->GetGUID());
169
171
172 if (relocated_for_ai && !c->isNeedNotify(NOTIFY_VISIBILITY_CHANGED))
174 }
175}
176
178{
179 for (PlayerMapType::iterator iter = m.begin(); iter != m.end(); ++iter)
180 {
181 Player* player = iter->GetSource();
182
185
187 }
188}
189
191{
192 if (!i_creature.IsAlive())
193 return;
194
195 for (CreatureMapType::iterator iter = m.begin(); iter != m.end(); ++iter)
196 {
197 Creature* c = iter->GetSource();
199
202 }
203}
204
206{
207 for (CreatureMapType::iterator iter = m.begin(); iter != m.end(); ++iter)
208 {
209 Creature* unit = iter->GetSource();
211 continue;
212
213 CreatureRelocationNotifier relocate(*unit);
214
217
218 cell.Visit(p, c2world_relocation, i_map, *unit, i_radius);
219 cell.Visit(p, c2grid_relocation, i_map, *unit, i_radius);
220 }
221}
222
224{
225 for (PlayerMapType::iterator iter = m.begin(); iter != m.end(); ++iter)
226 {
227 Player* player = iter->GetSource();
228 WorldObject const* viewPoint = player->m_seer;
229
231 continue;
232
233 if (player != viewPoint && !viewPoint->IsPositionValid())
234 continue;
235
236 PlayerRelocationNotifier relocate(*player);
237 Cell::VisitAllObjects(viewPoint, relocate, i_radius, false);
238 relocate.SendToSelf();
239 }
240}
241
243{
244 for (CreatureMapType::iterator iter = m.begin(); iter != m.end(); ++iter)
245 {
246 Creature* c = iter->GetSource();
248 if (isCreature)
250 }
251}
252
254{
255 for (PlayerMapType::iterator iter = m.begin(); iter != m.end(); ++iter)
256 {
257 Player* target = iter->GetSource();
258 if (!target->InSamePhase(i_phaseMask))
259 continue;
260
261 if (required3dDist)
262 {
263 if (target->GetExactDistSq(i_source) > i_distSq)
264 continue;
265 }
266 else
267 {
268 if (target->GetExactDist2dSq(i_source) > i_distSq)
269 continue;
270 }
271
272 // Send packet to all who are sharing the player's vision
273 if (target->HasSharedVision())
274 {
275 SharedVisionList::const_iterator i = target->GetSharedVisionList().begin();
276 for (; i != target->GetSharedVisionList().end(); ++i)
277 if ((*i)->m_seer == target)
278 SendPacket(*i);
279 }
280
281 if (target->m_seer == target || target->GetVehicle())
282 SendPacket(target);
283 }
284}
285
287{
288 for (CreatureMapType::iterator iter = m.begin(); iter != m.end(); ++iter)
289 {
290 Creature* target = iter->GetSource();
291 if (!target->InSamePhase(i_phaseMask))
292 continue;
293
294 if (required3dDist)
295 {
296 if (target->GetExactDistSq(i_source) > i_distSq)
297 continue;
298 }
299 else
300 {
301 if (target->GetExactDist2dSq(i_source) > i_distSq)
302 continue;
303 }
304
305 // Send packet to all who are sharing the creature's vision
306 if (target->HasSharedVision())
307 {
308 SharedVisionList::const_iterator i = target->GetSharedVisionList().begin();
309 for (; i != target->GetSharedVisionList().end(); ++i)
310 if ((*i)->m_seer == target)
311 SendPacket(*i);
312 }
313 }
314}
315
317{
318 for (DynamicObjectMapType::iterator iter = m.begin(); iter != m.end(); ++iter)
319 {
320 DynamicObject* target = iter->GetSource();
321 if (!target->InSamePhase(i_phaseMask))
322 continue;
323
324 if (required3dDist)
325 {
326 if (target->GetExactDistSq(i_source) > i_distSq)
327 continue;
328 }
329 else
330 {
331 if (target->GetExactDist2dSq(i_source) > i_distSq)
332 continue;
333 }
334
335 if (Unit* caster = target->GetCaster())
336 {
337 // Send packet back to the caster if the caster has vision of dynamic object
338 Player* player = caster->ToPlayer();
339 if (player && player->m_seer == target)
340 SendPacket(player);
341 }
342 }
343}
344
346{
347 for (PlayerMapType::iterator iter = m.begin(); iter != m.end(); ++iter)
348 {
349 Player* target = iter->GetSource();
350 if (!target->InSamePhase(i_phaseMask))
351 continue;
352
353 if (target->GetExactDist2dSq(i_source) > i_distSq)
354 continue;
355
356 // Send packet to all who are sharing the player's vision
357 if (target->HasSharedVision())
358 {
359 SharedVisionList::const_iterator i = target->GetSharedVisionList().begin();
360 for (; i != target->GetSharedVisionList().end(); ++i)
361 if ((*i)->m_seer == target)
362 SendPacket(*i);
363 }
364
365 if (target->m_seer == target || target->GetVehicle())
366 SendPacket(target);
367 }
368}
369
371{
372 for (CreatureMapType::iterator iter = m.begin(); iter != m.end(); ++iter)
373 {
374 Creature* target = iter->GetSource();
375 if (!target->InSamePhase(i_phaseMask))
376 continue;
377
378 if (target->GetExactDist2dSq(i_source) > i_distSq)
379 continue;
380
381 // Send packet to all who are sharing the creature's vision
382 if (target->HasSharedVision())
383 {
384 SharedVisionList::const_iterator i = target->GetSharedVisionList().begin();
385 for (; i != target->GetSharedVisionList().end(); ++i)
386 if ((*i)->m_seer == target)
387 SendPacket(*i);
388 }
389 }
390}
391
393{
394 for (DynamicObjectMapType::iterator iter = m.begin(); iter != m.end(); ++iter)
395 {
396 DynamicObject* target = iter->GetSource();
397 if (!target->InSamePhase(i_phaseMask))
398 continue;
399
400 if (target->GetExactDist2dSq(i_source) > i_distSq)
401 continue;
402
403 if (Unit* caster = target->GetCaster())
404 {
405 // Send packet back to the caster if the caster has vision of dynamic object
406 Player* player = caster->ToPlayer();
407 if (player && player->m_seer == target)
408 SendPacket(player);
409 }
410 }
411}
412
413/*
414void
415MessageDistDeliverer::VisitObject(Player* player)
416{
417 if (!i_ownTeamOnly || (i_source.GetTypeId() == TYPEID_PLAYER && player->GetTeam() == ((Player&)i_source).GetTeam()))
418 {
419 SendPacket(player);
420 }
421}
422*/
423
424template<class T>
426{
427 for (typename GridRefManager<T>::iterator iter = m.begin(); iter != m.end(); ++iter)
428 if (iter->GetSource()->IsInWorld())
429 iter->GetSource()->Update(i_timeDiff);
430}
431
436
441
446
451
456
461
462template void ObjectUpdater::Visit<Creature>(CreatureMapType&);
463template void ObjectUpdater::Visit<GameObject>(GameObjectMapType&);
464template void ObjectUpdater::Visit<DynamicObject>(DynamicObjectMapType&);
@ CORPSE_BONES
Definition Corpse.h:29
void CreatureUnitRelocationWorker(Creature *c, Unit *u)
@ NOTIFY_VISIBILITY_CHANGED
@ TYPEID_DYNAMICOBJECT
Definition ObjectGuid.h:41
@ TYPEID_GAMEOBJECT
Definition ObjectGuid.h:40
@ TYPEID_UNIT
Definition ObjectGuid.h:38
@ TYPEID_PLAYER
Definition ObjectGuid.h:39
@ SPELL_AURA_GHOST
@ UNIT_STATE_SIGHTLESS
Definition Unit.h:263
CorpseType GetType() const
Definition Corpse.h:72
void TriggerAlert(Unit const *who) const
void MoveInLineOfSight_Safe(Unit *who)
== Reactions At =================================
CreatureAI * AI() const
Definition Creature.h:154
Unit * GetCaster() const
iterator begin()
TypeID GetTypeId() const
Definition Object.h:93
static ObjectGuid GetGUID(Object const *o)
Definition Object.h:78
static Player * ToPlayer(Object *o)
Definition Object.h:180
void SendDirectMessage(WorldPacket const *data) const
Definition Player.cpp:6161
GuidUnorderedSet m_clientGUIDs
Definition Player.h:2095
void UpdateVisibilityOf(WorldObject *target)
Definition Player.cpp:22172
WorldObject * m_seer
Definition Player.h:2061
void SendInitialVisiblePackets(Unit *target) const
Definition Player.cpp:22250
WorldObject const *const i_searchObj
Definition Unit.h:769
Vehicle * GetVehicle() const
Definition Unit.h:1737
bool IsAlive() const
Definition Unit.h:1234
bool HasStealthAura() const
Definition Unit.h:1165
bool IsInFlight() const
Definition Unit.h:1119
bool IsAIEnabled() const
Definition Unit.h:798
SharedVisionList const & GetSharedVisionList()
Definition Unit.h:1305
bool HasAuraType(AuraType auraType) const
Definition Unit.cpp:4542
bool HasUnitState(const uint32 f) const
Definition Unit.h:876
bool HasSharedVision() const
Definition Unit.h:1308
bool HasData() const
Definition UpdateData.h:69
void AddOutOfRangeGUID(GuidSet &guids)
bool BuildPacket(WorldPacket *packet)
bool isNeedNotify(uint16 f) const
Definition Object.h:547
bool CanSeeOrDetect(WorldObject const *obj, bool implicitDetect=false, bool distanceCheck=false, bool checkAlert=false) const
Definition Object.cpp:1547
bool InSamePhase(uint32 phasemask) const
Definition Object.h:369
Transport * GetTransport() const
Definition Object.h:564
bool IsWithinDistInMap(WorldObject const *obj, float dist2compare, bool is3D=true, bool incOwnRadius=true, bool incTargetRadius=true) const
Definition Object.cpp:1192
TC_GAME_API Player * FindPlayer(ObjectGuid const &)
static void VisitAllObjects(WorldObject const *obj, T &visitor, float radius, bool dont_load=true)
Definition CellImpl.h:192
void Visit(CellCoord const &, TypeContainerVisitor< T, CONTAINER > &visitor, Map &, WorldObject const &obj, float radius) const
Definition CellImpl.h:50
float GetExactDist2dSq(const float x, const float y) const
Definition Position.h:100
bool IsPositionValid() const
Definition Position.cpp:44
float GetExactDistSq(float x, float y, float z) const
Definition Position.h:113
void Visit(GridRefManager< T > &)
void Visit(GridRefManager< T > &)
void Visit(GridRefManager< T > &)
void Visit(PlayerMapType &m)
WorldObject const * i_source
void SendPacket(Player *player)
void Visit(GridRefManager< T > &m)
void Visit(GridRefManager< T > &m)
void Visit(GridRefManager< T > &)
GuidUnorderedSet vis_guids
std::set< Unit * > i_visibleNow
bool operator()(WorldObject *target) const
Definition Spell.cpp:8362