Consolidate IsInGroupOrRaid

This commit is contained in:
nytmyr
2025-01-20 13:52:28 -06:00
parent 17284ea956
commit f296ff5a50
+12 -39
View File
@@ -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()) { if (!other || !IsOfClientBotMerc() || !other->IsOfClientBotMerc()) {
return false; return false;
} }
@@ -9428,64 +9428,37 @@ bool Mob::IsInGroupOrRaid(Mob *other, bool same_raid_group) {
return true; return true;
} }
Raid* raid = nullptr; Raid* raid = IsBot() ? CastToBot()->GetStoredRaid() : (IsRaidGrouped() ? GetRaid() : nullptr);
if (IsBot()) {
raid = CastToBot()->GetStoredRaid();
}
else {
if (IsRaidGrouped()) {
raid = GetRaid();
}
}
if (IsRaidGrouped()) {
if (!raid) {
return false;
}
}
if (raid) { if (raid) {
if (!other->IsRaidGrouped()) { if (!other->IsRaidGrouped()) {
return false; return false;
} }
Raid* other_raid = nullptr; Raid* other_raid = other->IsBot() ? other->CastToBot()->GetStoredRaid() : other->GetRaid();
if (other->IsBot()) {
other_raid = other->CastToBot()->GetStoredRaid();
}
else {
other_raid = other->GetRaid();
}
if (!other_raid) { if (!other_raid) {
return false; return false;
} }
auto raid_group = raid->GetGroup(GetCleanName()); 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 false;
} }
return true; return true;
} }
else {
auto* group = GetGroup();
auto* group_other = other->GetGroup();
if (group) { Group* group = GetGroup();
if (!group_other || group != group_other) { Group* other_group = other->GetGroup();
return false;
}
return true; return group && group == other_group;
}
}
return false;
} }
bool Mob::DoLosChecks(Mob* who, Mob* other) { bool Mob::DoLosChecks(Mob* who, Mob* other) {