mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-01-15 23:20:36 +01:00
Core/AI: Implement OnAuraApplied and OnAuraRemoved hooks (#31288)
Closes #26894
(cherry picked from commit 3bb4f56773)
This commit is contained in:
@@ -26,6 +26,7 @@
|
||||
|
||||
class AreaBoundary;
|
||||
class AreaTrigger;
|
||||
class AuraApplication;
|
||||
class Creature;
|
||||
class DynamicObject;
|
||||
class GameObject;
|
||||
@@ -144,6 +145,12 @@ class TC_GAME_API CreatureAI : public UnitAI
|
||||
// Called when a channeled spell finishes
|
||||
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
|
||||
virtual bool IsEscorted() const { return false; }
|
||||
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
#include "PetDefines.h"
|
||||
#include "Player.h"
|
||||
#include "ScriptMgr.h"
|
||||
#include "SpellAuras.h"
|
||||
#include "Vehicle.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);
|
||||
}
|
||||
|
||||
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*/)
|
||||
{
|
||||
GetScript()->ProcessEventsFor(SMART_EVENT_DAMAGED, doneBy, damage);
|
||||
|
||||
@@ -132,6 +132,12 @@ class TC_GAME_API SmartAI : public CreatureAI
|
||||
// Called when a spell starts
|
||||
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)
|
||||
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_FAILED:
|
||||
case SMART_EVENT_ON_SPELL_START:
|
||||
case SMART_EVENT_ON_AURA_APPLIED:
|
||||
case SMART_EVENT_ON_AURA_REMOVED:
|
||||
{
|
||||
if (!spell)
|
||||
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_FAILED: 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_SEND_EVENT_TRIGGER: 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_FAILED:
|
||||
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))
|
||||
return false;
|
||||
|
||||
@@ -189,8 +189,10 @@ enum SMART_EVENT
|
||||
SMART_EVENT_ON_DESPAWN = 86, // NONE
|
||||
SMART_EVENT_SEND_EVENT_TRIGGER = 87, // 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
|
||||
@@ -1608,7 +1610,9 @@ const uint32 SmartAIEventMask[SMART_EVENT_END][2] =
|
||||
{SMART_EVENT_ON_SPELL_START, 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_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
|
||||
|
||||
@@ -1593,6 +1593,19 @@ void Aura::HandleAuraSpecificMods(AuraApplication const* aurApp, Unit* caster, b
|
||||
}
|
||||
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)
|
||||
|
||||
Reference in New Issue
Block a user