From deadb86e31268d3f62b67be07146ff1f6047b1fd Mon Sep 17 00:00:00 2001 From: hondacrx Date: Tue, 31 May 2022 20:46:07 -0400 Subject: [PATCH] Core/SAI: Implemented new action SMART_ACTION_TRIGGER_GAME_EVENT Port From (https://github.com/TrinityCore/TrinityCore/commit/9d0187dd5669d73bcb94ffe76b4fc3975a5455cc) --- Source/Framework/Constants/SmartAIConst.cs | 1 + Source/Game/AI/SmartScripts/SmartAIManager.cs | 14 ++++++++++++++ Source/Game/AI/SmartScripts/SmartScript.cs | 13 +++++++++++++ 3 files changed, 28 insertions(+) diff --git a/Source/Framework/Constants/SmartAIConst.cs b/Source/Framework/Constants/SmartAIConst.cs index 863efad12..ef291bf97 100644 --- a/Source/Framework/Constants/SmartAIConst.cs +++ b/Source/Framework/Constants/SmartAIConst.cs @@ -396,6 +396,7 @@ namespace Framework.Constants ActivateGameobject = 147, // GameObjectActions AddToStoredTargetList = 148, // varID BecomePersonalCloneForPlayer = 149, // summonType 1-8, duration in ms + TriggerGameEvent = 150, // eventId, useSaiTargetAsGameEventSource End } diff --git a/Source/Game/AI/SmartScripts/SmartAIManager.cs b/Source/Game/AI/SmartScripts/SmartAIManager.cs index 557d6f79f..6932e1fff 100644 --- a/Source/Game/AI/SmartScripts/SmartAIManager.cs +++ b/Source/Game/AI/SmartScripts/SmartAIManager.cs @@ -804,6 +804,7 @@ namespace Game.AI SmartActions.ActivateGameobject => Marshal.SizeOf(typeof(SmartAction.ActivateGameObject)), SmartActions.AddToStoredTargetList => Marshal.SizeOf(typeof(SmartAction.AddToStoredTargets)), SmartActions.BecomePersonalCloneForPlayer => Marshal.SizeOf(typeof(SmartAction.BecomePersonalClone)), + SmartActions.TriggerGameEvent => Marshal.SizeOf(typeof(SmartAction.TriggerGameEvent)), _ => Marshal.SizeOf(typeof(SmartAction.Raw)), }; @@ -2088,6 +2089,11 @@ namespace Game.AI } break; } + case SmartActions.TriggerGameEvent: + { + TC_SAI_IS_BOOLEAN_VALID(e, e.Action.triggerGameEvent.useSaiTargetAsGameEventSource); + break; + } // No longer supported case SmartActions.SetUnitFlag: case SmartActions.RemoveUnitFlag: @@ -3135,6 +3141,9 @@ namespace Game.AI [FieldOffset(4)] public BecomePersonalClone becomePersonalClone; + [FieldOffset(4)] + public TriggerGameEvent triggerGameEvent; + [FieldOffset(4)] public Raw raw; @@ -3668,6 +3677,11 @@ namespace Game.AI public uint type; public uint duration; } + public struct TriggerGameEvent + { + public uint eventId; + public uint useSaiTargetAsGameEventSource; + } public struct Raw { public uint param1; diff --git a/Source/Game/AI/SmartScripts/SmartScript.cs b/Source/Game/AI/SmartScripts/SmartScript.cs index 6c8c3292f..ddac36962 100644 --- a/Source/Game/AI/SmartScripts/SmartScript.cs +++ b/Source/Game/AI/SmartScripts/SmartScript.cs @@ -2467,6 +2467,19 @@ namespace Game.AI _timedActionList.RemoveAll(script => { return script.EventId > e.EventId; }); break; } + case SmartActions.TriggerGameEvent: + { + WorldObject sourceObject = GetBaseObjectOrUnit(unit); + foreach (WorldObject target in targets) + { + if (e.Action.triggerGameEvent.useSaiTargetAsGameEventSource != 0) + GameEvents.Trigger(e.Action.triggerGameEvent.eventId, sourceObject, target); + else + GameEvents.Trigger(e.Action.triggerGameEvent.eventId, target, sourceObject); + } + + break; + } default: Log.outError(LogFilter.Sql, "SmartScript.ProcessAction: Entry {0} SourceType {1}, Event {2}, Unhandled Action type {3}", e.EntryOrGuid, e.GetScriptType(), e.EventId, e.GetActionType()); break;