mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-01-25 03:12:09 +01:00
Core/Weather: merged commit 6eb9973947
This commit is contained in:
@@ -35,6 +35,8 @@
|
||||
#include "Transport.h"
|
||||
#include "Vehicle.h"
|
||||
#include "VMapFactory.h"
|
||||
#include "Weather.h"
|
||||
#include "WeatherMgr.h"
|
||||
|
||||
u_map_magic MapMagic = { {'M','A','P','S'} };
|
||||
u_map_magic MapVersionMagic = { {'v','1','.','6'} };
|
||||
@@ -48,6 +50,9 @@ u_map_magic MapLiquidMagic = { {'M','L','I','Q'} };
|
||||
|
||||
GridState* si_GridStates[MAX_GRID_STATE];
|
||||
|
||||
ZoneDynamicInfo::ZoneDynamicInfo() : MusicId(0), DefaultWeather(nullptr), WeatherId(WEATHER_STATE_FINE),
|
||||
WeatherGrade(0.0f), OverrideLightId(0), LightFadeInTime(0) { }
|
||||
|
||||
Map::~Map()
|
||||
{
|
||||
// UnloadAll must be called before deleting the map
|
||||
@@ -254,6 +259,8 @@ i_scriptLock(false), _defaultLight(GetDefaultMapLight(id))
|
||||
//lets initialize visibility distance for map
|
||||
Map::InitVisibilityDistance();
|
||||
|
||||
_weatherUpdateTimer.SetInterval(time_t(1 * IN_MILLISECONDS));
|
||||
|
||||
sScriptMgr->OnCreateMap(this);
|
||||
}
|
||||
|
||||
@@ -532,7 +539,6 @@ bool Map::AddPlayerToMap(Player* player)
|
||||
|
||||
SendInitSelf(player);
|
||||
SendInitTransports(player);
|
||||
SendZoneDynamicInfo(player);
|
||||
|
||||
player->m_clientGUIDs.clear();
|
||||
player->UpdateObjectVisibility(false);
|
||||
@@ -774,6 +780,15 @@ void Map::Update(const uint32 t_diff)
|
||||
i_scriptLock = false;
|
||||
}
|
||||
|
||||
if (_weatherUpdateTimer.Passed())
|
||||
{
|
||||
for (auto&& zoneInfo : _zoneDynamicInfo)
|
||||
if (zoneInfo.second.DefaultWeather && !zoneInfo.second.DefaultWeather->Update(_weatherUpdateTimer.GetInterval()))
|
||||
zoneInfo.second.DefaultWeather.reset();
|
||||
|
||||
_weatherUpdateTimer.Reset();
|
||||
}
|
||||
|
||||
MoveAllCreaturesInMoveList();
|
||||
MoveAllGameObjectsInMoveList();
|
||||
|
||||
@@ -3901,10 +3916,9 @@ void Map::RemoveOldCorpses()
|
||||
}
|
||||
}
|
||||
|
||||
void Map::SendZoneDynamicInfo(Player* player)
|
||||
void Map::SendZoneDynamicInfo(uint32 zoneId, Player* player) const
|
||||
{
|
||||
uint32 zoneId = GetZoneId(player->GetPositionX(), player->GetPositionY(), player->GetPositionZ());
|
||||
ZoneDynamicInfoMap::const_iterator itr = _zoneDynamicInfo.find(zoneId);
|
||||
auto itr = _zoneDynamicInfo.find(zoneId);
|
||||
if (itr == _zoneDynamicInfo.end())
|
||||
return;
|
||||
|
||||
@@ -3916,14 +3930,7 @@ void Map::SendZoneDynamicInfo(Player* player)
|
||||
player->SendDirectMessage(&data);
|
||||
}
|
||||
|
||||
if (uint32 weather = itr->second.WeatherId)
|
||||
{
|
||||
WorldPacket data(SMSG_WEATHER, 4 + 4 + 1);
|
||||
data << uint32(weather);
|
||||
data << float(itr->second.WeatherGrade);
|
||||
data << uint8(0);
|
||||
player->SendDirectMessage(&data);
|
||||
}
|
||||
SendZoneWeather(itr->second, player);
|
||||
|
||||
if (uint32 overrideLight = itr->second.OverrideLightId)
|
||||
{
|
||||
@@ -3935,11 +3942,38 @@ void Map::SendZoneDynamicInfo(Player* player)
|
||||
}
|
||||
}
|
||||
|
||||
void Map::SendZoneWeather(uint32 zoneId, Player* player) const
|
||||
{
|
||||
if (!player->HasAuraType(SPELL_AURA_FORCE_WEATHER))
|
||||
{
|
||||
auto itr = _zoneDynamicInfo.find(zoneId);
|
||||
if (itr == _zoneDynamicInfo.end())
|
||||
return;
|
||||
|
||||
SendZoneWeather(itr->second, player);
|
||||
}
|
||||
}
|
||||
|
||||
void Map::SendZoneWeather(ZoneDynamicInfo const& zoneDynamicInfo, Player* player) const
|
||||
{
|
||||
if (WeatherState weatherId = zoneDynamicInfo.WeatherId)
|
||||
{
|
||||
WorldPacket data(SMSG_WEATHER, 4 + 4 + 1);
|
||||
data << uint32(weatherId);
|
||||
data << float(zoneDynamicInfo.WeatherGrade);
|
||||
data << uint8(0);
|
||||
player->SendDirectMessage(&data);
|
||||
}
|
||||
else if (zoneDynamicInfo.DefaultWeather)
|
||||
{
|
||||
zoneDynamicInfo.DefaultWeather->SendWeatherUpdateToPlayer(player);
|
||||
}
|
||||
else
|
||||
Weather::SendFineWeatherUpdateToPlayer(player);
|
||||
}
|
||||
|
||||
void Map::SetZoneMusic(uint32 zoneId, uint32 musicId)
|
||||
{
|
||||
if (_zoneDynamicInfo.find(zoneId) == _zoneDynamicInfo.end())
|
||||
_zoneDynamicInfo.insert(ZoneDynamicInfoMap::value_type(zoneId, ZoneDynamicInfo()));
|
||||
|
||||
_zoneDynamicInfo[zoneId].MusicId = musicId;
|
||||
|
||||
Map::PlayerList const& players = GetPlayers();
|
||||
@@ -3947,7 +3981,7 @@ void Map::SetZoneMusic(uint32 zoneId, uint32 musicId)
|
||||
{
|
||||
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))
|
||||
{
|
||||
WorldPacket data(SMSG_PLAY_MUSIC, 4);
|
||||
data << uint32(musicId);
|
||||
@@ -3957,11 +3991,25 @@ void Map::SetZoneMusic(uint32 zoneId, uint32 musicId)
|
||||
}
|
||||
}
|
||||
|
||||
void Map::SetZoneWeather(uint32 zoneId, uint32 weatherId, float weatherGrade)
|
||||
Weather* Map::GetOrGenerateZoneDefaultWeather(uint32 zoneId)
|
||||
{
|
||||
if (_zoneDynamicInfo.find(zoneId) == _zoneDynamicInfo.end())
|
||||
_zoneDynamicInfo.insert(ZoneDynamicInfoMap::value_type(zoneId, ZoneDynamicInfo()));
|
||||
WeatherData const* weatherData = WeatherMgr::GetWeatherData(zoneId);
|
||||
if (!weatherData)
|
||||
return nullptr;
|
||||
|
||||
ZoneDynamicInfo& info = _zoneDynamicInfo[zoneId];
|
||||
if (!info.DefaultWeather)
|
||||
{
|
||||
info.DefaultWeather = Trinity::make_unique<Weather>(zoneId, weatherData);
|
||||
info.DefaultWeather->ReGenerate();
|
||||
info.DefaultWeather->UpdateWeather();
|
||||
}
|
||||
|
||||
return info.DefaultWeather.get();
|
||||
}
|
||||
|
||||
void Map::SetZoneWeather(uint32 zoneId, WeatherState weatherId, float weatherGrade)
|
||||
{
|
||||
ZoneDynamicInfo& info = _zoneDynamicInfo[zoneId];
|
||||
info.WeatherId = weatherId;
|
||||
info.WeatherGrade = weatherGrade;
|
||||
@@ -3983,9 +4031,6 @@ void Map::SetZoneWeather(uint32 zoneId, uint32 weatherId, float weatherGrade)
|
||||
|
||||
void Map::SetZoneOverrideLight(uint32 zoneId, uint32 lightId, uint32 fadeInTime)
|
||||
{
|
||||
if (_zoneDynamicInfo.find(zoneId) == _zoneDynamicInfo.end())
|
||||
_zoneDynamicInfo.insert(ZoneDynamicInfoMap::value_type(zoneId, ZoneDynamicInfo()));
|
||||
|
||||
ZoneDynamicInfo& info = _zoneDynamicInfo[zoneId];
|
||||
info.OverrideLightId = lightId;
|
||||
info.LightFadeInTime = fadeInTime;
|
||||
|
||||
Reference in New Issue
Block a user