Core/AreaTriggers: Refactor

* Moved IsServerside to custom flags
* Flags moved from areatrigger_template to areatrigger_create_properties
* New field to create custom CreateProperties (IsCustom)
* New field to reference custom areatriggers (IsAreatriggerCustom)
* Moved fields for shape data to areatrigger_create_properties
Port From (https://github.com/TrinityCore/TrinityCore/commit/37eb2e64a6ad075e9866af6feb72bb4fbccb2adc)
This commit is contained in:
hondacrx
2024-02-05 11:48:37 -05:00
parent ad880fc6b5
commit 34253877b0
11 changed files with 334 additions and 355 deletions
+125 -125
View File
@@ -17,18 +17,18 @@ namespace Game.DataStorage
public void LoadAreaTriggerTemplates()
{
uint oldMSTime = Time.GetMSTime();
MultiMap<uint, Vector2> verticesByCreateProperties = new();
MultiMap<uint, Vector2> verticesTargetByCreateProperties = new();
MultiMap<uint, Vector3> splinesByCreateProperties = new();
MultiMap<AreaTriggerId, Vector2> verticesByCreateProperties = new();
MultiMap<AreaTriggerId, Vector2> verticesTargetByCreateProperties = new();
MultiMap<AreaTriggerId, Vector3> splinesByCreateProperties = new();
MultiMap<AreaTriggerId, AreaTriggerAction> actionsByAreaTrigger = new();
// 0 1 2 3 4
SQLResult templateActions = DB.World.Query("SELECT AreaTriggerId, IsServerSide, ActionType, ActionParam, TargetType FROM `areatrigger_template_actions`");
// 0 1 2 3 4
SQLResult templateActions = DB.World.Query("SELECT AreaTriggerId, IsCustom, ActionType, ActionParam, TargetType FROM `areatrigger_template_actions`");
if (!templateActions.IsEmpty())
{
do
{
AreaTriggerId areaTriggerId = new(templateActions.Read<uint>(0), templateActions.Read<byte>(1) == 1);
AreaTriggerId areaTriggerId = new(templateActions.Read<uint>(0), templateActions.Read<bool>(1));
AreaTriggerAction action;
action.Param = templateActions.Read<uint>(3);
@@ -37,13 +37,13 @@ namespace Game.DataStorage
if (action.ActionType >= AreaTriggerActionTypes.Max)
{
Log.outError(LogFilter.Sql, $"Table `areatrigger_template_actions` has invalid ActionType ({action.ActionType}, IsServerSide: {areaTriggerId.IsServerSide}) for AreaTriggerId {areaTriggerId.Id} and Param {action.Param}");
Log.outError(LogFilter.Sql, $"Table `areatrigger_template_actions` has invalid ActionType ({action.ActionType}, for AreaTriggerId ({areaTriggerId.Id},{areaTriggerId.IsCustom}) and Param {action.Param}");
continue;
}
if (action.TargetType >= AreaTriggerActionUserTypes.Max)
{
Log.outError(LogFilter.Sql, $"Table `areatrigger_template_actions` has invalid TargetType ({action.TargetType}, IsServerSide: {areaTriggerId.IsServerSide}) for AreaTriggerId {areaTriggerId} and Param {action.Param}");
Log.outError(LogFilter.Sql, $"Table `areatrigger_template_actions` has invalid TargetType ({action.TargetType} for AreaTriggerId ({areaTriggerId.Id},{areaTriggerId.IsCustom}) and Param {action.Param}");
continue;
}
@@ -52,7 +52,7 @@ namespace Game.DataStorage
{
if (Global.ObjectMgr.GetWorldSafeLoc(action.Param) == null)
{
Log.outError(LogFilter.Sql, $"Table `areatrigger_template_actions` has invalid (Id: {areaTriggerId}, IsServerSide: {areaTriggerId.IsServerSide}) with TargetType=Teleport and Param ({action.Param}) not a valid world safe loc entry");
Log.outError(LogFilter.Sql, $"Table `areatrigger_template_actions` has invalid (Id: {areaTriggerId}, for AreaTriggerId ({areaTriggerId.Id},{areaTriggerId.IsCustom}) with TargetType=Teleport and Param ({action.Param}) not a valid world safe loc entry");
continue;
}
}
@@ -66,20 +66,20 @@ namespace Game.DataStorage
Log.outInfo(LogFilter.ServerLoading, "Loaded 0 AreaTrigger templates actions. DB table `areatrigger_template_actions` is empty.");
}
// 0 1 2 3 4 5
SQLResult vertices = DB.World.Query("SELECT AreaTriggerCreatePropertiesId, Idx, VerticeX, VerticeY, VerticeTargetX, VerticeTargetY FROM `areatrigger_create_properties_polygon_vertex` ORDER BY `AreaTriggerCreatePropertiesId`, `Idx`");
// 0 1 2 3 4 5 6
SQLResult vertices = DB.World.Query("SELECT AreaTriggerCreatePropertiesId, IsCustom, Idx, VerticeX, VerticeY, VerticeTargetX, VerticeTargetY FROM `areatrigger_create_properties_polygon_vertex` ORDER BY `AreaTriggerCreatePropertiesId`, `IsCustom`, `Idx`");
if (!vertices.IsEmpty())
{
do
{
uint areaTriggerCreatePropertiesId = vertices.Read<uint>(0);
AreaTriggerId createPropertiesId = new (vertices.Read<uint>(0), vertices.Read<bool>(1));
verticesByCreateProperties.Add(areaTriggerCreatePropertiesId, new Vector2(vertices.Read<float>(2), vertices.Read<float>(3)));
verticesByCreateProperties.Add(createPropertiesId, new Vector2(vertices.Read<float>(3), vertices.Read<float>(4)));
if (!vertices.IsNull(4) && !vertices.IsNull(5))
verticesTargetByCreateProperties.Add(areaTriggerCreatePropertiesId, new Vector2(vertices.Read<float>(4), vertices.Read<float>(5)));
else if (vertices.IsNull(4) != vertices.IsNull(5))
Log.outError(LogFilter.Sql, $"Table `areatrigger_create_properties_polygon_vertex` has listed invalid target vertices (AreaTriggerCreatePropertiesId: {areaTriggerCreatePropertiesId}, Index: {vertices.Read<uint>(1)}).");
if (!vertices.IsNull(5) && !vertices.IsNull(6))
verticesTargetByCreateProperties.Add(createPropertiesId, new Vector2(vertices.Read<float>(5), vertices.Read<float>(6)));
else if (vertices.IsNull(5) != vertices.IsNull(6))
Log.outError(LogFilter.Sql, $"Table `areatrigger_create_properties_polygon_vertex` has listed invalid target vertices (AreaTriggerCreatePropertiesId: (Id: {createPropertiesId.Id}, IsCustom: {createPropertiesId.IsCustom}), Index: {vertices.Read<uint>(1)}).");
}
while (vertices.NextRow());
}
@@ -88,16 +88,14 @@ namespace Game.DataStorage
Log.outInfo(LogFilter.ServerLoading, "Loaded 0 AreaTrigger polygon polygon vertices. DB table `areatrigger_create_properties_polygon_vertex` is empty.");
}
// 0 1 2 3
SQLResult splines = DB.World.Query("SELECT AreaTriggerCreatePropertiesId, X, Y, Z FROM `areatrigger_create_properties_spline_point` ORDER BY `AreaTriggerCreatePropertiesId`, `Idx`");
// 0 1 2 3 4
SQLResult splines = DB.World.Query("SELECT AreaTriggerCreatePropertiesId, IsCustom, X, Y, Z FROM `areatrigger_create_properties_spline_point` ORDER BY `AreaTriggerCreatePropertiesId`, `IsCustom`, `Idx`");
if (!splines.IsEmpty())
{
do
{
uint areaTriggerCreatePropertiesId = splines.Read<uint>(0);
Vector3 spline = new(splines.Read<float>(1), splines.Read<float>(2), splines.Read<float>(3));
splinesByCreateProperties.Add(areaTriggerCreatePropertiesId, spline);
AreaTriggerId createPropertiesId = new(splines.Read<uint>(0), splines.Read<bool>(1));
splinesByCreateProperties.Add(createPropertiesId, new(splines.Read<float>(2), splines.Read<float>(3), splines.Read<float>(4)));
}
while (splines.NextRow());
}
@@ -106,23 +104,15 @@ namespace Game.DataStorage
Log.outInfo(LogFilter.ServerLoading, "Loaded 0 AreaTrigger splines. DB table `areatrigger_create_properties_spline_point` is empty.");
}
// 0 1 2
SQLResult templates = DB.World.Query("SELECT Id, IsServerSide, Flags FROM `areatrigger_template`");
// 0 1 2
SQLResult templates = DB.World.Query("SELECT Id, IsCustom, Flags FROM `areatrigger_template`");
if (!templates.IsEmpty())
{
do
{
AreaTriggerTemplate areaTriggerTemplate = new();
areaTriggerTemplate.Id = new(templates.Read<uint>(0), templates.Read<byte>(1) == 1);
areaTriggerTemplate.Flags = (AreaTriggerFlags)templates.Read<uint>(2);
if (areaTriggerTemplate.Id.IsServerSide && areaTriggerTemplate.Flags != 0)
{
Log.outError(LogFilter.Sql, $"Table `areatrigger_template` has listed server-side areatrigger (Id: {areaTriggerTemplate.Id.Id}, IsServerSide: {areaTriggerTemplate.Id.IsServerSide}) with none-zero flags");
continue;
}
areaTriggerTemplate.Id = new(templates.Read<uint>(0), templates.Read<bool>(1));
areaTriggerTemplate.Flags = (AreaTriggerFlag)templates.Read<uint>(2);
areaTriggerTemplate.Actions = actionsByAreaTrigger[areaTriggerTemplate.Id];
_areaTriggerTemplateStore[areaTriggerTemplate.Id] = areaTriggerTemplate;
@@ -130,31 +120,36 @@ namespace Game.DataStorage
while (templates.NextRow());
}
// 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 18 19 20
// 0 1 2 3 4
SQLResult areatriggerCreateProperties = DB.World.Query("SELECT Id, IsCustom, AreaTriggerId, IsAreatriggerCustom, Flags, " +
//5 6 7 8 9 10 11 12 13 +
"MoveCurveId, ScaleCurveId, MorphCurveId, FacingCurveId, AnimId, AnimKitId, DecalPropertiesId, TimeToTarget, TimeToTargetScale, " +
//14 15 16 17 18 19 20 21 22 23
"Shape, ShapeData0, ShapeData1, ShapeData2, ShapeData3, ShapeData4, ShapeData5, ShapeData6, ShapeData7, ScriptName FROM `areatrigger_create_properties`");
if (!areatriggerCreateProperties.IsEmpty())
{
do
{
AreaTriggerCreateProperties createProperties = new();
createProperties.Id = areatriggerCreateProperties.Read<uint>(0);
AreaTriggerId createPropertiesId = new(areatriggerCreateProperties.Read<uint>(0), areatriggerCreateProperties.Read<bool>(1));
createProperties.Id = createPropertiesId;
uint areatriggerId = areatriggerCreateProperties.Read<uint>(1);
createProperties.Template = GetAreaTriggerTemplate(new AreaTriggerId(areatriggerId, false));
AreaTriggerId areaTriggerId = new(areatriggerCreateProperties.Read<uint>(2), areatriggerCreateProperties.Read<bool>(3));
createProperties.Template = GetAreaTriggerTemplate(areaTriggerId);
AreaTriggerTypes shape = (AreaTriggerTypes)areatriggerCreateProperties.Read<byte>(11);
createProperties.Flags = (AreaTriggerCreatePropertiesFlag)areatriggerCreateProperties.Read<uint>(4);
if (areatriggerId != 0 && createProperties.Template == null)
AreaTriggerShapeType shape = (AreaTriggerShapeType)areatriggerCreateProperties.Read<byte>(14);
if (areaTriggerId.Id != 0 && createProperties.Template == null)
{
Log.outError(LogFilter.Sql, $"Table `areatrigger_create_properties` reference invalid AreaTriggerId {areatriggerId} for AreaTriggerCreatePropertiesId {createProperties.Id}");
Log.outError(LogFilter.Sql, $"Table `areatrigger_create_properties` references invalid AreaTrigger (Id: {areaTriggerId.Id}, IsCustom: {areaTriggerId.IsCustom}) for AreaTriggerCreatePropertiesId (Id: {createPropertiesId.Id}, IsCustom: {createPropertiesId.IsCustom})");
continue;
}
if (shape >= AreaTriggerTypes.Max)
if (shape >= AreaTriggerShapeType.Max)
{
Log.outError(LogFilter.Sql, $"Table `areatrigger_create_properties` has listed areatrigger create properties {createProperties.Id} with invalid shape {shape}.");
Log.outError(LogFilter.Sql, $"Table `areatrigger_create_properties` has listed AreaTriggerCreatePropertiesId (Id: {createPropertiesId.Id}, IsCustom: {createPropertiesId.IsCustom}) with invalid shape {shape}.");
continue;
}
@@ -162,35 +157,35 @@ namespace Game.DataStorage
{
if (value != 0 && !CliDB.CurveStorage.ContainsKey(value))
{
Log.outError(LogFilter.Sql, $"Table `areatrigger_create_properties` has listed areatrigger (AreaTriggerCreatePropertiesId: {createProperties.Id}, Id: {areatriggerId}) with invalid Curve ({value}), set to 0!");
Log.outError(LogFilter.Sql, $"Table `areatrigger_create_properties` has listed AreaTrigger (Id: {areaTriggerId.Id}, IsCustom: {areaTriggerId.IsCustom}) for AreaTriggerCreatePropertiesId (Id: {createPropertiesId.Id}, IsCustom: {createPropertiesId.IsCustom}) with invalid Curve ({value}), set to 0!");
return 0;
}
return value;
}
createProperties.MoveCurveId = ValidateAndSetCurve(areatriggerCreateProperties.Read<uint>(2));
createProperties.ScaleCurveId = ValidateAndSetCurve(areatriggerCreateProperties.Read<uint>(3));
createProperties.MorphCurveId = ValidateAndSetCurve(areatriggerCreateProperties.Read<uint>(4));
createProperties.FacingCurveId = ValidateAndSetCurve(areatriggerCreateProperties.Read<uint>(5));
createProperties.MoveCurveId = ValidateAndSetCurve(areatriggerCreateProperties.Read<uint>(5));
createProperties.ScaleCurveId = ValidateAndSetCurve(areatriggerCreateProperties.Read<uint>(6));
createProperties.MorphCurveId = ValidateAndSetCurve(areatriggerCreateProperties.Read<uint>(7));
createProperties.FacingCurveId = ValidateAndSetCurve(areatriggerCreateProperties.Read<uint>(8));
createProperties.AnimId = areatriggerCreateProperties.Read<int>(6);
createProperties.AnimKitId = areatriggerCreateProperties.Read<uint>(7);
createProperties.DecalPropertiesId = areatriggerCreateProperties.Read<uint>(8);
createProperties.AnimId = areatriggerCreateProperties.Read<int>(9);
createProperties.AnimKitId = areatriggerCreateProperties.Read<uint>(10);
createProperties.DecalPropertiesId = areatriggerCreateProperties.Read<uint>(11);
createProperties.TimeToTarget = areatriggerCreateProperties.Read<uint>(9);
createProperties.TimeToTargetScale = areatriggerCreateProperties.Read<uint>(10);
createProperties.TimeToTarget = areatriggerCreateProperties.Read<uint>(12);
createProperties.TimeToTargetScale = areatriggerCreateProperties.Read<uint>(13);
createProperties.Shape.TriggerType = shape;
unsafe
{
for (byte i = 0; i < SharedConst.MaxAreatriggerEntityData; ++i)
createProperties.Shape.DefaultDatas.Data[i] = areatriggerCreateProperties.Read<float>(12 + i);
createProperties.Shape.DefaultDatas.Data[i] = areatriggerCreateProperties.Read<float>(15 + i);
}
createProperties.ScriptId = Global.ObjectMgr.GetScriptId(areatriggerCreateProperties.Read<string>(20));
createProperties.ScriptId = Global.ObjectMgr.GetScriptId(areatriggerCreateProperties.Read<string>(23));
if (shape == AreaTriggerTypes.Polygon)
if (shape == AreaTriggerShapeType.Polygon)
{
if (createProperties.Shape.PolygonDatas.Height <= 0.0f)
{
@@ -200,12 +195,12 @@ namespace Game.DataStorage
}
}
createProperties.PolygonVertices = verticesByCreateProperties[createProperties.Id];
createProperties.PolygonVerticesTarget = verticesTargetByCreateProperties[createProperties.Id];
if (!createProperties.PolygonVerticesTarget.Empty() && createProperties.PolygonVertices.Count != createProperties.PolygonVerticesTarget.Count)
createProperties.Shape.PolygonVertices = verticesByCreateProperties[createProperties.Id];
createProperties.Shape.PolygonVerticesTarget = verticesTargetByCreateProperties[createProperties.Id];
if (!createProperties.Shape.PolygonVerticesTarget.Empty() && createProperties.Shape.PolygonVertices.Count != createProperties.Shape.PolygonVerticesTarget.Count)
{
Log.outError(LogFilter.Sql, $"Table `areatrigger_create_properties_polygon_vertex` has invalid target vertices, either all or none vertices must have a corresponding target vertex (AreaTriggerCreatePropertiesId: {createProperties.Id}).");
createProperties.PolygonVerticesTarget.Clear();
Log.outError(LogFilter.Sql, $"Table `areatrigger_create_properties_polygon_vertex` has invalid target vertices, either all or none vertices must have a corresponding target vertex (AreaTriggerCreatePropertiesId: (Id: {createPropertiesId.Id}, IsCustom: {createPropertiesId.IsCustom})).");
createProperties.Shape.PolygonVerticesTarget.Clear();
}
createProperties.SplinePoints = splinesByCreateProperties[createProperties.Id];
@@ -219,54 +214,44 @@ namespace Game.DataStorage
Log.outInfo(LogFilter.ServerLoading, "Loaded 0 AreaTrigger create properties. DB table `areatrigger_create_properties` is empty.");
}
// 0 1 2 3 4 5 6 7
SQLResult circularMovementInfos = DB.World.Query("SELECT AreaTriggerCreatePropertiesId, StartDelay, CircleRadius, BlendFromRadius, InitialAngle, ZOffset, CounterClockwise, CanLoop FROM `areatrigger_create_properties_orbit`");
// 0 1 2 3 4 5 6 7 8
SQLResult circularMovementInfos = DB.World.Query("SELECT AreaTriggerCreatePropertiesId, IsCustom, StartDelay, CircleRadius, BlendFromRadius, InitialAngle, ZOffset, CounterClockwise, CanLoop FROM `areatrigger_create_properties_orbit`");
if (!circularMovementInfos.IsEmpty())
{
do
{
uint areaTriggerCreatePropertiesId = circularMovementInfos.Read<uint>(0);
AreaTriggerId createPropertiesId = new(circularMovementInfos.Read<uint>(0), circularMovementInfos.Read<bool>(1));
var createProperties = _areaTriggerCreateProperties.LookupByKey(areaTriggerCreatePropertiesId);
var createProperties = _areaTriggerCreateProperties.LookupByKey(createPropertiesId);
if (createProperties == null)
{
Log.outError(LogFilter.Sql, $"Table `areatrigger_create_properties_orbit` reference invalid AreaTriggerCreatePropertiesId {areaTriggerCreatePropertiesId}");
Log.outError(LogFilter.Sql, $"Table `areatrigger_create_properties_orbit` reference invalid AreaTriggerCreatePropertiesId: (Id: {createPropertiesId.Id}, IsCustom: {createPropertiesId.IsCustom})");
continue;
}
AreaTriggerOrbitInfo orbitInfo = new();
orbitInfo.StartDelay = circularMovementInfos.Read<uint>(1);
orbitInfo.Radius = circularMovementInfos.Read<float>(2);
if (!float.IsFinite(orbitInfo.Radius))
orbitInfo.StartDelay = circularMovementInfos.Read<uint>(2);
float ValidateAndSetFloat(float value)
{
Log.outError(LogFilter.Sql, $"Table `areatrigger_create_properties_orbit` has listed areatrigger (AreaTriggerCreatePropertiesId: {areaTriggerCreatePropertiesId}) with invalid Radius ({orbitInfo.Radius}), set to 0!");
orbitInfo.Radius = 0.0f;
if (!float.IsFinite(value))
{
Log.outError(LogFilter.Sql, $"Table `areatrigger_create_properties_orbit` has listed areatrigger (AreaTriggerCreatePropertiesId: {createPropertiesId.Id}, IsCustom: {createPropertiesId.IsCustom}) with invalid Float ({value}), set to 0!");
return 0;
}
return value;
}
orbitInfo.BlendFromRadius = circularMovementInfos.Read<float>(3);
if (!float.IsFinite(orbitInfo.BlendFromRadius))
{
Log.outError(LogFilter.Sql, $"Table `areatrigger_create_properties_orbit` has listed areatrigger (AreaTriggerCreatePropertiesId: {areaTriggerCreatePropertiesId}) with invalid BlendFromRadius ({orbitInfo.BlendFromRadius}), set to 0!");
orbitInfo.BlendFromRadius = 0.0f;
}
orbitInfo.InitialAngle = circularMovementInfos.Read<float>(4);
if (!float.IsFinite(orbitInfo.InitialAngle))
{
Log.outError(LogFilter.Sql, $"Table `areatrigger_create_properties_orbit` has listed areatrigger (AreaTriggerCreatePropertiesId: {areaTriggerCreatePropertiesId}) with invalid InitialAngle ({orbitInfo.InitialAngle}), set to 0!");
orbitInfo.InitialAngle = 0.0f;
}
orbitInfo.Radius = ValidateAndSetFloat(circularMovementInfos.Read<float>(3));
orbitInfo.BlendFromRadius = circularMovementInfos.Read<float>(4);
orbitInfo.InitialAngle = circularMovementInfos.Read<float>(5);
orbitInfo.ZOffset = circularMovementInfos.Read<float>(6);
orbitInfo.ZOffset = circularMovementInfos.Read<float>(5);
if (!float.IsFinite(orbitInfo.ZOffset))
{
Log.outError(LogFilter.Sql, $"Table `spell_areatrigger_circular` has listed areatrigger (MiscId: {areaTriggerCreatePropertiesId}) with invalid ZOffset ({orbitInfo.ZOffset}), set to 0!");
orbitInfo.ZOffset = 0.0f;
}
orbitInfo.CounterClockwise = circularMovementInfos.Read<bool>(6);
orbitInfo.CanLoop = circularMovementInfos.Read<bool>(7);
orbitInfo.CounterClockwise = circularMovementInfos.Read<bool>(7);
orbitInfo.CanLoop = circularMovementInfos.Read<bool>(8);
createProperties.OrbitInfo = orbitInfo;
}
@@ -289,34 +274,56 @@ namespace Game.DataStorage
uint oldMSTime = Time.GetMSTime();
// Load area trigger positions (to put them on the server)
// 0 1 2 3 4 5 6 7 8 9 10 11
SQLResult result = DB.World.Query("SELECT SpawnId, AreaTriggerId, IsServerSide, MapId, SpawnDifficulties, PosX, PosY, PosZ, Orientation, PhaseUseFlags, PhaseId, PhaseGroup, " +
//12 13 14 15 16 17 18 19 20 21 22
"Shape, ShapeData0, ShapeData1, ShapeData2, ShapeData3, ShapeData4, ShapeData5, ShapeData6, ShapeData7, SpellForVisuals, ScriptName FROM `areatrigger`");
// 0 1 2 3 4 5 6 7 8 9 10 11 12 13
SQLResult result = DB.World.Query("SELECT SpawnId, AreaTriggerCreatePropertiesId, IsCustom, MapId, SpawnDifficulties, PosX, PosY, PosZ, Orientation, PhaseUseFlags, PhaseId, PhaseGroup, SpellForVisuals, ScriptName FROM `areatrigger`");
if (!result.IsEmpty())
{
do
{
ulong spawnId = result.Read<ulong>(0);
AreaTriggerId areaTriggerId = new(result.Read<uint>(1), result.Read<byte>(2) == 1);
AreaTriggerId createPropertiesId = new(result.Read<uint>(1), result.Read<bool>(2));
WorldLocation location = new(result.Read<uint>(3), result.Read<float>(5), result.Read<float>(6), result.Read<float>(7), result.Read<float>(8));
AreaTriggerTypes shape = (AreaTriggerTypes)result.Read<byte>(12);
if (GetAreaTriggerTemplate(areaTriggerId) == null)
AreaTriggerCreateProperties createProperties = GetAreaTriggerCreateProperties(createPropertiesId);
if (createProperties == null)
{
Log.outError(LogFilter.Sql, $"Table `areatrigger` has listed areatrigger that doesn't exist: Id: {areaTriggerId.Id}, IsServerSide: {areaTriggerId.IsServerSide} for SpawnId {spawnId}");
Log.outError(LogFilter.Sql, $"Table `areatrigger` has listed AreaTriggerCreatePropertiesId (Id: {createPropertiesId.Id}, IsCustom: {createPropertiesId.IsCustom}) that doesn't exist for SpawnId {spawnId}");
continue;
}
if (createProperties.Flags != AreaTriggerCreatePropertiesFlag.None)
{
Log.outError(LogFilter.Sql, $"Table `areatrigger` has listed AreaTriggerCreatePropertiesId (Id: {createPropertiesId.Id}, IsCustom: {createPropertiesId.IsCustom}) with non - zero flags");
continue;
}
if (createProperties.ScaleCurveId != 0 || createProperties.MorphCurveId != 0 || createProperties.FacingCurveId != 0 || createProperties.MoveCurveId != 0)
{
Log.outError(LogFilter.Sql, $"Table `areatrigger` has listed AreaTriggerCreatePropertiesId (Id: {createPropertiesId.Id}, IsCustom: {createPropertiesId.IsCustom}) with curve values");
continue;
}
if (createProperties.TimeToTarget != 0 || createProperties.TimeToTargetScale != 0 || createProperties.FacingCurveId != 0 || createProperties.MoveCurveId != 0)
{
Log.outError(LogFilter.Sql, $"Table `areatrigger` has listed AreaTriggerCreatePropertiesId (Id: {createPropertiesId.Id}, IsCustom: {createPropertiesId.IsCustom}) with time to target values");
continue;
}
if (createProperties.OrbitInfo != null)
{
Log.outError(LogFilter.Sql, $"Table `areatrigger` has listed AreaTriggerCreatePropertiesId (Id: {createPropertiesId.Id}, IsCustom: {createPropertiesId.IsCustom}) with orbit info");
continue;
}
if (createProperties.HasSplines())
{
Log.outError(LogFilter.Sql, $"Table `areatrigger` has listed AreaTriggerCreatePropertiesId (Id: {createPropertiesId.Id}, IsCustom: {createPropertiesId.IsCustom}) with splines");
continue;
}
if (!GridDefines.IsValidMapCoord(location))
{
Log.outError(LogFilter.Sql, $"Table `areatrigger` has listed an invalid position: SpawnId: {spawnId}, MapId: {location.GetMapId()}, Position: {location}");
continue;
}
if (shape >= AreaTriggerTypes.Max)
{
Log.outError(LogFilter.Sql, $"Table `areatrigger` has listed areatrigger SpawnId: {spawnId} with invalid shape {shape}.");
Log.outError(LogFilter.Sql, $"Table `areatrigger` has listed an invalid position: SpawnId: {spawnId}, MapId {location.GetMapId()}, Position {location}");
continue;
}
@@ -330,31 +337,24 @@ namespace Game.DataStorage
AreaTriggerSpawn spawn = new();
spawn.SpawnId = spawnId;
spawn.MapId = location.GetMapId();
spawn.TriggerId = areaTriggerId;
spawn.Id = createPropertiesId;
spawn.SpawnPoint = new Position(location);
spawn.PhaseUseFlags = (PhaseUseFlagsValues)result.Read<byte>(9);
spawn.PhaseId = result.Read<uint>(10);
spawn.PhaseGroup = result.Read<uint>(11);
spawn.Shape.TriggerType = shape;
unsafe
if (!result.IsNull(12))
{
for (var i = 0; i < SharedConst.MaxAreatriggerEntityData; ++i)
spawn.Shape.DefaultDatas.Data[i] = result.Read<float>(13 + i);
}
if (!result.IsNull(21))
{
spawn.SpellForVisuals = result.Read<uint>(21);
spawn.SpellForVisuals = result.Read<uint>(12);
if (!Global.SpellMgr.HasSpellInfo(spawn.SpellForVisuals.Value, Difficulty.None))
{
Log.outError(LogFilter.Sql, $"Table `areatrigger` has listed areatrigger SpawnId: {spawnId} with invalid SpellForVisual {spawn.SpellForVisuals}, set to none.");
Log.outError(LogFilter.Sql, $"Table `areatrigger` has areatrigger (GUID: {spawnId}) with invalid SpellForVisual {spawn.SpellForVisuals}, set to none.");
spawn.SpellForVisuals = null;
}
}
spawn.ScriptId = Global.ObjectMgr.GetScriptId(result.Read<string>(22));
spawn.ScriptId = Global.ObjectMgr.GetScriptId(result.Read<string>(13));
spawn.spawnGroupData = Global.ObjectMgr.GetLegacySpawnGroup();
// Add the trigger to a map::cell map, which is later used by GridLoader to query
@@ -384,9 +384,9 @@ namespace Game.DataStorage
return _areaTriggerTemplateStore.LookupByKey(areaTriggerId);
}
public AreaTriggerCreateProperties GetAreaTriggerCreateProperties(uint spellMiscValue)
public AreaTriggerCreateProperties GetAreaTriggerCreateProperties(AreaTriggerId areaTriggerCreatePropertiesId)
{
return _areaTriggerCreateProperties.LookupByKey(spellMiscValue);
return _areaTriggerCreateProperties.LookupByKey(areaTriggerCreatePropertiesId);
}
public SortedSet<ulong> GetAreaTriggersForMapAndCell(uint mapId, Difficulty difficulty, uint cellId)
@@ -406,6 +406,6 @@ namespace Game.DataStorage
Dictionary<(uint, Difficulty), Dictionary<uint, SortedSet<ulong>>> _areaTriggerSpawnsByLocation = new();
Dictionary<ulong, AreaTriggerSpawn> _areaTriggerSpawnsBySpawnId = new();
Dictionary<AreaTriggerId, AreaTriggerTemplate> _areaTriggerTemplateStore = new();
Dictionary<uint, AreaTriggerCreateProperties> _areaTriggerCreateProperties = new();
Dictionary<AreaTriggerId, AreaTriggerCreateProperties> _areaTriggerCreateProperties = new();
}
}