diff --git a/src/server/game/Maps/Map.cpp b/src/server/game/Maps/Map.cpp index cb620b2a02..c1f205a981 100644 --- a/src/server/game/Maps/Map.cpp +++ b/src/server/game/Maps/Map.cpp @@ -21,6 +21,7 @@ #include "BattlegroundScript.h" #include "CellImpl.h" #include "CharacterPackets.h" +#include "ChatPackets.h" #include "Conversation.h" #include "DB2Stores.h" #include "DatabaseEnv.h" @@ -2692,6 +2693,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, Optional team) const +{ + bool foundPlayerToSend = false; + + for (MapReference const& ref : GetPlayers()) + { + Player* player = ref.GetSource(); + if (player->IsInWorld() && + player->GetZoneId() == zone && + player->GetSession() != self && + (!team || 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); @@ -3974,21 +3996,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, Optional team) const +{ + WorldPackets::Chat::Chat packet; + packet.Initialize(CHAT_MSG_SYSTEM, LANG_UNIVERSAL, nullptr, nullptr, text); + SendZoneMessage(zoneId, packet.Write(), self, team); +} + void Map::SetZoneMusic(uint32 zoneId, uint32 musicId) { _zoneDynamicInfo[zoneId].MusicId = musicId; - Map::PlayerList const& players = GetPlayers(); - if (!players.empty()) - { - 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->HasAuraType(SPELL_AURA_FORCE_WEATHER)) - player->SendDirectMessage(playMusic.GetRawPacket()); - } + WorldPackets::Misc::PlayMusic playMusic(musicId); + SendZoneMessage(zoneId, WorldPackets::Misc::PlayMusic(musicId).Write()); } Weather* Map::GetOrGenerateZoneDefaultWeather(uint32 zoneId) @@ -4000,7 +4021,7 @@ Weather* Map::GetOrGenerateZoneDefaultWeather(uint32 zoneId) ZoneDynamicInfo& info = _zoneDynamicInfo[zoneId]; if (!info.DefaultWeather) { - info.DefaultWeather = std::make_unique(zoneId, weatherData); + info.DefaultWeather = std::make_unique(this, zoneId, weatherData); info.DefaultWeather->ReGenerate(); info.DefaultWeather->UpdateWeather(); } @@ -4037,7 +4058,7 @@ void Map::SetZoneWeather(uint32 zoneId, WeatherState weatherId, float intensity) for (Map::PlayerList::const_iterator itr = players.begin(); itr != players.end(); ++itr) if (Player* player = itr->GetSource()) - if (player->GetZoneId() == zoneId) + if (player->GetZoneId() == zoneId && !player->HasAuraType(SPELL_AURA_FORCE_WEATHER)) player->SendDirectMessage(weather.GetRawPacket()); } } @@ -4060,20 +4081,11 @@ void Map::SetZoneOverrideLight(uint32 zoneId, uint32 areaLightId, uint32 overrid lightOverride.TransitionMilliseconds = static_cast(transitionTime.count()); } - Map::PlayerList const& players = GetPlayers(); - if (!players.empty()) - { - WorldPackets::Misc::OverrideLight overrideLight; - overrideLight.AreaLightID = areaLightId; - overrideLight.OverrideLightID = overrideLightId; - overrideLight.TransitionMilliseconds = static_cast(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(transitionTime.count()); + SendZoneMessage(zoneId, overrideLight.Write()); } void Map::UpdateAreaDependentAuras() diff --git a/src/server/game/Maps/Map.h b/src/server/game/Maps/Map.h index 2753ea1855..173aad3e69 100644 --- a/src/server/game/Maps/Map.h +++ b/src/server/game/Maps/Map.h @@ -66,6 +66,7 @@ class Unit; class Weather; class WorldObject; class WorldPacket; +class WorldSession; struct DungeonEncounterEntry; struct MapDifficultyEntry; struct MapEntry; @@ -399,6 +400,7 @@ class TC_GAME_API Map : public GridRefManager void RemoveWorldObject(WorldObject* obj); void SendToPlayers(WorldPacket const* data) const; + bool SendZoneMessage(uint32 zone, WorldPacket const* packet, WorldSession const* self = nullptr, Optional team = { }) const; typedef MapRefManager PlayerList; PlayerList const& GetPlayers() const { return m_mapRefManager; } @@ -546,6 +548,7 @@ class TC_GAME_API Map : public GridRefManager void SendZoneDynamicInfo(uint32 zoneId, Player* player) const; void SendZoneWeather(uint32 zoneId, Player* player) const; void SendZoneWeather(ZoneDynamicInfo const& zoneDynamicInfo, Player* player) const; + void SendZoneText(uint32 zoneId, const char* text, WorldSession const* self = nullptr, Optional team = { }) const; void SetZoneMusic(uint32 zoneId, uint32 musicId); Weather* GetOrGenerateZoneDefaultWeather(uint32 zoneId); diff --git a/src/server/game/Weather/Weather.cpp b/src/server/game/Weather/Weather.cpp index 3cdce2d2bc..83601ce0ab 100644 --- a/src/server/game/Weather/Weather.cpp +++ b/src/server/game/Weather/Weather.cpp @@ -22,6 +22,7 @@ #include "GameTime.h" #include "Weather.h" #include "Log.h" +#include "Map.h" #include "MiscPackets.h" #include "Player.h" #include "Random.h" @@ -30,8 +31,8 @@ #include "World.h" /// Create the Weather object -Weather::Weather(uint32 zoneId, WeatherData const* weatherChances) - : m_zone(zoneId), m_weatherChances(weatherChances) +Weather::Weather(Map* map, uint32 zoneId, WeatherData const* weatherChances) + : m_map(map), m_zone(zoneId), m_weatherChances(weatherChances) { m_timer.SetInterval(sWorld->getIntConfig(CONFIG_INTERVAL_CHANGEWEATHER)); m_type = WEATHER_TYPE_FINE; @@ -216,7 +217,7 @@ bool Weather::UpdateWeather() WorldPackets::Misc::Weather weather(state, m_intensity); //- Returns false if there were no players found to update - if (!sWorld->SendZoneMessage(m_zone, weather.Write())) + if (!m_map->SendZoneMessage(m_zone, weather.Write())) return false; ///- Log the event diff --git a/src/server/game/Weather/Weather.h b/src/server/game/Weather/Weather.h index e35fcd2aec..ecdfc60a3c 100644 --- a/src/server/game/Weather/Weather.h +++ b/src/server/game/Weather/Weather.h @@ -26,6 +26,7 @@ #include "SharedDefines.h" #include "Timer.h" +class Map; class Player; #define WEATHER_SEASONS 4 @@ -66,7 +67,7 @@ class TC_GAME_API Weather { public: - Weather(uint32 zoneId, WeatherData const* weatherChances); + Weather(Map* map, uint32 zoneId, WeatherData const* weatherChances); ~Weather() { } bool Update(uint32 diff); @@ -83,6 +84,7 @@ class TC_GAME_API Weather uint32 GetScriptId() const { return m_weatherChances->ScriptId; } private: + Map* m_map; uint32 m_zone; WeatherType m_type; float m_intensity; diff --git a/src/server/game/World/World.cpp b/src/server/game/World/World.cpp index fc6cac584a..649e1c2f9f 100644 --- a/src/server/game/World/World.cpp +++ b/src/server/game/World/World.cpp @@ -2601,37 +2601,6 @@ void World::SendGlobalText(char const* text, WorldSession* self) free(buf); } -/// Send a packet to all players (or players selected team) in the zone (except self if mentioned) -bool World::SendZoneMessage(uint32 zone, WorldPacket const* packet, WorldSession* self, Optional team) -{ - bool foundPlayerToSend = false; - SessionMap::const_iterator itr; - - for (itr = m_sessions.begin(); itr != m_sessions.end(); ++itr) - { - if (itr->second && - itr->second->GetPlayer() && - itr->second->GetPlayer()->IsInWorld() && - itr->second->GetPlayer()->GetZoneId() == zone && - itr->second != self && - (!team || itr->second->GetPlayer()->GetTeam() == team)) - { - itr->second->SendPacket(packet); - foundPlayerToSend = true; - } - } - - return foundPlayerToSend; -} - -/// Send a System Message to all players in the zone (except self if mentioned) -void World::SendZoneText(uint32 zone, char const* text, WorldSession* self, Optional team) -{ - WorldPackets::Chat::Chat packet; - packet.Initialize(CHAT_MSG_SYSTEM, LANG_UNIVERSAL, nullptr, nullptr, text); - SendZoneMessage(zone, packet.Write(), self, team); -} - /// Kick (and save) all players void World::KickAll() { diff --git a/src/server/game/World/World.h b/src/server/game/World/World.h index 85e9d59268..85d77c43da 100644 --- a/src/server/game/World/World.h +++ b/src/server/game/World/World.h @@ -654,8 +654,6 @@ class TC_GAME_API World void SendServerMessage(ServerMessageType messageID, std::string_view stringParam = {}, Player const* player = nullptr); void SendGlobalMessage(WorldPacket const* packet, WorldSession* self = nullptr, Optional team = { }); void SendGlobalGMMessage(WorldPacket const* packet, WorldSession* self = nullptr, Optional team = { }); - bool SendZoneMessage(uint32 zone, WorldPacket const* packet, WorldSession* self = nullptr, Optional team = { }); - void SendZoneText(uint32 zone, const char *text, WorldSession* self = nullptr, Optional team = { }); /// Are we in the middle of a shutdown? bool IsShuttingDown() const { return m_ShutdownTimer > 0; } diff --git a/src/server/scripts/OutdoorPvP/OutdoorPvPSI.cpp b/src/server/scripts/OutdoorPvP/OutdoorPvPSI.cpp index 692662e5d8..96d9f1ac86 100644 --- a/src/server/scripts/OutdoorPvP/OutdoorPvPSI.cpp +++ b/src/server/scripts/OutdoorPvP/OutdoorPvPSI.cpp @@ -98,7 +98,7 @@ bool OutdoorPvPSI::HandleAreaTrigger(Player* player, uint32 trigger, bool /*ente { TeamApplyBuff(TEAM_ALLIANCE, SI_CENARION_FAVOR); /// @todo: confirm this text - sWorld->SendZoneText(OutdoorPvPSIBuffZones[0], sObjectMgr->GetTrinityStringForDBCLocale(LANG_OPVP_SI_CAPTURE_A)); + m_map->SendZoneText(OutdoorPvPSIBuffZones[0], sObjectMgr->GetTrinityStringForDBCLocale(LANG_OPVP_SI_CAPTURE_A)); m_LastController = ALLIANCE; newScore = 0; SetWorldState(SI_GATHERED_H, 0); @@ -124,7 +124,7 @@ bool OutdoorPvPSI::HandleAreaTrigger(Player* player, uint32 trigger, bool /*ente { TeamApplyBuff(TEAM_HORDE, SI_CENARION_FAVOR); /// @todo: confirm this text - sWorld->SendZoneText(OutdoorPvPSIBuffZones[0], sObjectMgr->GetTrinityStringForDBCLocale(LANG_OPVP_SI_CAPTURE_H)); + m_map->SendZoneText(OutdoorPvPSIBuffZones[0], sObjectMgr->GetTrinityStringForDBCLocale(LANG_OPVP_SI_CAPTURE_H)); m_LastController = HORDE; SetWorldState(SI_GATHERED_A, 0); newScore = 0;