Core/AI: Implement OnAuraApplied and OnAuraRemoved hooks (#31288)

Closes #26894

(cherry picked from commit 3bb4f5677359e3af9fe4b80e42157816786dca49)
This commit is contained in:
offl
2025-10-04 13:21:02 +02:00
committed by ModoX
parent 3f80825c00
commit d1e07ac655
7 changed files with 49 additions and 2 deletions
+7
View File
@@ -26,6 +26,7 @@
class AreaBoundary; class AreaBoundary;
class AreaTrigger; class AreaTrigger;
class AuraApplication;
class Creature; class Creature;
class DynamicObject; class DynamicObject;
class GameObject; class GameObject;
@@ -144,6 +145,12 @@ class TC_GAME_API CreatureAI : public UnitAI
// Called when a channeled spell finishes // Called when a channeled spell finishes
virtual void OnChannelFinished(SpellInfo const* /*spell*/) { } virtual void OnChannelFinished(SpellInfo const* /*spell*/) { }
// Called when aura is applied
virtual void OnAuraApplied(AuraApplication const* /*aurApp*/) { }
// Called when aura is removed
virtual void OnAuraRemoved(AuraApplication const* /*aurApp*/) { }
// Should return true if the NPC is currently being escorted // Should return true if the NPC is currently being escorted
virtual bool IsEscorted() const { return false; } virtual bool IsEscorted() const { return false; }
@@ -29,6 +29,7 @@
#include "PetDefines.h" #include "PetDefines.h"
#include "Player.h" #include "Player.h"
#include "ScriptMgr.h" #include "ScriptMgr.h"
#include "SpellAuras.h"
#include "Vehicle.h" #include "Vehicle.h"
#include "WaypointManager.h" #include "WaypointManager.h"
@@ -611,6 +612,16 @@ void SmartAI::OnSpellStart(SpellInfo const* spellInfo)
GetScript()->ProcessEventsFor(SMART_EVENT_ON_SPELL_START, nullptr, 0, 0, false, spellInfo); GetScript()->ProcessEventsFor(SMART_EVENT_ON_SPELL_START, nullptr, 0, 0, false, spellInfo);
} }
void SmartAI::OnAuraApplied(AuraApplication const* aurApp)
{
GetScript()->ProcessEventsFor(SMART_EVENT_ON_AURA_APPLIED, nullptr, 0, 0, false, aurApp->GetBase()->GetSpellInfo());
}
void SmartAI::OnAuraRemoved(AuraApplication const* aurApp)
{
GetScript()->ProcessEventsFor(SMART_EVENT_ON_AURA_REMOVED, nullptr, 0, 0, false, aurApp->GetBase()->GetSpellInfo());
}
void SmartAI::DamageTaken(Unit* doneBy, uint32& damage, DamageEffectType /*damageType*/, SpellInfo const* /*spellInfo = nullptr*/) void SmartAI::DamageTaken(Unit* doneBy, uint32& damage, DamageEffectType /*damageType*/, SpellInfo const* /*spellInfo = nullptr*/)
{ {
GetScript()->ProcessEventsFor(SMART_EVENT_DAMAGED, doneBy, damage); GetScript()->ProcessEventsFor(SMART_EVENT_DAMAGED, doneBy, damage);
@@ -132,6 +132,12 @@ class TC_GAME_API SmartAI : public CreatureAI
// Called when a spell starts // Called when a spell starts
void OnSpellStart(SpellInfo const* spellInfo) override; void OnSpellStart(SpellInfo const* spellInfo) override;
// Called when aura is applied
void OnAuraApplied(AuraApplication const* aurApp) override;
// Called when aura is removed
void OnAuraRemoved(AuraApplication const* aurApp) override;
// Called at any Damage from any attacker (before damage apply) // Called at any Damage from any attacker (before damage apply)
void DamageTaken(Unit* doneBy, uint32& damage, DamageEffectType /*damageType*/, SpellInfo const* /*spellInfo = nullptr*/) override; void DamageTaken(Unit* doneBy, uint32& damage, DamageEffectType /*damageType*/, SpellInfo const* /*spellInfo = nullptr*/) override;
@@ -3366,6 +3366,8 @@ void SmartScript::ProcessEvent(SmartScriptHolder& e, Unit* unit, uint32 var0, ui
case SMART_EVENT_ON_SPELL_CAST: case SMART_EVENT_ON_SPELL_CAST:
case SMART_EVENT_ON_SPELL_FAILED: case SMART_EVENT_ON_SPELL_FAILED:
case SMART_EVENT_ON_SPELL_START: case SMART_EVENT_ON_SPELL_START:
case SMART_EVENT_ON_AURA_APPLIED:
case SMART_EVENT_ON_AURA_REMOVED:
{ {
if (!spell) if (!spell)
return; return;
@@ -844,6 +844,8 @@ bool SmartAIMgr::CheckUnusedEventParams(SmartScriptHolder const& e)
case SMART_EVENT_ON_SPELL_CAST: return sizeof(SmartEvent::spellCast); case SMART_EVENT_ON_SPELL_CAST: return sizeof(SmartEvent::spellCast);
case SMART_EVENT_ON_SPELL_FAILED: return sizeof(SmartEvent::spellCast); case SMART_EVENT_ON_SPELL_FAILED: return sizeof(SmartEvent::spellCast);
case SMART_EVENT_ON_SPELL_START: return sizeof(SmartEvent::spellCast); case SMART_EVENT_ON_SPELL_START: return sizeof(SmartEvent::spellCast);
case SMART_EVENT_ON_AURA_APPLIED: return sizeof(SmartEvent::spellCast);
case SMART_EVENT_ON_AURA_REMOVED: return sizeof(SmartEvent::spellCast);
case SMART_EVENT_ON_DESPAWN: return NO_PARAMS; case SMART_EVENT_ON_DESPAWN: return NO_PARAMS;
case SMART_EVENT_SEND_EVENT_TRIGGER: return NO_PARAMS; case SMART_EVENT_SEND_EVENT_TRIGGER: return NO_PARAMS;
case SMART_EVENT_AREATRIGGER_EXIT: return NO_PARAMS; case SMART_EVENT_AREATRIGGER_EXIT: return NO_PARAMS;
@@ -1255,6 +1257,8 @@ bool SmartAIMgr::IsEventValid(SmartScriptHolder& e)
case SMART_EVENT_ON_SPELL_CAST: case SMART_EVENT_ON_SPELL_CAST:
case SMART_EVENT_ON_SPELL_FAILED: case SMART_EVENT_ON_SPELL_FAILED:
case SMART_EVENT_ON_SPELL_START: case SMART_EVENT_ON_SPELL_START:
case SMART_EVENT_ON_AURA_APPLIED:
case SMART_EVENT_ON_AURA_REMOVED:
{ {
if (!IsSpellValid(e, e.event.spellCast.spell)) if (!IsSpellValid(e, e.event.spellCast.spell))
return false; return false;
@@ -189,8 +189,10 @@ enum SMART_EVENT
SMART_EVENT_ON_DESPAWN = 86, // NONE SMART_EVENT_ON_DESPAWN = 86, // NONE
SMART_EVENT_SEND_EVENT_TRIGGER = 87, // NONE SMART_EVENT_SEND_EVENT_TRIGGER = 87, // NONE
SMART_EVENT_AREATRIGGER_EXIT = 88, // NONE SMART_EVENT_AREATRIGGER_EXIT = 88, // NONE
SMART_EVENT_ON_AURA_APPLIED = 89, // SpellID, CooldownMin, CooldownMax
SMART_EVENT_ON_AURA_REMOVED = 90, // SpellID, CooldownMin, CooldownMax
SMART_EVENT_END = 89 SMART_EVENT_END = 91
}; };
struct SmartEvent struct SmartEvent
@@ -1608,7 +1610,9 @@ const uint32 SmartAIEventMask[SMART_EVENT_END][2] =
{SMART_EVENT_ON_SPELL_START, SMART_SCRIPT_TYPE_MASK_CREATURE }, {SMART_EVENT_ON_SPELL_START, SMART_SCRIPT_TYPE_MASK_CREATURE },
{SMART_EVENT_ON_DESPAWN, SMART_SCRIPT_TYPE_MASK_CREATURE }, {SMART_EVENT_ON_DESPAWN, SMART_SCRIPT_TYPE_MASK_CREATURE },
{SMART_EVENT_SEND_EVENT_TRIGGER, SMART_SCRIPT_TYPE_MASK_EVENT }, {SMART_EVENT_SEND_EVENT_TRIGGER, SMART_SCRIPT_TYPE_MASK_EVENT },
{SMART_EVENT_AREATRIGGER_EXIT, SMART_SCRIPT_TYPE_MASK_AREATRIGGER + SMART_SCRIPT_TYPE_MASK_AREATRIGGER_ENTITY } {SMART_EVENT_AREATRIGGER_EXIT, SMART_SCRIPT_TYPE_MASK_AREATRIGGER + SMART_SCRIPT_TYPE_MASK_AREATRIGGER_ENTITY },
{SMART_EVENT_ON_AURA_APPLIED, SMART_SCRIPT_TYPE_MASK_CREATURE },
{SMART_EVENT_ON_AURA_REMOVED, SMART_SCRIPT_TYPE_MASK_CREATURE },
}; };
enum SmartEventFlags enum SmartEventFlags
@@ -1593,6 +1593,19 @@ void Aura::HandleAuraSpecificMods(AuraApplication const* aurApp, Unit* caster, b
} }
break; break;
} }
if (apply)
{
if (Creature* creature = target->ToCreature())
if (CreatureAI* ai = creature->AI())
ai->OnAuraApplied(aurApp);
}
else
{
if (Creature* creature = target->ToCreature())
if (CreatureAI* ai = creature->AI())
ai->OnAuraRemoved(aurApp);
}
} }
bool Aura::CanBeAppliedOn(Unit* target) bool Aura::CanBeAppliedOn(Unit* target)