From 3171cd3fa9dbcec43f5d70b74ab2f54a2aa44173 Mon Sep 17 00:00:00 2001 From: ForesterDev <11771800+ForesterDev@users.noreply.github.com> Date: Sun, 7 Jun 2020 11:22:13 +0300 Subject: 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) --- .../ScarletMonastery/boss_headless_horseman.cpp | 40 ++++++++++++++-------- .../boss_mograine_and_whitemane.cpp | 6 ++-- 2 files changed, 29 insertions(+), 17 deletions(-) (limited to 'src/server/scripts/EasternKingdoms/ScarletMonastery') diff --git a/src/server/scripts/EasternKingdoms/ScarletMonastery/boss_headless_horseman.cpp b/src/server/scripts/EasternKingdoms/ScarletMonastery/boss_headless_horseman.cpp index 800d63776d3..2effc6e0da3 100644 --- a/src/server/scripts/EasternKingdoms/ScarletMonastery/boss_headless_horseman.cpp +++ b/src/server/scripts/EasternKingdoms/ScarletMonastery/boss_headless_horseman.cpp @@ -205,7 +205,7 @@ struct npc_wisp_invis : public ScriptedAI DoCastSelf(_firstSpell); } - void SpellHit(Unit* /*caster*/, SpellInfo const* spellInfo) override + void SpellHit(WorldObject* /*caster*/, SpellInfo const* spellInfo) override { if (spellInfo->Id == SPELL_HEADLESS_HORSEMAN___WISP_FLIGHT_PORT && _creatureType == 4) me->SetDisplayId(DISPLAYID_INVIS_WISP_MAN); @@ -327,17 +327,21 @@ struct npc_head : public ScriptedAI } } - void SpellHit(Unit* caster, SpellInfo const* spell) override + void SpellHit(WorldObject* caster, SpellInfo const* spellInfo) override { + Unit* unitCaster = caster->ToUnit(); + if (!unitCaster) + return; + if (!_withBody) return; - if (spell->Id == SPELL_HEADLESS_HORSEMAN_CLIMAX___SEND_HEAD) + if (spellInfo->Id == SPELL_HEADLESS_HORSEMAN_CLIMAX___SEND_HEAD) { _withBody = false; if (!_bodyGUID) - _bodyGUID = caster->GetGUID(); + _bodyGUID = unitCaster->GetGUID(); me->RemoveAllAuras(); me->RemoveUnitFlag(UNIT_FLAG_NOT_SELECTABLE); @@ -348,9 +352,9 @@ struct npc_head : public ScriptedAI DoTalk(SAY_LOST_HEAD); - _scheduler.Schedule(2s, [caster, this](TaskContext /*context*/) + _scheduler.Schedule(2s, [unitCaster, this](TaskContext /*context*/) { - me->GetMotionMaster()->MoveFleeing(caster); + me->GetMotionMaster()->MoveFleeing(unitCaster); }); } } @@ -609,10 +613,14 @@ struct boss_headless_horseman : public ScriptedAI head->AI()->SetData(DATA_HEAD_TALK, SAY_PLAYER_DEATH); } - void SpellHitTarget(Unit* unit, SpellInfo const* spell) override + void SpellHitTarget(WorldObject* target, SpellInfo const* spellInfo) override { - if (spell->Id == SPELL_CONFLAGRATION && unit->HasAura(SPELL_CONFLAGRATION)) - DoTalk(SAY_CONFLAGRATION, unit); + Unit* unitTarget = target->ToUnit(); + if (!unitTarget) + return; + + if (spellInfo->Id == SPELL_CONFLAGRATION && unitTarget->HasAura(SPELL_CONFLAGRATION)) + DoTalk(SAY_CONFLAGRATION, unitTarget); } void JustDied(Unit* /*killer*/) override @@ -633,8 +641,12 @@ struct boss_headless_horseman : public ScriptedAI } } - void SpellHit(Unit* caster, SpellInfo const* spellInfo) override + void SpellHit(WorldObject* caster, SpellInfo const* spellInfo) override { + Unit* unitCaster = caster->ToUnit(); + if (!unitCaster) + return; + if (_withHead) return; @@ -652,8 +664,8 @@ struct boss_headless_horseman : public ScriptedAI DoTalk(SAY_REJOINED); DoCastSelf(SPELL_HEADLESS_HORSEMAN_CLIMAX___HEAD_VISUAL); - caster->GetMotionMaster()->Clear(); - caster->GetMotionMaster()->MoveFollow(me, 6.f, 0.f); + unitCaster->GetMotionMaster()->Clear(); + unitCaster->GetMotionMaster()->MoveFollow(me, 6.f, 0.f); switch (_phase) { @@ -830,9 +842,9 @@ struct npc_pulsing_pumpkin : public ScriptedAI me->AddUnitFlag(UNIT_FLAG_STUNNED); } - void SpellHit(Unit* /*caster*/, SpellInfo const* spell) override + void SpellHit(WorldObject* /*caster*/, SpellInfo const* spellInfo) override { - if (spell->Id == SPELL_SPROUTING) + if (spellInfo->Id == SPELL_SPROUTING) { _sprouted = true; me->RemoveAllAuras(); diff --git a/src/server/scripts/EasternKingdoms/ScarletMonastery/boss_mograine_and_whitemane.cpp b/src/server/scripts/EasternKingdoms/ScarletMonastery/boss_mograine_and_whitemane.cpp index f6a17c53a2f..3f2c21135c6 100644 --- a/src/server/scripts/EasternKingdoms/ScarletMonastery/boss_mograine_and_whitemane.cpp +++ b/src/server/scripts/EasternKingdoms/ScarletMonastery/boss_mograine_and_whitemane.cpp @@ -181,10 +181,10 @@ public: damage = 0; } - void SpellHit(Unit* /*who*/, SpellInfo const* spell) override + void SpellHit(WorldObject* /*caster*/, SpellInfo const* spellInfo) override { // Casted from Whitemane - if (spell->Id == SPELL_SCARLET_RESURRECTION) + if (spellInfo->Id == SPELL_SCARLET_RESURRECTION) { scheduler.Schedule(3s, [this](TaskContext /*context*/) { @@ -400,7 +400,7 @@ public: }); } - void SpellHitTarget(Unit* target, SpellInfo const* spellInfo) override + void SpellHitTarget(WorldObject* target, SpellInfo const* spellInfo) override { if (target->GetEntry() == NPC_MOGRAINE && spellInfo->Id == SPELL_SCARLET_RESURRECTION) MograineResurrected(); -- cgit v1.2.3