Merge pull request #631 from avirar/AvoidShadowCrashAction_crashfix

Update OldKingdomActions.cpp
This commit is contained in:
bash
2024-10-21 20:37:07 +02:00
committed by GitHub

View File

@@ -10,7 +10,6 @@ bool AttackNadoxGuardianAction::Execute(Event event)
{ {
return false; return false;
} }
return Attack(target); return Attack(target);
} }
@@ -24,6 +23,10 @@ bool AttackJedogaVolunteerAction::Execute(Event event)
for (auto i = targets.begin(); i != targets.end(); ++i) for (auto i = targets.begin(); i != targets.end(); ++i)
{ {
Unit* unit = botAI->GetUnit(*i); Unit* unit = botAI->GetUnit(*i);
if (!unit) // Null check for safety
{
continue; // Skip null or invalid units
}
if (unit && unit->GetEntry() == NPC_TWILIGHT_VOLUNTEER) if (unit && unit->GetEntry() == NPC_TWILIGHT_VOLUNTEER)
{ {
target = unit; target = unit;
@@ -55,6 +58,10 @@ bool AvoidShadowCrashAction::Execute(Event event)
// This doesn't seem to avoid casts very well, perhaps because this isn't checked while allies are casting. // This doesn't seem to avoid casts very well, perhaps because this isn't checked while allies are casting.
// TODO: Revisit if this is an issue in heroics, otherwise ignore shadow crashes for the most part. // TODO: Revisit if this is an issue in heroics, otherwise ignore shadow crashes for the most part.
victim = botAI->GetUnit(unit->GetTarget()); victim = botAI->GetUnit(unit->GetTarget());
if (!victim)
{
return false; // Exit early if no victim is found
}
if (victim && bot->GetExactDist2d(victim) < radius) if (victim && bot->GetExactDist2d(victim) < radius)
{ {
return MoveAway(victim, targetDist - bot->GetExactDist2d(victim->GetPosition())); return MoveAway(victim, targetDist - bot->GetExactDist2d(victim->GetPosition()));
@@ -65,12 +72,21 @@ bool AvoidShadowCrashAction::Execute(Event event)
if (botAI->IsMelee(bot)) { return false; } if (botAI->IsMelee(bot)) { return false; }
GuidVector members = AI_VALUE(GuidVector, "group members"); GuidVector members = AI_VALUE(GuidVector, "group members");
if (members.empty())
{
return false; // Exit early if no group members are found
}
for (auto& member : members) for (auto& member : members)
{ {
if (bot->GetGUID() == member) if (bot->GetGUID() == member)
{ {
continue; continue;
} }
Unit* memberUnit = botAI->GetUnit(member);
if (!memberUnit)
{
continue; // Skip if the memberUnit is null
}
float currentDist = bot->GetExactDist2d(botAI->GetUnit(member)); float currentDist = bot->GetExactDist2d(botAI->GetUnit(member));
if (currentDist < radius) if (currentDist < radius)
{ {