mirror of
https://github.com/liyunfan1223/mod-playerbots.git
synced 2026-06-20 15:39:25 +02:00
# Pull Request
- Applies the clean and corrected singletons, Meyer pattern. (cherry
picked from @SmashingQuasar )
Testing by just playing the game in various ways. Been tested by myself
@Celandriel and @SmashingQuasar
---
## Complexity & Impact
- Does this change add new decision branches?
- [x] No
- [ ] Yes (**explain below**)
- Does this change increase per-bot or per-tick processing?
- [x] No
- [ ] Yes (**describe and justify impact**)
- Could this logic scale poorly under load?
- [x] No
- [ ] Yes (**explain why**)
---
## Defaults & Configuration
- Does this change modify default bot behavior?
- [x] No
- [ ] Yes (**explain why**)
---
## AI Assistance
- Was AI assistance (e.g. ChatGPT or similar tools) used while working
on this change?
- [x] No
- [ ] Yes (**explain below**)
---
## Final Checklist
- [x] Stability is not compromised
- [x] Performance impact is understood, tested, and acceptable
- [x] Added logic complexity is justified and explained
- [x] Documentation updated if needed
---
## Notes for Reviewers
Anything that significantly improves realism at the cost of stability or
performance should be carefully discussed
before merging.
---------
Co-authored-by: Nicolas Lebacq <nicolas.cordier@outlook.com>
Co-authored-by: Keleborn <22352763+Celandriel@users.noreply.github.com>
175 lines
4.0 KiB
C++
175 lines
4.0 KiB
C++
/*
|
|
* Copyright (C) 2016+ AzerothCore <www.azerothcore.org>, released under GNU AGPL v3 license, you may redistribute it
|
|
* and/or modify it under version 3 of the License, or (at your option), any later version.
|
|
*/
|
|
|
|
#include "GroupValues.h"
|
|
|
|
#include "Playerbots.h"
|
|
#include "ServerFacade.h"
|
|
|
|
GuidVector GroupMembersValue::Calculate()
|
|
{
|
|
GuidVector members;
|
|
|
|
Group* group = bot->GetGroup();
|
|
if (group)
|
|
{
|
|
for (GroupReference* ref = group->GetFirstMember(); ref; ref = ref->next())
|
|
{
|
|
members.push_back(ref->GetSource()->GetGUID());
|
|
}
|
|
}
|
|
else
|
|
members.push_back(bot->GetGUID());
|
|
|
|
return members;
|
|
}
|
|
|
|
bool IsFollowingPartyValue::Calculate()
|
|
{
|
|
if (botAI->GetGroupLeader() == bot)
|
|
return true;
|
|
|
|
if (botAI->HasStrategy("follow", BOT_STATE_NON_COMBAT))
|
|
return true;
|
|
|
|
return false;
|
|
};
|
|
|
|
bool IsNearLeaderValue::Calculate()
|
|
{
|
|
Player* groupLeader = botAI->GetGroupLeader();
|
|
|
|
if (!groupLeader)
|
|
return false;
|
|
|
|
if (groupLeader == bot)
|
|
return true;
|
|
|
|
return ServerFacade::instance().GetDistance2d(bot, botAI->GetGroupLeader()) < sPlayerbotAIConfig.sightDistance;
|
|
}
|
|
|
|
bool BoolANDValue::Calculate()
|
|
{
|
|
std::vector<std::string> values = split(getQualifier(), ',');
|
|
|
|
for (auto value : values)
|
|
{
|
|
if (!AI_VALUE(bool, value))
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
uint32 GroupBoolCountValue::Calculate()
|
|
{
|
|
uint32 count = 0;
|
|
|
|
for (ObjectGuid guid : AI_VALUE(GuidVector, "group members"))
|
|
{
|
|
Player* player = ObjectAccessor::FindPlayer(guid);
|
|
|
|
if (!player)
|
|
continue;
|
|
|
|
if (player->GetMapId() != bot->GetMapId())
|
|
continue;
|
|
|
|
if (!GET_PLAYERBOT_AI(player))
|
|
continue;
|
|
|
|
if (PAI_VALUE2(bool, "and", getQualifier()))
|
|
return count++;
|
|
}
|
|
|
|
return count;
|
|
};
|
|
|
|
bool GroupBoolANDValue::Calculate()
|
|
{
|
|
for (ObjectGuid guid : AI_VALUE(GuidVector, "group members"))
|
|
{
|
|
Player* player = ObjectAccessor::FindPlayer(guid);
|
|
|
|
if (!player)
|
|
continue;
|
|
|
|
if (player->GetMapId() != bot->GetMapId())
|
|
continue;
|
|
|
|
if (!GET_PLAYERBOT_AI(player))
|
|
continue;
|
|
|
|
if (!PAI_VALUE2(bool, "and", getQualifier()))
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
};
|
|
|
|
bool GroupBoolORValue::Calculate()
|
|
{
|
|
for (ObjectGuid guid : AI_VALUE(GuidVector, "group members"))
|
|
{
|
|
Player* player = ObjectAccessor::FindPlayer(guid);
|
|
|
|
if (!player)
|
|
continue;
|
|
|
|
if (player->GetMapId() != bot->GetMapId())
|
|
continue;
|
|
|
|
if (!GET_PLAYERBOT_AI(player))
|
|
continue;
|
|
|
|
if (PAI_VALUE2(bool, "and", getQualifier()))
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
};
|
|
|
|
bool GroupReadyValue::Calculate()
|
|
{
|
|
bool inDungeon = !WorldPosition(bot).isOverworld();
|
|
|
|
for (ObjectGuid guid : AI_VALUE(GuidVector, "group members"))
|
|
{
|
|
Player* member = ObjectAccessor::FindPlayer(guid);
|
|
|
|
if (!member)
|
|
continue;
|
|
|
|
if (inDungeon) // In dungeons all following members need to be alive before continueing.
|
|
{
|
|
PlayerbotAI* memberAi = GET_PLAYERBOT_AI(member);
|
|
|
|
bool isFollowing = memberAi ? memberAi->HasStrategy("follow", BOT_STATE_NON_COMBAT) : true;
|
|
|
|
if (!member->IsAlive() && isFollowing)
|
|
return false;
|
|
}
|
|
|
|
// We only wait for members that are in range otherwise we might be waiting for bots stuck in dead loops
|
|
// forever.
|
|
if (botAI->GetGroupLeader() &&
|
|
ServerFacade::instance().GetDistance2d(member, botAI->GetGroupLeader()) > sPlayerbotAIConfig.sightDistance)
|
|
continue;
|
|
|
|
if (member->GetHealthPct() < sPlayerbotAIConfig.almostFullHealth)
|
|
return false;
|
|
|
|
if (!member->GetPower(POWER_MANA))
|
|
continue;
|
|
|
|
float mana = (static_cast<float>(member->GetPower(POWER_MANA)) / member->GetMaxPower(POWER_MANA)) * 100;
|
|
|
|
if (mana < sPlayerbotAIConfig.mediumMana)
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
};
|