diff --git a/Source/Framework/Constants/SmartAIConst.cs b/Source/Framework/Constants/SmartAIConst.cs index c8bc471b3..fc7c8f3eb 100644 --- a/Source/Framework/Constants/SmartAIConst.cs +++ b/Source/Framework/Constants/SmartAIConst.cs @@ -232,6 +232,8 @@ namespace Framework.Constants OnDespawn = 86, // NONE SendEventTrigger = 87, // NONE AreatriggerExit = 88, // None + OnAuraApplied = 89, // SpellID, CooldownMin, CooldownMax + OnAuraRemoved = 90, // SpellID, CooldownMin, CooldownMax End } diff --git a/Source/Game/AI/CoreAI/CreatureAI.cs b/Source/Game/AI/CoreAI/CreatureAI.cs index c9a08204a..671c39a62 100644 --- a/Source/Game/AI/CoreAI/CreatureAI.cs +++ b/Source/Game/AI/CoreAI/CreatureAI.cs @@ -297,7 +297,7 @@ namespace Game.AI if (!me.IsTapListNotClearedOnEvade()) me.SetTappedBy(null); - + me.ResetPlayerDamageReq(); me.SetLastDamagedTime(0); me.SetCannotReachTarget(false); @@ -494,6 +494,12 @@ namespace Game.AI // Called when a channeled spell finishes public virtual void OnChannelFinished(SpellInfo spell) { } + // Called when aura is applied + public virtual void OnAuraApplied(AuraApplication aurApp) { } + + // Called when aura is removed + public virtual void OnAuraRemoved(AuraApplication aurApp) { } + // Should return true if the NPC is currently being escorted public virtual bool IsEscorted() { return false; } diff --git a/Source/Game/AI/SmartScripts/SmartAI.cs b/Source/Game/AI/SmartScripts/SmartAI.cs index 32a2a091d..5859126fc 100644 --- a/Source/Game/AI/SmartScripts/SmartAI.cs +++ b/Source/Game/AI/SmartScripts/SmartAI.cs @@ -642,6 +642,16 @@ namespace Game.AI GetScript().ProcessEventsFor(SmartEvents.OnSpellStart, null, 0, 0, false, spellInfo); } + public override void OnAuraApplied(AuraApplication aurApp) + { + GetScript().ProcessEventsFor(SmartEvents.OnAuraApplied, null, 0, 0, false, aurApp.GetBase().GetSpellInfo()); + } + + public override void OnAuraRemoved(AuraApplication aurApp) + { + GetScript().ProcessEventsFor(SmartEvents.OnAuraRemoved, null, 0, 0, false, aurApp.GetBase().GetSpellInfo()); + } + public override void DamageTaken(Unit attacker, ref uint damage, DamageEffectType damageType, SpellInfo spellInfo = null) { GetScript().ProcessEventsFor(SmartEvents.Damaged, attacker, damage); diff --git a/Source/Game/AI/SmartScripts/SmartAIManager.cs b/Source/Game/AI/SmartScripts/SmartAIManager.cs index ce8d220d2..ca1758415 100644 --- a/Source/Game/AI/SmartScripts/SmartAIManager.cs +++ b/Source/Game/AI/SmartScripts/SmartAIManager.cs @@ -628,6 +628,8 @@ namespace Game.AI SmartEvents.OnSpellCast => Marshal.SizeOf(typeof(SmartEvent.SpellCast)), SmartEvents.OnSpellFailed => Marshal.SizeOf(typeof(SmartEvent.SpellCast)), SmartEvents.OnSpellStart => Marshal.SizeOf(typeof(SmartEvent.SpellCast)), + SmartEvents.OnAuraApplied => Marshal.SizeOf(typeof(SmartEvent.SpellCast)), + SmartEvents.OnAuraRemoved => Marshal.SizeOf(typeof(SmartEvent.SpellCast)), SmartEvents.OnDespawn => 0, SmartEvents.SendEventTrigger => 0, SmartEvents.AreatriggerExit => 0, @@ -1056,6 +1058,8 @@ namespace Game.AI case SmartEvents.OnSpellCast: case SmartEvents.OnSpellFailed: case SmartEvents.OnSpellStart: + case SmartEvents.OnAuraApplied: + case SmartEvents.OnAuraRemoved: { if (!IsSpellValid(e, e.Event.spellCast.spell)) return false; @@ -2587,6 +2591,8 @@ namespace Game.AI SmartEvents.OnDespawn => SmartScriptTypeMaskId.Creature, SmartEvents.SendEventTrigger => SmartScriptTypeMaskId.Event, SmartEvents.AreatriggerExit => SmartScriptTypeMaskId.Areatrigger + SmartScriptTypeMaskId.AreatrigggerEntity, + SmartEvents.OnAuraApplied => SmartScriptTypeMaskId.Creature, + SmartEvents.OnAuraRemoved => SmartScriptTypeMaskId.Creature, _ => 0, }; diff --git a/Source/Game/AI/SmartScripts/SmartScript.cs b/Source/Game/AI/SmartScripts/SmartScript.cs index 5b139152a..008bfd9e6 100644 --- a/Source/Game/AI/SmartScripts/SmartScript.cs +++ b/Source/Game/AI/SmartScripts/SmartScript.cs @@ -3500,6 +3500,8 @@ namespace Game.AI case SmartEvents.OnSpellCast: case SmartEvents.OnSpellFailed: case SmartEvents.OnSpellStart: + case SmartEvents.OnAuraApplied: + case SmartEvents.OnAuraRemoved: { if (spell == null) return; diff --git a/Source/Game/Spells/Auras/Aura.cs b/Source/Game/Spells/Auras/Aura.cs index 023d6983d..4ce7d4309 100644 --- a/Source/Game/Spells/Auras/Aura.cs +++ b/Source/Game/Spells/Auras/Aura.cs @@ -1486,6 +1486,19 @@ namespace Game.Spells } break; } + + Creature creature = target.ToCreature(); + if (creature != null) + { + var ai = creature.GetAI(); + if (ai != null) + { + if (apply) + ai.OnAuraApplied(aurApp); + else + ai.OnAuraRemoved(aurApp); + } + } } bool CanBeAppliedOn(Unit target)