diff --git a/src/game/WorldHandlers/Spell.cpp b/src/game/WorldHandlers/Spell.cpp index 883420d0..aeb0d35f 100644 --- a/src/game/WorldHandlers/Spell.cpp +++ b/src/game/WorldHandlers/Spell.cpp @@ -4978,6 +4978,10 @@ SpellCastResult Spell::CheckCast(bool strict) lockId = go->GetGOInfo()->GetLockId(); if (!lockId) { return SPELL_FAILED_ALREADY_OPEN; } + + // Is the lock within the spell max range? + if (!IsLockInRange(go)) + { return SPELL_FAILED_OUT_OF_RANGE; } } else if (Item* item = m_targets.getItemTarget()) { @@ -5000,6 +5004,7 @@ SpellCastResult Spell::CheckCast(bool strict) // check lock compatibility SpellCastResult res = CanOpenLock(SpellEffectIndex(i), lockId, skillId, reqSkillValue, skillValue); + if (res != SPELL_CAST_OK) { return res; } @@ -6513,6 +6518,19 @@ bool SpellEvent::IsDeletable() const return m_Spell->IsDeletable(); } +bool Spell::IsLockInRange(GameObject* go) +{ + const SpellRangeEntry* srange = sSpellRangeStore.LookupEntry(m_spellInfo->rangeIndex); + + + // This check is not related to bounding radius + float dx = m_caster->GetPositionX() - go->GetPositionX(); + float dy = m_caster->GetPositionY() - go->GetPositionY(); + float dz = m_caster->GetPositionZ() - go->GetPositionZ(); + + return (dx * dx + dy * dy + dz * dz < srange->maxRange); +} + SpellCastResult Spell::CanOpenLock(SpellEffectIndex effIndex, uint32 lockId, SkillType& skillId, int32& reqSkillValue, int32& skillValue) { if (!lockId) // possible case for GO and maybe for items. diff --git a/src/game/WorldHandlers/Spell.h b/src/game/WorldHandlers/Spell.h index 13a91242..d924efc4 100644 --- a/src/game/WorldHandlers/Spell.h +++ b/src/game/WorldHandlers/Spell.h @@ -578,6 +578,7 @@ class Spell void DoAllEffectOnTarget(ItemTargetInfo* target); bool IsAliveUnitPresentInTargetList(); SpellCastResult CanOpenLock(SpellEffectIndex effIndex, uint32 lockid, SkillType& skillid, int32& reqSkillValue, int32& skillValue); + bool IsLockInRange(GameObject* go); SpellCastResult CanTameUnit(bool isGM = false); // -------------------------------------------