Core/World: implement database support for default map and realm wide world states

Port From (https://github.com/TrinityCore/TrinityCore/commit/737d94d7efe0b6c308ac1bf3692b6aa2e43f5adb)
This commit is contained in:
hondacrx
2022-06-25 22:52:20 -04:00
parent ed7a07d893
commit 7be2eb52cc
9 changed files with 217 additions and 0 deletions
+27
View File
@@ -87,6 +87,8 @@ namespace Game.Maps
Global.MMapMgr.LoadMapInstance(Global.WorldMgr.GetDataPath(), GetId(), i_InstanceId);
_worldStateValues = Global.WorldStateMgr.GetInitialWorldStatesForMap(this);
Global.ScriptMgr.OnCreateMap(this);
}
@@ -574,6 +576,29 @@ namespace Game.Maps
Cell cell = new(player.GetPositionX(), player.GetPositionY());
GetMultiPersonalPhaseTracker().OnOwnerPhaseChanged(player, GetGrid(cell.GetGridX(), cell.GetGridY()), this, cell);
}
public int GetWorldStateValue(int worldStateId)
{
return _worldStateValues.LookupByKey(worldStateId);
}
public Dictionary<int, int> GetWorldStateValues() { return _worldStateValues; }
public void SetWorldStateValue(int worldStateId, int value)
{
int oldValue = _worldStateValues.LookupByKey(worldStateId);
_worldStateValues[worldStateId] = value;
WorldStateTemplate worldStateTemplate = Global.WorldStateMgr.GetWorldStateTemplate(worldStateId);
if (worldStateTemplate != null)
Global.ScriptMgr.OnWorldStateValueChange(worldStateTemplate, oldValue, value, this);
// Broadcast update to all players on the map
UpdateWorldState updateWorldState = new();
updateWorldState.VariableID = (uint)worldStateId;
updateWorldState.Value = value;
SendToPlayers(updateWorldState);
}
void InitializeObject(WorldObject obj)
{
@@ -5257,6 +5282,8 @@ namespace Game.Maps
Queue<FarSpellCallback> _farSpellCallbacks = new();
MultiPersonalPhaseTracker _multiPersonalPhaseTracker = new();
Dictionary<int, int> _worldStateValues = new();
#endregion
}