Compare commits

...

6 Commits

Author SHA1 Message Date
SaW
1f7b831422 Slots 2025-11-19 21:34:54 +01:00
SaW
4af85d3a14 Final 2025-11-01 21:58:09 +01:00
SaW
f9fce01282 bot to player 2025-10-30 22:01:34 +01:00
SaW
3577acebd4 Restore original behavior
Restores original behavior before this was touched 9mo ago.
2025-10-30 21:58:28 +01:00
SaW
ade388cba0 Combine if member & isAssist 2025-10-28 18:26:51 +01:00
SaW
1848fb553a FIX: Refactor/restore ..AssistOfIndex Functions
FIX: Refactor/restore IsAssistTankOfIndex, IsRangedDpsAssistantOfIndex, and IsHealAssistantOfIndex to improve readability, and modernize the approach using std::vector.

- Restores their original behavior, previously incorrectly optimized in https://github.com/mod-playerbots/mod-playerbots/pull/865
- Removed redundant double group iteration
- Refactored as per original PR's intent
- +Index/member validity check
2025-10-27 21:17:52 +01:00

View File

@@ -1769,80 +1769,6 @@ bool PlayerbotAI::IsCombo(Player* player)
(player->getClass() == CLASS_DRUID && player->HasAura(768)); // cat druid (player->getClass() == CLASS_DRUID && player->HasAura(768)); // cat druid
} }
bool PlayerbotAI::IsRangedDps(Player* player, bool bySpec) { return IsRanged(player, bySpec) && IsDps(player, bySpec); }
bool PlayerbotAI::IsHealAssistantOfIndex(Player* player, int index)
{
Group* group = player->GetGroup();
if (!group)
{
return false;
}
int counter = 0;
for (GroupReference* ref = group->GetFirstMember(); ref; ref = ref->next())
{
Player* member = ref->GetSource();
if (!member)
{
continue;
}
if (IsHeal(member)) // Check if the member is a healer
{
bool isAssistant = group->IsAssistant(member->GetGUID());
// Check if the index matches for both assistant and non-assistant healers
if ((isAssistant && index == counter) || (!isAssistant && index == counter))
{
return player == member;
}
counter++;
}
}
return false;
}
bool PlayerbotAI::IsRangedDpsAssistantOfIndex(Player* player, int index)
{
Group* group = player->GetGroup();
if (!group)
{
return false;
}
int counter = 0;
for (GroupReference* ref = group->GetFirstMember(); ref; ref = ref->next())
{
Player* member = ref->GetSource();
if (!member)
{
continue;
}
if (IsRangedDps(member)) // Check if the member is a ranged DPS
{
bool isAssistant = group->IsAssistant(member->GetGUID());
// Check the index for both assistant and non-assistant ranges
if ((isAssistant && index == counter) || (!isAssistant && index == counter))
{
return player == member;
}
counter++;
}
}
return false;
}
bool PlayerbotAI::HasAggro(Unit* unit) bool PlayerbotAI::HasAggro(Unit* unit)
{ {
if (!unit) if (!unit)
@@ -2186,7 +2112,6 @@ bool PlayerbotAI::IsMainTank(Player* player)
} }
ObjectGuid mainTank = ObjectGuid(); ObjectGuid mainTank = ObjectGuid();
Group::MemberSlotList const& slots = group->GetMemberSlots();
for (Group::member_citerator itr = slots.begin(); itr != slots.end(); ++itr) for (Group::member_citerator itr = slots.begin(); itr != slots.end(); ++itr)
{ {
@@ -2298,50 +2223,109 @@ uint32 PlayerbotAI::GetGroupTankNum(Player* player)
return result; return result;
} }
bool PlayerbotAI::IsHealAssistantOfIndex(Player* player, int index)
{
Group* group = player->GetGroup();
if (!group)
return false;
Group::MemberSlotList const& slots = group->GetMemberSlots();
int counter = 0;
for (GroupReference* ref = group->GetFirstMember(); ref; ref = ref->next())
{
Player* member = ref->GetSource();
if (member && group->IsAssistant(member->GetGUID()) && IsHeal(member))
{
if (index == counter)
return player == member;
counter++;
}
}
// Non-assistants
for (GroupReference* ref = group->GetFirstMember(); ref; ref = ref->next())
{
Player* member = ref->GetSource();
if (member && !group->IsAssistant(member->GetGUID()) && IsHeal(member))
{
if (index == counter)
return player == member;
counter++;
}
}
return false;
}
bool PlayerbotAI::IsRangedDps(Player* player, bool bySpec) { return IsRanged(player, bySpec) && IsDps(player, bySpec); }
bool PlayerbotAI::IsRangedDpsAssistantOfIndex(Player* player, int index)
{
Group* group = player->GetGroup();
if (!group)
return false;
Group::MemberSlotList const& slots = group->GetMemberSlots();
int counter = 0;
for (GroupReference* ref = group->GetFirstMember(); ref; ref = ref->next())
{
Player* member = ref->GetSource();
if (member && group->IsAssistant(member->GetGUID()) && IsRangedDps(member))
{
if (index == counter)
return player == member;
counter++;
}
}
// Non-assistants
for (GroupReference* ref = group->GetFirstMember(); ref; ref = ref->next())
{
Player* member = ref->GetSource();
if (member && !group->IsAssistant(member->GetGUID()) && IsRangedDps(member))
{
if (index == counter)
return player == member;
counter++;
}
}
return false;
}
bool PlayerbotAI::IsAssistTank(Player* player) { return IsTank(player) && !IsMainTank(player); } bool PlayerbotAI::IsAssistTank(Player* player) { return IsTank(player) && !IsMainTank(player); }
bool PlayerbotAI::IsAssistTankOfIndex(Player* player, int index) bool PlayerbotAI::IsAssistTankOfIndex(Player* player, int index)
{ {
Group* group = player->GetGroup(); Group* group = player->GetGroup();
if (!group) if (!group)
{
return false; return false;
}
Group::MemberSlotList const& slots = group->GetMemberSlots();
int counter = 0; int counter = 0;
for (GroupReference* ref = group->GetFirstMember(); ref; ref = ref->next()) for (GroupReference* ref = group->GetFirstMember(); ref; ref = ref->next())
{ {
Player* member = ref->GetSource(); Player* member = ref->GetSource();
if (member && group->IsAssistant(member->GetGUID()) && IsAssistTank(member))
if (!member)
{
continue;
}
if (group->IsAssistant(member->GetGUID()) && IsAssistTank(member))
{ {
if (index == counter) if (index == counter)
{
return player == member; return player == member;
}
counter++; counter++;
} }
} }
// not enough // Non-assistants
for (GroupReference* ref = group->GetFirstMember(); ref; ref = ref->next()) for (GroupReference* ref = group->GetFirstMember(); ref; ref = ref->next())
{ {
Player* member = ref->GetSource(); Player* member = ref->GetSource();
if (member && !group->IsAssistant(member->GetGUID()) && IsAssistTank(member))
if (!member)
{
continue;
}
if (!group->IsAssistant(member->GetGUID()) && IsAssistTank(member))
{ {
if (index == counter) if (index == counter)
{
return player == member; return player == member;
}
counter++; counter++;
} }
} }