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

View File

@@ -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());
}
}

View File

@@ -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 :(

View File

@@ -18,6 +18,7 @@
#ifndef AllPackets_h__
#define AllPackets_h__
#include "MiscPackets.h"
#include "WorldStatePackets.h"
#include "TotemPackets.h"
#include "BankPackets.h"

View File

@@ -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;
}

View File

@@ -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__

View File

@@ -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

View File

@@ -42,7 +42,7 @@ struct WeatherData
uint32 ScriptId;
};
enum WeatherState
enum WeatherState : uint32
{
WEATHER_STATE_FINE = 0,
WEATHER_STATE_FOG = 1,

View File

@@ -26,6 +26,7 @@
#include "Weather.h"
#include "WorldPacket.h"
#include "WorldSession.h"
#include "MiscPackets.h"
#include <memory>
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)

View File

@@ -15,6 +15,7 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#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)
{