aboutsummaryrefslogtreecommitdiff
path: root/src/server/game/AI/SmartScripts
diff options
context:
space:
mode:
authoroffl <11556157+offl@users.noreply.github.com>2022-02-18 19:14:44 +0200
committerGitHub <noreply@github.com>2022-02-18 19:14:44 +0200
commit3dca705acc953d20e4a43d4c2b3c97a84e5ab346 (patch)
tree40e929c09e081a195ecc3ab2eba8df09cd38cd2c /src/server/game/AI/SmartScripts
parent410c3ff25f1484858263255bd3433f52280fa8ec (diff)
Core/AI: OnSpellCast, OnSpellFailed, OnSpellStart hooks (#27704)
Diffstat (limited to 'src/server/game/AI/SmartScripts')
-rw-r--r--src/server/game/AI/SmartScripts/SmartAI.cpp15
-rw-r--r--src/server/game/AI/SmartScripts/SmartAI.h9
-rw-r--r--src/server/game/AI/SmartScripts/SmartScript.cpp14
-rw-r--r--src/server/game/AI/SmartScripts/SmartScriptMgr.cpp14
-rw-r--r--src/server/game/AI/SmartScripts/SmartScriptMgr.h15
5 files changed, 66 insertions, 1 deletions
diff --git a/src/server/game/AI/SmartScripts/SmartAI.cpp b/src/server/game/AI/SmartScripts/SmartAI.cpp
index 7a9bb9c0f2c..751337ca3d1 100644
--- a/src/server/game/AI/SmartScripts/SmartAI.cpp
+++ b/src/server/game/AI/SmartScripts/SmartAI.cpp
@@ -619,6 +619,21 @@ void SmartAI::SpellHitTarget(WorldObject* target, SpellInfo const* spellInfo)
GetScript()->ProcessEventsFor(SMART_EVENT_SPELLHIT_TARGET, target->ToUnit(), 0, 0, false, spellInfo, target->ToGameObject());
}
+void SmartAI::OnSpellCast(SpellInfo const* spellInfo)
+{
+ GetScript()->ProcessEventsFor(SMART_EVENT_ON_SPELL_CAST, nullptr, 0, 0, false, spellInfo);
+}
+
+void SmartAI::OnSpellFailed(SpellInfo const* spellInfo)
+{
+ GetScript()->ProcessEventsFor(SMART_EVENT_ON_SPELL_FAILED, nullptr, 0, 0, false, spellInfo);
+}
+
+void SmartAI::OnSpellStart(SpellInfo const* spellInfo)
+{
+ GetScript()->ProcessEventsFor(SMART_EVENT_ON_SPELL_START, nullptr, 0, 0, false, spellInfo);
+}
+
void SmartAI::DamageTaken(Unit* doneBy, uint32& damage, DamageEffectType /*damageType*/, SpellInfo const* /*spellInfo = nullptr*/)
{
GetScript()->ProcessEventsFor(SMART_EVENT_DAMAGED, doneBy, damage);
diff --git a/src/server/game/AI/SmartScripts/SmartAI.h b/src/server/game/AI/SmartScripts/SmartAI.h
index fce124740b2..f18316abf38 100644
--- a/src/server/game/AI/SmartScripts/SmartAI.h
+++ b/src/server/game/AI/SmartScripts/SmartAI.h
@@ -123,6 +123,15 @@ class TC_GAME_API SmartAI : public CreatureAI
// Called when spell hits a target
void SpellHitTarget(WorldObject* target, SpellInfo const* spellInfo) override;
+ // Called when a spell finishes
+ void OnSpellCast(SpellInfo const* spellInfo) override;
+
+ // Called when a spell fails
+ void OnSpellFailed(SpellInfo const* spellInfo) override;
+
+ // Called when a spell starts
+ void OnSpellStart(SpellInfo const* spellInfo) override;
+
// Called at any Damage from any attacker (before damage apply)
void DamageTaken(Unit* doneBy, uint32& damage, DamageEffectType /*damageType*/, SpellInfo const* /*spellInfo = nullptr*/) override;
diff --git a/src/server/game/AI/SmartScripts/SmartScript.cpp b/src/server/game/AI/SmartScripts/SmartScript.cpp
index ad5303a428f..b9aa990a071 100644
--- a/src/server/game/AI/SmartScripts/SmartScript.cpp
+++ b/src/server/game/AI/SmartScripts/SmartScript.cpp
@@ -2930,6 +2930,20 @@ void SmartScript::ProcessEvent(SmartScriptHolder& e, Unit* unit, uint32 var0, ui
}
break;
}
+ case SMART_EVENT_ON_SPELL_CAST:
+ case SMART_EVENT_ON_SPELL_FAILED:
+ case SMART_EVENT_ON_SPELL_START:
+ {
+ if (!spell)
+ return;
+
+ if (spell->Id != e.event.spellCast.spell)
+ return;
+
+ RecalcTimer(e, e.event.spellCast.cooldownMin, e.event.spellCast.cooldownMax);
+ ProcessAction(e, nullptr, 0, 0, bvar, spell);
+ break;
+ }
case SMART_EVENT_OOC_LOS:
{
if (!me || me->IsEngaged())
diff --git a/src/server/game/AI/SmartScripts/SmartScriptMgr.cpp b/src/server/game/AI/SmartScripts/SmartScriptMgr.cpp
index 9139c09867f..e7fb0dcbf63 100644
--- a/src/server/game/AI/SmartScripts/SmartScriptMgr.cpp
+++ b/src/server/game/AI/SmartScripts/SmartScriptMgr.cpp
@@ -769,6 +769,9 @@ bool SmartAIMgr::CheckUnusedEventParams(SmartScriptHolder const& e)
//case SMART_EVENT_SCENE_CANCEL: return sizeof(SmartEvent::raw);
//case SMART_EVENT_SCENE_COMPLETE: return sizeof(SmartEvent::raw);
case SMART_EVENT_SUMMONED_UNIT_DIES: return sizeof(SmartEvent::summoned);
+ 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);
default:
TC_LOG_WARN("sql.sql", "SmartAIMgr: Entry %d SourceType %u Event %u Action %u is using an event with no unused params specified in SmartAIMgr::CheckUnusedEventParams(), please report this.",
e.entryOrGuid, e.GetScriptType(), e.event_id, e.GetActionType());
@@ -1099,6 +1102,17 @@ bool SmartAIMgr::IsEventValid(SmartScriptHolder& e)
if (!IsMinMaxValid(e, e.event.spellHit.cooldownMin, e.event.spellHit.cooldownMax))
return false;
break;
+ case SMART_EVENT_ON_SPELL_CAST:
+ case SMART_EVENT_ON_SPELL_FAILED:
+ case SMART_EVENT_ON_SPELL_START:
+ {
+ if (!IsSpellValid(e, e.event.spellCast.spell))
+ return false;
+
+ if (!IsMinMaxValid(e, e.event.spellCast.cooldownMin, e.event.spellCast.cooldownMax))
+ return false;
+ break;
+ }
case SMART_EVENT_OOC_LOS:
case SMART_EVENT_IC_LOS:
if (!IsMinMaxValid(e, e.event.los.cooldownMin, e.event.los.cooldownMax))
diff --git a/src/server/game/AI/SmartScripts/SmartScriptMgr.h b/src/server/game/AI/SmartScripts/SmartScriptMgr.h
index 25c3a10c078..a6ca8b46f57 100644
--- a/src/server/game/AI/SmartScripts/SmartScriptMgr.h
+++ b/src/server/game/AI/SmartScripts/SmartScriptMgr.h
@@ -182,8 +182,11 @@ enum SMART_EVENT
SMART_EVENT_SCENE_CANCEL = 80, // don't use on 3.3.5a
SMART_EVENT_SCENE_COMPLETE = 81, // don't use on 3.3.5a
SMART_EVENT_SUMMONED_UNIT_DIES = 82, // CreatureId(0 all), CooldownMin, CooldownMax
+ SMART_EVENT_ON_SPELL_CAST = 83, // SpellID, CooldownMin, CooldownMax
+ SMART_EVENT_ON_SPELL_FAILED = 84, // SpellID, CooldownMin, CooldownMax
+ SMART_EVENT_ON_SPELL_START = 85, // SpellID, CooldownMin, CooldownMax
- SMART_EVENT_END = 83
+ SMART_EVENT_END = 86
};
struct SmartEvent
@@ -410,6 +413,13 @@ struct SmartEvent
struct
{
+ uint32 spell;
+ uint32 cooldownMin;
+ uint32 cooldownMax;
+ } spellCast;
+
+ struct
+ {
uint32 param1;
uint32 param2;
uint32 param3;
@@ -1498,6 +1508,9 @@ const uint32 SmartAIEventMask[SMART_EVENT_END][2] =
{SMART_EVENT_SCENE_CANCEL, 0 },
{SMART_EVENT_SCENE_COMPLETE, 0 },
{SMART_EVENT_SUMMONED_UNIT_DIES, SMART_SCRIPT_TYPE_MASK_CREATURE + SMART_SCRIPT_TYPE_MASK_GAMEOBJECT },
+ {SMART_EVENT_ON_SPELL_CAST, SMART_SCRIPT_TYPE_MASK_CREATURE },
+ {SMART_EVENT_ON_SPELL_FAILED, SMART_SCRIPT_TYPE_MASK_CREATURE },
+ {SMART_EVENT_ON_SPELL_START, SMART_SCRIPT_TYPE_MASK_CREATURE },
};
enum SmartEventFlags