diff --git a/playerbot/PlayerbotAI.cpp b/playerbot/PlayerbotAI.cpp index 047c507e..b2423f63 100644 --- a/playerbot/PlayerbotAI.cpp +++ b/playerbot/PlayerbotAI.cpp @@ -4089,6 +4089,40 @@ bool PlayerbotAI::CastSpell(uint32 spellId, Unit* target, Item* itemTarget, bool StopMoving(); } + for (uint32 j = 0; j < MAX_EFFECT_INDEX; ++j) + { + uint8 slot = 0; + switch (pSpellInfo->Effect[j]) + { + case SPELL_EFFECT_SUMMON_OBJECT_SLOT1: slot = 0; break; + case SPELL_EFFECT_SUMMON_OBJECT_SLOT2: slot = 1; break; + case SPELL_EFFECT_SUMMON_OBJECT_SLOT3: slot = 2; break; + case SPELL_EFFECT_SUMMON_OBJECT_SLOT4: slot = 3; break; + default: continue; + } + + if (ObjectGuid guid = bot->m_ObjectSlotGuid[slot]) + { + if (GameObject* obj = bot ? bot->GetMap()->GetGameObject(guid) : nullptr) + { + //Object is not mine because I created an object with same guid on different map. + //Make object mine, remove it from my list and give it back to the original owner. + if (obj->GetOwnerGuid() != bot->GetObjectGuid()) + { + ObjectGuid ownerGuid = obj->GetOwnerGuid(); + obj->SetOwnerGuid(bot->GetObjectGuid()); + obj->SetLootState(GO_JUST_DEACTIVATED); + + bot->RemoveGameObject(obj, false, pSpellInfo->Id != obj->GetSpellId()); + bot->m_ObjectSlotGuid[slot].Clear(); + + obj->SetOwnerGuid(ownerGuid); + } + } + } + } + + SpellCastResult spellSuccess = spell->SpellStart(&targets); if (pSpellInfo->Effect[0] == SPELL_EFFECT_OPEN_LOCK || diff --git a/playerbot/strategy/actions/GenericSpellActions.cpp b/playerbot/strategy/actions/GenericSpellActions.cpp index d7ad7986..e9db7b49 100644 --- a/playerbot/strategy/actions/GenericSpellActions.cpp +++ b/playerbot/strategy/actions/GenericSpellActions.cpp @@ -58,52 +58,11 @@ bool CastSpellAction::Execute(Event& event) } else { - // Temporary fix for core crash - if (spellName == "freezing trap" || - spellName == "frost trap" || - spellName == "immolation trap" || - spellName == "explosive trap") + if (GetTargetName() == "current target" && (!bot->GetCurrentSpell(CURRENT_MELEE_SPELL) && !bot->GetCurrentSpell(CURRENT_AUTOREPEAT_SPELL))) { - uint32 spellId = AI_VALUE2(uint32,"spell id", spellName); - - const SpellEntry* pSpellInfo = sServerFacade.LookupSpellInfo(spellId); - if (!pSpellInfo) - return false; - - for (uint32 j = 0; j < MAX_EFFECT_INDEX; ++j) - { - uint8 slot = 0; - switch (pSpellInfo->Effect[j]) - { - case SPELL_EFFECT_SUMMON_OBJECT_SLOT1: slot = 0; break; - case SPELL_EFFECT_SUMMON_OBJECT_SLOT2: slot = 1; break; - case SPELL_EFFECT_SUMMON_OBJECT_SLOT3: slot = 2; break; - case SPELL_EFFECT_SUMMON_OBJECT_SLOT4: slot = 3; break; - default: continue; - } - - if (ObjectGuid guid = bot->m_ObjectSlotGuid[slot]) - { - if (GameObject* obj = bot ? bot->GetMap()->GetGameObject(guid) : nullptr) - { - obj->SetLootState(GO_JUST_DEACTIVATED); - - //if (obj->GetOwnerGuid() != bot->GetOwnerGuid()) - obj->SetOwnerGuid(bot->GetObjectGuid()); - - bot->RemoveGameObject(obj, false, pSpellInfo->Id != obj->GetSpellId()); - - bot->m_ObjectSlotGuid[slot].Clear(); - } - } - } - } - - if (GetTargetName() == "current target" && (!bot->GetCurrentSpell(CURRENT_MELEE_SPELL) && !bot->GetCurrentSpell(CURRENT_AUTOREPEAT_SPELL))) - { if (bot->getClass() == CLASS_HUNTER && spellName != "auto shot" && sServerFacade.GetDistance2d(bot, GetTarget()) > 5.0f) - ai->CastSpell("auto shot", GetTarget()); - } + ai->CastSpell("auto shot", GetTarget()); + } executed = ai->CastSpell(spellName, GetTarget(), nullptr, false, &spellDuration); }