diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/server/game/Maps/Map.cpp | 76 | ||||
-rw-r--r-- | src/server/game/Maps/Map.h | 3 | ||||
-rw-r--r-- | src/server/game/Weather/Weather.cpp | 7 | ||||
-rw-r--r-- | src/server/game/Weather/Weather.h | 4 | ||||
-rw-r--r-- | src/server/game/World/World.cpp | 31 | ||||
-rw-r--r-- | src/server/game/World/World.h | 2 | ||||
-rw-r--r-- | src/server/scripts/OutdoorPvP/OutdoorPvPSI.cpp | 4 |
7 files changed, 51 insertions, 76 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() diff --git a/src/server/game/Maps/Map.h b/src/server/game/Maps/Map.h index e51e50cbf7e..84783d95c0c 100644 --- a/src/server/game/Maps/Map.h +++ b/src/server/game/Maps/Map.h @@ -55,6 +55,7 @@ class Unit; class Weather; class WorldObject; class WorldPacket; +class WorldSession; struct MapDifficulty; struct MapEntry; struct Position; @@ -484,6 +485,7 @@ class TC_GAME_API Map : public GridRefManager<NGridType> void RemoveWorldObject(WorldObject* obj) { i_worldObjects.erase(obj); } void SendToPlayers(WorldPacket const* data) const; + bool SendZoneMessage(uint32 zone, WorldPacket const* packet, WorldSession const* self = nullptr, uint32 team = 0) const; typedef MapRefManager PlayerList; PlayerList const& GetPlayers() const { return m_mapRefManager; } @@ -615,6 +617,7 @@ class TC_GAME_API Map : public GridRefManager<NGridType> 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, uint32 team = 0) 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 f9bfe072d8e..429f58b3395 100644 --- a/src/server/game/Weather/Weather.cpp +++ b/src/server/game/Weather/Weather.cpp @@ -22,6 +22,7 @@ #include "Weather.h" #include "GameTime.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 16b470b1dc6..cb53a09b5ab 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); @@ -84,6 +85,7 @@ class TC_GAME_API Weather private: WeatherState GetWeatherState() const; + 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 f080cc537a7..b49ef889c1a 100644 --- a/src/server/game/World/World.cpp +++ b/src/server/game/World/World.cpp @@ -2738,37 +2738,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, uint32 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 == 0 || 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, uint32 team) -{ - WorldPacket data; - ChatHandler::BuildChatPacket(data, CHAT_MSG_SYSTEM, LANG_UNIVERSAL, nullptr, nullptr, text); - SendZoneMessage(zone, &data, 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 62caaefc129..beaa20e93e8 100644 --- a/src/server/game/World/World.h +++ b/src/server/game/World/World.h @@ -655,8 +655,6 @@ class TC_GAME_API World void SendServerMessage(ServerMessageType messageID, std::string stringParam = "", Player* player = nullptr); void SendGlobalMessage(WorldPacket const* packet, WorldSession* self = nullptr, uint32 team = 0); void SendGlobalGMMessage(WorldPacket const* packet, WorldSession* self = nullptr, uint32 team = 0); - bool SendZoneMessage(uint32 zone, WorldPacket const* packet, WorldSession* self = nullptr, uint32 team = 0); - void SendZoneText(uint32 zone, const char *text, WorldSession* self = nullptr, uint32 team = 0); /// 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 de3c530139f..a3ccc12b8f5 100644 --- a/src/server/scripts/OutdoorPvP/OutdoorPvPSI.cpp +++ b/src/server/scripts/OutdoorPvP/OutdoorPvPSI.cpp @@ -108,7 +108,7 @@ bool OutdoorPvPSI::HandleAreaTrigger(Player* player, uint32 trigger) { 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; m_Gathered_A = 0; m_Gathered_H = 0; @@ -134,7 +134,7 @@ bool OutdoorPvPSI::HandleAreaTrigger(Player* player, uint32 trigger) { 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; m_Gathered_A = 0; m_Gathered_H = 0; |