bool PlayerbotAI::CanCastSpell(uint32 spellid, Unit* target, bool checkHasSpell) { if (!spellid) return false; if (!target) target = bot; if (checkHasSpell && !bot->HasSpell(spellid)) return false; if (bot->HasSpellCooldown(spellid)) return false; bool positiveSpell = IsPositiveSpell(spellid); if (positiveSpell && bot->IsHostileTo(target)) return false; if (!positiveSpell && bot->IsFriendlyTo(target)) return false; SpellEntry const *spellInfo = sSpellStore.LookupEntry(spellid ); if (!spellInfo) return false; if (target->IsImmuneToSpell(spellInfo, false)) return false; if (bot != target && bot->GetDistance(target) > sPlayerbotAIConfig.sightDistance) return false; ObjectGuid oldSel = bot->GetSelectionGuid(); bot->SetSelectionGuid(target->GetObjectGuid()); Spell *spell = new Spell(bot, spellInfo, false ); spell->m_targets.setUnitTarget(target); spell->m_CastItem = aiObjectContext->GetValue<Item*>("item for spell", spellid)->Get(); spell->m_targets.setItemTarget(spell->m_CastItem); SpellCastResult result = spell->CheckCast(false); delete spell; bot->SetSelectionGuid(oldSel); switch (result) { case SPELL_FAILED_NOT_INFRONT: case SPELL_FAILED_NOT_STANDING: case SPELL_FAILED_UNIT_NOT_INFRONT: case SPELL_FAILED_MOVING: case SPELL_FAILED_TRY_AGAIN: case SPELL_FAILED_BAD_IMPLICIT_TARGETS: case SPELL_FAILED_BAD_TARGETS: case SPELL_CAST_OK: return true; default: return false; } }