AzerothCore 3.3.5a
OpenSource WoW Emulator
Loading...
Searching...
No Matches
Acore::MessageDistDelivererToHostile Struct Reference

#include "GridNotifiers.h"

Public Member Functions

 MessageDistDelivererToHostile (Unit *src, WorldPacket *msg, float dist)
 
void Visit (PlayerMapType &m)
 
void Visit (CreatureMapType &m)
 
void Visit (DynamicObjectMapType &m)
 
template<class SKIP >
void Visit (GridRefMgr< SKIP > &)
 
void SendPacket (Player *player)
 

Public Attributes

Uniti_source
 
WorldPacketi_message
 
uint32 i_phaseMask
 
float i_distSq
 

Detailed Description

Constructor & Destructor Documentation

◆ MessageDistDelivererToHostile()

Acore::MessageDistDelivererToHostile::MessageDistDelivererToHostile ( Unit src,
WorldPacket msg,
float  dist 
)
inline
139 : i_source(src), i_message(msg), i_phaseMask(src->GetPhaseMask()), i_distSq(dist * dist)
140 {
141 }
uint32 GetPhaseMask() const
Definition: Object.h:446
uint32 i_phaseMask
Definition: GridNotifiers.h:136
float i_distSq
Definition: GridNotifiers.h:137
Unit * i_source
Definition: GridNotifiers.h:134
WorldPacket * i_message
Definition: GridNotifiers.h:135

Member Function Documentation

◆ SendPacket()

void Acore::MessageDistDelivererToHostile::SendPacket ( Player player)
inline
148 {
149 // never send packet to self
150 if (player == i_source || !player->HaveAtClient(i_source) || player->IsFriendlyTo(i_source))
151 return;
152
153 player->GetSession()->SendPacket(i_message);
154 }
bool HaveAtClient(WorldObject const *u) const
Definition: Player.cpp:11408
WorldSession * GetSession() const
Definition: Player.h:1978
bool IsFriendlyTo(Unit const *unit) const
Definition: Unit.cpp:10203
void SendPacket(WorldPacket const *packet)
Send a packet to the client.
Definition: WorldSession.cpp:214

References Player::GetSession(), Player::HaveAtClient(), i_message, i_source, Unit::IsFriendlyTo(), and WorldSession::SendPacket().

Referenced by Visit().

◆ Visit() [1/4]

void MessageDistDelivererToHostile::Visit ( CreatureMapType m)
322{
323 for (CreatureMapType::iterator iter = m.begin(); iter != m.end(); ++iter)
324 {
325 Creature* target = iter->GetSource();
326 if (!target->HasSharedVision() || !target->InSamePhase(i_phaseMask))
327 continue;
328
329 if (target->GetExactDist2dSq(i_source) > i_distSq)
330 continue;
331
332 // Send packet to all who are sharing the creature's vision
333 SharedVisionList::const_iterator i = target->GetSharedVisionList().begin();
334 for (; i != target->GetSharedVisionList().end(); ++i)
335 if ((*i)->m_seer == target)
336 SendPacket(*i);
337 }
338}
Definition: LinkedList.h:139
Definition: Creature.h:46
bool InSamePhase(WorldObject const *obj) const
Definition: Object.h:447
float GetExactDist2dSq(const float x, const float y) const
Definition: Position.h:157
SharedVisionList const & GetSharedVisionList()
Definition: Unit.h:1284
bool HasSharedVision() const
Definition: Unit.h:1287
iterator begin()
Definition: GridRefMgr.h:35
iterator end()
Definition: GridRefMgr.h:36
void SendPacket(Player *player)
Definition: GridNotifiers.h:147

References GridRefMgr< OBJECT >::begin(), GridRefMgr< OBJECT >::end(), Position::GetExactDist2dSq(), Unit::GetSharedVisionList(), Unit::HasSharedVision(), i_distSq, i_phaseMask, i_source, WorldObject::InSamePhase(), and SendPacket().

◆ Visit() [2/4]

void MessageDistDelivererToHostile::Visit ( DynamicObjectMapType m)
341{
342 for (DynamicObjectMapType::iterator iter = m.begin(); iter != m.end(); ++iter)
343 {
344 DynamicObject* target = iter->GetSource();
345 if (!target->GetCasterGUID().IsPlayer() || !target->InSamePhase(i_phaseMask))
346 continue;
347
348 if (target->GetExactDist2dSq(i_source) > i_distSq)
349 continue;
350
351 // Send packet back to the caster if the caster has vision of dynamic object
352 Player* caster = (Player*)target->GetCaster();
353 if (caster && caster->m_seer == target)
354 SendPacket(caster);
355 }
356}
Definition: DynamicObject.h:35
Unit * GetCaster() const
Definition: DynamicObject.h:55
ObjectGuid GetCasterGUID() const
Definition: DynamicObject.h:59
bool IsPlayer() const
Definition: ObjectGuid.h:168
Definition: Player.h:1064
WorldObject * m_seer
Definition: Player.h:2314

References GridRefMgr< OBJECT >::begin(), GridRefMgr< OBJECT >::end(), DynamicObject::GetCaster(), DynamicObject::GetCasterGUID(), Position::GetExactDist2dSq(), i_distSq, i_phaseMask, i_source, WorldObject::InSamePhase(), ObjectGuid::IsPlayer(), Player::m_seer, and SendPacket().

◆ Visit() [3/4]

template<class SKIP >
void Acore::MessageDistDelivererToHostile::Visit ( GridRefMgr< SKIP > &  )
inline
145{}

◆ Visit() [4/4]

void MessageDistDelivererToHostile::Visit ( PlayerMapType m)
297{
298 for (PlayerMapType::iterator iter = m.begin(); iter != m.end(); ++iter)
299 {
300 Player* target = iter->GetSource();
301 if (!target->InSamePhase(i_phaseMask))
302 continue;
303
304 if (target->GetExactDist2dSq(i_source) > i_distSq)
305 continue;
306
307 // Send packet to all who are sharing the player's vision
308 if (target->HasSharedVision())
309 {
310 SharedVisionList::const_iterator i = target->GetSharedVisionList().begin();
311 for (; i != target->GetSharedVisionList().end(); ++i)
312 if ((*i)->m_seer == target)
313 SendPacket(*i);
314 }
315
316 if (target->m_seer == target || target->GetVehicle())
317 SendPacket(target);
318 }
319}
Vehicle * GetVehicle() const
Definition: Unit.h:1673

References GridRefMgr< OBJECT >::begin(), GridRefMgr< OBJECT >::end(), Position::GetExactDist2dSq(), Unit::GetSharedVisionList(), Unit::GetVehicle(), Unit::HasSharedVision(), i_distSq, i_phaseMask, i_source, WorldObject::InSamePhase(), Player::m_seer, and SendPacket().

Member Data Documentation

◆ i_distSq

float Acore::MessageDistDelivererToHostile::i_distSq

Referenced by Visit().

◆ i_message

WorldPacket* Acore::MessageDistDelivererToHostile::i_message

Referenced by SendPacket().

◆ i_phaseMask

uint32 Acore::MessageDistDelivererToHostile::i_phaseMask

Referenced by Visit().

◆ i_source

Unit* Acore::MessageDistDelivererToHostile::i_source

Referenced by SendPacket(), and Visit().