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:
Shauren
2022-06-25 22:48:27 +02:00
parent e708bd28d1
commit 737d94d7ef
10 changed files with 331 additions and 0 deletions

View File

@@ -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*/) { }