mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-01-16 07:30:42 +01:00
Core/World: implement database support for default map and realm wide world states
Co-Authored-By: Shauren <shauren.trinity@gmail.com>
This commit is contained in:
@@ -56,6 +56,8 @@
|
||||
#include "WeatherMgr.h"
|
||||
#include "World.h"
|
||||
#include "WorldSession.h"
|
||||
#include "WorldStateMgr.h"
|
||||
#include "WorldStatePackets.h"
|
||||
#include <sstream>
|
||||
|
||||
#include "Hacks/boost_1_74_fibonacci_heap.h"
|
||||
@@ -371,6 +373,8 @@ i_scriptLock(false), _respawnCheckTimer(0)
|
||||
|
||||
MMAP::MMapFactory::createOrGetMMapManager()->loadMapInstance(sWorld->GetDataPath(), GetId(), i_InstanceId);
|
||||
|
||||
_worldStateValues = sWorldStateMgr->GetInitialWorldStatesForMap(this);
|
||||
|
||||
sScriptMgr->OnCreateMap(this);
|
||||
}
|
||||
|
||||
@@ -684,6 +688,30 @@ void Map::UpdatePersonalPhasesForPlayer(Player const* player)
|
||||
GetMultiPersonalPhaseTracker().OnOwnerPhaseChanged(player, getNGrid(cell.GridX(), cell.GridY()), this, cell);
|
||||
}
|
||||
|
||||
int32 Map::GetWorldStateValue(int32 worldStateId) const
|
||||
{
|
||||
if (int32 const* value = Trinity::Containers::MapGetValuePtr(_worldStateValues, worldStateId))
|
||||
return *value;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void Map::SetWorldStateValue(int32 worldStateId, int32 value)
|
||||
{
|
||||
auto itr = _worldStateValues.try_emplace(worldStateId, 0).first;
|
||||
int32 oldValue = itr->second;
|
||||
itr->second = value;
|
||||
|
||||
if (WorldStateTemplate const* worldStateTemplate = sWorldStateMgr->GetWorldStateTemplate(worldStateId))
|
||||
sScriptMgr->OnWorldStateValueChange(worldStateTemplate, oldValue, value, this);
|
||||
|
||||
// Broadcast update to all players on the map
|
||||
WorldPackets::WorldState::UpdateWorldState updateWorldState;
|
||||
updateWorldState.VariableID = worldStateId;
|
||||
updateWorldState.Value = value;
|
||||
SendToPlayers(updateWorldState.Write());
|
||||
}
|
||||
|
||||
template<class T>
|
||||
void Map::InitializeObject(T* /*obj*/) { }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user