Core/Misc: Move zone packet sending from World to Map (#30024)
(cherry picked from commit 70d6121ef47573555218ad072c425cfb74c29558)
This commit is contained in:
@@ -21,6 +21,7 @@
|
||||
#include "BattlegroundScript.h"
|
||||
#include "CellImpl.h"
|
||||
#include "CharacterPackets.h"
|
||||
#include "ChatPackets.h"
|
||||
#include "Conversation.h"
|
||||
#include "DB2Stores.h"
|
||||
#include "DatabaseEnv.h"
|
||||
@@ -2692,6 +2693,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, Optional<Team> team) const
|
||||
{
|
||||
bool foundPlayerToSend = false;
|
||||
|
||||
for (MapReference const& ref : GetPlayers())
|
||||
{
|
||||
Player* player = ref.GetSource();
|
||||
if (player->IsInWorld() &&
|
||||
player->GetZoneId() == zone &&
|
||||
player->GetSession() != self &&
|
||||
(!team || 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);
|
||||
@@ -3974,21 +3996,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, Optional<Team> team) const
|
||||
{
|
||||
WorldPackets::Chat::Chat packet;
|
||||
packet.Initialize(CHAT_MSG_SYSTEM, LANG_UNIVERSAL, nullptr, nullptr, text);
|
||||
SendZoneMessage(zoneId, packet.Write(), self, team);
|
||||
}
|
||||
|
||||
void Map::SetZoneMusic(uint32 zoneId, uint32 musicId)
|
||||
{
|
||||
_zoneDynamicInfo[zoneId].MusicId = musicId;
|
||||
|
||||
Map::PlayerList const& players = GetPlayers();
|
||||
if (!players.empty())
|
||||
{
|
||||
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->HasAuraType(SPELL_AURA_FORCE_WEATHER))
|
||||
player->SendDirectMessage(playMusic.GetRawPacket());
|
||||
}
|
||||
WorldPackets::Misc::PlayMusic playMusic(musicId);
|
||||
SendZoneMessage(zoneId, WorldPackets::Misc::PlayMusic(musicId).Write());
|
||||
}
|
||||
|
||||
Weather* Map::GetOrGenerateZoneDefaultWeather(uint32 zoneId)
|
||||
@@ -4000,7 +4021,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();
|
||||
}
|
||||
@@ -4037,7 +4058,7 @@ void Map::SetZoneWeather(uint32 zoneId, WeatherState weatherId, float intensity)
|
||||
|
||||
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))
|
||||
player->SendDirectMessage(weather.GetRawPacket());
|
||||
}
|
||||
}
|
||||
@@ -4060,20 +4081,11 @@ void Map::SetZoneOverrideLight(uint32 zoneId, uint32 areaLightId, uint32 overrid
|
||||
lightOverride.TransitionMilliseconds = static_cast<uint32>(transitionTime.count());
|
||||
}
|
||||
|
||||
Map::PlayerList const& players = GetPlayers();
|
||||
if (!players.empty())
|
||||
{
|
||||
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()
|
||||
|
||||
@@ -66,6 +66,7 @@ class Unit;
|
||||
class Weather;
|
||||
class WorldObject;
|
||||
class WorldPacket;
|
||||
class WorldSession;
|
||||
struct DungeonEncounterEntry;
|
||||
struct MapDifficultyEntry;
|
||||
struct MapEntry;
|
||||
@@ -399,6 +400,7 @@ class TC_GAME_API Map : public GridRefManager<NGridType>
|
||||
void RemoveWorldObject(WorldObject* obj);
|
||||
|
||||
void SendToPlayers(WorldPacket const* data) const;
|
||||
bool SendZoneMessage(uint32 zone, WorldPacket const* packet, WorldSession const* self = nullptr, Optional<Team> team = { }) const;
|
||||
|
||||
typedef MapRefManager PlayerList;
|
||||
PlayerList const& GetPlayers() const { return m_mapRefManager; }
|
||||
@@ -546,6 +548,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, Optional<Team> team = { }) const;
|
||||
|
||||
void SetZoneMusic(uint32 zoneId, uint32 musicId);
|
||||
Weather* GetOrGenerateZoneDefaultWeather(uint32 zoneId);
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
#include "GameTime.h"
|
||||
#include "Weather.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
|
||||
|
||||
@@ -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);
|
||||
@@ -83,6 +84,7 @@ class TC_GAME_API Weather
|
||||
uint32 GetScriptId() const { return m_weatherChances->ScriptId; }
|
||||
|
||||
private:
|
||||
Map* m_map;
|
||||
uint32 m_zone;
|
||||
WeatherType m_type;
|
||||
float m_intensity;
|
||||
|
||||
@@ -2601,37 +2601,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, Optional<Team> 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 || 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, Optional<Team> team)
|
||||
{
|
||||
WorldPackets::Chat::Chat packet;
|
||||
packet.Initialize(CHAT_MSG_SYSTEM, LANG_UNIVERSAL, nullptr, nullptr, text);
|
||||
SendZoneMessage(zone, packet.Write(), self, team);
|
||||
}
|
||||
|
||||
/// Kick (and save) all players
|
||||
void World::KickAll()
|
||||
{
|
||||
|
||||
@@ -654,8 +654,6 @@ class TC_GAME_API World
|
||||
void SendServerMessage(ServerMessageType messageID, std::string_view stringParam = {}, Player const* player = nullptr);
|
||||
void SendGlobalMessage(WorldPacket const* packet, WorldSession* self = nullptr, Optional<Team> team = { });
|
||||
void SendGlobalGMMessage(WorldPacket const* packet, WorldSession* self = nullptr, Optional<Team> team = { });
|
||||
bool SendZoneMessage(uint32 zone, WorldPacket const* packet, WorldSession* self = nullptr, Optional<Team> team = { });
|
||||
void SendZoneText(uint32 zone, const char *text, WorldSession* self = nullptr, Optional<Team> team = { });
|
||||
|
||||
/// Are we in the middle of a shutdown?
|
||||
bool IsShuttingDown() const { return m_ShutdownTimer > 0; }
|
||||
|
||||
@@ -98,7 +98,7 @@ bool OutdoorPvPSI::HandleAreaTrigger(Player* player, uint32 trigger, bool /*ente
|
||||
{
|
||||
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;
|
||||
newScore = 0;
|
||||
SetWorldState(SI_GATHERED_H, 0);
|
||||
@@ -124,7 +124,7 @@ bool OutdoorPvPSI::HandleAreaTrigger(Player* player, uint32 trigger, bool /*ente
|
||||
{
|
||||
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;
|
||||
SetWorldState(SI_GATHERED_A, 0);
|
||||
newScore = 0;
|
||||
|
||||
Reference in New Issue
Block a user