From 552f12655eef6b3110c914b43c42c831edfeb1ab Mon Sep 17 00:00:00 2001 From: hondacrx Date: Tue, 7 Dec 2021 17:21:58 -0500 Subject: [PATCH] Core/AreaTriggers: Move ScriptName from areatrigger_template to areatrigger_create_properties and areatrigger tables Port From (https://github.com/TrinityCore/TrinityCore/commit/77ddb4da816b4dfc7ff03b79b88b5ca80918bc2d) --- .../Game/DataStorage/AreaTriggerDataStorage.cs | 17 ++++++++++------- Source/Game/Entities/AreaTrigger/AreaTrigger.cs | 12 +++++++++++- .../Entities/AreaTrigger/AreaTriggerTemplate.cs | 5 ++++- .../world/master/2021_12_04_00_world.sql | 7 +++++++ 4 files changed, 32 insertions(+), 9 deletions(-) create mode 100644 sql/updates/world/master/2021_12_04_00_world.sql diff --git a/Source/Game/DataStorage/AreaTriggerDataStorage.cs b/Source/Game/DataStorage/AreaTriggerDataStorage.cs index 5c5337db9..3af3c274d 100644 --- a/Source/Game/DataStorage/AreaTriggerDataStorage.cs +++ b/Source/Game/DataStorage/AreaTriggerDataStorage.cs @@ -120,8 +120,8 @@ namespace Game.DataStorage Log.outInfo(LogFilter.ServerLoading, "Loaded 0 AreaTrigger splines. DB table `areatrigger_create_properties_spline_point` is empty."); } - // 0 1 2 3 - SQLResult templates = DB.World.Query("SELECT Id, IsServerSide, Flags, ScriptName FROM `areatrigger_template`"); + // 0 1 2 + SQLResult templates = DB.World.Query("SELECT Id, IsServerSide, Flags FROM `areatrigger_template`"); if (!templates.IsEmpty()) { do @@ -137,7 +137,6 @@ namespace Game.DataStorage continue; } - areaTriggerTemplate.ScriptId = Global.ObjectMgr.GetScriptId(templates.Read(3)); areaTriggerTemplate.Actions = actionsByAreaTrigger[areaTriggerTemplate.Id]; _areaTriggerTemplateStore[areaTriggerTemplate.Id] = areaTriggerTemplate; @@ -147,8 +146,8 @@ namespace Game.DataStorage // 0 1 2 3 4 5 6 7 8 9 10 SQLResult areatriggerCreateProperties = DB.World.Query("SELECT Id, AreaTriggerId, MoveCurveId, ScaleCurveId, MorphCurveId, FacingCurveId, AnimId, AnimKitId, DecalPropertiesId, TimeToTarget, TimeToTargetScale, " + - //11 12 13 14 15 16 17 - "Shape, ShapeData0, ShapeData1, ShapeData2, ShapeData3, ShapeData4, ShapeData5 FROM `areatrigger_create_properties`"); + //11 12 13 14 15 16 17 18 + "Shape, ShapeData0, ShapeData1, ShapeData2, ShapeData3, ShapeData4, ShapeData5, ScriptName FROM `areatrigger_create_properties`"); if (!areatriggerCreateProperties.IsEmpty()) { do @@ -203,6 +202,8 @@ namespace Game.DataStorage createProperties.Shape.DefaultDatas.Data[i] = areatriggerCreateProperties.Read(12 + i); } + createProperties.ScriptId = Global.ObjectMgr.GetScriptId(areatriggerCreateProperties.Read(18)); + if (shape == AreaTriggerTypes.Polygon) if (createProperties.Shape.PolygonDatas.Height <= 0.0f) createProperties.Shape.PolygonDatas.Height = 1.0f; @@ -287,8 +288,8 @@ namespace Game.DataStorage // Load area trigger positions (to put them on the server) // 0 1 2 3 4 5 6 7 8 9 10 SQLResult templates = DB.World.Query("SELECT SpawnId, AreaTriggerId, IsServerSide, MapId, PosX, PosY, PosZ, Orientation, PhaseUseFlags, PhaseId, PhaseGroup, " + - //11 12 13 14 15 16 17 - "Shape, ShapeData0, ShapeData1, ShapeData2, ShapeData3, ShapeData4, ShapeData5 FROM `areatrigger`"); + //11 12 13 14 15 16 17 18 + "Shape, ShapeData0, ShapeData1, ShapeData2, ShapeData3, ShapeData4, ShapeData5, ScriptName FROM `areatrigger`"); if (!templates.IsEmpty()) { do @@ -332,6 +333,8 @@ namespace Game.DataStorage spawn.Shape.DefaultDatas.Data[i] = templates.Read(12 + i); } + spawn.ScriptId = Global.ObjectMgr.GetScriptId(templates.Read(18)); + // Add the trigger to a map::cell map, which is later used by GridLoader to query CellCoord cellCoord = GridDefines.ComputeCellCoord(spawn.Location.GetPositionX(), spawn.Location.GetPositionY()); if (!_areaTriggerSpawnsByLocation.ContainsKey((spawn.Location.GetMapId(), cellCoord.GetId()))) diff --git a/Source/Game/Entities/AreaTrigger/AreaTrigger.cs b/Source/Game/Entities/AreaTrigger/AreaTrigger.cs index cd1f6aac6..96a3c81a2 100644 --- a/Source/Game/Entities/AreaTrigger/AreaTrigger.cs +++ b/Source/Game/Entities/AreaTrigger/AreaTrigger.cs @@ -225,6 +225,8 @@ namespace Game.Entities public override bool LoadFromDB(ulong spawnId, Map map, bool addToMap, bool allowDuplicate) { + _spawnId = spawnId; + AreaTriggerSpawn position = Global.AreaTriggerDataStorage.GetAreaTriggerSpawn(spawnId); if (position == null) return false; @@ -499,7 +501,13 @@ namespace Game.Entities public uint GetScriptId() { - return GetTemplate() != null ? GetTemplate().ScriptId : 0; + if (_spawnId != 0) + return Global.AreaTriggerDataStorage.GetAreaTriggerSpawn(_spawnId).ScriptId; + + if (GetCreateProperties() != null) + return GetCreateProperties().ScriptId; + + return 0; } public Unit GetCaster() @@ -1051,6 +1059,8 @@ namespace Game.Entities AreaTriggerFieldData m_areaTriggerData; + ulong _spawnId; + ObjectGuid _targetGuid; AuraEffect _aurEff; diff --git a/Source/Game/Entities/AreaTrigger/AreaTriggerTemplate.cs b/Source/Game/Entities/AreaTrigger/AreaTriggerTemplate.cs index 2ade9196f..c01ce38b1 100644 --- a/Source/Game/Entities/AreaTrigger/AreaTriggerTemplate.cs +++ b/Source/Game/Entities/AreaTrigger/AreaTriggerTemplate.cs @@ -252,7 +252,6 @@ namespace Game.Entities { public AreaTriggerId Id; public AreaTriggerFlags Flags; - public uint ScriptId; public List Actions = new(); @@ -316,6 +315,8 @@ namespace Game.Entities public List PolygonVerticesTarget = new(); public List SplinePoints = new(); public Optional OrbitInfo; + + public uint ScriptId; } public class AreaTriggerSpawn @@ -328,6 +329,8 @@ namespace Game.Entities public byte PhaseUseFlags; public AreaTriggerShapeInfo Shape = new(); + + public uint ScriptId; } public struct AreaTriggerAction diff --git a/sql/updates/world/master/2021_12_04_00_world.sql b/sql/updates/world/master/2021_12_04_00_world.sql new file mode 100644 index 000000000..5dbdc66da --- /dev/null +++ b/sql/updates/world/master/2021_12_04_00_world.sql @@ -0,0 +1,7 @@ +ALTER TABLE `areatrigger` ADD `ScriptName` varchar(64) NOT NULL DEFAULT '' AFTER `ShapeData5`; +ALTER TABLE `areatrigger_create_properties` ADD `ScriptName` varchar(64) NOT NULL DEFAULT '' AFTER `ShapeData5`; + +UPDATE `areatrigger` SET `ScriptName`=COALESCE((SELECT att.`ScriptName` FROM `areatrigger_template` att WHERE att.`Id`=`AreaTriggerId` AND att.`IsServerSide`=`IsServerSide`), ''); +UPDATE `areatrigger_create_properties` SET `ScriptName`=COALESCE((SELECT att.`ScriptName` FROM `areatrigger_template` att WHERE att.`Id`=`AreaTriggerId` AND att.`IsServerSide`=0), ''); + +ALTER TABLE `areatrigger_template` DROP `ScriptName`;