fix(Core/AI): Ignore PvP flagged players for aggressive pets if owner is not PvP flagged. (#21922)

This commit is contained in:
Benjamin Jackson
2025-04-21 03:40:56 -04:00
committed by GitHub
parent 3baadd0637
commit 9ced420849

View File

@@ -514,9 +514,22 @@ Unit* PetAI::SelectNextTarget(bool allowAutoSelect) const
// To prevent aggressive pets from chain selecting targets and running off, we
// only select a random target if certain conditions are met.
if (allowAutoSelect)
{
if (!me->GetCharmInfo()->IsReturning() || me->GetCharmInfo()->IsFollowing() || me->GetCharmInfo()->IsAtStay())
{
if (Unit* nearTarget = me->ToCreature()->SelectNearestTargetInAttackDistance(MAX_AGGRO_RADIUS))
return nearTarget;
{
if (nearTarget->IsPlayer() && nearTarget->ToPlayer()->IsPvP() && !owner->IsPvP()) // If owner is not PvP flagged and target is PvP flagged, do not attack
{
return nullptr; /// @todo: try for another target
}
else
{
return nearTarget;
}
}
}
}
// Default - no valid targets
return nullptr;