Core\Packet\Misc: Weather (#9648)

This commit is contained in:
IntelligentQuantum
2022-01-04 22:22:13 +03:30
committed by GitHub
parent e7a7c20c32
commit fb249836e9
9 changed files with 111 additions and 38 deletions
+11 -12
View File
@@ -29,6 +29,7 @@
#include "LFGMgr.h" #include "LFGMgr.h"
#include "MapInstanced.h" #include "MapInstanced.h"
#include "Metric.h" #include "Metric.h"
#include "MiscPackets.h"
#include "Object.h" #include "Object.h"
#include "ObjectAccessor.h" #include "ObjectAccessor.h"
#include "ObjectGridLoader.h" #include "ObjectGridLoader.h"
@@ -39,6 +40,7 @@
#include "VMapFactory.h" #include "VMapFactory.h"
#include "VMapMgr2.h" #include "VMapMgr2.h"
#include "Vehicle.h" #include "Vehicle.h"
#include "Weather.h"
union u_map_magic 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_h[4] = { 0x1111, 0x2222, 0x4444, 0x8888 };
static uint16 const holetab_v[4] = { 0x000F, 0x00F0, 0x0F00, 0xF000 }; 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() Map::~Map()
{ {
// UnloadAll must be called before deleting the map // UnloadAll must be called before deleting the map
@@ -3655,13 +3660,10 @@ void Map::SendZoneDynamicInfo(Player* player)
player->SendDirectMessage(&data); player->SendDirectMessage(&data);
} }
if (uint32 weather = itr->second.WeatherId) if (WeatherState weatherId = itr->second.WeatherId)
{ {
WorldPacket data(SMSG_WEATHER, 4 + 4 + 1); WorldPackets::Misc::Weather weather(weatherId, itr->second.WeatherGrade);
data << uint32(weather); player->SendDirectMessage(weather.Write());
data << float(itr->second.WeatherGrade);
data << uint8(0);
player->SendDirectMessage(&data);
} }
if (uint32 overrideLight = itr->second.OverrideLightId) 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()) if (_zoneDynamicInfo.find(zoneId) == _zoneDynamicInfo.end())
_zoneDynamicInfo.insert(ZoneDynamicInfoMap::value_type(zoneId, ZoneDynamicInfo())); _zoneDynamicInfo.insert(ZoneDynamicInfoMap::value_type(zoneId, ZoneDynamicInfo()));
@@ -3721,15 +3723,12 @@ void Map::SetZoneWeather(uint32 zoneId, uint32 weatherId, float weatherGrade)
if (!players.isEmpty()) if (!players.isEmpty())
{ {
WorldPacket data(SMSG_WEATHER, 4 + 4 + 1); WorldPackets::Misc::Weather weather(weatherId, weatherGrade);
data << uint32(weatherId);
data << float(weatherGrade);
data << uint8(0);
for (Map::PlayerList::const_iterator itr = players.begin(); itr != players.end(); ++itr) for (Map::PlayerList::const_iterator itr = players.begin(); itr != players.end(); ++itr)
if (Player* player = itr->GetSource()) if (Player* player = itr->GetSource())
if (player->GetZoneId() == zoneId) if (player->GetZoneId() == zoneId)
player->SendDirectMessage(&data); player->SendDirectMessage(weather.Write());
} }
} }
+9 -7
View File
@@ -60,6 +60,8 @@ class StaticTransport;
class MotionTransport; class MotionTransport;
class PathGenerator; class PathGenerator;
enum WeatherState : uint32;
namespace Acore namespace Acore
{ {
struct ObjectUpdater; struct ObjectUpdater;
@@ -271,13 +273,13 @@ enum LevelRequirementVsMode
struct ZoneDynamicInfo struct ZoneDynamicInfo
{ {
ZoneDynamicInfo() { } ZoneDynamicInfo();
uint32 MusicId{0}; uint32 MusicId;
uint32 WeatherId{0}; WeatherState WeatherId;
float WeatherGrade{0.0f}; float WeatherGrade;
uint32 OverrideLightId{0}; uint32 OverrideLightId;
uint32 LightFadeInTime{0}; uint32 LightFadeInTime;
}; };
#if defined(__GNUC__) #if defined(__GNUC__)
@@ -597,7 +599,7 @@ public:
void PlayDirectSoundToMap(uint32 soundId, uint32 zoneId = 0); void PlayDirectSoundToMap(uint32 soundId, uint32 zoneId = 0);
void SetZoneMusic(uint32 zoneId, uint32 musicId); 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); void SetZoneOverrideLight(uint32 zoneId, uint32 lightId, Milliseconds fadeInTime);
// Checks encounter state at kill/spellcast, originally in InstanceScript however not every map has instance script :( // Checks encounter state at kill/spellcast, originally in InstanceScript however not every map has instance script :(
@@ -18,6 +18,7 @@
#ifndef AllPackets_h__ #ifndef AllPackets_h__
#define AllPackets_h__ #define AllPackets_h__
#include "MiscPackets.h"
#include "WorldStatePackets.h" #include "WorldStatePackets.h"
#include "TotemPackets.h" #include "TotemPackets.h"
#include "BankPackets.h" #include "BankPackets.h"
@@ -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 <http://www.gnu.org/licenses/>.
*/
#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;
}
@@ -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 <http://www.gnu.org/licenses/>.
*/
#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__
+6 -10
View File
@@ -25,6 +25,7 @@
#include "Util.h" #include "Util.h"
#include "World.h" #include "World.h"
#include "WorldPacket.h" #include "WorldPacket.h"
#include "MiscPackets.h"
/// Create the Weather object /// Create the Weather object
Weather::Weather(uint32 zone, WeatherData const* weatherChances) Weather::Weather(uint32 zone, WeatherData const* weatherChances)
@@ -186,12 +187,10 @@ bool Weather::ReGenerate()
return m_type != old_type || m_grade != old_grade; 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)); WorldPackets::Misc::Weather weather(GetWeatherState(), m_grade);
data << uint32(GetWeatherState()); player->SendDirectMessage(weather.Write());
data << (float)m_grade;
data << uint8(0);
} }
/// Send the new weather to all players in the zone /// Send the new weather to all players in the zone
@@ -205,13 +204,10 @@ bool Weather::UpdateWeather()
WeatherState state = GetWeatherState(); WeatherState state = GetWeatherState();
WorldPacket data(SMSG_WEATHER, (4 + 4 + 1)); WorldPackets::Misc::Weather weather(state, m_grade);
data << uint32(state);
data << (float)m_grade;
data << uint8(0);
//- Returns false if there were no players found to update //- 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; return false;
///- Log the event ///- Log the event
+1 -1
View File
@@ -42,7 +42,7 @@ struct WeatherData
uint32 ScriptId; uint32 ScriptId;
}; };
enum WeatherState enum WeatherState : uint32
{ {
WEATHER_STATE_FINE = 0, WEATHER_STATE_FINE = 0,
WEATHER_STATE_FOG = 1, WEATHER_STATE_FOG = 1,
+3 -5
View File
@@ -26,6 +26,7 @@
#include "Weather.h" #include "Weather.h"
#include "WorldPacket.h" #include "WorldPacket.h"
#include "WorldSession.h" #include "WorldSession.h"
#include "MiscPackets.h"
#include <memory> #include <memory>
namespace WeatherMgr namespace WeatherMgr
@@ -144,11 +145,8 @@ namespace WeatherMgr
void SendFineWeatherUpdateToPlayer(Player* player) void SendFineWeatherUpdateToPlayer(Player* player)
{ {
WorldPacket data(SMSG_WEATHER, (4 + 4 + 1)); WorldPackets::Misc::Weather weather(WEATHER_STATE_FINE);
data << (uint32)WEATHER_STATE_FINE; player->SendDirectMessage(weather.Write());
data << (float)0.0f;
data << uint8(0);
player->GetSession()->SendPacket(&data);
} }
void Update(uint32 diff) void Update(uint32 diff)
@@ -15,6 +15,7 @@
* with this program. If not, see <http://www.gnu.org/licenses/>. * with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "MiscPackets.h"
#include "Opcodes.h" #include "Opcodes.h"
#include "Player.h" #include "Player.h"
#include "ScriptMgr.h" #include "ScriptMgr.h"
@@ -140,9 +141,8 @@ public:
if (!map->IsDungeon()) if (!map->IsDungeon())
return; return;
WorldPacket data(SMSG_WEATHER, (4 + 4 + 4)); WorldPackets::Misc::Weather weather(WEATHER_STATE_HEAVY_SANDSTORM, 1.0f);
data << uint32(WEATHER_STATE_HEAVY_SANDSTORM) << float(1) << uint8(0); map->SendToPlayers(weather.Write());
map->SendToPlayers(&data);
for (uint8 i = 0; i < NUM_TORNADOS; ++i) for (uint8 i = 0; i < NUM_TORNADOS; ++i)
{ {