From 888fd1147764d6b79a45a46fef99167682b027f1 Mon Sep 17 00:00:00 2001 From: hondacrx Date: Mon, 25 Jul 2022 22:25:09 -0400 Subject: [PATCH] Core/Maps: Split Ebon Hold and Exile's reach by faction and removed forced sanctuary hack Port From (https://github.com/TrinityCore/TrinityCore/commit/515c0a43ef8fcf41ffb2785c5940f0234e757ec3) --- Source/Game/DataStorage/Structs/A_Records.cs | 3 --- Source/Game/DataStorage/Structs/M_Records.cs | 18 ++++++++++++- Source/Game/Maps/MapManager.cs | 27 ++++++++++++++++++-- Source/Game/Scripting/ScriptManager.cs | 3 +++ 4 files changed, 45 insertions(+), 6 deletions(-) diff --git a/Source/Game/DataStorage/Structs/A_Records.cs b/Source/Game/DataStorage/Structs/A_Records.cs index d5f42c627..f0b76bbb3 100644 --- a/Source/Game/DataStorage/Structs/A_Records.cs +++ b/Source/Game/DataStorage/Structs/A_Records.cs @@ -147,9 +147,6 @@ namespace Game.DataStorage public bool IsSanctuary() { - if (ContinentID == 609) - return true; - return HasFlag(AreaFlags.Sanctuary); } diff --git a/Source/Game/DataStorage/Structs/M_Records.cs b/Source/Game/DataStorage/Structs/M_Records.cs index be7e60a42..404b0bcf9 100644 --- a/Source/Game/DataStorage/Structs/M_Records.cs +++ b/Source/Game/DataStorage/Structs/M_Records.cs @@ -86,11 +86,27 @@ namespace Game.DataStorage public bool IsContinent() { - return Id == 0 || Id == 1 || Id == 530 || Id == 571 || Id == 870 || Id == 1116 || Id == 1220; + switch (Id) + { + case 0: + case 1: + case 530: + case 571: + case 870: + case 1116: + case 1220: + case 1642: + case 1643: + case 2222: + return true; + default: + return false; + } } public bool IsDynamicDifficultyMap() { return (Flags[0] & MapFlags.CanToggleDifficulty) != 0; } public bool IsGarrison() { return (Flags[0] & MapFlags.Garrison) != 0; } + public bool IsSplitByFaction() { return Id == 609 || Id == 2175; } } public sealed class MapChallengeModeRecord diff --git a/Source/Game/Maps/MapManager.cs b/Source/Game/Maps/MapManager.cs index bfb73bd0c..2e9e4715d 100644 --- a/Source/Game/Maps/MapManager.cs +++ b/Source/Game/Maps/MapManager.cs @@ -22,6 +22,7 @@ using Game.DataStorage; using Game.Garrisons; using Game.Groups; using Game.Maps; +using Game.Scripting; using System; using System.Collections; using System.Collections.Generic; @@ -232,6 +233,9 @@ namespace Game.Entities else { newInstanceId = 0; + if (entry.IsSplitByFaction()) + newInstanceId = (uint)player.GetTeamId(); + map = FindMap_i(mapId, newInstanceId); if (!map) map = CreateWorldMap(mapId, newInstanceId); @@ -356,7 +360,7 @@ namespace Game.Entities } public uint GenerateInstanceId() - { + { if (_nextInstanceId == 0xFFFFFFFF) { Log.outError(LogFilter.Maps, "Instance ID overflow!! Can't continue, shutting down server. "); @@ -438,6 +442,13 @@ namespace Game.Entities } } + public void AddSC_BuiltInScripts() + { + foreach (var (_, mapEntry) in CliDB.MapStorage) + if (mapEntry.IsWorldMap() && mapEntry.IsSplitByFaction()) + new SplitByFactionMapScript($"world_map_set_faction_worldstates_{mapEntry.Id}", mapEntry.Id); + } + public void IncreaseScheduledScriptsCount() { ++_scheduledScripts; } public void DecreaseScheduledScriptCount() { --_scheduledScripts; } public void DecreaseScheduledScriptCount(uint count) { _scheduledScripts -= count; } @@ -445,11 +456,23 @@ namespace Game.Entities Dictionary<(uint mapId, uint instanceId), Map> i_maps = new(); IntervalTimer i_timer = new(); - object _mapsLock= new(); + object _mapsLock = new(); uint i_gridCleanUpDelay; BitSet _freeInstanceIds; uint _nextInstanceId; MapUpdater m_updater; uint _scheduledScripts; } + + // hack to allow conditions to access what faction owns the map (these worldstates should not be set on these maps) + class SplitByFactionMapScript : WorldMapScript + { + public SplitByFactionMapScript(string name, uint mapId) : base(name, mapId) { } + + public override void OnCreate(Map map) + { + Global.WorldStateMgr.SetValue(WorldStates.TeamInInstanceAlliance, map.GetInstanceId() == TeamId.Alliance ? 1 : 0, false, map); + Global.WorldStateMgr.SetValue(WorldStates.TeamInInstanceHorde, map.GetInstanceId() == TeamId.Horde ? 1 : 0, false, map); + } + } } diff --git a/Source/Game/Scripting/ScriptManager.cs b/Source/Game/Scripting/ScriptManager.cs index e8353394e..0521d3f73 100644 --- a/Source/Game/Scripting/ScriptManager.cs +++ b/Source/Game/Scripting/ScriptManager.cs @@ -59,6 +59,9 @@ namespace Game.Scripting //Load Scripts.dll LoadScripts(); + // MapScripts + Global.MapMgr.AddSC_BuiltInScripts(); + Log.outInfo(LogFilter.ServerLoading, $"Loaded {GetScriptCount()} C# scripts in {Time.GetMSTimeDiffToNow(oldMSTime)} ms"); }