diff --git a/Source/Game/AI/SmartScripts/SmartAI.cs b/Source/Game/AI/SmartScripts/SmartAI.cs index 8e64197df..272254d37 100644 --- a/Source/Game/AI/SmartScripts/SmartAI.cs +++ b/Source/Game/AI/SmartScripts/SmartAI.cs @@ -565,7 +565,7 @@ namespace Game.AI return false; } - public override void JustAppeared() + public override void InitializeAI() { _despawnTime = 0; _respawnTime = 0; @@ -711,14 +711,6 @@ namespace Game.AI GetScript().ProcessEventsFor(apply ? SmartEvents.PassengerBoarded : SmartEvents.PassengerRemoved, passenger, (uint)seatId, 0, apply); } - public override void InitializeAI() - { - _script.OnInitialize(me); - - if (!me.IsDead()) - GetScript().OnReset(); - } - public override void OnCharmed(bool apply) { if (apply) // do this before we change charmed state, as charmed state might prevent these things from processing @@ -893,9 +885,7 @@ namespace Game.AI public void SetScript9(SmartScriptHolder e, uint entry, Unit invoker) { - if (invoker != null) - GetScript().LastInvoker = invoker.GetGUID(); - GetScript().SetScript9(e, entry); + GetScript().SetScript9(e, entry, invoker); } public override void OnGameEvent(bool start, ushort eventId) @@ -1088,9 +1078,6 @@ namespace Game.AI public override void Reset() { - // call respawn event on reset - GetScript().ProcessEventsFor(SmartEvents.Respawn); - GetScript().OnReset(); } @@ -1142,9 +1129,7 @@ namespace Game.AI public void SetScript9(SmartScriptHolder e, uint entry, Unit invoker) { - if (invoker != null) - GetScript().LastInvoker = invoker.GetGUID(); - GetScript().SetScript9(e, entry); + GetScript().SetScript9(e, entry, invoker); } public override void OnGameEvent(bool start, ushort eventId) @@ -1195,10 +1180,7 @@ namespace Game.AI public void SetScript9(SmartScriptHolder e, uint entry, Unit invoker) { - if (invoker) - GetScript().LastInvoker = invoker.GetGUID(); - - GetScript().SetScript9(e, entry); + GetScript().SetScript9(e, entry, invoker); } public SmartScript GetScript() { return _script; } diff --git a/Source/Game/AI/SmartScripts/SmartAIManager.cs b/Source/Game/AI/SmartScripts/SmartAIManager.cs index e7ddc418e..b0cdd1283 100644 --- a/Source/Game/AI/SmartScripts/SmartAIManager.cs +++ b/Source/Game/AI/SmartScripts/SmartAIManager.cs @@ -491,8 +491,8 @@ namespace Game.AI Log.outError(LogFilter.Sql, "SmartAIMgr: Entry {e.entryOrGuid} SourceType {e.GetScriptType()} Event {e.GetEventType()} Action {}e.GetActionType() has invoker target, but action does not provide any invoker!"); // allow this to load for now // return false; - break; } + break; case SmartTargets.PlayerRange: case SmartTargets.Self: case SmartTargets.Victim: diff --git a/Source/Game/AI/SmartScripts/SmartScript.cs b/Source/Game/AI/SmartScripts/SmartScript.cs index 43b599a7f..14df4ec9a 100644 --- a/Source/Game/AI/SmartScripts/SmartScript.cs +++ b/Source/Game/AI/SmartScripts/SmartScript.cs @@ -39,6 +39,7 @@ namespace Game.AI List _events = new(); List _installEvents = new(); List _timedActionList = new(); + ObjectGuid mTimedActionListInvoker; Creature _me; ObjectGuid _meOrigGUID; GameObject _go; @@ -3638,9 +3639,12 @@ namespace Game.AI case SmartEvents.DistanceCreature: case SmartEvents.DistanceGameobject: { - ProcessEvent(e); if (e.GetScriptType() == SmartScriptType.TimedActionlist) { + Unit invoker9 = null; + if (_me != null && !mTimedActionListInvoker.IsEmpty()) + invoker9 = Global.ObjAccessor.GetUnit(_me, mTimedActionListInvoker); + ProcessEvent(e, invoker9); e.EnableTimed = false;//disable event if it is in an ActionList and was processed once foreach (var holder in _timedActionList) { @@ -3652,6 +3656,8 @@ namespace Game.AI } } } + else + ProcessEvent(e); break; } } @@ -3994,12 +4000,14 @@ namespace Game.AI return searcher.GetTarget(); } - public void SetScript9(SmartScriptHolder e, uint entry) + public void SetScript9(SmartScriptHolder e, uint entry, Unit invoker) { _timedActionList.Clear(); _timedActionList = Global.SmartAIMgr.GetScript((int)entry, SmartScriptType.TimedActionlist); if (_timedActionList.Empty()) return; + + mTimedActionListInvoker = invoker != null ? invoker.GetGUID() : ObjectGuid.Empty; int i = 0; foreach (var holder in _timedActionList.ToList()) {