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

#include "GridNotifiers.h"

Public Member Functions

 MessageDistDeliverer (WorldObject const *src, WorldPacket const *msg, float dist, bool own_team_only=false, Player const *skipped=nullptr, bool req3dDist=false)
 
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

WorldObject const * i_source
 
WorldPacket const * i_message
 
uint32 i_phaseMask
 
float i_distSq
 
TeamId teamId
 
Player const * skipped_receiver
 
bool required3dDist
 

Detailed Description

Constructor & Destructor Documentation

◆ MessageDistDeliverer()

Acore::MessageDistDeliverer::MessageDistDeliverer ( WorldObject const *  src,
WorldPacket const *  msg,
float  dist,
bool  own_team_only = false,
Player const *  skipped = nullptr,
bool  req3dDist = false 
)
inline
109 : i_source(src), i_message(msg), i_phaseMask(src->GetPhaseMask()), i_distSq(dist * dist)
110 , teamId((own_team_only && src->IsPlayer()) ? src->ToPlayer()->GetTeamId() : TEAM_NEUTRAL)
111 , skipped_receiver(skipped), required3dDist(req3dDist)
112 {
113 }
@ TEAM_NEUTRAL
Definition: SharedDefines.h:762
Player const * skipped_receiver
Definition: GridNotifiers.h:106
float i_distSq
Definition: GridNotifiers.h:104
WorldObject const * i_source
Definition: GridNotifiers.h:101
uint32 i_phaseMask
Definition: GridNotifiers.h:103
bool required3dDist
Definition: GridNotifiers.h:107
WorldPacket const * i_message
Definition: GridNotifiers.h:102
TeamId teamId
Definition: GridNotifiers.h:105

Member Function Documentation

◆ SendPacket()

void Acore::MessageDistDeliverer::SendPacket ( Player player)
inline
120 {
121 // never send packet to self
122 if (player == i_source || (teamId != TEAM_NEUTRAL && player->GetTeamId() != teamId) || skipped_receiver == player)
123 return;
124
125 if (!player->HaveAtClient(i_source))
126 return;
127
128 player->GetSession()->SendPacket(i_message);
129 }
bool HaveAtClient(WorldObject const *u) const
Definition: Player.cpp:11408
TeamId GetTeamId(bool original=false) const
Definition: Player.h:2088
WorldSession * GetSession() const
Definition: Player.h:1978
void SendPacket(WorldPacket const *packet)
Send a packet to the client.
Definition: WorldSession.cpp:214

References Player::GetSession(), Player::GetTeamId(), Player::HaveAtClient(), i_message, i_source, WorldSession::SendPacket(), skipped_receiver, TEAM_NEUTRAL, and teamId.

Referenced by Visit().

◆ Visit() [1/4]

void MessageDistDeliverer::Visit ( CreatureMapType m)
244{
245 for (CreatureMapType::iterator iter = m.begin(); iter != m.end(); ++iter)
246 {
247 Creature* target = iter->GetSource();
248 if (!target->HasSharedVision() || !target->InSamePhase(i_phaseMask))
249 continue;
250
251 if (required3dDist)
252 {
253 if (target->GetExactDistSq(i_source) > i_distSq)
254 continue;
255 }
256 else
257 if (target->GetExactDist2dSq(i_source) > i_distSq)
258 continue;
259
260 // Send packet to all who are sharing the creature's vision
261 SharedVisionList::const_iterator i = target->GetSharedVisionList().begin();
262 for (; i != target->GetSharedVisionList().end(); ++i)
263 if ((*i)->m_seer == target)
264 SendPacket(*i);
265 }
266}
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
float GetExactDistSq(float x, float y, float z) const
Definition: Position.h:170
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:119

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

◆ Visit() [2/4]

void MessageDistDeliverer::Visit ( DynamicObjectMapType m)
269{
270 for (DynamicObjectMapType::iterator iter = m.begin(); iter != m.end(); ++iter)
271 {
272 DynamicObject* target = iter->GetSource();
273 if (!target->GetCasterGUID().IsPlayer() || !target->InSamePhase(i_phaseMask))
274 continue;
275
276 // Xinef: Check whether the dynobject allows to see through it
277 if (!target->IsViewpoint())
278 continue;
279
280 if (required3dDist)
281 {
282 if (target->GetExactDistSq(i_source) > i_distSq)
283 continue;
284 }
285 else
286 if (target->GetExactDist2dSq(i_source) > i_distSq)
287 continue;
288
289 // Send packet back to the caster if the caster has vision of dynamic object
290 Player* caster = (Player*)target->GetCaster();
291 if (caster && caster->m_seer == target)
292 SendPacket(caster);
293 }
294}
Definition: DynamicObject.h:35
Unit * GetCaster() const
Definition: DynamicObject.h:55
ObjectGuid GetCasterGUID() const
Definition: DynamicObject.h:59
bool IsViewpoint() const
Definition: DynamicObject.h:61
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(), Position::GetExactDistSq(), i_distSq, i_phaseMask, i_source, WorldObject::InSamePhase(), ObjectGuid::IsPlayer(), DynamicObject::IsViewpoint(), Player::m_seer, required3dDist, and SendPacket().

◆ Visit() [3/4]

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

◆ Visit() [4/4]

void MessageDistDeliverer::Visit ( PlayerMapType m)
213{
214 for (PlayerMapType::iterator iter = m.begin(); iter != m.end(); ++iter)
215 {
216 Player* target = iter->GetSource();
217 if (!target->InSamePhase(i_phaseMask))
218 continue;
219
220 if (required3dDist)
221 {
222 if (target->GetExactDistSq(i_source) > i_distSq)
223 continue;
224 }
225 else
226 if (target->GetExactDist2dSq(i_source) > i_distSq)
227 continue;
228
229 // Send packet to all who are sharing the player's vision
230 if (target->HasSharedVision())
231 {
232 SharedVisionList::const_iterator i = target->GetSharedVisionList().begin();
233 for (; i != target->GetSharedVisionList().end(); ++i)
234 if ((*i)->m_seer == target)
235 SendPacket(*i);
236 }
237
238 if (target->m_seer == target || target->GetVehicle())
239 SendPacket(target);
240 }
241}
Vehicle * GetVehicle() const
Definition: Unit.h:1673

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

Member Data Documentation

◆ i_distSq

float Acore::MessageDistDeliverer::i_distSq

Referenced by Visit().

◆ i_message

WorldPacket const* Acore::MessageDistDeliverer::i_message

Referenced by SendPacket().

◆ i_phaseMask

uint32 Acore::MessageDistDeliverer::i_phaseMask

Referenced by Visit().

◆ i_source

WorldObject const* Acore::MessageDistDeliverer::i_source

Referenced by SendPacket(), and Visit().

◆ required3dDist

bool Acore::MessageDistDeliverer::required3dDist

Referenced by Visit().

◆ skipped_receiver

Player const* Acore::MessageDistDeliverer::skipped_receiver

Referenced by SendPacket().

◆ teamId

TeamId Acore::MessageDistDeliverer::teamId

Referenced by SendPacket().