From 7cf0ebe3286b04ba00540344811ff392a3dc2d98 Mon Sep 17 00:00:00 2001 From: bash Date: Thu, 9 Oct 2025 01:36:08 +0200 Subject: [PATCH] check bot and target world-state before spell creation and before prepare --- src/PlayerbotAI.cpp | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/PlayerbotAI.cpp b/src/PlayerbotAI.cpp index 9019724e..395a18eb 100644 --- a/src/PlayerbotAI.cpp +++ b/src/PlayerbotAI.cpp @@ -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)