From f296ff5a501ce71b6f4f8c5789cb0431a6a2db2a Mon Sep 17 00:00:00 2001 From: nytmyr <53322305+nytmyr@users.noreply.github.com> Date: Mon, 20 Jan 2025 13:52:28 -0600 Subject: [PATCH] Consolidate IsInGroupOrRaid --- zone/mob.cpp | 51 ++++++++++++--------------------------------------- 1 file changed, 12 insertions(+), 39 deletions(-) diff --git a/zone/mob.cpp b/zone/mob.cpp index c62524892..134e51e45 100644 --- a/zone/mob.cpp +++ b/zone/mob.cpp @@ -9419,7 +9419,7 @@ void Mob::ClearDataBucketCache() } } -bool Mob::IsInGroupOrRaid(Mob *other, bool same_raid_group) { +bool Mob::IsInGroupOrRaid(Mob* other, bool same_raid_group) { if (!other || !IsOfClientBotMerc() || !other->IsOfClientBotMerc()) { return false; } @@ -9428,64 +9428,37 @@ bool Mob::IsInGroupOrRaid(Mob *other, bool same_raid_group) { return true; } - Raid* raid = nullptr; - - if (IsBot()) { - raid = CastToBot()->GetStoredRaid(); - } - else { - if (IsRaidGrouped()) { - raid = GetRaid(); - } - } - - if (IsRaidGrouped()) { - if (!raid) { - return false; - } - } + Raid* raid = IsBot() ? CastToBot()->GetStoredRaid() : (IsRaidGrouped() ? GetRaid() : nullptr); if (raid) { if (!other->IsRaidGrouped()) { return false; } - Raid* other_raid = nullptr; - - if (other->IsBot()) { - other_raid = other->CastToBot()->GetStoredRaid(); - } - else { - other_raid = other->GetRaid(); - } + Raid* other_raid = other->IsBot() ? other->CastToBot()->GetStoredRaid() : other->GetRaid(); if (!other_raid) { return false; } auto raid_group = raid->GetGroup(GetCleanName()); - auto raid_other_group = other_raid->GetGroup(other->GetCleanName()); + auto other_raid_group = other_raid->GetGroup(other->GetCleanName()); - if (raid_group == RAID_GROUPLESS || raid_other_group == RAID_GROUPLESS || (same_raid_group && raid_group != raid_other_group)) { + if ( + raid_group == RAID_GROUPLESS || + other_raid_group == RAID_GROUPLESS || + (same_raid_group && raid_group != other_raid_group) + ) { return false; } return true; } - else { - auto* group = GetGroup(); - auto* group_other = other->GetGroup(); - if (group) { - if (!group_other || group != group_other) { - return false; - } + Group* group = GetGroup(); + Group* other_group = other->GetGroup(); - return true; - } - } - - return false; + return group && group == other_group; } bool Mob::DoLosChecks(Mob* who, Mob* other) {