Skip to content

Commit

Permalink
Fix crash when using portals while travelling
Browse files Browse the repository at this point in the history
Use queue GO use packet instead of casting spell directly as teleport spell script going to crash because bot is being teleported
  • Loading branch information
celguar committed May 21, 2024
1 parent 892c125 commit 2ad028a
Showing 1 changed file with 19 additions and 11 deletions.
30 changes: 19 additions & 11 deletions playerbot/strategy/actions/MovementActions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -507,18 +507,26 @@ bool MovementAction::MoveTo(uint32 mapId, float x, float y, float z, bool idle,
ai->Unmount();
}

Spell* spell = new Spell(bot, pSpellInfo, false);
SpellCastTargets targets;
targets.setUnitTarget(bot);
#ifdef MANGOS
spell->prepare(&targets, NULL);
#endif
#ifdef CMANGOS
spell->SpellStart(&targets, NULL);
#endif
SpellCastResult castResult = spell->cast(true);
std::list<ObjectGuid> gos = *context->GetValue<std::list<ObjectGuid> >("nearest game objects");
for (std::list<ObjectGuid>::iterator i = gos.begin(); i != gos.end(); i++)
{
GameObject* go = ai->GetGameObject(*i);
if (!go)
continue;

if (go->GetEntry() != entry)
continue;

if (!bot->GetGameObjectIfCanInteractWith(go->GetObjectGuid(), MAX_GAMEOBJECT_TYPE))
continue;

return castResult == SPELL_CAST_OK;
std::unique_ptr<WorldPacket> packet(new WorldPacket(CMSG_GAMEOBJ_USE));
*packet << *i;
bot->GetSession()->QueuePacket(std::move(packet));
return true;
}

return false;
}

if (pathType == TravelNodePathType::areaTrigger)
Expand Down

0 comments on commit 2ad028a

Please sign in to comment.