From fb249836e913ba857a6013a0d681dbedfec89683 Mon Sep 17 00:00:00 2001 From: IntelligentQuantum Date: Tue, 4 Jan 2022 22:22:13 +0330 Subject: [PATCH] Core\Packet\Misc: Weather (#9648) --- src/server/game/Maps/Map.cpp | 23 +++++----- src/server/game/Maps/Map.h | 16 ++++--- src/server/game/Server/Packets/AllPackets.h | 1 + .../game/Server/Packets/MiscPackets.cpp | 32 +++++++++++++ src/server/game/Server/Packets/MiscPackets.h | 45 +++++++++++++++++++ src/server/game/Weather/Weather.cpp | 16 +++---- src/server/game/Weather/Weather.h | 2 +- src/server/game/Weather/WeatherMgr.cpp | 8 ++-- .../RuinsOfAhnQiraj/boss_ossirian.cpp | 6 +-- 9 files changed, 111 insertions(+), 38 deletions(-) create mode 100644 src/server/game/Server/Packets/MiscPackets.cpp create mode 100644 src/server/game/Server/Packets/MiscPackets.h diff --git a/src/server/game/Maps/Map.cpp b/src/server/game/Maps/Map.cpp index 0d7bfa35c..6aa457cdf 100644 --- a/src/server/game/Maps/Map.cpp +++ b/src/server/game/Maps/Map.cpp @@ -29,6 +29,7 @@ #include "LFGMgr.h" #include "MapInstanced.h" #include "Metric.h" +#include "MiscPackets.h" #include "Object.h" #include "ObjectAccessor.h" #include "ObjectGridLoader.h" @@ -39,6 +40,7 @@ #include "VMapFactory.h" #include "VMapMgr2.h" #include "Vehicle.h" +#include "Weather.h" union u_map_magic { @@ -55,6 +57,9 @@ u_map_magic MapLiquidMagic = { {'M', 'L', 'I', 'Q'} }; static uint16 const holetab_h[4] = { 0x1111, 0x2222, 0x4444, 0x8888 }; static uint16 const holetab_v[4] = { 0x000F, 0x00F0, 0x0F00, 0xF000 }; +ZoneDynamicInfo::ZoneDynamicInfo() : MusicId(0), WeatherId(WEATHER_STATE_FINE), + WeatherGrade(0.0f), OverrideLightId(0), LightFadeInTime(0) { } + Map::~Map() { // UnloadAll must be called before deleting the map @@ -3655,13 +3660,10 @@ void Map::SendZoneDynamicInfo(Player* player) player->SendDirectMessage(&data); } - if (uint32 weather = itr->second.WeatherId) + if (WeatherState weatherId = itr->second.WeatherId) { - WorldPacket data(SMSG_WEATHER, 4 + 4 + 1); - data << uint32(weather); - data << float(itr->second.WeatherGrade); - data << uint8(0); - player->SendDirectMessage(&data); + WorldPackets::Misc::Weather weather(weatherId, itr->second.WeatherGrade); + player->SendDirectMessage(weather.Write()); } if (uint32 overrideLight = itr->second.OverrideLightId) @@ -3709,7 +3711,7 @@ void Map::SetZoneMusic(uint32 zoneId, uint32 musicId) } } -void Map::SetZoneWeather(uint32 zoneId, uint32 weatherId, float weatherGrade) +void Map::SetZoneWeather(uint32 zoneId, WeatherState weatherId, float weatherGrade) { if (_zoneDynamicInfo.find(zoneId) == _zoneDynamicInfo.end()) _zoneDynamicInfo.insert(ZoneDynamicInfoMap::value_type(zoneId, ZoneDynamicInfo())); @@ -3721,15 +3723,12 @@ void Map::SetZoneWeather(uint32 zoneId, uint32 weatherId, float weatherGrade) if (!players.isEmpty()) { - WorldPacket data(SMSG_WEATHER, 4 + 4 + 1); - data << uint32(weatherId); - data << float(weatherGrade); - data << uint8(0); + WorldPackets::Misc::Weather weather(weatherId, weatherGrade); for (Map::PlayerList::const_iterator itr = players.begin(); itr != players.end(); ++itr) if (Player* player = itr->GetSource()) if (player->GetZoneId() == zoneId) - player->SendDirectMessage(&data); + player->SendDirectMessage(weather.Write()); } } diff --git a/src/server/game/Maps/Map.h b/src/server/game/Maps/Map.h index c674004f0..c30492bdb 100644 --- a/src/server/game/Maps/Map.h +++ b/src/server/game/Maps/Map.h @@ -60,6 +60,8 @@ class StaticTransport; class MotionTransport; class PathGenerator; +enum WeatherState : uint32; + namespace Acore { struct ObjectUpdater; @@ -271,13 +273,13 @@ enum LevelRequirementVsMode struct ZoneDynamicInfo { - ZoneDynamicInfo() { } + ZoneDynamicInfo(); - uint32 MusicId{0}; - uint32 WeatherId{0}; - float WeatherGrade{0.0f}; - uint32 OverrideLightId{0}; - uint32 LightFadeInTime{0}; + uint32 MusicId; + WeatherState WeatherId; + float WeatherGrade; + uint32 OverrideLightId; + uint32 LightFadeInTime; }; #if defined(__GNUC__) @@ -597,7 +599,7 @@ public: void PlayDirectSoundToMap(uint32 soundId, uint32 zoneId = 0); void SetZoneMusic(uint32 zoneId, uint32 musicId); - void SetZoneWeather(uint32 zoneId, uint32 weatherId, float weatherGrade); + void SetZoneWeather(uint32 zoneId, WeatherState weatherId, float weatherGrade); void SetZoneOverrideLight(uint32 zoneId, uint32 lightId, Milliseconds fadeInTime); // Checks encounter state at kill/spellcast, originally in InstanceScript however not every map has instance script :( diff --git a/src/server/game/Server/Packets/AllPackets.h b/src/server/game/Server/Packets/AllPackets.h index 8ea2d21fc..e18eec4ac 100644 --- a/src/server/game/Server/Packets/AllPackets.h +++ b/src/server/game/Server/Packets/AllPackets.h @@ -18,6 +18,7 @@ #ifndef AllPackets_h__ #define AllPackets_h__ +#include "MiscPackets.h" #include "WorldStatePackets.h" #include "TotemPackets.h" #include "BankPackets.h" diff --git a/src/server/game/Server/Packets/MiscPackets.cpp b/src/server/game/Server/Packets/MiscPackets.cpp new file mode 100644 index 000000000..59513d42d --- /dev/null +++ b/src/server/game/Server/Packets/MiscPackets.cpp @@ -0,0 +1,32 @@ +/* + * This file is part of the AzerothCore Project. See AUTHORS file for Copyright information + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU Affero General Public License as published by the + * Free Software Foundation; either version 3 of the License, or (at your + * option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + */ + +#include "MiscPackets.h" + +WorldPackets::Misc::Weather::Weather() : ServerPacket(SMSG_WEATHER, 4 + 4 + 1) { } + +WorldPackets::Misc::Weather::Weather(WeatherState weatherID, float intensity /*= 0.0f*/, bool abrupt /*= false*/) + : ServerPacket(SMSG_WEATHER, 4 + 4 + 1), Abrupt(abrupt), Intensity(intensity), WeatherID(weatherID) { } + +WorldPacket const* WorldPackets::Misc::Weather::Write() +{ + _worldPacket << uint32(WeatherID); + _worldPacket << float(Intensity); + _worldPacket << uint8(Abrupt); + + return &_worldPacket; +} diff --git a/src/server/game/Server/Packets/MiscPackets.h b/src/server/game/Server/Packets/MiscPackets.h new file mode 100644 index 000000000..fa3e1b4be --- /dev/null +++ b/src/server/game/Server/Packets/MiscPackets.h @@ -0,0 +1,45 @@ +/* + * This file is part of the AzerothCore Project. See AUTHORS file for Copyright information + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU Affero General Public License as published by the + * Free Software Foundation; either version 3 of the License, or (at your + * option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + */ + +#ifndef MiscPackets_h__ +#define MiscPackets_h__ + +#include "Packet.h" +#include "Weather.h" + +enum WeatherState : uint32; + +namespace WorldPackets +{ + namespace Misc + { + class AC_GAME_API Weather final : public ServerPacket + { + public: + Weather(); + Weather(WeatherState weatherID, float intensity = 0.0f, bool abrupt = false); + + WorldPacket const* Write() override; + + bool Abrupt = false; + float Intensity = 0.0f; + WeatherState WeatherID = WeatherState(0); + }; + } +} + +#endif // MiscPackets_h__ diff --git a/src/server/game/Weather/Weather.cpp b/src/server/game/Weather/Weather.cpp index 1546f4bd9..f588b85b2 100644 --- a/src/server/game/Weather/Weather.cpp +++ b/src/server/game/Weather/Weather.cpp @@ -25,6 +25,7 @@ #include "Util.h" #include "World.h" #include "WorldPacket.h" +#include "MiscPackets.h" /// Create the Weather object Weather::Weather(uint32 zone, WeatherData const* weatherChances) @@ -186,12 +187,10 @@ bool Weather::ReGenerate() return m_type != old_type || m_grade != old_grade; } -void Weather::SendWeatherUpdateToPlayer(Player* /*player*/) +void Weather::SendWeatherUpdateToPlayer(Player* player) { - WorldPacket data(SMSG_WEATHER, (4 + 4 + 1)); - data << uint32(GetWeatherState()); - data << (float)m_grade; - data << uint8(0); + WorldPackets::Misc::Weather weather(GetWeatherState(), m_grade); + player->SendDirectMessage(weather.Write()); } /// Send the new weather to all players in the zone @@ -205,13 +204,10 @@ bool Weather::UpdateWeather() WeatherState state = GetWeatherState(); - WorldPacket data(SMSG_WEATHER, (4 + 4 + 1)); - data << uint32(state); - data << (float)m_grade; - data << uint8(0); + WorldPackets::Misc::Weather weather(state, m_grade); //- Returns false if there were no players found to update - if (!sWorld->SendZoneMessage(m_zone, &data)) + if (!sWorld->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 e8620d7ee..917167695 100644 --- a/src/server/game/Weather/Weather.h +++ b/src/server/game/Weather/Weather.h @@ -42,7 +42,7 @@ struct WeatherData uint32 ScriptId; }; -enum WeatherState +enum WeatherState : uint32 { WEATHER_STATE_FINE = 0, WEATHER_STATE_FOG = 1, diff --git a/src/server/game/Weather/WeatherMgr.cpp b/src/server/game/Weather/WeatherMgr.cpp index 3c46d0bb3..c39bb043f 100644 --- a/src/server/game/Weather/WeatherMgr.cpp +++ b/src/server/game/Weather/WeatherMgr.cpp @@ -26,6 +26,7 @@ #include "Weather.h" #include "WorldPacket.h" #include "WorldSession.h" +#include "MiscPackets.h" #include namespace WeatherMgr @@ -144,11 +145,8 @@ namespace WeatherMgr void SendFineWeatherUpdateToPlayer(Player* player) { - WorldPacket data(SMSG_WEATHER, (4 + 4 + 1)); - data << (uint32)WEATHER_STATE_FINE; - data << (float)0.0f; - data << uint8(0); - player->GetSession()->SendPacket(&data); + WorldPackets::Misc::Weather weather(WEATHER_STATE_FINE); + player->SendDirectMessage(weather.Write()); } void Update(uint32 diff) diff --git a/src/server/scripts/Kalimdor/RuinsOfAhnQiraj/boss_ossirian.cpp b/src/server/scripts/Kalimdor/RuinsOfAhnQiraj/boss_ossirian.cpp index abe782f01..750466ed3 100644 --- a/src/server/scripts/Kalimdor/RuinsOfAhnQiraj/boss_ossirian.cpp +++ b/src/server/scripts/Kalimdor/RuinsOfAhnQiraj/boss_ossirian.cpp @@ -15,6 +15,7 @@ * with this program. If not, see . */ +#include "MiscPackets.h" #include "Opcodes.h" #include "Player.h" #include "ScriptMgr.h" @@ -140,9 +141,8 @@ public: if (!map->IsDungeon()) return; - WorldPacket data(SMSG_WEATHER, (4 + 4 + 4)); - data << uint32(WEATHER_STATE_HEAVY_SANDSTORM) << float(1) << uint8(0); - map->SendToPlayers(&data); + WorldPackets::Misc::Weather weather(WEATHER_STATE_HEAVY_SANDSTORM, 1.0f); + map->SendToPlayers(weather.Write()); for (uint8 i = 0; i < NUM_TORNADOS; ++i) {