diff options
Diffstat (limited to 'src/server/game/Maps/Map.cpp')
-rw-r--r-- | src/server/game/Maps/Map.cpp | 76 |
1 files changed, 39 insertions, 37 deletions
diff --git a/src/server/game/Maps/Map.cpp b/src/server/game/Maps/Map.cpp index 7c49e8d5ad3..b4aeab293ea 100644 --- a/src/server/game/Maps/Map.cpp +++ b/src/server/game/Maps/Map.cpp @@ -18,6 +18,7 @@ #include "Map.h" #include "Battleground.h" #include "CellImpl.h" +#include "Chat.h" #include "DatabaseEnv.h" #include "DisableMgr.h" #include "DynamicTree.h" @@ -3674,6 +3675,27 @@ void Map::SendToPlayers(WorldPacket const* data) const itr->GetSource()->SendDirectMessage(data); } +/// Send a packet to all players (or players selected team) in the zone (except self if mentioned) +bool Map::SendZoneMessage(uint32 zone, WorldPacket const* packet, WorldSession const* self, uint32 team) const +{ + bool foundPlayerToSend = false; + + for (MapReference const& ref : GetPlayers()) + { + Player* player = ref.GetSource(); + if (player->IsInWorld() && + player->GetZoneId() == zone && + player->GetSession() != self && + (team == 0 || player->GetTeam() == team)) + { + player->SendDirectMessage(packet); + foundPlayerToSend = true; + } + } + + return foundPlayerToSend; +} + bool Map::ActiveObjectsNearGrid(NGridType const& ngrid) const { CellCoord cell_min(ngrid.getX() * MAX_NUMBER_OF_CELLS, ngrid.getY() * MAX_NUMBER_OF_CELLS); @@ -4730,21 +4752,20 @@ void Map::SendZoneWeather(ZoneDynamicInfo const& zoneDynamicInfo, Player* player Weather::SendFineWeatherUpdateToPlayer(player); } +/// Send a System Message to all players in the zone (except self if mentioned) +void Map::SendZoneText(uint32 zoneId, char const* text, WorldSession const* self, uint32 team) const +{ + WorldPacket data; + ChatHandler::BuildChatPacket(data, CHAT_MSG_SYSTEM, LANG_UNIVERSAL, nullptr, nullptr, text); + SendZoneMessage(zoneId, &data, self, team); +} + void Map::SetZoneMusic(uint32 zoneId, uint32 musicId) { _zoneDynamicInfo[zoneId].MusicId = musicId; - Map::PlayerList const& players = GetPlayers(); - if (!players.isEmpty()) - { - WorldPackets::Misc::PlayMusic playMusic(musicId); - playMusic.Write(); - - for (Map::PlayerList::const_iterator itr = players.begin(); itr != players.end(); ++itr) - if (Player* player = itr->GetSource()) - if (player->GetZoneId() == zoneId) - player->SendDirectMessage(playMusic.GetRawPacket()); - } + WorldPackets::Misc::PlayMusic playMusic(musicId); + SendZoneMessage(zoneId, WorldPackets::Misc::PlayMusic(musicId).Write()); } Weather* Map::GetOrGenerateZoneDefaultWeather(uint32 zoneId) @@ -4756,7 +4777,7 @@ Weather* Map::GetOrGenerateZoneDefaultWeather(uint32 zoneId) ZoneDynamicInfo& info = _zoneDynamicInfo[zoneId]; if (!info.DefaultWeather) { - info.DefaultWeather = std::make_unique<Weather>(zoneId, weatherData); + info.DefaultWeather = std::make_unique<Weather>(this, zoneId, weatherData); info.DefaultWeather->ReGenerate(); info.DefaultWeather->UpdateWeather(); } @@ -4770,17 +4791,7 @@ void Map::SetZoneWeather(uint32 zoneId, WeatherState weatherId, float intensity) info.WeatherId = weatherId; info.Intensity = intensity; - Map::PlayerList const& players = GetPlayers(); - if (!players.isEmpty()) - { - WorldPackets::Misc::Weather weather(weatherId, intensity); - weather.Write(); - - for (Map::PlayerList::const_iterator itr = players.begin(); itr != players.end(); ++itr) - if (Player* player = itr->GetSource()) - if (player->GetZoneId() == zoneId) - player->SendDirectMessage(weather.GetRawPacket()); - } + SendZoneMessage(zoneId, WorldPackets::Misc::Weather(weatherId, intensity).Write()); } void Map::SetZoneOverrideLight(uint32 zoneId, uint32 areaLightId, uint32 overrideLightId, Milliseconds transitionTime) @@ -4801,20 +4812,11 @@ void Map::SetZoneOverrideLight(uint32 zoneId, uint32 areaLightId, uint32 overrid lightOverride.TransitionMilliseconds = static_cast<uint32>(transitionTime.count()); } - Map::PlayerList const& players = GetPlayers(); - if (!players.isEmpty()) - { - WorldPackets::Misc::OverrideLight overrideLight; - overrideLight.AreaLightID = areaLightId; - overrideLight.OverrideLightID = overrideLightId; - overrideLight.TransitionMilliseconds = static_cast<uint32>(transitionTime.count()); - overrideLight.Write(); - - for (Map::PlayerList::const_iterator itr = players.begin(); itr != players.end(); ++itr) - if (Player* player = itr->GetSource()) - if (player->GetZoneId() == zoneId) - player->SendDirectMessage(overrideLight.GetRawPacket()); - } + WorldPackets::Misc::OverrideLight overrideLight; + overrideLight.AreaLightID = areaLightId; + overrideLight.OverrideLightID = overrideLightId; + overrideLight.TransitionMilliseconds = static_cast<uint32>(transitionTime.count()); + SendZoneMessage(zoneId, overrideLight.Write()); } void Map::UpdateAreaDependentAuras() |