Skip to content

Commit

Permalink
-Rpg craft fix: Rare crash when bots randomly place traps and the go …
Browse files Browse the repository at this point in the history
…to a different map.
  • Loading branch information
mostlikely4r committed Sep 20, 2024
1 parent 8c04f6b commit 33cbf87
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 44 deletions.
34 changes: 34 additions & 0 deletions playerbot/PlayerbotAI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 ||
Expand Down
47 changes: 3 additions & 44 deletions playerbot/strategy/actions/GenericSpellActions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit 33cbf87

Please sign in to comment.