diff --git a/Source/Framework/Constants/AreaTriggerConst.cs b/Source/Framework/Constants/AreaTriggerConst.cs index 0b7acf324..42721e249 100644 --- a/Source/Framework/Constants/AreaTriggerConst.cs +++ b/Source/Framework/Constants/AreaTriggerConst.cs @@ -3,23 +3,13 @@ namespace Framework.Constants { - public enum AreaTriggerFlags + public enum AreaTriggerFlag { - HasAbsoluteOrientation = 0x01, - HasDynamicShape = 0x02, // Implemented For Spheres - HasAttached = 0x04, - HasFaceMovementDir = 0x08, - HasFollowsTerrain = 0x010, // Nyi - Unk1 = 0x020, - HasTargetRollPitchYaw = 0x040, // Nyi - HasAnimID = 0x080, - Unk3 = 0x100, - HasAnimKitID = 0x200, - HasCircularMovement = 0x400, - Unk5 = 0x800 + None = 0x00, + IsServerSide = 0x01 } - public enum AreaTriggerTypes + public enum AreaTriggerShapeType { Sphere = 0, Box = 1, @@ -49,4 +39,21 @@ namespace Framework.Constants Caster = 5, Max = 6 } + + public enum AreaTriggerCreatePropertiesFlag + { + None = 0x00, + HasAbsoluteOrientation = 0x01, + HasDynamicShape = 0x02, + HasAttached = 0x04, + HasFaceMovementDir = 0x08, + HasFollowsTerrain = 0x10, // NYI + Unk1 = 0x20, + HasTargetRollPitchYaw = 0x40, // NYI + HasAnimId = 0x80, // DEPRECATED + Unk3 = 0x100, + HasAnimKitId = 0x200, // DEPRECATED + HasCircularMovement = 0x400, // DEPRECATED + Unk5 = 0x800, + } } diff --git a/Source/Framework/Constants/Language.cs b/Source/Framework/Constants/Language.cs index 9effb842b..f33ad2c58 100644 --- a/Source/Framework/Constants/Language.cs +++ b/Source/Framework/Constants/Language.cs @@ -1039,7 +1039,9 @@ namespace Framework.Constants CmdparserCurrencyNoExist = 1516, CmdparserQuestNoExist = 1517, - // 1516-1998 - Free + // 1516-1996 - Free + DebugAreatriggerEntityEntered = 1997, + DebugAreatriggerEntityLeft = 1998, DebugAreatriggerLeft = 1999, // Ticket Strings 2000-2030 CommandTicketnew = 2000, // 3.3.5 Reserved diff --git a/Source/Framework/Constants/SmartAIConst.cs b/Source/Framework/Constants/SmartAIConst.cs index d1fadf30c..efc2af10e 100644 --- a/Source/Framework/Constants/SmartAIConst.cs +++ b/Source/Framework/Constants/SmartAIConst.cs @@ -19,7 +19,7 @@ namespace Framework.Constants TimedActionlist = 9, Scene = 10, AreaTriggerEntity = 11, - AreaTriggerEntityServerside = 12, + AreaTriggerEntityCustom = 12, Max = 11 } diff --git a/Source/Game/AI/SmartScripts/SmartAIManager.cs b/Source/Game/AI/SmartScripts/SmartAIManager.cs index 73c177612..b6240168b 100644 --- a/Source/Game/AI/SmartScripts/SmartAIManager.cs +++ b/Source/Game/AI/SmartScripts/SmartAIManager.cs @@ -127,11 +127,11 @@ namespace Game.AI } break; } - case SmartScriptType.AreaTriggerEntityServerside: + case SmartScriptType.AreaTriggerEntityCustom: { if (Global.AreaTriggerDataStorage.GetAreaTriggerTemplate(new AreaTriggerId((uint)temp.EntryOrGuid, true)) == null) { - Log.outError(LogFilter.Sql, $"SmartAIMgr.LoadFromDB: AreaTrigger entry ({temp.EntryOrGuid} IsServerSide true) does not exist, skipped loading."); + Log.outError(LogFilter.Sql, $"SmartAIMgr.LoadFromDB: AreaTrigger entry ({temp.EntryOrGuid} IsCustom true) does not exist, skipped loading."); continue; } break; @@ -1123,9 +1123,9 @@ namespace Game.AI } case SmartEvents.AreatriggerOntrigger: { - if (e.Event.areatrigger.id != 0 && (e.GetScriptType() == SmartScriptType.AreaTriggerEntity || e.GetScriptType() == SmartScriptType.AreaTriggerEntityServerside)) + if (e.Event.areatrigger.id != 0 && (e.GetScriptType() == SmartScriptType.AreaTriggerEntity || e.GetScriptType() == SmartScriptType.AreaTriggerEntityCustom)) { - Log.outError(LogFilter.Sql, $"SmartAIMgr: Entry {e.EntryOrGuid} SourceType {e.GetScriptType()} Event {e.EventId} Action {e.GetActionType()} areatrigger param not supported for SMART_SCRIPT_TYPE_AREATRIGGER_ENTITY and SMART_SCRIPT_TYPE_AREATRIGGER_ENTITY_SERVERSIDE, skipped."); + Log.outError(LogFilter.Sql, $"SmartAIMgr: Entry {e.EntryOrGuid} SourceType {e.GetScriptType()} Event {e.EventId} Action {e.GetActionType()} areatrigger param not supported for SMART_SCRIPT_TYPE_AREATRIGGER_ENTITY and SMART_SCRIPT_TYPE_AREATRIGGER_ENTITY_CUSTOM, skipped."); return false; } @@ -2351,7 +2351,7 @@ namespace Game.AI SmartScriptType.TimedActionlist => SmartScriptTypeMaskId.TimedActionlist, SmartScriptType.Scene => SmartScriptTypeMaskId.Scene, SmartScriptType.AreaTriggerEntity => SmartScriptTypeMaskId.AreatrigggerEntity, - SmartScriptType.AreaTriggerEntityServerside => SmartScriptTypeMaskId.AreatrigggerEntity, + SmartScriptType.AreaTriggerEntityCustom => SmartScriptTypeMaskId.AreatrigggerEntity, _ => 0, }; diff --git a/Source/Game/AI/SmartScripts/SmartScript.cs b/Source/Game/AI/SmartScripts/SmartScript.cs index 38c41adc2..47d71c208 100644 --- a/Source/Game/AI/SmartScripts/SmartScript.cs +++ b/Source/Game/AI/SmartScripts/SmartScript.cs @@ -2240,7 +2240,7 @@ namespace Game.AI Log.outDebug(LogFilter.ScriptsAi, $"SmartScript::ProcessAction:: SMART_ACTION_PLAY_ANIMKIT: target: {target.GetName()} ({target.GetGUID()}), AnimKit: {e.Action.animKit.animKit}, Type: {e.Action.animKit.type}"); } - else if(IsGameObject(target)) + else if (IsGameObject(target)) { switch (e.Action.animKit.type) { @@ -3764,9 +3764,7 @@ namespace Game.AI public void OnUpdate(uint diff) { - if ((_scriptType == SmartScriptType.Creature || _scriptType == SmartScriptType.GameObject - || _scriptType == SmartScriptType.AreaTriggerEntity || _scriptType == SmartScriptType.AreaTriggerEntityServerside) - && GetBaseObject() == null) + if ((_scriptType == SmartScriptType.Creature || _scriptType == SmartScriptType.GameObject || _scriptType == SmartScriptType.AreaTriggerEntity || _scriptType == SmartScriptType.AreaTriggerEntityCustom) && GetBaseObject() == null) return; if (_me != null && _me.IsInEvadeMode()) @@ -3930,7 +3928,7 @@ namespace Game.AI FillScript(e, _go, null, null, null, 0); break; case SmartScriptType.AreaTriggerEntity: - case SmartScriptType.AreaTriggerEntityServerside: + case SmartScriptType.AreaTriggerEntityCustom: e = Global.SmartAIMgr.GetScript((int)_areaTrigger.GetEntry(), _scriptType); FillScript(e, _areaTrigger, null, null, null, 0); break; @@ -4041,8 +4039,8 @@ namespace Game.AI break; case TypeId.AreaTrigger: _areaTrigger = obj.ToAreaTrigger(); - _scriptType = _areaTrigger.IsServerSide() ? SmartScriptType.AreaTriggerEntityServerside : SmartScriptType.AreaTriggerEntity; - Log.outDebug(LogFilter.ScriptsAi, $"SmartScript.OnInitialize: source is AreaTrigger {_areaTrigger.GetEntry()}, IsServerSide {_areaTrigger.IsServerSide()}"); + _scriptType = _areaTrigger.IsCustom() ? SmartScriptType.AreaTriggerEntityCustom : SmartScriptType.AreaTriggerEntity; + Log.outDebug(LogFilter.ScriptsAi, $"SmartScript.OnInitialize: source is AreaTrigger {_areaTrigger.GetEntry()}, IsCustom {_areaTrigger.IsCustom()}"); break; default: Log.outError(LogFilter.Scripts, "SmartScript.OnInitialize: Unhandled TypeID !WARNING!"); @@ -4104,7 +4102,7 @@ namespace Game.AI Cell.VisitGridObjects(_me, searcher, range); return searcher.GetTarget(); } - + void DoFindFriendlyCC(List creatures, float range) { if (_me == null) @@ -4204,7 +4202,7 @@ namespace Game.AI } public bool HasAnyEventWithFlag(SmartEventFlags flag) { return _allEventFlags.HasAnyFlag(flag); } - + public bool IsUnit(WorldObject obj) { return obj != null && (obj.IsTypeId(TypeId.Unit) || obj.IsTypeId(TypeId.Player)); } public bool IsPlayer(WorldObject obj) { return obj != null && obj.IsTypeId(TypeId.Player); } diff --git a/Source/Game/DataStorage/AreaTriggerDataStorage.cs b/Source/Game/DataStorage/AreaTriggerDataStorage.cs index 49cfc2554..0596ca834 100644 --- a/Source/Game/DataStorage/AreaTriggerDataStorage.cs +++ b/Source/Game/DataStorage/AreaTriggerDataStorage.cs @@ -17,18 +17,18 @@ namespace Game.DataStorage public void LoadAreaTriggerTemplates() { uint oldMSTime = Time.GetMSTime(); - MultiMap verticesByCreateProperties = new(); - MultiMap verticesTargetByCreateProperties = new(); - MultiMap splinesByCreateProperties = new(); + MultiMap verticesByCreateProperties = new(); + MultiMap verticesTargetByCreateProperties = new(); + MultiMap splinesByCreateProperties = new(); MultiMap 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(0), templateActions.Read(1) == 1); + AreaTriggerId areaTriggerId = new(templateActions.Read(0), templateActions.Read(1)); AreaTriggerAction action; action.Param = templateActions.Read(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(0); + AreaTriggerId createPropertiesId = new (vertices.Read(0), vertices.Read(1)); - verticesByCreateProperties.Add(areaTriggerCreatePropertiesId, new Vector2(vertices.Read(2), vertices.Read(3))); + verticesByCreateProperties.Add(createPropertiesId, new Vector2(vertices.Read(3), vertices.Read(4))); - if (!vertices.IsNull(4) && !vertices.IsNull(5)) - verticesTargetByCreateProperties.Add(areaTriggerCreatePropertiesId, new Vector2(vertices.Read(4), vertices.Read(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(1)})."); + if (!vertices.IsNull(5) && !vertices.IsNull(6)) + verticesTargetByCreateProperties.Add(createPropertiesId, new Vector2(vertices.Read(5), vertices.Read(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(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(0); - Vector3 spline = new(splines.Read(1), splines.Read(2), splines.Read(3)); - - splinesByCreateProperties.Add(areaTriggerCreatePropertiesId, spline); + AreaTriggerId createPropertiesId = new(splines.Read(0), splines.Read(1)); + splinesByCreateProperties.Add(createPropertiesId, new(splines.Read(2), splines.Read(3), splines.Read(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(0), templates.Read(1) == 1); - - areaTriggerTemplate.Flags = (AreaTriggerFlags)templates.Read(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(0), templates.Read(1)); + areaTriggerTemplate.Flags = (AreaTriggerFlag)templates.Read(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(0); + AreaTriggerId createPropertiesId = new(areatriggerCreateProperties.Read(0), areatriggerCreateProperties.Read(1)); + createProperties.Id = createPropertiesId; - uint areatriggerId = areatriggerCreateProperties.Read(1); - createProperties.Template = GetAreaTriggerTemplate(new AreaTriggerId(areatriggerId, false)); + AreaTriggerId areaTriggerId = new(areatriggerCreateProperties.Read(2), areatriggerCreateProperties.Read(3)); + createProperties.Template = GetAreaTriggerTemplate(areaTriggerId); - AreaTriggerTypes shape = (AreaTriggerTypes)areatriggerCreateProperties.Read(11); + createProperties.Flags = (AreaTriggerCreatePropertiesFlag)areatriggerCreateProperties.Read(4); - if (areatriggerId != 0 && createProperties.Template == null) + AreaTriggerShapeType shape = (AreaTriggerShapeType)areatriggerCreateProperties.Read(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(2)); - createProperties.ScaleCurveId = ValidateAndSetCurve(areatriggerCreateProperties.Read(3)); - createProperties.MorphCurveId = ValidateAndSetCurve(areatriggerCreateProperties.Read(4)); - createProperties.FacingCurveId = ValidateAndSetCurve(areatriggerCreateProperties.Read(5)); + createProperties.MoveCurveId = ValidateAndSetCurve(areatriggerCreateProperties.Read(5)); + createProperties.ScaleCurveId = ValidateAndSetCurve(areatriggerCreateProperties.Read(6)); + createProperties.MorphCurveId = ValidateAndSetCurve(areatriggerCreateProperties.Read(7)); + createProperties.FacingCurveId = ValidateAndSetCurve(areatriggerCreateProperties.Read(8)); - createProperties.AnimId = areatriggerCreateProperties.Read(6); - createProperties.AnimKitId = areatriggerCreateProperties.Read(7); - createProperties.DecalPropertiesId = areatriggerCreateProperties.Read(8); + createProperties.AnimId = areatriggerCreateProperties.Read(9); + createProperties.AnimKitId = areatriggerCreateProperties.Read(10); + createProperties.DecalPropertiesId = areatriggerCreateProperties.Read(11); - createProperties.TimeToTarget = areatriggerCreateProperties.Read(9); - createProperties.TimeToTargetScale = areatriggerCreateProperties.Read(10); + createProperties.TimeToTarget = areatriggerCreateProperties.Read(12); + createProperties.TimeToTargetScale = areatriggerCreateProperties.Read(13); createProperties.Shape.TriggerType = shape; unsafe { for (byte i = 0; i < SharedConst.MaxAreatriggerEntityData; ++i) - createProperties.Shape.DefaultDatas.Data[i] = areatriggerCreateProperties.Read(12 + i); + createProperties.Shape.DefaultDatas.Data[i] = areatriggerCreateProperties.Read(15 + i); } - createProperties.ScriptId = Global.ObjectMgr.GetScriptId(areatriggerCreateProperties.Read(20)); + createProperties.ScriptId = Global.ObjectMgr.GetScriptId(areatriggerCreateProperties.Read(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(0); + AreaTriggerId createPropertiesId = new(circularMovementInfos.Read(0), circularMovementInfos.Read(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(1); - orbitInfo.Radius = circularMovementInfos.Read(2); - if (!float.IsFinite(orbitInfo.Radius)) + orbitInfo.StartDelay = circularMovementInfos.Read(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(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(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(3)); + orbitInfo.BlendFromRadius = circularMovementInfos.Read(4); + orbitInfo.InitialAngle = circularMovementInfos.Read(5); + orbitInfo.ZOffset = circularMovementInfos.Read(6); - orbitInfo.ZOffset = circularMovementInfos.Read(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(6); - orbitInfo.CanLoop = circularMovementInfos.Read(7); + orbitInfo.CounterClockwise = circularMovementInfos.Read(7); + orbitInfo.CanLoop = circularMovementInfos.Read(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(0); - AreaTriggerId areaTriggerId = new(result.Read(1), result.Read(2) == 1); + AreaTriggerId createPropertiesId = new(result.Read(1), result.Read(2)); WorldLocation location = new(result.Read(3), result.Read(5), result.Read(6), result.Read(7), result.Read(8)); - AreaTriggerTypes shape = (AreaTriggerTypes)result.Read(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(9); spawn.PhaseId = result.Read(10); spawn.PhaseGroup = result.Read(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(13 + i); - } - - if (!result.IsNull(21)) - { - spawn.SpellForVisuals = result.Read(21); + spawn.SpellForVisuals = result.Read(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(22)); + spawn.ScriptId = Global.ObjectMgr.GetScriptId(result.Read(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 GetAreaTriggersForMapAndCell(uint mapId, Difficulty difficulty, uint cellId) @@ -406,6 +406,6 @@ namespace Game.DataStorage Dictionary<(uint, Difficulty), Dictionary>> _areaTriggerSpawnsByLocation = new(); Dictionary _areaTriggerSpawnsBySpawnId = new(); Dictionary _areaTriggerTemplateStore = new(); - Dictionary _areaTriggerCreateProperties = new(); + Dictionary _areaTriggerCreateProperties = new(); } } diff --git a/Source/Game/Entities/AreaTrigger/AreaTrigger.cs b/Source/Game/Entities/AreaTrigger/AreaTrigger.cs index 6d3b502fd..c1cb2e27d 100644 --- a/Source/Game/Entities/AreaTrigger/AreaTrigger.cs +++ b/Source/Game/Entities/AreaTrigger/AreaTrigger.cs @@ -69,31 +69,31 @@ namespace Game.Entities HandleUnitEnterExit(new List()); base.RemoveFromWorld(); - if (_spawnId != 0) + if (IsStaticSpawn()) GetMap().GetAreaTriggerBySpawnIdStore().Remove(_spawnId, this); GetMap().GetObjectsStore().Remove(GetGUID()); } } - bool Create(uint areaTriggerCreatePropertiesId, Unit caster, Unit target, SpellInfo spellInfo, Position pos, int duration, SpellCastVisualField spellVisual, Spell spell, AuraEffect aurEff) + bool Create(AreaTriggerId areaTriggerCreatePropertiesId, Map map, Position pos, int duration, AreaTriggerSpawn spawnData = null, Unit caster = null, Unit target = null, SpellCastVisual spellVisual = default, SpellInfo spellInfo = null, Spell spell = null, AuraEffect aurEff = null) { _targetGuid = target != null ? target.GetGUID() : ObjectGuid.Empty; _aurEff = aurEff; - SetMap(caster.GetMap()); + SetMap(map); Relocate(pos); RelocateStationaryPosition(pos); if (!IsPositionValid()) { - Log.outError(LogFilter.AreaTrigger, $"AreaTrigger (areaTriggerCreatePropertiesId: {areaTriggerCreatePropertiesId}) not created. Invalid coordinates (X: {GetPositionX()} Y: {GetPositionY()})"); + Log.outError(LogFilter.AreaTrigger, $"AreaTrigger (AreaTriggerCreatePropertiesId: (Id: {areaTriggerCreatePropertiesId.Id}, IsCustom: {areaTriggerCreatePropertiesId.IsCustom})) not created. Invalid coordinates (X: {GetPositionX()} Y: {GetPositionY()})"); return false; } _areaTriggerCreateProperties = Global.AreaTriggerDataStorage.GetAreaTriggerCreateProperties(areaTriggerCreatePropertiesId); if (_areaTriggerCreateProperties == null) { - Log.outError(LogFilter.AreaTrigger, $"AreaTrigger (areaTriggerCreatePropertiesId {areaTriggerCreatePropertiesId}) not created. Invalid areatrigger create properties id ({areaTriggerCreatePropertiesId})"); + Log.outError(LogFilter.AreaTrigger, $"AreaTrigger (AreaTriggerCreatePropertiesId: (Id: {areaTriggerCreatePropertiesId.Id}, IsCustom: {areaTriggerCreatePropertiesId.IsCustom})) not created. Invalid areatrigger create properties id"); return false; } @@ -101,64 +101,77 @@ namespace Game.Entities _areaTriggerTemplate = _areaTriggerCreateProperties.Template; - _Create(ObjectGuid.Create(HighGuid.AreaTrigger, GetMapId(), GetTemplate() != null ? GetTemplate().Id.Id : 0, caster.GetMap().GenerateLowGuid(HighGuid.AreaTrigger))); + _Create(ObjectGuid.Create(HighGuid.AreaTrigger, GetMapId(), GetTemplate() != null ? GetTemplate().Id.Id : 0, GetMap().GenerateLowGuid(HighGuid.AreaTrigger))); if (GetTemplate() != null) SetEntry(GetTemplate().Id.Id); - SetDuration(duration); - SetObjectScale(1.0f); + SetDuration(duration); _shape = GetCreateProperties().Shape; var areaTriggerData = m_values.ModifyValue(m_areaTriggerData); - SetUpdateFieldValue(areaTriggerData.ModifyValue(m_areaTriggerData.Caster), caster.GetGUID()); + if (caster != null) + SetUpdateFieldValue(areaTriggerData.ModifyValue(m_areaTriggerData.Caster), caster.GetGUID()); if (spell != null) SetUpdateFieldValue(areaTriggerData.ModifyValue(m_areaTriggerData.CreatingEffectGUID), spell.m_castId); - SetUpdateFieldValue(areaTriggerData.ModifyValue(m_areaTriggerData.SpellID), spellInfo.Id); - SetUpdateFieldValue(areaTriggerData.ModifyValue(m_areaTriggerData.SpellForVisuals), spellInfo.Id); + if (spellInfo != null && !IsStaticSpawn()) + SetUpdateFieldValue(areaTriggerData.ModifyValue(m_areaTriggerData.SpellID), spellInfo.Id); + if (spellInfo != null) + SetUpdateFieldValue(areaTriggerData.ModifyValue(m_areaTriggerData.SpellForVisuals), spellInfo.Id); SpellCastVisualField spellCastVisual = areaTriggerData.ModifyValue(m_areaTriggerData.SpellVisual); SetUpdateFieldValue(ref spellCastVisual.SpellXSpellVisualID, spellVisual.SpellXSpellVisualID); SetUpdateFieldValue(ref spellCastVisual.ScriptVisualID, spellVisual.ScriptVisualID); - SetUpdateFieldValue(areaTriggerData.ModifyValue(m_areaTriggerData.TimeToTargetScale), GetCreateProperties().TimeToTargetScale != 0 ? GetCreateProperties().TimeToTargetScale : m_areaTriggerData.Duration); - SetUpdateFieldValue(areaTriggerData.ModifyValue(m_areaTriggerData.BoundsRadius2D), GetCreateProperties().GetMaxSearchRadius()); + if (!IsStaticSpawn()) + SetUpdateFieldValue(areaTriggerData.ModifyValue(m_areaTriggerData.TimeToTargetScale), GetCreateProperties().TimeToTargetScale != 0 ? GetCreateProperties().TimeToTargetScale : m_areaTriggerData.Duration); + SetUpdateFieldValue(areaTriggerData.ModifyValue(m_areaTriggerData.BoundsRadius2D), GetCreateProperties().Shape.GetMaxSearchRadius()); SetUpdateFieldValue(areaTriggerData.ModifyValue(m_areaTriggerData.DecalPropertiesID), GetCreateProperties().DecalPropertiesId); + if (IsServerSide()) + SetUpdateFieldValue(areaTriggerData.ModifyValue(m_areaTriggerData.DecalPropertiesID), 24u); // Blue decal, for .debug areatrigger visibility - SetScaleCurve(areaTriggerData.ModifyValue(m_areaTriggerData.ExtraScaleCurve), GetCreateProperties().ExtraScale); + AreaTriggerScaleCurveTemplate extraScaleCurve = IsStaticSpawn() ? new AreaTriggerScaleCurveTemplate() : GetCreateProperties().ExtraScale; + SetScaleCurve(areaTriggerData.ModifyValue(m_areaTriggerData.ExtraScaleCurve), extraScaleCurve); - Player modOwner = caster.GetSpellModOwner(); - if (modOwner != null) + if (caster != null) { - float multiplier = 1.0f; - int flat = 0; - modOwner.GetSpellModValues(spellInfo, SpellModOp.Radius, spell, (float)m_areaTriggerData.BoundsRadius2D, ref flat, ref multiplier); - if (multiplier != 1.0f) + Player modOwner = caster.GetSpellModOwner(); + if (modOwner != null) { - AreaTriggerScaleCurveTemplate overrideScale = new(); - overrideScale.Curve = multiplier; - SetScaleCurve(areaTriggerData.ModifyValue(m_areaTriggerData.OverrideScaleCurve), overrideScale); + float multiplier = 1.0f; + int flat = 0; + modOwner.GetSpellModValues(spellInfo, SpellModOp.Radius, spell, (float)m_areaTriggerData.BoundsRadius2D, ref flat, ref multiplier); + if (multiplier != 1.0f) + { + AreaTriggerScaleCurveTemplate overrideScale = new(); + overrideScale.Curve = multiplier; + SetScaleCurve(areaTriggerData.ModifyValue(m_areaTriggerData.OverrideScaleCurve), overrideScale); + } } } VisualAnim visualAnim = areaTriggerData.ModifyValue(m_areaTriggerData.VisualAnim); SetUpdateFieldValue(visualAnim.ModifyValue(visualAnim.AnimationDataID), GetCreateProperties().AnimId); SetUpdateFieldValue(visualAnim.ModifyValue(visualAnim.AnimKitID), GetCreateProperties().AnimKitId); - if (GetTemplate() != null && GetTemplate().HasFlag(AreaTriggerFlags.Unk3)) + if (GetCreateProperties() != null && GetCreateProperties().Flags.HasFlag(AreaTriggerCreatePropertiesFlag.Unk3)) SetUpdateFieldValue(visualAnim.ModifyValue(visualAnim.Field_C), true); - PhasingHandler.InheritPhaseShift(this, caster); - - if (target != null && GetTemplate() != null && GetTemplate().HasFlag(AreaTriggerFlags.HasAttached)) + if (caster != null) + PhasingHandler.InheritPhaseShift(this, caster); + else if (IsStaticSpawn() && spawnData != null) { - m_movementInfo.transport.guid = target.GetGUID(); + if (spawnData.PhaseUseFlags != 0 || spawnData.PhaseId != 0 || spawnData.PhaseGroup != 0) + PhasingHandler.InitDbPhaseShift(GetPhaseShift(), spawnData.PhaseUseFlags, spawnData.PhaseId, spawnData.PhaseGroup); } - UpdatePositionData(); - SetZoneScript(); + if (target != null && GetCreateProperties() != null && GetCreateProperties().Flags.HasFlag(AreaTriggerCreatePropertiesFlag.HasAttached)) + m_movementInfo.transport.guid = target.GetGUID(); + + if (!IsStaticSpawn()) + UpdatePositionData(); UpdateShape(); @@ -167,7 +180,7 @@ namespace Game.Entities if (GetCreateProperties().OrbitInfo != null) { AreaTriggerOrbitInfo orbit = GetCreateProperties().OrbitInfo; - if (target != null && GetTemplate() != null && GetTemplate().HasFlag(AreaTriggerFlags.HasAttached)) + if (target != null && GetCreateProperties() != null && GetCreateProperties().Flags.HasFlag(AreaTriggerCreatePropertiesFlag.HasAttached)) orbit.PathTarget = target.GetGUID(); else orbit.Center = new(pos.posX, pos.posY, pos.posZ); @@ -180,16 +193,21 @@ namespace Game.Entities } // movement on transport of areatriggers on unit is handled by themself - ITransport transport = m_movementInfo.transport.guid.IsEmpty() ? caster.GetTransport() : null; - if (transport != null) + ITransport transport = null; + if (caster != null) { - float x, y, z, o; - pos.GetPosition(out x, out y, out z, out o); - transport.CalculatePassengerOffset(ref x, ref y, ref z, ref o); - m_movementInfo.transport.pos.Relocate(x, y, z, o); + transport = m_movementInfo.transport.guid.IsEmpty() ? caster.GetTransport() : null; - // This object must be added to transport before adding to map for the client to properly display it - transport.AddPassenger(this); + if (transport != null) + { + float x, y, z, o; + pos.GetPosition(out x, out y, out z, out o); + transport.CalculatePassengerOffset(ref x, ref y, ref z, ref o); + m_movementInfo.transport.pos.Relocate(x, y, z, o); + + // This object must be added to transport before adding to map for the client to properly display it + transport.AddPassenger(this); + } } AI_Initialize(); @@ -198,24 +216,27 @@ namespace Game.Entities if (HasOrbit()) Relocate(CalculateOrbitPosition()); - if (!GetMap().AddToMap(this)) - { // Returning false will cause the object to be deleted - remove from transport - if (transport != null) - transport.RemovePassenger(this); - return false; + if (!IsStaticSpawn()) + { + if (!GetMap().AddToMap(this)) + { // Returning false will cause the object to be deleted - remove from transport + if (transport != null) + transport.RemovePassenger(this); + return false; + } } - caster._RegisterAreaTrigger(this); + caster?._RegisterAreaTrigger(this); _ai.OnCreate(spell); return true; } - public static AreaTrigger CreateAreaTrigger(uint areaTriggerCreatePropertiesId, Unit caster, Unit target, SpellInfo spellInfo, Position pos, int duration, SpellCastVisualField spellVisual, Spell spell = null, AuraEffect aurEff = null) + public static AreaTrigger CreateAreaTrigger(AreaTriggerId areaTriggerCreatePropertiesId, Position pos, int duration, Unit caster, Unit target, SpellCastVisual spellVisual = default, SpellInfo spellInfo = null, Spell spell = null, AuraEffect aurEff = null) { AreaTrigger at = new(); - if (!at.Create(areaTriggerCreatePropertiesId, caster, target, spellInfo, pos, duration, spellVisual, spell, aurEff)) + if (!at.Create(areaTriggerCreatePropertiesId, caster.GetMap(), pos, duration, null, caster, target, spellVisual, spellInfo, spell, aurEff)) return null; return at; @@ -230,70 +251,23 @@ namespace Game.Entities { _spawnId = spawnId; - AreaTriggerSpawn position = Global.AreaTriggerDataStorage.GetAreaTriggerSpawn(spawnId); - if (position == null) + AreaTriggerSpawn spawnData = Global.AreaTriggerDataStorage.GetAreaTriggerSpawn(spawnId); + if (spawnData == null) return false; - AreaTriggerTemplate areaTriggerTemplate = Global.AreaTriggerDataStorage.GetAreaTriggerTemplate(position.TriggerId); - if (areaTriggerTemplate == null) + AreaTriggerCreateProperties createProperties = Global.AreaTriggerDataStorage.GetAreaTriggerCreateProperties(spawnData.Id); + if (createProperties == null) return false; - return CreateServer(map, areaTriggerTemplate, position); - } - - bool CreateServer(Map map, AreaTriggerTemplate areaTriggerTemplate, AreaTriggerSpawn position) - { - SetMap(map); - Relocate(position.SpawnPoint); - RelocateStationaryPosition(position.SpawnPoint); - if (!IsPositionValid()) + SpellInfo spellInfo = null; + SpellCastVisual spellVisual = default; + if (spawnData.SpellForVisuals != 0) { - Log.outError(LogFilter.AreaTrigger, $"AreaTriggerServer (id {areaTriggerTemplate.Id}) not created. Invalid coordinates (X: {GetPositionX()} Y: {GetPositionY()})"); - return false; + spellInfo = Global.SpellMgr.GetSpellInfo((uint)spawnData.SpellForVisuals, Difficulty.None); + if (spellInfo != null) + spellVisual.SpellXSpellVisualID = spellInfo.GetSpellXSpellVisualId(); } - - SetZoneScript(); - - _areaTriggerTemplate = areaTriggerTemplate; - - _Create(ObjectGuid.Create(HighGuid.AreaTrigger, GetMapId(), areaTriggerTemplate.Id.Id, GetMap().GenerateLowGuid(HighGuid.AreaTrigger))); - - SetEntry(areaTriggerTemplate.Id.Id); - - SetObjectScale(1.0f); - SetDuration(-1); - - _shape = position.Shape; - - if (position.SpellForVisuals.HasValue) - { - SpellInfo spellInfo = Global.SpellMgr.GetSpellInfo(position.SpellForVisuals.Value, Difficulty.None); - SetUpdateFieldValue(m_areaTriggerData.ModifyValue(m_areaTriggerData.SpellForVisuals), position.SpellForVisuals.Value); - - SpellCastVisualField spellCastVisual = m_areaTriggerData.ModifyValue(m_areaTriggerData.SpellVisual); - SetUpdateFieldValue(ref spellCastVisual.SpellXSpellVisualID, spellInfo.GetSpellXSpellVisualId()); - SetUpdateFieldValue(ref spellCastVisual.ScriptVisualID, 0u); - } - - SetUpdateFieldValue(m_areaTriggerData.ModifyValue(m_areaTriggerData.BoundsRadius2D), _shape.GetMaxSearchRadius()); - if (IsServerSide()) - SetUpdateFieldValue(m_areaTriggerData.ModifyValue(m_areaTriggerData.DecalPropertiesID), 24u); // blue decal, for .debug areatrigger visibility - - SetScaleCurve(m_areaTriggerData.ModifyValue(m_areaTriggerData.ExtraScaleCurve), new AreaTriggerScaleCurveTemplate()); - - VisualAnim visualAnim = m_areaTriggerData.ModifyValue(m_areaTriggerData.VisualAnim); - SetUpdateFieldValue(visualAnim.ModifyValue(visualAnim.AnimationDataID), -1); - - if (position.PhaseUseFlags != 0 || position.PhaseId != 0 || position.PhaseGroup != 0) - PhasingHandler.InitDbPhaseShift(GetPhaseShift(), position.PhaseUseFlags, position.PhaseId, position.PhaseGroup); - - UpdateShape(); - - AI_Initialize(); - - _ai.OnCreate(null); - - return true; + return Create(spawnData.Id, map, spawnData.SpawnPoint, -1, spawnData, null, null, spellVisual, spellInfo); } public override void Update(uint diff) @@ -301,7 +275,7 @@ namespace Game.Entities base.Update(diff); _timeSinceCreated += diff; - if (!IsServerSide()) + if (!IsStaticSpawn()) { // "If" order matter here, Orbit > Attached > Splines if (HasOverridePosition()) @@ -312,7 +286,7 @@ namespace Game.Entities { UpdateOrbitPosition(diff); } - else if (GetTemplate() != null && GetTemplate().HasFlag(AreaTriggerFlags.HasAttached)) + else if (GetCreateProperties() != null && GetCreateProperties().Flags.HasFlag(AreaTriggerCreatePropertiesFlag.HasAttached)) { Unit target = GetTarget(); if (target != null) @@ -322,7 +296,7 @@ namespace Game.Entities if (createProperties != null && createProperties.FacingCurveId != 0) orientation = Global.DB2Mgr.GetCurveValueAt(createProperties.FacingCurveId, GetProgress()); - if (GetTemplate() == null || !GetTemplate().HasFlag(AreaTriggerFlags.HasAbsoluteOrientation)) + if (GetCreateProperties() == null || !GetCreateProperties().Flags.HasFlag(AreaTriggerCreatePropertiesFlag.HasAbsoluteOrientation)) orientation += target.GetOrientation(); GetMap().AreaTriggerRelocation(this, target.GetPositionX(), target.GetPositionY(), target.GetPositionZ(), orientation); @@ -338,7 +312,7 @@ namespace Game.Entities if (createProperties != null && createProperties.FacingCurveId != 0) { float orientation = Global.DB2Mgr.GetCurveValueAt(createProperties.FacingCurveId, GetProgress()); - if (GetTemplate() == null || !GetTemplate().HasFlag(AreaTriggerFlags.HasAbsoluteOrientation)) + if (GetCreateProperties() == null || !GetCreateProperties().Flags.HasFlag(AreaTriggerCreatePropertiesFlag.HasAbsoluteOrientation)) orientation += GetStationaryO(); SetOrientation(orientation); @@ -597,22 +571,22 @@ namespace Game.Entities switch (_shape.TriggerType) { - case AreaTriggerTypes.Sphere: + case AreaTriggerShapeType.Sphere: SearchUnitInSphere(targetList); break; - case AreaTriggerTypes.Box: + case AreaTriggerShapeType.Box: SearchUnitInBox(targetList); break; - case AreaTriggerTypes.Polygon: + case AreaTriggerShapeType.Polygon: SearchUnitInPolygon(targetList); break; - case AreaTriggerTypes.Cylinder: + case AreaTriggerShapeType.Cylinder: SearchUnitInCylinder(targetList); break; - case AreaTriggerTypes.Disk: + case AreaTriggerShapeType.Disk: SearchUnitInDisk(targetList); break; - case AreaTriggerTypes.BoundedPlane: + case AreaTriggerShapeType.BoundedPlane: SearchUnitInBoundedPlane(targetList); break; default: @@ -621,7 +595,7 @@ namespace Game.Entities if (GetTemplate() != null) { - var conditions = Global.ConditionMgr.GetConditionsForAreaTrigger(GetTemplate().Id.Id, GetTemplate().Id.IsServerSide); + var conditions = Global.ConditionMgr.GetConditionsForAreaTrigger(GetTemplate().Id.Id, GetTemplate().Id.IsCustom); if (!conditions.Empty()) targetList.RemoveAll(target => !Global.ConditionMgr.IsObjectMeetToConditions(target, conditions)); } @@ -632,7 +606,7 @@ namespace Game.Entities void SearchUnits(List targetList, float radius, bool check3D) { var check = new AnyUnitInObjectRangeCheck(this, radius, check3D); - if (IsServerSide()) + if (IsStaticSpawn()) { var searcher = new PlayerListSearcher(this, targetList, check); Cell.VisitWorldObjects(this, searcher, GetMaxSearchRadius()); @@ -781,7 +755,7 @@ namespace Game.Entities if (player != null) { if (player.IsDebugAreaTriggers) - player.SendSysMessage(CypherStrings.DebugAreatriggerEntered, GetEntry()); + player.SendSysMessage(CypherStrings.DebugAreatriggerEntityEntered, GetEntry(), IsCustom(), IsStaticSpawn(), GetGUID().GetCounter()); player.UpdateQuestObjectiveProgress(QuestObjectiveType.AreaTriggerEnter, (int)GetEntry(), 1); } @@ -800,7 +774,7 @@ namespace Game.Entities if (player != null) { if (player.IsDebugAreaTriggers) - player.SendSysMessage(CypherStrings.DebugAreatriggerLeft, GetEntry()); + player.SendSysMessage(CypherStrings.DebugAreatriggerEntityLeft, GetEntry(), IsCustom(), IsStaticSpawn(), GetGUID().GetCounter()); player.UpdateQuestObjectiveProgress(QuestObjectiveType.AreaTriggerExit, (int)GetEntry(), 1); } @@ -859,15 +833,16 @@ namespace Game.Entities void UpdatePolygonVertices() { AreaTriggerCreateProperties createProperties = GetCreateProperties(); + AreaTriggerShapeInfo shape = GetShape(); float newOrientation = GetOrientation(); // No need to recalculate, orientation didn't change - if (MathFunctions.fuzzyEq(_verticesUpdatePreviousOrientation, newOrientation) && (createProperties == null) || createProperties.PolygonVerticesTarget.Empty()) + if (MathFunctions.fuzzyEq(_verticesUpdatePreviousOrientation, newOrientation) && shape.PolygonVerticesTarget.Empty()) return; - _polygonVertices = createProperties.PolygonVertices; + _polygonVertices = shape.PolygonVertices; - if (!createProperties.PolygonVerticesTarget.Empty()) + if (!shape.PolygonVerticesTarget.Empty()) { float progress = GetProgress(); if (createProperties.MorphCurveId != 0) @@ -876,7 +851,7 @@ namespace Game.Entities for (var i = 0; i < _polygonVertices.Count; ++i) { Vector2 vertex = _polygonVertices[i]; - Vector2 vertexTarget = createProperties.PolygonVerticesTarget[i]; + Vector2 vertexTarget = shape.PolygonVerticesTarget[i]; vertex.X = MathFunctions.Lerp(vertex.X, vertexTarget.X, progress); vertex.Y = MathFunctions.Lerp(vertex.Y, vertexTarget.Y, progress); @@ -1004,12 +979,12 @@ namespace Game.Entities void DoActions(Unit unit) { - Unit caster = IsServerSide() ? unit : GetCaster(); + Unit caster = IsStaticSpawn() ? unit : GetCaster(); if (caster != null && GetTemplate() != null) { foreach (AreaTriggerAction action in GetTemplate().Actions) { - if (IsServerSide() || UnitFitToActionRequirement(unit, caster, action)) + if (IsStaticSpawn() || UnitFitToActionRequirement(unit, caster, action)) { switch (action.ActionType) { @@ -1210,7 +1185,7 @@ namespace Game.Entities if (createProperties != null && createProperties.FacingCurveId != 0) orientation = Global.DB2Mgr.GetCurveValueAt(createProperties.FacingCurveId, GetProgress()); - if (GetTemplate() == null || !GetTemplate().HasFlag(AreaTriggerFlags.HasAbsoluteOrientation)) + if (GetCreateProperties() == null || !GetCreateProperties().Flags.HasFlag(AreaTriggerCreatePropertiesFlag.HasAbsoluteOrientation)) { orientation += angle; orientation += cmi.CounterClockwise ? MathFunctions.PiOver4 : -MathFunctions.PiOver4; @@ -1266,7 +1241,7 @@ namespace Game.Entities float progress = Global.DB2Mgr.GetCurveValueAt(createProperties.MoveCurveId, currentTimePercent); if (progress < 0.0f || progress > 1.0f) { - Log.outError(LogFilter.AreaTrigger, $"AreaTrigger (Id: {GetEntry()}, AreaTriggerCreatePropertiesId: {createProperties.Id}) has wrong progress ({progress}) caused by curve calculation (MoveCurveId: {createProperties.MorphCurveId})"); + Log.outError(LogFilter.AreaTrigger, $"AreaTrigger (Id: {GetEntry()}, AreaTriggerCreatePropertiesId: (Id: {createProperties.Id.Id}, IsCustom: {createProperties.Id.IsCustom})) has wrong progress ({progress}) caused by curve calculation (MoveCurveId: {createProperties.MoveCurveId})"); } else currentTimePercent = progress; @@ -1283,7 +1258,7 @@ namespace Game.Entities if (createProperties != null && createProperties.FacingCurveId != 0) orientation += Global.DB2Mgr.GetCurveValueAt(createProperties.FacingCurveId, GetProgress()); - if (GetTemplate() != null && !GetTemplate().HasFlag(AreaTriggerFlags.HasAbsoluteOrientation) && GetTemplate().HasFlag(AreaTriggerFlags.HasFaceMovementDir)) + if (GetCreateProperties() != null && !GetCreateProperties().Flags.HasFlag(AreaTriggerCreatePropertiesFlag.HasAbsoluteOrientation) && GetCreateProperties().Flags.HasFlag(AreaTriggerCreatePropertiesFlag.HasFaceMovementDir)) { _spline.Evaluate_Derivative(lastPositionIndex, percentFromLastPoint, out Vector3 derivative); if (derivative.X != 0.0f || derivative.Y != 0.0f) @@ -1313,7 +1288,7 @@ namespace Game.Entities if (GetCreateProperties().FacingCurveId != 0) { orientation = Global.DB2Mgr.GetCurveValueAt(GetCreateProperties().FacingCurveId, GetProgress()); - if (GetTemplate() == null || !GetTemplate().HasFlag(AreaTriggerFlags.HasAbsoluteOrientation)) + if (GetCreateProperties() == null || !GetCreateProperties().Flags.HasFlag(AreaTriggerCreatePropertiesFlag.HasAbsoluteOrientation)) orientation += GetStationaryO(); } @@ -1342,7 +1317,7 @@ namespace Game.Entities if (base.IsNeverVisibleFor(seer, allowServersideObjects)) return true; - if (IsServerSide() && !allowServersideObjects) + if (IsCustom() && !allowServersideObjects) { Player seerPlayer = seer.ToPlayer(); if (seerPlayer != null) @@ -1418,7 +1393,9 @@ namespace Game.Entities public T GetAI() where T : AreaTriggerAI { return (T)_ai; } - public bool IsServerSide() { return _areaTriggerTemplate.Id.IsServerSide; } + public bool IsCustom() { return _areaTriggerTemplate.Id.IsCustom; } + public bool IsServerSide() { return _areaTriggerTemplate.Flags.HasFlag(AreaTriggerFlag.IsServerSide); } + public bool IsStaticSpawn() { return _spawnId != 0; } [System.Diagnostics.Conditional("DEBUG")] void DebugVisualizePosition() diff --git a/Source/Game/Entities/AreaTrigger/AreaTriggerTemplate.cs b/Source/Game/Entities/AreaTrigger/AreaTriggerTemplate.cs index 56922f203..68e8f947c 100644 --- a/Source/Game/Entities/AreaTrigger/AreaTriggerTemplate.cs +++ b/Source/Game/Entities/AreaTrigger/AreaTriggerTemplate.cs @@ -119,17 +119,17 @@ namespace Game.Entities public struct AreaTriggerId { public uint Id; - public bool IsServerSide; + public bool IsCustom; - public AreaTriggerId(uint id, bool isServerSide) + public AreaTriggerId(uint id, bool isCustom) { Id = id; - IsServerSide = isServerSide; + IsCustom = isCustom; } public override int GetHashCode() { - return Id.GetHashCode() ^ IsServerSide.GetHashCode(); + return Id.GetHashCode() ^ IsCustom.GetHashCode(); } public override bool Equals(object obj) @@ -139,7 +139,7 @@ namespace Game.Entities public static bool operator ==(AreaTriggerId left, AreaTriggerId right) { - return left.Id == right.Id && left.IsServerSide == right.IsServerSide; + return left.Id == right.Id && left.IsCustom == right.IsCustom; } public static bool operator !=(AreaTriggerId left, AreaTriggerId right) { @@ -149,27 +149,44 @@ namespace Game.Entities public class AreaTriggerShapeInfo : AreaTriggerData { - public AreaTriggerTypes TriggerType; + public AreaTriggerShapeType TriggerType; + public List PolygonVertices; + public List PolygonVerticesTarget; public AreaTriggerShapeInfo() { - TriggerType = AreaTriggerTypes.Max; + TriggerType = AreaTriggerShapeType.Max; + PolygonVertices = new(); + PolygonVerticesTarget = new(); } public unsafe float GetMaxSearchRadius() { switch (TriggerType) { - case AreaTriggerTypes.Sphere: + case AreaTriggerShapeType.Sphere: return Math.Max(SphereDatas.Radius, SphereDatas.RadiusTarget); - case AreaTriggerTypes.Box: + case AreaTriggerShapeType.Box: return MathF.Sqrt(Math.Max(BoxDatas.Extents[0] * BoxDatas.Extents[0] + BoxDatas.Extents[1] * BoxDatas.Extents[1], BoxDatas.ExtentsTarget[0] * BoxDatas.ExtentsTarget[0] + BoxDatas.ExtentsTarget[1] * BoxDatas.ExtentsTarget[1])); - case AreaTriggerTypes.Cylinder: + case AreaTriggerShapeType.Polygon: + { + Position center = new(0.0f, 0.0f); + float maxSearchRadius = 0.0f; + + foreach (var vertex in PolygonVertices) + maxSearchRadius = Math.Max(maxSearchRadius, center.GetExactDist2d(vertex.X, vertex.Y)); + + foreach (var vertex in PolygonVerticesTarget) + maxSearchRadius = Math.Max(maxSearchRadius, center.GetExactDist2d(vertex.X, vertex.Y)); + + return maxSearchRadius; + } + case AreaTriggerShapeType.Cylinder: return Math.Max(CylinderDatas.Radius, CylinderDatas.RadiusTarget); - case AreaTriggerTypes.Disk: + case AreaTriggerShapeType.Disk: return Math.Max(DiskDatas.OuterRadius, DiskDatas.OuterRadiusTarget); - case AreaTriggerTypes.BoundedPlane: + case AreaTriggerShapeType.BoundedPlane: return MathF.Sqrt(Math.Max(BoundedPlaneDatas.Extents[0] * BoundedPlaneDatas.Extents[0] / 4 + BoundedPlaneDatas.Extents[1] * BoundedPlaneDatas.Extents[1] / 4, BoundedPlaneDatas.ExtentsTarget[0] * BoundedPlaneDatas.ExtentsTarget[0] / 4 + BoundedPlaneDatas.ExtentsTarget[1] * BoundedPlaneDatas.ExtentsTarget[1] / 4)); } @@ -177,12 +194,12 @@ namespace Game.Entities return 0.0f; } - public bool IsSphere() { return TriggerType == AreaTriggerTypes.Sphere; } - public bool IsBox() { return TriggerType == AreaTriggerTypes.Box; } - public bool IsPolygon() { return TriggerType == AreaTriggerTypes.Polygon; } - public bool IsCylinder() { return TriggerType == AreaTriggerTypes.Cylinder; } - public bool IsDisk() { return TriggerType == AreaTriggerTypes.Disk; } - public bool IsBoudedPlane() { return TriggerType == AreaTriggerTypes.BoundedPlane; } + public bool IsSphere() { return TriggerType == AreaTriggerShapeType.Sphere; } + public bool IsBox() { return TriggerType == AreaTriggerShapeType.Box; } + public bool IsPolygon() { return TriggerType == AreaTriggerShapeType.Polygon; } + public bool IsCylinder() { return TriggerType == AreaTriggerShapeType.Cylinder; } + public bool IsDisk() { return TriggerType == AreaTriggerShapeType.Disk; } + public bool IsBoundedPlane() { return TriggerType == AreaTriggerShapeType.BoundedPlane; } } public class AreaTriggerOrbitInfo @@ -225,43 +242,15 @@ namespace Game.Entities public class AreaTriggerTemplate { public AreaTriggerId Id; - public AreaTriggerFlags Flags; - + public AreaTriggerFlag Flags; public List Actions = new(); - - public bool HasFlag(AreaTriggerFlags flag) { return Flags.HasAnyFlag(flag); } } - public unsafe class AreaTriggerCreateProperties + public class AreaTriggerCreateProperties { - public AreaTriggerCreateProperties() - { - ExtraScale = new(); - } - - public bool HasSplines() { return SplinePoints.Count >= 2; } - - public float GetMaxSearchRadius() - { - if (Shape.TriggerType == AreaTriggerTypes.Polygon) - { - Position center = new(0.0f, 0.0f); - float maxSearchRadius = 0.0f; - - foreach (var vertex in PolygonVertices) - maxSearchRadius = Math.Max(maxSearchRadius, center.GetExactDist2d(vertex.X, vertex.Y)); - - foreach (var vertex in PolygonVerticesTarget) - maxSearchRadius = Math.Max(maxSearchRadius, center.GetExactDist2d(vertex.X, vertex.Y)); - - return maxSearchRadius; - } - - return Shape.GetMaxSearchRadius(); - } - - public uint Id; + public AreaTriggerId Id; public AreaTriggerTemplate Template; + public AreaTriggerCreatePropertiesFlag Flags; public uint MoveCurveId; public uint ScaleCurveId; @@ -280,18 +269,23 @@ namespace Game.Entities public AreaTriggerScaleCurveTemplate ExtraScale; public AreaTriggerShapeInfo Shape = new(); - public List PolygonVertices = new(); - public List PolygonVerticesTarget = new(); public List SplinePoints = new(); public AreaTriggerOrbitInfo OrbitInfo; public uint ScriptId; + + public AreaTriggerCreateProperties() + { + Id = new(0, false); + ExtraScale = new(); + } + + public bool HasSplines() { return SplinePoints.Count >= 2; } } public class AreaTriggerSpawn : SpawnData { - public AreaTriggerId TriggerId; - public AreaTriggerShapeInfo Shape = new(); + public AreaTriggerId Id; public uint? SpellForVisuals; public AreaTriggerSpawn() : base(SpawnObjectType.AreaTrigger) { } diff --git a/Source/Game/Entities/Object/WorldObject.cs b/Source/Game/Entities/Object/WorldObject.cs index 839c53b09..daf7fbfe8 100644 --- a/Source/Game/Entities/Object/WorldObject.cs +++ b/Source/Game/Entities/Object/WorldObject.cs @@ -429,20 +429,19 @@ namespace Game.Entities { AreaTrigger areaTrigger = ToAreaTrigger(); AreaTriggerCreateProperties createProperties = areaTrigger.GetCreateProperties(); - AreaTriggerTemplate areaTriggerTemplate = areaTrigger.GetTemplate(); AreaTriggerShapeInfo shape = areaTrigger.GetShape(); data.WriteUInt32(areaTrigger.GetTimeSinceCreated()); data.WriteVector3(areaTrigger.GetRollPitchYaw()); - bool hasAbsoluteOrientation = areaTriggerTemplate != null && areaTriggerTemplate.HasFlag(AreaTriggerFlags.HasAbsoluteOrientation); - bool hasDynamicShape = areaTriggerTemplate != null && areaTriggerTemplate.HasFlag(AreaTriggerFlags.HasDynamicShape); - bool hasAttached = areaTriggerTemplate != null && areaTriggerTemplate.HasFlag(AreaTriggerFlags.HasAttached); - bool hasFaceMovementDir = areaTriggerTemplate != null && areaTriggerTemplate.HasFlag(AreaTriggerFlags.HasFaceMovementDir); - bool hasFollowsTerrain = areaTriggerTemplate != null && areaTriggerTemplate.HasFlag(AreaTriggerFlags.HasFollowsTerrain); - bool hasUnk1 = areaTriggerTemplate != null && areaTriggerTemplate.HasFlag(AreaTriggerFlags.Unk1); - bool hasTargetRollPitchYaw = areaTriggerTemplate != null && areaTriggerTemplate.HasFlag(AreaTriggerFlags.HasTargetRollPitchYaw); + bool hasAbsoluteOrientation = createProperties != null && createProperties.Flags.HasFlag(AreaTriggerCreatePropertiesFlag.HasAbsoluteOrientation); + bool hasDynamicShape = createProperties != null && createProperties.Flags.HasFlag(AreaTriggerCreatePropertiesFlag.HasDynamicShape); + bool hasAttached = createProperties != null && createProperties.Flags.HasFlag(AreaTriggerCreatePropertiesFlag.HasAttached); + bool hasFaceMovementDir = createProperties != null && createProperties.Flags.HasFlag(AreaTriggerCreatePropertiesFlag.HasFaceMovementDir); + bool hasFollowsTerrain = createProperties != null && createProperties.Flags.HasFlag(AreaTriggerCreatePropertiesFlag.HasFollowsTerrain); + bool hasUnk1 = createProperties != null && createProperties.Flags.HasFlag(AreaTriggerCreatePropertiesFlag.Unk1); + bool hasTargetRollPitchYaw = createProperties != null && createProperties.Flags.HasFlag(AreaTriggerCreatePropertiesFlag.HasTargetRollPitchYaw); bool hasScaleCurveID = createProperties != null && createProperties.ScaleCurveId != 0; bool hasMorphCurveID = createProperties != null && createProperties.MorphCurveId != 0; bool hasFacingCurveID = createProperties != null && createProperties.FacingCurveId != 0; @@ -452,7 +451,7 @@ namespace Game.Entities bool hasAreaTriggerPolygon = createProperties != null && shape.IsPolygon(); bool hasAreaTriggerCylinder = shape.IsCylinder(); bool hasDisk = shape.IsDisk(); - bool hasBoundedPlane = shape.IsBoudedPlane(); + bool hasBoundedPlane = shape.IsBoundedPlane(); bool hasAreaTriggerSpline = areaTrigger.HasSplines(); bool hasOrbit = areaTrigger.HasOrbit(); bool hasMovementScript = false; @@ -525,15 +524,15 @@ namespace Game.Entities if (hasAreaTriggerPolygon) { - data.WriteInt32(createProperties.PolygonVertices.Count); - data.WriteInt32(createProperties.PolygonVerticesTarget.Count); + data.WriteInt32(shape.PolygonVertices.Count); + data.WriteInt32(shape.PolygonVerticesTarget.Count); data.WriteFloat(shape.PolygonDatas.Height); data.WriteFloat(shape.PolygonDatas.HeightTarget); - foreach (var vertice in createProperties.PolygonVertices) + foreach (var vertice in shape.PolygonVertices) data.WriteVector2(vertice); - foreach (var vertice in createProperties.PolygonVerticesTarget) + foreach (var vertice in shape.PolygonVerticesTarget) data.WriteVector2(vertice); } diff --git a/Source/Game/Spells/Auras/AuraEffect.cs b/Source/Game/Spells/Auras/AuraEffect.cs index 41c7abddb..326f9c210 100644 --- a/Source/Game/Spells/Auras/AuraEffect.cs +++ b/Source/Game/Spells/Auras/AuraEffect.cs @@ -5775,7 +5775,8 @@ namespace Game.Spells if (apply) { - AreaTrigger.CreateAreaTrigger((uint)GetMiscValue(), GetCaster(), target, GetSpellInfo(), target, GetBase().GetDuration(), GetBase().GetSpellVisual(), null, this); + AreaTriggerId createPropertiesId = new((uint)GetMiscValue(), false); + AreaTrigger.CreateAreaTrigger(createPropertiesId, target, GetBase().GetDuration(), GetCaster(), target, GetBase().GetSpellVisual(), GetSpellInfo(), null, this); } else { diff --git a/Source/Game/Spells/SpellEffects.cs b/Source/Game/Spells/SpellEffects.cs index 387d75cee..51dbdf1b2 100644 --- a/Source/Game/Spells/SpellEffects.cs +++ b/Source/Game/Spells/SpellEffects.cs @@ -5067,8 +5067,9 @@ namespace Game.Spells if (unitCaster == null || !m_targets.HasDst()) return; + AreaTriggerId createPropertiesId = new((uint)effectInfo.MiscValue, false); int duration = GetSpellInfo().CalcDuration(GetCaster()); - AreaTrigger.CreateAreaTrigger((uint)effectInfo.MiscValue, unitCaster, null, GetSpellInfo(), destTarget.GetPosition(), duration, m_SpellVisual, this); + AreaTrigger.CreateAreaTrigger(createPropertiesId, destTarget.GetPosition(), duration, unitCaster, null, m_SpellVisual, GetSpellInfo(), this); } [SpellEffectHandler(SpellEffectName.RemoveTalent)]