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:11444
TeamId GetTeamId(bool original=false) const
Definition: Player.h:2108
WorldSession * GetSession() const
Definition: Player.h:1998
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)
243{
244 for (CreatureMapType::iterator iter = m.begin(); iter != m.end(); ++iter)
245 {
246 Creature* target = iter->GetSource();
247 if (!target->HasSharedVision() || !target->InSamePhase(i_phaseMask))
248 continue;
249
250 if (required3dDist)
251 {
252 if (target->GetExactDistSq(i_source) > i_distSq)
253 continue;
254 }
255 else
256 if (target->GetExactDist2dSq(i_source) > i_distSq)
257 continue;
258
259 // Send packet to all who are sharing the creature's vision
260 SharedVisionList::const_iterator i = target->GetSharedVisionList().begin();
261 for (; i != target->GetSharedVisionList().end(); ++i)
262 if ((*i)->m_seer == target)
263 SendPacket(*i);
264 }
265}
Definition: LinkedList.h:139
Definition: Creature.h:43
bool InSamePhase(WorldObject const *obj) const
Definition: Object.h:452
float GetExactDist2dSq(const float x, const float y) const
Definition: Position.h:156
float GetExactDistSq(float x, float y, float z) const
Definition: Position.h:169
SharedVisionList const & GetSharedVisionList()
Definition: Unit.h:1737
bool HasSharedVision() const
Definition: Unit.h:1740
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)
268{
269 for (DynamicObjectMapType::iterator iter = m.begin(); iter != m.end(); ++iter)
270 {
271 DynamicObject* target = iter->GetSource();
272 if (!target->GetCasterGUID().IsPlayer() || !target->InSamePhase(i_phaseMask))
273 continue;
274
275 // Xinef: Check whether the dynobject allows to see through it
276 if (!target->IsViewpoint())
277 continue;
278
279 if (required3dDist)
280 {
281 if (target->GetExactDistSq(i_source) > i_distSq)
282 continue;
283 }
284 else
285 if (target->GetExactDist2dSq(i_source) > i_distSq)
286 continue;
287
288 // Send packet back to the caster if the caster has vision of dynamic object
289 Player* caster = (Player*)target->GetCaster();
290 if (caster && caster->m_seer == target)
291 SendPacket(caster);
292 }
293}
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:1081
WorldObject * m_seer
Definition: Player.h:2334

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

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().