From ae99ce586a57e64c921437f8d6c01c20af002a97 Mon Sep 17 00:00:00 2001 From: Skjalf <47818697+Nyeriah@users.noreply.github.com> Date: Tue, 26 Sep 2023 18:27:23 -0300 Subject: [PATCH] fix(Scripts/Karazhan): Fix Aran combat movement behavior (#17359) * fix(Scripts/Karazhan): Fix Aran combat movement behavior * Update SmartScript.cpp --- src/server/game/Entities/Creature/Creature.cpp | 18 ++++++++++++++++++ src/server/game/Entities/Creature/Creature.h | 6 ++++++ .../Karazhan/boss_shade_of_aran.cpp | 15 ++++++++++++++- 3 files changed, 38 insertions(+), 1 deletion(-) diff --git a/src/server/game/Entities/Creature/Creature.cpp b/src/server/game/Entities/Creature/Creature.cpp index f8a41cc57..8340fbc72 100644 --- a/src/server/game/Entities/Creature/Creature.cpp +++ b/src/server/game/Entities/Creature/Creature.cpp @@ -3707,6 +3707,24 @@ uint32 Creature::GetPlayerDamageReq() const return _playerDamageReq; } +bool Creature::CanCastSpell(uint32 spellID) const +{ + SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(spellID); + int32 currentPower = GetPower(getPowerType()); + + if (HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_SILENCED) || IsSpellProhibited(spellInfo->GetSchoolMask())) + { + return false; + } + + if (spellInfo && (currentPower < spellInfo->CalcPowerCost(this, spellInfo->GetSchoolMask()))) + { + return false; + } + + return true; +} + std::string Creature::GetDebugInfo() const { std::stringstream sstr; diff --git a/src/server/game/Entities/Creature/Creature.h b/src/server/game/Entities/Creature/Creature.h index c7c3102a1..d0a6b8b72 100644 --- a/src/server/game/Entities/Creature/Creature.h +++ b/src/server/game/Entities/Creature/Creature.h @@ -399,6 +399,12 @@ public: * */ void ResumeChasingVictim() { GetMotionMaster()->MoveChase(GetVictim()); }; + /** + * @brief Returns true if the creature is able to cast the spell. + * + * */ + bool CanCastSpell(uint32 spellID) const; + std::string GetDebugInfo() const override; protected: diff --git a/src/server/scripts/EasternKingdoms/Karazhan/boss_shade_of_aran.cpp b/src/server/scripts/EasternKingdoms/Karazhan/boss_shade_of_aran.cpp index fa75f1d3d..df45f50f1 100644 --- a/src/server/scripts/EasternKingdoms/Karazhan/boss_shade_of_aran.cpp +++ b/src/server/scripts/EasternKingdoms/Karazhan/boss_shade_of_aran.cpp @@ -256,7 +256,20 @@ struct boss_shade_of_aran : public BossAI if (AvailableSpells) { CurrentNormalSpell = Spells[rand() % AvailableSpells]; - DoCast(target, CurrentNormalSpell); + + if (!me->CanCastSpell(CurrentNormalSpell)) + { + me->SetWalk(false); + me->ResumeChasingVictim(); + } + else + { + DoCast(target, CurrentNormalSpell); + if (me->GetVictim()) + { + me->GetMotionMaster()->MoveChase(me->GetVictim(), 45.0f); + } + } } } context.Repeat(2s);