aboutsummaryrefslogtreecommitdiff
path: root/src/server/game
diff options
context:
space:
mode:
authorForesterDev <11771800+ForesterDev@users.noreply.github.com>2020-06-07 11:22:13 +0300
committerShauren <shauren.trinity@gmail.com>2022-01-06 20:46:25 +0100
commit3171cd3fa9dbcec43f5d70b74ab2f54a2aa44173 (patch)
tree838c54078c04b1fdae4ec1aac6fdc70ebdae45b2 /src/server/game
parentf0242d4ec7857a18145dd0a9965fcb8526e981c8 (diff)
Core/AI: refactor SpellHit and SpellHitTarget. (#24691)
* Core/AI: refactor SpellHit and SpellHitTarget. - now caster/target is WorldObject instead of Unit - remove SpellHitByGameObject / SpellHitTargetGameObject (handled by SpellHit / SpellHitTarget) - rename parameters in scripts according parent methods * Restore logic in Algalon script * Changed check for REMORSELESS_WINTER hit to avoid dublicate call, because it has TARGET_UNIT_CASTER for effects 0/1 and TARGET_GAMEOBJECT_SRC_AREA for effect 2 * Fix build after merge (cherry picked from commit e3b232fe0e5c21a87d3fe71813e9d750259823f1)
Diffstat (limited to 'src/server/game')
-rw-r--r--src/server/game/AI/CoreAI/GameObjectAI.h6
-rw-r--r--src/server/game/AI/CreatureAI.h6
-rw-r--r--src/server/game/AI/SmartScripts/SmartAI.cpp22
-rw-r--r--src/server/game/AI/SmartScripts/SmartAI.h10
-rw-r--r--src/server/game/Spells/Spell.cpp20
5 files changed, 20 insertions, 44 deletions
diff --git a/src/server/game/AI/CoreAI/GameObjectAI.h b/src/server/game/AI/CoreAI/GameObjectAI.h
index 8a28e192a65..7ba7d955bc4 100644
--- a/src/server/game/AI/CoreAI/GameObjectAI.h
+++ b/src/server/game/AI/CoreAI/GameObjectAI.h
@@ -97,12 +97,10 @@ class TC_GAME_API GameObjectAI
virtual void EventInform(uint32 /*eventId*/) { }
// Called when hit by a spell
- virtual void SpellHit(Unit* /*caster*/, SpellInfo const* /*spellInfo*/) { }
- virtual void SpellHitByGameObject(GameObject* /*caster*/, SpellInfo const* /*spellInfo*/) { }
+ virtual void SpellHit(WorldObject* /*caster*/, SpellInfo const* /*spellInfo*/) { }
// Called when spell hits a target
- virtual void SpellHitTarget(Unit* /*target*/, SpellInfo const* /*spellInfo*/) { }
- virtual void SpellHitTargetGameObject(GameObject* /*target*/, SpellInfo const* /*spellInfo*/) { }
+ virtual void SpellHitTarget(WorldObject* /*target*/, SpellInfo const* /*spellInfo*/) { }
// Called when the gameobject summon successfully other creature
virtual void JustSummoned(Creature* /*summon*/) { }
diff --git a/src/server/game/AI/CreatureAI.h b/src/server/game/AI/CreatureAI.h
index 1b6c9cce090..53f2e71e2bf 100644
--- a/src/server/game/AI/CreatureAI.h
+++ b/src/server/game/AI/CreatureAI.h
@@ -134,12 +134,10 @@ class TC_GAME_API CreatureAI : public UnitAI
virtual void JustUnregisteredAreaTrigger(AreaTrigger* /*areaTrigger*/) { }
// Called when hit by a spell
- virtual void SpellHit(Unit* /*caster*/, SpellInfo const* /*spellInfo*/) { }
- virtual void SpellHitByGameObject(GameObject* /*caster*/, SpellInfo const* /*spellInfo*/) { }
+ virtual void SpellHit(WorldObject* /*caster*/, SpellInfo const* /*spellInfo*/) { }
// Called when spell hits a target
- virtual void SpellHitTarget(Unit* /*target*/, SpellInfo const* /*spellInfo*/) { }
- virtual void SpellHitTargetGameObject(GameObject* /*target*/, SpellInfo const* /*spellInfo*/) { }
+ virtual void SpellHitTarget(WorldObject* /*target*/, SpellInfo const* /*spellInfo*/) { }
// Called when a spell cast gets interrupted
virtual void OnSpellCastInterrupt(SpellInfo const* /*spell*/) { }
diff --git a/src/server/game/AI/SmartScripts/SmartAI.cpp b/src/server/game/AI/SmartScripts/SmartAI.cpp
index a26aa46f5bf..40cf810295e 100644
--- a/src/server/game/AI/SmartScripts/SmartAI.cpp
+++ b/src/server/game/AI/SmartScripts/SmartAI.cpp
@@ -615,24 +615,14 @@ void SmartAI::AttackStart(Unit* who)
}
}
-void SmartAI::SpellHit(Unit* unit, SpellInfo const* spellInfo)
+void SmartAI::SpellHit(WorldObject* caster, SpellInfo const* spellInfo)
{
- GetScript()->ProcessEventsFor(SMART_EVENT_SPELLHIT, unit, 0, 0, false, spellInfo);
+ GetScript()->ProcessEventsFor(SMART_EVENT_SPELLHIT, caster->ToUnit(), 0, 0, false, spellInfo, caster->ToGameObject());
}
-void SmartAI::SpellHitByGameObject(GameObject* object, SpellInfo const* spellInfo)
+void SmartAI::SpellHitTarget(WorldObject* target, SpellInfo const* spellInfo)
{
- GetScript()->ProcessEventsFor(SMART_EVENT_SPELLHIT, nullptr, 0, 0, false, spellInfo, object);
-}
-
-void SmartAI::SpellHitTarget(Unit* target, SpellInfo const* spellInfo)
-{
- GetScript()->ProcessEventsFor(SMART_EVENT_SPELLHIT_TARGET, target, 0, 0, false, spellInfo);
-}
-
-void SmartAI::SpellHitTargetGameObject(GameObject* target, SpellInfo const* spellInfo)
-{
- GetScript()->ProcessEventsFor(SMART_EVENT_SPELLHIT_TARGET, nullptr, 0, 0, false, spellInfo, target);
+ GetScript()->ProcessEventsFor(SMART_EVENT_SPELLHIT_TARGET, target->ToUnit(), 0, 0, false, spellInfo, target->ToGameObject());
}
void SmartAI::DamageTaken(Unit* doneBy, uint32& damage)
@@ -1102,9 +1092,9 @@ void SmartGameObjectAI::EventInform(uint32 eventId)
GetScript()->ProcessEventsFor(SMART_EVENT_GO_EVENT_INFORM, nullptr, eventId);
}
-void SmartGameObjectAI::SpellHit(Unit* unit, SpellInfo const* spellInfo)
+void SmartGameObjectAI::SpellHit(WorldObject* caster, SpellInfo const* spellInfo)
{
- GetScript()->ProcessEventsFor(SMART_EVENT_SPELLHIT, unit, 0, 0, false, spellInfo);
+ GetScript()->ProcessEventsFor(SMART_EVENT_SPELLHIT, caster->ToUnit(), 0, 0, false, spellInfo);
}
void SmartGameObjectAI::JustSummoned(Creature* creature)
diff --git a/src/server/game/AI/SmartScripts/SmartAI.h b/src/server/game/AI/SmartScripts/SmartAI.h
index bc112d8641f..9ecf7703def 100644
--- a/src/server/game/AI/SmartScripts/SmartAI.h
+++ b/src/server/game/AI/SmartScripts/SmartAI.h
@@ -99,12 +99,10 @@ class TC_GAME_API SmartAI : public CreatureAI
void MoveInLineOfSight(Unit* who) override;
// Called when hit by a spell
- void SpellHit(Unit* unit, SpellInfo const* spellInfo) override;
- void SpellHitByGameObject(GameObject* object, SpellInfo const* spellInfo) override;
+ void SpellHit(WorldObject* caster, SpellInfo const* spellInfo) override;
// Called when spell hits a target
- void SpellHitTarget(Unit* target, SpellInfo const* spellInfo) override;
- void SpellHitTargetGameObject(GameObject* object, SpellInfo const* spellInfo) override;
+ void SpellHitTarget(WorldObject* target, SpellInfo const* spellInfo) override;
// Called at any Damage from any attacker (before damage apply)
void DamageTaken(Unit* doneBy, uint32& damage) override;
@@ -270,7 +268,9 @@ class TC_GAME_API SmartGameObjectAI : public GameObjectAI
void OnGameEvent(bool start, uint16 eventId) override;
void OnLootStateChanged(uint32 state, Unit* unit) override;
void EventInform(uint32 eventId) override;
- void SpellHit(Unit* unit, SpellInfo const* spellInfo) override;
+
+ // Called when hit by a spell
+ void SpellHit(WorldObject* caster, SpellInfo const* spellInfo) override;
// Called when the gameobject summon successfully other creature
void JustSummoned(Creature* creature) override;
diff --git a/src/server/game/Spells/Spell.cpp b/src/server/game/Spells/Spell.cpp
index 4690176be01..4975457c2d6 100644
--- a/src/server/game/Spells/Spell.cpp
+++ b/src/server/game/Spells/Spell.cpp
@@ -2695,12 +2695,7 @@ void Spell::TargetInfo::DoDamageAndTriggers(Spell* spell)
//AI functions
if (Creature* cHitTarget = _spellHitTarget->ToCreature())
if (CreatureAI* hitTargetAI = cHitTarget->AI())
- {
- if (spell->m_caster->GetTypeId() == TYPEID_GAMEOBJECT)
- hitTargetAI->SpellHitByGameObject(spell->m_caster->ToGameObject(), spell->m_spellInfo);
- else
- hitTargetAI->SpellHit(spell->m_caster->ToUnit(), spell->m_spellInfo);
- }
+ hitTargetAI->SpellHit(spell->m_caster, spell->m_spellInfo);
if (spell->m_caster->GetTypeId() == TYPEID_UNIT && spell->m_caster->ToCreature()->IsAIEnabled())
spell->m_caster->ToCreature()->AI()->SpellHitTarget(_spellHitTarget, spell->m_spellInfo);
@@ -2744,19 +2739,14 @@ void Spell::GOTargetInfo::DoTargetSpellHit(Spell* spell, SpellEffectInfo const&
spell->HandleEffects(nullptr, nullptr, go, spellEffectInfo, SPELL_EFFECT_HANDLE_HIT_TARGET);
- //AI functions
+ // AI functions
if (go->AI())
- {
- if (spell->m_caster->GetTypeId() == TYPEID_GAMEOBJECT)
- go->AI()->SpellHitByGameObject(spell->m_caster->ToGameObject(), spell->m_spellInfo);
- else
- go->AI()->SpellHit(spell->m_caster->ToUnit(), spell->m_spellInfo);
- }
+ go->AI()->SpellHit(spell->m_caster, spell->m_spellInfo);
if (spell->m_caster->GetTypeId() == TYPEID_UNIT && spell->m_caster->ToCreature()->IsAIEnabled())
- spell->m_caster->ToCreature()->AI()->SpellHitTargetGameObject(go, spell->m_spellInfo);
+ spell->m_caster->ToCreature()->AI()->SpellHitTarget(go, spell->m_spellInfo);
else if (spell->m_caster->GetTypeId() == TYPEID_GAMEOBJECT && spell->m_caster->ToGameObject()->AI())
- spell->m_caster->ToGameObject()->AI()->SpellHitTargetGameObject(go, spell->m_spellInfo);
+ spell->m_caster->ToGameObject()->AI()->SpellHitTarget(go, spell->m_spellInfo);
spell->CallScriptOnHitHandlers();
spell->CallScriptAfterHitHandlers();