diff --git a/src/server/scripts/Events/midsummer.cpp b/src/server/scripts/Events/midsummer.cpp index cb2fc42fb..b3e34e646 100644 --- a/src/server/scripts/Events/midsummer.cpp +++ b/src/server/scripts/Events/midsummer.cpp @@ -389,15 +389,23 @@ public: bool handled; bool Load() override { handled = false; return true; } + SpellCastResult CheckCast() + { + GetCaster()->GetCreaturesWithEntryInRange(_crList, 100.0f, NPC_TORCH_TARGET); + if (_crList.empty()) + { + return SPELL_FAILED_NOT_HERE; + } + + return SPELL_CAST_OK; + } + void ThrowNextTorch(Unit* caster) { - std::list crList; - caster->GetCreaturesWithEntryInRange(crList, 100.0f, NPC_TORCH_TARGET); - - uint8 rand = urand(0, crList.size() - 1); + uint8 rand = urand(0, _crList.size() - 1); Position pos; pos.Relocate(0.0f, 0.0f, 0.0f); - for (std::list::const_iterator itr = crList.begin(); itr != crList.end(); ++itr, --rand) + for (std::list::const_iterator itr = _crList.begin(); itr != _crList.end(); ++itr, --rand) { if (caster->GetDistance(*itr) < 5) { @@ -473,8 +481,14 @@ public: { AfterCast += SpellCastFn(spell_midsummer_fling_torch_SpellScript::HandleFinish); if (m_scriptSpellId == 45671) + { + OnCheckCast += SpellCheckCastFn(spell_midsummer_fling_torch_SpellScript::CheckCast); OnEffectHitTarget += SpellEffectFn(spell_midsummer_fling_torch_SpellScript::HandleScript, EFFECT_0, SPELL_EFFECT_SCRIPT_EFFECT); + } } + + private: + std::list _crList; }; SpellScript* GetSpellScript() const override