mirror of
https://github.com/mod-playerbots/mod-playerbots
synced 2025-11-29 15:58:20 +08:00
Fix Crash QuestAction (#665)
Added checks to ensure bot and botAI are valid at function start. Added extra pointer checks when accessing unit and gameobj in loops that iterate over nearest NPCs and game objects. This adjustment ensures that objects are initialized correctly before being used in the ProcessQuests function.
This commit is contained in:
@@ -15,9 +15,13 @@
|
||||
bool QuestAction::Execute(Event event)
|
||||
{
|
||||
ObjectGuid guid = event.getObject();
|
||||
|
||||
Player* master = GetMaster();
|
||||
|
||||
// Checks if the bot and botAI are valid
|
||||
if (!bot || !botAI)
|
||||
return false;
|
||||
|
||||
// Sets guid based on bot or master target
|
||||
if (!guid)
|
||||
{
|
||||
if (!master)
|
||||
@@ -36,19 +40,27 @@ bool QuestAction::Execute(Event event)
|
||||
}
|
||||
|
||||
bool result = false;
|
||||
|
||||
// Check the nearest NPCs
|
||||
GuidVector npcs = AI_VALUE(GuidVector, "nearest npcs");
|
||||
for (const auto npc : npcs)
|
||||
for (const auto& npc : npcs)
|
||||
{
|
||||
Unit* unit = botAI->GetUnit(npc);
|
||||
if (unit && bot->GetDistance(unit) <= INTERACTION_DISTANCE)
|
||||
{
|
||||
result |= ProcessQuests(unit);
|
||||
}
|
||||
}
|
||||
|
||||
// Checks the nearest game objects
|
||||
std::list<ObjectGuid> gos = AI_VALUE(std::list<ObjectGuid>, "nearest game objects");
|
||||
for (const auto go : gos)
|
||||
for (const auto& go : gos)
|
||||
{
|
||||
GameObject* gameobj = botAI->GetGameObject(go);
|
||||
if (gameobj && bot->GetDistance(gameobj) <= INTERACTION_DISTANCE)
|
||||
{
|
||||
result |= ProcessQuests(gameobj);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
Reference in New Issue
Block a user