aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/server/game/Entities/Object/Object.cpp4
-rw-r--r--src/server/game/Entities/Player/Player.cpp6
-rw-r--r--src/server/game/Entities/Unit/Unit.cpp92
-rw-r--r--src/server/game/Grids/Notifiers/GridNotifiers.cpp136
-rw-r--r--src/server/game/Grids/Notifiers/GridNotifiers.h50
-rw-r--r--src/server/game/Grids/Notifiers/GridNotifiersImpl.h142
-rw-r--r--src/server/game/Spells/SpellEffects.cpp5
7 files changed, 190 insertions, 245 deletions
diff --git a/src/server/game/Entities/Object/Object.cpp b/src/server/game/Entities/Object/Object.cpp
index cde6da3c0d4..d1634c70148 100644
--- a/src/server/game/Entities/Object/Object.cpp
+++ b/src/server/game/Entities/Object/Object.cpp
@@ -1657,13 +1657,13 @@ void WorldObject::SendMessageToSet(WorldPacket const* data, bool self) const
void WorldObject::SendMessageToSetInRange(WorldPacket const* data, float dist, bool /*self*/) const
{
- Trinity::MessageDistDeliverer notifier(this, data, dist);
+ Trinity::MessageDistDeliverer<> notifier(this, data, dist);
Cell::VisitWorldObjects(this, notifier, dist);
}
void WorldObject::SendMessageToSet(WorldPacket const* data, Player const* skipped_rcvr) const
{
- Trinity::MessageDistDeliverer notifier(this, data, GetVisibilityRange(), false, skipped_rcvr);
+ Trinity::MessageDistDeliverer<> notifier(this, data, GetVisibilityRange(), false, skipped_rcvr);
Cell::VisitWorldObjects(this, notifier, GetVisibilityRange());
}
diff --git a/src/server/game/Entities/Player/Player.cpp b/src/server/game/Entities/Player/Player.cpp
index 22cb8b25ab6..5581fdd8e4f 100644
--- a/src/server/game/Entities/Player/Player.cpp
+++ b/src/server/game/Entities/Player/Player.cpp
@@ -6094,7 +6094,7 @@ void Player::SendMessageToSetInRange(WorldPacket const* data, float dist, bool s
if (self)
SendDirectMessage(data);
- Trinity::MessageDistDeliverer notifier(this, data, dist);
+ Trinity::MessageDistDeliverer<> notifier(this, data, dist);
Cell::VisitWorldObjects(this, notifier, dist);
}
@@ -6103,7 +6103,7 @@ void Player::SendMessageToSetInRange(WorldPacket const* data, float dist, bool s
if (self)
SendDirectMessage(data);
- Trinity::MessageDistDeliverer notifier(this, data, dist, own_team_only);
+ Trinity::MessageDistDeliverer<> notifier(this, data, dist, own_team_only);
Cell::VisitWorldObjects(this, notifier, dist);
}
@@ -6114,7 +6114,7 @@ void Player::SendMessageToSet(WorldPacket const* data, Player const* skipped_rcv
// we use World::GetMaxVisibleDistance() because i cannot see why not use a distance
// update: replaced by GetMap()->GetVisibilityDistance()
- Trinity::MessageDistDeliverer notifier(this, data, GetVisibilityRange(), false, skipped_rcvr);
+ Trinity::MessageDistDeliverer<> notifier(this, data, GetVisibilityRange(), false, skipped_rcvr);
Cell::VisitWorldObjects(this, notifier, GetVisibilityRange());
}
diff --git a/src/server/game/Entities/Unit/Unit.cpp b/src/server/game/Entities/Unit/Unit.cpp
index ff72d4162e0..88ebe46999a 100644
--- a/src/server/game/Entities/Unit/Unit.cpp
+++ b/src/server/game/Entities/Unit/Unit.cpp
@@ -14505,103 +14505,27 @@ uint32 Unit::GetCastSpellXSpellVisualId(SpellInfo const* spellInfo) const
struct CombatLogSender
{
- WorldObject const* i_source;
WorldPackets::CombatLog::CombatLogServerPacket const* i_message;
- float const i_distSq;
- CombatLogSender(WorldObject const* src, WorldPackets::CombatLog::CombatLogServerPacket* msg, float dist)
- : i_source(src), i_message(msg), i_distSq(dist * dist)
+
+ explicit CombatLogSender(WorldPackets::CombatLog::CombatLogServerPacket* msg)
+ : i_message(msg)
{
msg->Write();
}
- bool IsInRangeHelper(WorldObject const* object) const;
- void Visit(PlayerMapType &m);
- void Visit(CreatureMapType &m);
- void Visit(DynamicObjectMapType &m);
- template<class SKIP> void Visit(GridRefManager<SKIP>&) { }
-
- void SendPacket(Player* player)
+ WorldPacket const* operator()(Player* player) const
{
- if (!player->HaveAtClient(i_source))
- return;
-
if (player->IsAdvancedCombatLoggingEnabled())
- player->SendDirectMessage(i_message->GetFullLogPacket());
+ return i_message->GetFullLogPacket();
else
- player->SendDirectMessage(i_message->GetBasicLogPacket());
+ return i_message->GetBasicLogPacket();
}
};
-bool CombatLogSender::IsInRangeHelper(WorldObject const* object) const
-{
- if (!object->IsInPhase(i_source))
- return false;
-
- return object->GetExactDist2dSq(i_source) <= i_distSq;
-}
-
-void CombatLogSender::Visit(PlayerMapType& m)
-{
- for (PlayerMapType::iterator iter = m.begin(); iter != m.end(); ++iter)
- {
- Player* target = iter->GetSource();
- if (!IsInRangeHelper(target))
- continue;
-
- // Send packet to all who are sharing the player's vision
- if (target->HasSharedVision())
- {
- SharedVisionList::const_iterator i = target->GetSharedVisionList().begin();
- for (; i != target->GetSharedVisionList().end(); ++i)
- if ((*i)->m_seer == target)
- SendPacket(*i);
- }
-
- if (target->m_seer == target || target->GetVehicle())
- SendPacket(target);
- }
-}
-
-void CombatLogSender::Visit(CreatureMapType& m)
-{
- for (CreatureMapType::iterator iter = m.begin(); iter != m.end(); ++iter)
- {
- Creature* target = iter->GetSource();
- if (!IsInRangeHelper(target))
- continue;
-
- // Send packet to all who are sharing the creature's vision
- if (target->HasSharedVision())
- {
- SharedVisionList::const_iterator i = target->GetSharedVisionList().begin();
- for (; i != target->GetSharedVisionList().end(); ++i)
- if ((*i)->m_seer == target)
- SendPacket(*i);
- }
- }
-}
-
-void CombatLogSender::Visit(DynamicObjectMapType& m)
-{
- for (DynamicObjectMapType::iterator iter = m.begin(); iter != m.end(); ++iter)
- {
- DynamicObject* target = iter->GetSource();
- if (!IsInRangeHelper(target))
- continue;
-
- if (Unit* caster = target->GetCaster())
- {
- // Send packet back to the caster if the caster has vision of dynamic object
- Player* player = caster->ToPlayer();
- if (player && player->m_seer == target)
- SendPacket(player);
- }
- }
-}
-
void Unit::SendCombatLogMessage(WorldPackets::CombatLog::CombatLogServerPacket* combatLog) const
{
- CombatLogSender notifier(this, combatLog, GetVisibilityRange());
+ CombatLogSender combatLogCustomizer(combatLog);
+ Trinity::MessageDistDeliverer<CombatLogSender> notifier(this, std::move(combatLogCustomizer), GetVisibilityRange());
Cell::VisitWorldObjects(this, notifier, GetVisibilityRange());
}
diff --git a/src/server/game/Grids/Notifiers/GridNotifiers.cpp b/src/server/game/Grids/Notifiers/GridNotifiers.cpp
index 4e1db87c417..35059a07aa9 100644
--- a/src/server/game/Grids/Notifiers/GridNotifiers.cpp
+++ b/src/server/game/Grids/Notifiers/GridNotifiers.cpp
@@ -250,142 +250,6 @@ void AIRelocationNotifier::Visit(CreatureMapType &m)
}
}
-void MessageDistDeliverer::Visit(PlayerMapType &m)
-{
- for (PlayerMapType::iterator iter = m.begin(); iter != m.end(); ++iter)
- {
- Player* target = iter->GetSource();
- if (!target->IsInPhase(i_source))
- continue;
-
- if (target->GetExactDist2dSq(i_source) > i_distSq)
- continue;
-
- // Send packet to all who are sharing the player's vision
- if (target->HasSharedVision())
- {
- SharedVisionList::const_iterator i = target->GetSharedVisionList().begin();
- for (; i != target->GetSharedVisionList().end(); ++i)
- if ((*i)->m_seer == target)
- SendPacket(*i);
- }
-
- if (target->m_seer == target || target->GetVehicle())
- SendPacket(target);
- }
-}
-
-void MessageDistDeliverer::Visit(CreatureMapType &m)
-{
- for (CreatureMapType::iterator iter = m.begin(); iter != m.end(); ++iter)
- {
- Creature* target = iter->GetSource();
- if (!target->IsInPhase(i_source))
- continue;
-
- if (target->GetExactDist2dSq(i_source) > i_distSq)
- continue;
-
- // Send packet to all who are sharing the creature's vision
- if (target->HasSharedVision())
- {
- SharedVisionList::const_iterator i = target->GetSharedVisionList().begin();
- for (; i != target->GetSharedVisionList().end(); ++i)
- if ((*i)->m_seer == target)
- SendPacket(*i);
- }
- }
-}
-
-void MessageDistDeliverer::Visit(DynamicObjectMapType &m)
-{
- for (DynamicObjectMapType::iterator iter = m.begin(); iter != m.end(); ++iter)
- {
- DynamicObject* target = iter->GetSource();
- if (!target->IsInPhase(i_source))
- continue;
-
- if (target->GetExactDist2dSq(i_source) > i_distSq)
- continue;
-
- if (Unit* caster = target->GetCaster())
- {
- // Send packet back to the caster if the caster has vision of dynamic object
- Player* player = caster->ToPlayer();
- if (player && player->m_seer == target)
- SendPacket(player);
- }
- }
-}
-
-void MessageDistDelivererToHostile::Visit(PlayerMapType &m)
-{
- for (PlayerMapType::iterator iter = m.begin(); iter != m.end(); ++iter)
- {
- Player* target = iter->GetSource();
- if (!target->IsInPhase(i_source))
- continue;
-
- if (target->GetExactDist2dSq(i_source) > i_distSq)
- continue;
-
- // Send packet to all who are sharing the player's vision
- if (target->HasSharedVision())
- {
- SharedVisionList::const_iterator i = target->GetSharedVisionList().begin();
- for (; i != target->GetSharedVisionList().end(); ++i)
- if ((*i)->m_seer == target)
- SendPacket(*i);
- }
-
- if (target->m_seer == target || target->GetVehicle())
- SendPacket(target);
- }
-}
-
-void MessageDistDelivererToHostile::Visit(CreatureMapType &m)
-{
- for (CreatureMapType::iterator iter = m.begin(); iter != m.end(); ++iter)
- {
- Creature* target = iter->GetSource();
- if (!target->IsInPhase(i_source))
- continue;
-
- if (target->GetExactDist2dSq(i_source) > i_distSq)
- continue;
-
- // Send packet to all who are sharing the creature's vision
- if (target->HasSharedVision())
- {
- SharedVisionList::const_iterator i = target->GetSharedVisionList().begin();
- for (; i != target->GetSharedVisionList().end(); ++i)
- if ((*i)->m_seer == target)
- SendPacket(*i);
- }
- }
-}
-
-void MessageDistDelivererToHostile::Visit(DynamicObjectMapType &m)
-{
- for (DynamicObjectMapType::iterator iter = m.begin(); iter != m.end(); ++iter)
- {
- DynamicObject* target = iter->GetSource();
- if (!target->IsInPhase(i_source))
- continue;
-
- if (target->GetExactDist2dSq(i_source) > i_distSq)
- continue;
-
- if (Unit* caster = target->GetCaster())
- {
- // Send packet back to the caster if the caster has vision of dynamic object
- Player* player = caster->ToPlayer();
- if (player && player->m_seer == target)
- SendPacket(player);
- }
- }
-}
-
/*
void
MessageDistDeliverer::VisitObject(Player* player)
diff --git a/src/server/game/Grids/Notifiers/GridNotifiers.h b/src/server/game/Grids/Notifiers/GridNotifiers.h
index cf498800783..cae3d4bfd2e 100644
--- a/src/server/game/Grids/Notifiers/GridNotifiers.h
+++ b/src/server/game/Grids/Notifiers/GridNotifiers.h
@@ -118,15 +118,28 @@ namespace Trinity
void Visit(ConversationMapType &m) { updateObjects<Conversation>(m); }
};
+ struct MessageDistDelivererCustomizer
+ {
+ WorldPacket const* i_message;
+
+ MessageDistDelivererCustomizer(WorldPacket const* message) : i_message(message) { }
+
+ WorldPacket const* operator()(Player* /*player*/) const
+ {
+ return i_message;
+ }
+ };
+
+ template<typename PacketCustomizer = MessageDistDelivererCustomizer>
struct TC_GAME_API MessageDistDeliverer
{
WorldObject const* i_source;
- WorldPacket const* i_message;
+ PacketCustomizer i_messageCustomizer;
float i_distSq;
uint32 team;
Player const* skipped_receiver;
- MessageDistDeliverer(WorldObject const* src, WorldPacket const* msg, float dist, bool own_team_only = false, Player const* skipped = nullptr)
- : i_source(src), i_message(msg), i_distSq(dist * dist)
+ MessageDistDeliverer(WorldObject const* src, PacketCustomizer packetCustomizer, float dist, bool own_team_only = false, Player const* skipped = nullptr)
+ : i_source(src), i_messageCustomizer(std::move(packetCustomizer)), i_distSq(dist * dist)
, team(0)
, skipped_receiver(skipped)
{
@@ -135,12 +148,12 @@ namespace Trinity
team = player->GetTeam();
}
- void Visit(PlayerMapType &m);
- void Visit(CreatureMapType &m);
- void Visit(DynamicObjectMapType &m);
- template<class SKIP> void Visit(GridRefManager<SKIP> &) { }
+ void Visit(PlayerMapType &m) const;
+ void Visit(CreatureMapType &m) const;
+ void Visit(DynamicObjectMapType &m) const;
+ template<class SKIP> void Visit(GridRefManager<SKIP> &) const { }
- void SendPacket(Player* player)
+ void SendPacket(Player* player) const
{
// never send packet to self
if (player == i_source || (team && player->GetTeam() != team) || skipped_receiver == player)
@@ -149,33 +162,34 @@ namespace Trinity
if (!player->HaveAtClient(i_source))
return;
- player->SendDirectMessage(i_message);
+ player->SendDirectMessage(i_messageCustomizer(player));
}
};
+ template<typename PacketCustomizer = MessageDistDelivererCustomizer>
struct TC_GAME_API MessageDistDelivererToHostile
{
Unit* i_source;
- WorldPacket const* i_message;
+ PacketCustomizer i_messageCustomizer;
float i_distSq;
- MessageDistDelivererToHostile(Unit* src, WorldPacket const* msg, float dist)
- : i_source(src), i_message(msg), i_distSq(dist * dist)
+ MessageDistDelivererToHostile(Unit* src, PacketCustomizer packetCustomizer, float dist)
+ : i_source(src), i_messageCustomizer(std::move(packetCustomizer)), i_distSq(dist * dist)
{
}
- void Visit(PlayerMapType &m);
- void Visit(CreatureMapType &m);
- void Visit(DynamicObjectMapType &m);
- template<class SKIP> void Visit(GridRefManager<SKIP> &) { }
+ void Visit(PlayerMapType &m) const;
+ void Visit(CreatureMapType &m) const;
+ void Visit(DynamicObjectMapType &m) const;
+ template<class SKIP> void Visit(GridRefManager<SKIP> &) const { }
- void SendPacket(Player* player)
+ void SendPacket(Player* player) const
{
// never send packet to self
if (player == i_source || !player->HaveAtClient(i_source) || player->IsFriendlyTo(i_source))
return;
- player->SendDirectMessage(i_message);
+ player->SendDirectMessage(i_messageCustomizer(player));
}
};
diff --git a/src/server/game/Grids/Notifiers/GridNotifiersImpl.h b/src/server/game/Grids/Notifiers/GridNotifiersImpl.h
index e88edcaa1cc..1d0d644aba6 100644
--- a/src/server/game/Grids/Notifiers/GridNotifiersImpl.h
+++ b/src/server/game/Grids/Notifiers/GridNotifiersImpl.h
@@ -37,6 +37,148 @@ inline void Trinity::VisibleNotifier::Visit(GridRefManager<T> &m)
}
}
+template<typename PacketCustomizer>
+void Trinity::MessageDistDeliverer<PacketCustomizer>::Visit(PlayerMapType& m) const
+{
+ for (PlayerMapType::iterator iter = m.begin(); iter != m.end(); ++iter)
+ {
+ Player* target = iter->GetSource();
+ if (!target->IsInPhase(i_source))
+ continue;
+
+ if (target->GetExactDist2dSq(i_source) > i_distSq)
+ continue;
+
+ // Send packet to all who are sharing the player's vision
+ if (target->HasSharedVision())
+ {
+ SharedVisionList::const_iterator i = target->GetSharedVisionList().begin();
+ for (; i != target->GetSharedVisionList().end(); ++i)
+ if ((*i)->m_seer == target)
+ SendPacket(*i);
+ }
+
+ if (target->m_seer == target || target->GetVehicle())
+ SendPacket(target);
+ }
+}
+
+template<typename PacketCustomizer>
+void Trinity::MessageDistDeliverer<PacketCustomizer>::Visit(CreatureMapType& m) const
+{
+ for (CreatureMapType::iterator iter = m.begin(); iter != m.end(); ++iter)
+ {
+ Creature* target = iter->GetSource();
+ if (!target->IsInPhase(i_source))
+ continue;
+
+ if (target->GetExactDist2dSq(i_source) > i_distSq)
+ continue;
+
+ // Send packet to all who are sharing the creature's vision
+ if (target->HasSharedVision())
+ {
+ SharedVisionList::const_iterator i = target->GetSharedVisionList().begin();
+ for (; i != target->GetSharedVisionList().end(); ++i)
+ if ((*i)->m_seer == target)
+ SendPacket(*i);
+ }
+ }
+}
+
+template<typename PacketCustomizer>
+void Trinity::MessageDistDeliverer<PacketCustomizer>::Visit(DynamicObjectMapType& m) const
+{
+ for (DynamicObjectMapType::iterator iter = m.begin(); iter != m.end(); ++iter)
+ {
+ DynamicObject* target = iter->GetSource();
+ if (!target->IsInPhase(i_source))
+ continue;
+
+ if (target->GetExactDist2dSq(i_source) > i_distSq)
+ continue;
+
+ if (Unit* caster = target->GetCaster())
+ {
+ // Send packet back to the caster if the caster has vision of dynamic object
+ Player* player = caster->ToPlayer();
+ if (player && player->m_seer == target)
+ SendPacket(player);
+ }
+ }
+}
+
+template<typename PacketCustomizer>
+void Trinity::MessageDistDelivererToHostile<PacketCustomizer>::Visit(PlayerMapType& m) const
+{
+ for (PlayerMapType::iterator iter = m.begin(); iter != m.end(); ++iter)
+ {
+ Player* target = iter->GetSource();
+ if (!target->IsInPhase(i_source))
+ continue;
+
+ if (target->GetExactDist2dSq(i_source) > i_distSq)
+ continue;
+
+ // Send packet to all who are sharing the player's vision
+ if (target->HasSharedVision())
+ {
+ SharedVisionList::const_iterator i = target->GetSharedVisionList().begin();
+ for (; i != target->GetSharedVisionList().end(); ++i)
+ if ((*i)->m_seer == target)
+ SendPacket(*i);
+ }
+
+ if (target->m_seer == target || target->GetVehicle())
+ SendPacket(target);
+ }
+}
+
+template<typename PacketCustomizer>
+void Trinity::MessageDistDelivererToHostile<PacketCustomizer>::Visit(CreatureMapType& m) const
+{
+ for (CreatureMapType::iterator iter = m.begin(); iter != m.end(); ++iter)
+ {
+ Creature* target = iter->GetSource();
+ if (!target->IsInPhase(i_source))
+ continue;
+
+ if (target->GetExactDist2dSq(i_source) > i_distSq)
+ continue;
+
+ // Send packet to all who are sharing the creature's vision
+ if (target->HasSharedVision())
+ {
+ SharedVisionList::const_iterator i = target->GetSharedVisionList().begin();
+ for (; i != target->GetSharedVisionList().end(); ++i)
+ if ((*i)->m_seer == target)
+ SendPacket(*i);
+ }
+ }
+}
+
+template<typename PacketCustomizer>
+void Trinity::MessageDistDelivererToHostile<PacketCustomizer>::Visit(DynamicObjectMapType& m) const
+{
+ for (DynamicObjectMapType::iterator iter = m.begin(); iter != m.end(); ++iter)
+ {
+ DynamicObject* target = iter->GetSource();
+ if (!target->IsInPhase(i_source))
+ continue;
+
+ if (target->GetExactDist2dSq(i_source) > i_distSq)
+ continue;
+
+ if (Unit* caster = target->GetCaster())
+ {
+ // Send packet back to the caster if the caster has vision of dynamic object
+ Player* player = caster->ToPlayer();
+ if (player && player->m_seer == target)
+ SendPacket(player);
+ }
+ }
+}
+
// SEARCHERS & LIST SEARCHERS & WORKERS
// WorldObject searchers & workers
diff --git a/src/server/game/Spells/SpellEffects.cpp b/src/server/game/Spells/SpellEffects.cpp
index 28813195f2e..f713991563c 100644
--- a/src/server/game/Spells/SpellEffects.cpp
+++ b/src/server/game/Spells/SpellEffects.cpp
@@ -40,6 +40,7 @@
#include "Garrison.h"
#include "GossipDef.h"
#include "GridNotifiers.h"
+#include "GridNotifiersImpl.h"
#include "Group.h"
#include "Guild.h"
#include "InstanceScript.h"
@@ -4006,13 +4007,13 @@ void Spell::EffectForceDeselect(SpellEffIndex /*effIndex*/)
// clear focus
WorldPackets::Combat::BreakTarget breakTarget;
breakTarget.UnitGUID = m_caster->GetGUID();
- Trinity::MessageDistDelivererToHostile notifierBreak(m_caster, breakTarget.Write(), dist);
+ Trinity::MessageDistDelivererToHostile<> notifierBreak(m_caster, breakTarget.Write(), dist);
Cell::VisitWorldObjects(m_caster, notifierBreak, dist);
// and selection
WorldPackets::Spells::ClearTarget clearTarget;
clearTarget.Guid = m_caster->GetGUID();
- Trinity::MessageDistDelivererToHostile notifierClear(m_caster, clearTarget.Write(), dist);
+ Trinity::MessageDistDelivererToHostile<> notifierClear(m_caster, clearTarget.Write(), dist);
Cell::VisitWorldObjects(m_caster, notifierClear, dist);
// we should also force pets to remove us from current target