smarter dps target and tank target

This commit is contained in:
Yunfan Li
2023-10-22 01:27:37 +08:00
parent f303a9e83a
commit a63c6b6709
14 changed files with 184 additions and 53 deletions

View File

@@ -3,6 +3,7 @@
*/
#include "AttackersValue.h"
#include "PlayerbotAIConfig.h"
#include "TankTargetValue.h"
#include "Playerbots.h"
@@ -41,8 +42,53 @@ class FindTargetForTankStrategy : public FindNonCcTargetStrategy
float minThreat;
};
class FindTankTargetSmartStrategy : public FindTargetStrategy
{
public:
FindTankTargetSmartStrategy(PlayerbotAI* botAI) : FindTargetStrategy(botAI) { }
void CheckAttacker(Unit* attacker, ThreatMgr* threatMgr) override
{
if (Group* group = botAI->GetBot()->GetGroup())
{
ObjectGuid guid = group->GetTargetIcon(4);
if (guid && attacker->GetGUID() == guid)
return;
}
if (!attacker->IsAlive()) {
return;
}
if (!result || IsBetter(attacker, result)) {
result = attacker;
}
}
bool IsBetter(Unit* new_unit, Unit* old_unit) {
Player* bot = botAI->GetBot();
float new_threat = new_unit->GetThreatMgr().GetThreat(bot);
float old_threat = old_unit->GetThreatMgr().GetThreat(bot);
float new_dis = bot->GetDistance(new_unit);
float old_dis = bot->GetDistance(old_unit);
// hasAggro? -> withinMelee? -> threat
if (GetIntervalLevel(new_unit) > GetIntervalLevel(old_unit)) {
return true;
}
int32_t interval = GetIntervalLevel(new_unit);
if (interval == 1) {
return new_dis < old_dis;
}
return new_threat < old_threat;
}
int32_t GetIntervalLevel(Unit* unit) {
if (!botAI->HasAggro(unit)) {
return 1;
}
return 0;
}
};
Unit* TankTargetValue::Calculate()
{
FindTargetForTankStrategy strategy(botAI);
// FindTargetForTankStrategy strategy(botAI);
FindTankTargetSmartStrategy strategy(botAI);
return FindTarget(&strategy);
}