Core/WorldStates: Allow multiple map ids for world states
Port From (https://github.com/TrinityCore/TrinityCore/commit/f874f34f04228a41133cd7ce5621e3c637bbf48a)
This commit is contained in:
@@ -15,9 +15,12 @@
|
|||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
using Framework.Collections;
|
||||||
using Framework.Database;
|
using Framework.Database;
|
||||||
|
using Game.DataStorage;
|
||||||
using Game.Maps;
|
using Game.Maps;
|
||||||
using Game.Networking.Packets;
|
using Game.Networking.Packets;
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace Game
|
namespace Game
|
||||||
@@ -34,8 +37,8 @@ namespace Game
|
|||||||
{
|
{
|
||||||
uint oldMSTime = Time.GetMSTime();
|
uint oldMSTime = Time.GetMSTime();
|
||||||
|
|
||||||
// 0 1 2 3
|
// 0 1 2 3
|
||||||
SQLResult result = DB.World.Query("SELECT ID, DefaultValue, MapID, ScriptName FROM world_state");
|
SQLResult result = DB.World.Query("SELECT ID, DefaultValue, MapIDs, ScriptName FROM world_state");
|
||||||
if (result.IsEmpty())
|
if (result.IsEmpty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -45,17 +48,42 @@ namespace Game
|
|||||||
WorldStateTemplate worldState = new();
|
WorldStateTemplate worldState = new();
|
||||||
worldState.Id = id;
|
worldState.Id = id;
|
||||||
worldState.DefaultValue = result.Read<int>(1);
|
worldState.DefaultValue = result.Read<int>(1);
|
||||||
if (!result.IsNull(2))
|
|
||||||
worldState.MapId = result.Read<uint>(2);
|
string mapIds = result.Read<string>(2);
|
||||||
|
foreach (string mapIdToken in new StringArray(mapIds, ','))
|
||||||
|
{
|
||||||
|
if (!uint.TryParse(mapIdToken, out uint mapId))
|
||||||
|
{
|
||||||
|
Log.outError(LogFilter.Sql, $"Table `world_state` contains a world state {id} with non-integer MapID ({mapIdToken}), map ignored");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!CliDB.MapStorage.ContainsKey(mapId))
|
||||||
|
{
|
||||||
|
Log.outError(LogFilter.Sql, $"Table `world_state` contains a world state {id} with invalid MapID ({mapId}), map ignored");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
worldState.MapIds.Add(mapId);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!mapIds.IsEmpty() && worldState.MapIds.Empty())
|
||||||
|
{
|
||||||
|
Log.outError(LogFilter.Sql, "Table `world_state` contains a world state {id} with nonempty MapIDs ({mapIds}) but no valid map id was found, ignored");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
worldState.ScriptId = Global.ObjectMgr.GetScriptId(result.Read<string>(3));
|
worldState.ScriptId = Global.ObjectMgr.GetScriptId(result.Read<string>(3));
|
||||||
|
|
||||||
if (worldState.MapId.HasValue)
|
if (!worldState.MapIds.Empty())
|
||||||
{
|
{
|
||||||
if (!_worldStatesByMap.ContainsKey(worldState.MapId.Value))
|
foreach (uint mapId in worldState.MapIds)
|
||||||
_worldStatesByMap[worldState.MapId.Value] = new();
|
{
|
||||||
|
if (!_worldStatesByMap.ContainsKey(mapId))
|
||||||
|
_worldStatesByMap[mapId] = new();
|
||||||
|
|
||||||
_worldStatesByMap[worldState.MapId.Value][id] = worldState.DefaultValue;
|
_worldStatesByMap[mapId][id] = worldState.DefaultValue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
_realmWorldStateValues[id] = worldState.DefaultValue;
|
_realmWorldStateValues[id] = worldState.DefaultValue;
|
||||||
@@ -75,10 +103,10 @@ namespace Game
|
|||||||
public int GetValue(int worldStateId, Map map)
|
public int GetValue(int worldStateId, Map map)
|
||||||
{
|
{
|
||||||
WorldStateTemplate worldStateTemplate = GetWorldStateTemplate(worldStateId);
|
WorldStateTemplate worldStateTemplate = GetWorldStateTemplate(worldStateId);
|
||||||
if (worldStateTemplate == null || !worldStateTemplate.MapId.HasValue)
|
if (worldStateTemplate == null || worldStateTemplate.MapIds.Empty())
|
||||||
return _realmWorldStateValues.LookupByKey(worldStateId);
|
return _realmWorldStateValues.LookupByKey(worldStateId);
|
||||||
|
|
||||||
if (map.GetId() != worldStateTemplate.MapId)
|
if (!worldStateTemplate.MapIds.Contains(map.GetId()))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
return map.GetWorldStateValue(worldStateId);
|
return map.GetWorldStateValue(worldStateId);
|
||||||
@@ -87,7 +115,7 @@ namespace Game
|
|||||||
public void SetValue(int worldStateId, int value, Map map)
|
public void SetValue(int worldStateId, int value, Map map)
|
||||||
{
|
{
|
||||||
WorldStateTemplate worldStateTemplate = GetWorldStateTemplate(worldStateId);
|
WorldStateTemplate worldStateTemplate = GetWorldStateTemplate(worldStateId);
|
||||||
if (worldStateTemplate == null || !worldStateTemplate.MapId.HasValue)
|
if (worldStateTemplate == null || worldStateTemplate.MapIds.Empty())
|
||||||
{
|
{
|
||||||
int oldValue = _realmWorldStateValues.LookupByKey(worldStateId);
|
int oldValue = _realmWorldStateValues.LookupByKey(worldStateId);
|
||||||
_realmWorldStateValues[worldStateId] = value;
|
_realmWorldStateValues[worldStateId] = value;
|
||||||
@@ -103,7 +131,7 @@ namespace Game
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (map.GetId() != worldStateTemplate.MapId)
|
if (!worldStateTemplate.MapIds.Contains(map.GetId()))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
map.SetWorldStateValue(worldStateId, value);
|
map.SetWorldStateValue(worldStateId, value);
|
||||||
@@ -133,6 +161,6 @@ namespace Game
|
|||||||
public int DefaultValue;
|
public int DefaultValue;
|
||||||
public uint ScriptId;
|
public uint ScriptId;
|
||||||
|
|
||||||
public uint? MapId;
|
public List<uint> MapIds = new();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user