check bot and target world-state before spell creation and before prepare

This commit is contained in:
bash
2025-10-09 01:36:08 +02:00
parent e00c8fca2a
commit 7cf0ebe328

View File

@@ -3402,8 +3402,14 @@ bool PlayerbotAI::CastSpell(uint32 spellId, Unit* target, Item* itemTarget)
return false;
}
Spell* spell = new Spell(bot, spellInfo, TRIGGERED_NONE);
// early bot/target world-state check before spell creationg a spell, after pet
if (!bot->IsInWorld() || bot->IsDuringRemoveFromWorld() ||
(target && (!target->IsInWorld() || target->IsDuringRemoveFromWorld())))
{
return false;
}
Spell* spell = new Spell(bot, spellInfo, TRIGGERED_NONE);
SpellCastTargets targets;
if (spellInfo->Effects[0].Effect != SPELL_EFFECT_OPEN_LOCK &&
(spellInfo->Targets & TARGET_FLAG_ITEM || spellInfo->Targets & TARGET_FLAG_GAMEOBJECT_ITEM))
@@ -3491,6 +3497,15 @@ bool PlayerbotAI::CastSpell(uint32 spellId, Unit* target, Item* itemTarget)
// if (spellSuccess != SPELL_CAST_OK)
// return false;
// check bot/target world-state just before preparing the actual spel
Unit* unitTarget = targets.GetUnitTarget();
if (!bot->IsInWorld() || bot->IsDuringRemoveFromWorld() ||
(unitTarget && (!unitTarget->IsInWorld() || unitTarget->IsDuringRemoveFromWorld())))
{
delete spell;
return false;
}
SpellCastResult result = spell->prepare(&targets);
if (result != SPELL_CAST_OK)