mirror of
https://github.com/mod-playerbots/mod-playerbots.git
synced 2026-01-13 17:09:08 +00:00
Run clang-format
This commit is contained in:
@@ -1,240 +1,287 @@
|
||||
/*
|
||||
* Copyright (C) 2016+ AzerothCore <www.azerothcore.org>, released under GNU GPL v2 license, you may redistribute it and/or modify it under version 2 of the License, or (at your option), any later version.
|
||||
* Copyright (C) 2016+ AzerothCore <www.azerothcore.org>, released under GNU GPL v2 license, you may redistribute it
|
||||
* and/or modify it under version 2 of the License, or (at your option), any later version.
|
||||
*/
|
||||
|
||||
#include "DpsTargetValue.h"
|
||||
|
||||
#include "PlayerbotAIConfig.h"
|
||||
#include "Playerbots.h"
|
||||
|
||||
class FindMaxThreatGapTargetStrategy : public FindTargetStrategy
|
||||
{
|
||||
public:
|
||||
FindMaxThreatGapTargetStrategy(PlayerbotAI* botAI) : FindTargetStrategy(botAI), minThreat(0) { }
|
||||
public:
|
||||
FindMaxThreatGapTargetStrategy(PlayerbotAI* botAI) : FindTargetStrategy(botAI), minThreat(0) {}
|
||||
|
||||
void CheckAttacker(Unit* attacker, ThreatMgr* threatMgr) override
|
||||
void CheckAttacker(Unit* attacker, ThreatMgr* threatMgr) override
|
||||
{
|
||||
if (!attacker->IsAlive())
|
||||
{
|
||||
if (!attacker->IsAlive()) {
|
||||
return;
|
||||
}
|
||||
if (foundHighPriority) {
|
||||
return;
|
||||
}
|
||||
if (IsHighPriority(attacker)) {
|
||||
result = attacker;
|
||||
foundHighPriority = true;
|
||||
return;
|
||||
}
|
||||
Unit* victim = attacker->GetVictim();
|
||||
if (!result || CalcThreatGap(attacker, threatMgr) > CalcThreatGap(result, &result->GetThreatMgr()))
|
||||
result = attacker;
|
||||
return;
|
||||
}
|
||||
float CalcThreatGap(Unit* attacker, ThreatMgr* threatMgr) {
|
||||
Unit* victim = attacker->GetVictim();
|
||||
return threatMgr->GetThreat(victim) - threatMgr->GetThreat(attacker);
|
||||
if (foundHighPriority)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (IsHighPriority(attacker))
|
||||
{
|
||||
result = attacker;
|
||||
foundHighPriority = true;
|
||||
return;
|
||||
}
|
||||
Unit* victim = attacker->GetVictim();
|
||||
if (!result || CalcThreatGap(attacker, threatMgr) > CalcThreatGap(result, &result->GetThreatMgr()))
|
||||
result = attacker;
|
||||
}
|
||||
float CalcThreatGap(Unit* attacker, ThreatMgr* threatMgr)
|
||||
{
|
||||
Unit* victim = attacker->GetVictim();
|
||||
return threatMgr->GetThreat(victim) - threatMgr->GetThreat(attacker);
|
||||
}
|
||||
|
||||
protected:
|
||||
float minThreat;
|
||||
protected:
|
||||
float minThreat;
|
||||
};
|
||||
|
||||
// caster
|
||||
class CasterFindTargetSmartStrategy : public FindTargetStrategy
|
||||
{
|
||||
public:
|
||||
CasterFindTargetSmartStrategy(PlayerbotAI* botAI, float dps) : FindTargetStrategy(botAI), dps_(dps), targetExpectedLifeTime(1000000) { }
|
||||
public:
|
||||
CasterFindTargetSmartStrategy(PlayerbotAI* botAI, float dps)
|
||||
: FindTargetStrategy(botAI), dps_(dps), targetExpectedLifeTime(1000000)
|
||||
{
|
||||
}
|
||||
|
||||
void CheckAttacker(Unit* attacker, ThreatMgr* threatMgr) override
|
||||
void CheckAttacker(Unit* attacker, ThreatMgr* threatMgr) override
|
||||
{
|
||||
if (Group* group = botAI->GetBot()->GetGroup())
|
||||
{
|
||||
if (Group* group = botAI->GetBot()->GetGroup())
|
||||
{
|
||||
ObjectGuid guid = group->GetTargetIcon(4);
|
||||
if (guid && attacker->GetGUID() == guid)
|
||||
return;
|
||||
}
|
||||
if (!attacker->IsAlive()) {
|
||||
ObjectGuid guid = group->GetTargetIcon(4);
|
||||
if (guid && attacker->GetGUID() == guid)
|
||||
return;
|
||||
}
|
||||
if (foundHighPriority) {
|
||||
return;
|
||||
}
|
||||
if (IsHighPriority(attacker)) {
|
||||
result = attacker;
|
||||
foundHighPriority = true;
|
||||
return;
|
||||
}
|
||||
float expectedLifeTime = attacker->GetHealth() / dps_;
|
||||
// Unit* victim = attacker->GetVictim();
|
||||
if (!result || IsBetter(attacker, result)) {
|
||||
targetExpectedLifeTime = expectedLifeTime;
|
||||
result = attacker;
|
||||
}
|
||||
}
|
||||
bool IsBetter(Unit* new_unit, Unit* old_unit) {
|
||||
float new_time = new_unit->GetHealth() / dps_;
|
||||
float old_time = old_unit->GetHealth() / dps_;
|
||||
// [5-20] > (5-0] > (20-inf)
|
||||
if (GetIntervalLevel(new_unit) > GetIntervalLevel(old_unit)) {
|
||||
return true;
|
||||
}
|
||||
int32_t level = GetIntervalLevel(new_unit);
|
||||
if (level % 10 == 2 || level % 10 == 1) {
|
||||
return new_time < old_time;
|
||||
}
|
||||
// dont switch targets when all of them with low health
|
||||
Unit* currentTarget = botAI->GetAiObjectContext()->GetValue<Unit*>("current target")->Get();
|
||||
if (currentTarget == new_unit) {
|
||||
return true;
|
||||
}
|
||||
if (currentTarget == old_unit) {
|
||||
return false;
|
||||
}
|
||||
return new_time > old_time;
|
||||
if (!attacker->IsAlive())
|
||||
{
|
||||
return;
|
||||
}
|
||||
int32_t GetIntervalLevel(Unit* unit) {
|
||||
float time = unit->GetHealth() / dps_;
|
||||
float dis = unit->GetDistance(botAI->GetBot());
|
||||
float attackRange = botAI->IsRanged(botAI->GetBot()) ? sPlayerbotAIConfig->spellDistance : sPlayerbotAIConfig->meleeDistance;
|
||||
attackRange += 5.0f;
|
||||
int level = dis < attackRange ? 10 : 0;
|
||||
if (time >= 3 && time <= 20) {
|
||||
return level + 2;
|
||||
}
|
||||
if (time > 20) {
|
||||
return level + 1;
|
||||
}
|
||||
return level;
|
||||
if (foundHighPriority)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (IsHighPriority(attacker))
|
||||
{
|
||||
result = attacker;
|
||||
foundHighPriority = true;
|
||||
return;
|
||||
}
|
||||
float expectedLifeTime = attacker->GetHealth() / dps_;
|
||||
// Unit* victim = attacker->GetVictim();
|
||||
if (!result || IsBetter(attacker, result))
|
||||
{
|
||||
targetExpectedLifeTime = expectedLifeTime;
|
||||
result = attacker;
|
||||
}
|
||||
}
|
||||
bool IsBetter(Unit* new_unit, Unit* old_unit)
|
||||
{
|
||||
float new_time = new_unit->GetHealth() / dps_;
|
||||
float old_time = old_unit->GetHealth() / dps_;
|
||||
// [5-20] > (5-0] > (20-inf)
|
||||
if (GetIntervalLevel(new_unit) > GetIntervalLevel(old_unit))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
int32_t level = GetIntervalLevel(new_unit);
|
||||
if (level % 10 == 2 || level % 10 == 1)
|
||||
{
|
||||
return new_time < old_time;
|
||||
}
|
||||
// dont switch targets when all of them with low health
|
||||
Unit* currentTarget = botAI->GetAiObjectContext()->GetValue<Unit*>("current target")->Get();
|
||||
if (currentTarget == new_unit)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if (currentTarget == old_unit)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return new_time > old_time;
|
||||
}
|
||||
int32_t GetIntervalLevel(Unit* unit)
|
||||
{
|
||||
float time = unit->GetHealth() / dps_;
|
||||
float dis = unit->GetDistance(botAI->GetBot());
|
||||
float attackRange =
|
||||
botAI->IsRanged(botAI->GetBot()) ? sPlayerbotAIConfig->spellDistance : sPlayerbotAIConfig->meleeDistance;
|
||||
attackRange += 5.0f;
|
||||
int level = dis < attackRange ? 10 : 0;
|
||||
if (time >= 3 && time <= 20)
|
||||
{
|
||||
return level + 2;
|
||||
}
|
||||
if (time > 20)
|
||||
{
|
||||
return level + 1;
|
||||
}
|
||||
return level;
|
||||
}
|
||||
|
||||
protected:
|
||||
float dps_;
|
||||
float targetExpectedLifeTime;
|
||||
protected:
|
||||
float dps_;
|
||||
float targetExpectedLifeTime;
|
||||
};
|
||||
|
||||
// non caster
|
||||
class NonCasterFindTargetSmartStrategy : public FindTargetStrategy
|
||||
{
|
||||
public:
|
||||
NonCasterFindTargetSmartStrategy(PlayerbotAI* botAI, float dps) : FindTargetStrategy(botAI), dps_(dps), targetExpectedLifeTime(1000000) { }
|
||||
public:
|
||||
NonCasterFindTargetSmartStrategy(PlayerbotAI* botAI, float dps)
|
||||
: FindTargetStrategy(botAI), dps_(dps), targetExpectedLifeTime(1000000)
|
||||
{
|
||||
}
|
||||
|
||||
void CheckAttacker(Unit* attacker, ThreatMgr* threatMgr) override
|
||||
void CheckAttacker(Unit* attacker, ThreatMgr* threatMgr) override
|
||||
{
|
||||
if (Group* group = botAI->GetBot()->GetGroup())
|
||||
{
|
||||
if (Group* group = botAI->GetBot()->GetGroup())
|
||||
{
|
||||
ObjectGuid guid = group->GetTargetIcon(4);
|
||||
if (guid && attacker->GetGUID() == guid)
|
||||
return;
|
||||
}
|
||||
if (!attacker->IsAlive()) {
|
||||
ObjectGuid guid = group->GetTargetIcon(4);
|
||||
if (guid && attacker->GetGUID() == guid)
|
||||
return;
|
||||
}
|
||||
if (foundHighPriority) {
|
||||
return;
|
||||
}
|
||||
if (IsHighPriority(attacker)) {
|
||||
result = attacker;
|
||||
foundHighPriority = true;
|
||||
return;
|
||||
}
|
||||
float expectedLifeTime = attacker->GetHealth() / dps_;
|
||||
// Unit* victim = attacker->GetVictim();
|
||||
if (!result || IsBetter(attacker, result)) {
|
||||
targetExpectedLifeTime = expectedLifeTime;
|
||||
result = attacker;
|
||||
}
|
||||
}
|
||||
bool IsBetter(Unit* new_unit, Unit* old_unit) {
|
||||
float new_time = new_unit->GetHealth() / dps_;
|
||||
float old_time = old_unit->GetHealth() / dps_;
|
||||
// [5-20] > (5-0] > (20-inf)
|
||||
if (GetIntervalLevel(new_unit) > GetIntervalLevel(old_unit)) {
|
||||
return true;
|
||||
}
|
||||
// attack enemy in range and with lowest health
|
||||
int level = GetIntervalLevel(new_unit);
|
||||
if (level == 10) {
|
||||
return new_time < old_time;
|
||||
}
|
||||
// all targets are far away, choose the closest one
|
||||
return botAI->GetBot()->GetDistance(new_unit) < botAI->GetBot()->GetDistance(old_unit);
|
||||
if (!attacker->IsAlive())
|
||||
{
|
||||
return;
|
||||
}
|
||||
int32_t GetIntervalLevel(Unit* unit) {
|
||||
float time = unit->GetHealth() / dps_;
|
||||
float dis = unit->GetDistance(botAI->GetBot());
|
||||
float attackRange = botAI->IsRanged(botAI->GetBot()) ? sPlayerbotAIConfig->spellDistance : sPlayerbotAIConfig->meleeDistance;
|
||||
attackRange += 5.0f;
|
||||
int level = dis < attackRange ? 10 : 0;
|
||||
return level;
|
||||
if (foundHighPriority)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (IsHighPriority(attacker))
|
||||
{
|
||||
result = attacker;
|
||||
foundHighPriority = true;
|
||||
return;
|
||||
}
|
||||
float expectedLifeTime = attacker->GetHealth() / dps_;
|
||||
// Unit* victim = attacker->GetVictim();
|
||||
if (!result || IsBetter(attacker, result))
|
||||
{
|
||||
targetExpectedLifeTime = expectedLifeTime;
|
||||
result = attacker;
|
||||
}
|
||||
}
|
||||
bool IsBetter(Unit* new_unit, Unit* old_unit)
|
||||
{
|
||||
float new_time = new_unit->GetHealth() / dps_;
|
||||
float old_time = old_unit->GetHealth() / dps_;
|
||||
// [5-20] > (5-0] > (20-inf)
|
||||
if (GetIntervalLevel(new_unit) > GetIntervalLevel(old_unit))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
// attack enemy in range and with lowest health
|
||||
int level = GetIntervalLevel(new_unit);
|
||||
if (level == 10)
|
||||
{
|
||||
return new_time < old_time;
|
||||
}
|
||||
// all targets are far away, choose the closest one
|
||||
return botAI->GetBot()->GetDistance(new_unit) < botAI->GetBot()->GetDistance(old_unit);
|
||||
}
|
||||
int32_t GetIntervalLevel(Unit* unit)
|
||||
{
|
||||
float time = unit->GetHealth() / dps_;
|
||||
float dis = unit->GetDistance(botAI->GetBot());
|
||||
float attackRange =
|
||||
botAI->IsRanged(botAI->GetBot()) ? sPlayerbotAIConfig->spellDistance : sPlayerbotAIConfig->meleeDistance;
|
||||
attackRange += 5.0f;
|
||||
int level = dis < attackRange ? 10 : 0;
|
||||
return level;
|
||||
}
|
||||
|
||||
protected:
|
||||
float dps_;
|
||||
float targetExpectedLifeTime;
|
||||
protected:
|
||||
float dps_;
|
||||
float targetExpectedLifeTime;
|
||||
};
|
||||
|
||||
// combo
|
||||
class ComboFindTargetSmartStrategy : public FindTargetStrategy
|
||||
{
|
||||
public:
|
||||
ComboFindTargetSmartStrategy(PlayerbotAI* botAI, float dps) : FindTargetStrategy(botAI), dps_(dps), targetExpectedLifeTime(1000000) { }
|
||||
public:
|
||||
ComboFindTargetSmartStrategy(PlayerbotAI* botAI, float dps)
|
||||
: FindTargetStrategy(botAI), dps_(dps), targetExpectedLifeTime(1000000)
|
||||
{
|
||||
}
|
||||
|
||||
void CheckAttacker(Unit* attacker, ThreatMgr* threatMgr) override
|
||||
void CheckAttacker(Unit* attacker, ThreatMgr* threatMgr) override
|
||||
{
|
||||
if (Group* group = botAI->GetBot()->GetGroup())
|
||||
{
|
||||
if (Group* group = botAI->GetBot()->GetGroup())
|
||||
{
|
||||
ObjectGuid guid = group->GetTargetIcon(4);
|
||||
if (guid && attacker->GetGUID() == guid)
|
||||
return;
|
||||
}
|
||||
if (!attacker->IsAlive()) {
|
||||
ObjectGuid guid = group->GetTargetIcon(4);
|
||||
if (guid && attacker->GetGUID() == guid)
|
||||
return;
|
||||
}
|
||||
if (foundHighPriority) {
|
||||
return;
|
||||
}
|
||||
if (IsHighPriority(attacker)) {
|
||||
result = attacker;
|
||||
foundHighPriority = true;
|
||||
return;
|
||||
}
|
||||
float expectedLifeTime = attacker->GetHealth() / dps_;
|
||||
// Unit* victim = attacker->GetVictim();
|
||||
if (!result || IsBetter(attacker, result)) {
|
||||
targetExpectedLifeTime = expectedLifeTime;
|
||||
result = attacker;
|
||||
}
|
||||
}
|
||||
bool IsBetter(Unit* new_unit, Unit* old_unit) {
|
||||
float new_time = new_unit->GetHealth() / dps_;
|
||||
float old_time = old_unit->GetHealth() / dps_;
|
||||
// [5-20] > (5-0] > (20-inf)
|
||||
if (GetIntervalLevel(new_unit) > GetIntervalLevel(old_unit)) {
|
||||
if (!attacker->IsAlive())
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (foundHighPriority)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (IsHighPriority(attacker))
|
||||
{
|
||||
result = attacker;
|
||||
foundHighPriority = true;
|
||||
return;
|
||||
}
|
||||
float expectedLifeTime = attacker->GetHealth() / dps_;
|
||||
// Unit* victim = attacker->GetVictim();
|
||||
if (!result || IsBetter(attacker, result))
|
||||
{
|
||||
targetExpectedLifeTime = expectedLifeTime;
|
||||
result = attacker;
|
||||
}
|
||||
}
|
||||
bool IsBetter(Unit* new_unit, Unit* old_unit)
|
||||
{
|
||||
float new_time = new_unit->GetHealth() / dps_;
|
||||
float old_time = old_unit->GetHealth() / dps_;
|
||||
// [5-20] > (5-0] > (20-inf)
|
||||
if (GetIntervalLevel(new_unit) > GetIntervalLevel(old_unit))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
// attack enemy in range and with lowest health
|
||||
int level = GetIntervalLevel(new_unit);
|
||||
Player* bot = botAI->GetBot();
|
||||
if (level == 10)
|
||||
{
|
||||
Unit* combo_unit = bot->GetComboTarget();
|
||||
if (new_unit == combo_unit)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
// attack enemy in range and with lowest health
|
||||
int level = GetIntervalLevel(new_unit);
|
||||
Player* bot = botAI->GetBot();
|
||||
if (level == 10) {
|
||||
Unit* combo_unit = bot->GetComboTarget();
|
||||
if (new_unit == combo_unit) {
|
||||
return true;
|
||||
}
|
||||
return new_time < old_time;
|
||||
}
|
||||
// all targets are far away, choose the closest one
|
||||
return bot->GetDistance(new_unit) < bot->GetDistance(old_unit);
|
||||
}
|
||||
int32_t GetIntervalLevel(Unit* unit) {
|
||||
float time = unit->GetHealth() / dps_;
|
||||
float dis = unit->GetDistance(botAI->GetBot());
|
||||
float attackRange = botAI->IsRanged(botAI->GetBot()) ? sPlayerbotAIConfig->spellDistance : sPlayerbotAIConfig->meleeDistance;
|
||||
attackRange += 5.0f;
|
||||
int level = dis < attackRange ? 10 : 0;
|
||||
return level;
|
||||
return new_time < old_time;
|
||||
}
|
||||
// all targets are far away, choose the closest one
|
||||
return bot->GetDistance(new_unit) < bot->GetDistance(old_unit);
|
||||
}
|
||||
int32_t GetIntervalLevel(Unit* unit)
|
||||
{
|
||||
float time = unit->GetHealth() / dps_;
|
||||
float dis = unit->GetDistance(botAI->GetBot());
|
||||
float attackRange =
|
||||
botAI->IsRanged(botAI->GetBot()) ? sPlayerbotAIConfig->spellDistance : sPlayerbotAIConfig->meleeDistance;
|
||||
attackRange += 5.0f;
|
||||
int level = dis < attackRange ? 10 : 0;
|
||||
return level;
|
||||
}
|
||||
|
||||
protected:
|
||||
float dps_;
|
||||
float targetExpectedLifeTime;
|
||||
protected:
|
||||
float dps_;
|
||||
float targetExpectedLifeTime;
|
||||
};
|
||||
|
||||
Unit* DpsTargetValue::Calculate()
|
||||
@@ -245,10 +292,13 @@ Unit* DpsTargetValue::Calculate()
|
||||
|
||||
// FindLeastHpTargetStrategy strategy(botAI);
|
||||
float dps = AI_VALUE(float, "expected group dps");
|
||||
if (botAI->IsCaster(bot)) {
|
||||
if (botAI->IsCaster(bot))
|
||||
{
|
||||
CasterFindTargetSmartStrategy strategy(botAI, dps);
|
||||
return TargetValue::FindTarget(&strategy);
|
||||
} else if (botAI->IsCombo(bot)) {
|
||||
}
|
||||
else if (botAI->IsCombo(bot))
|
||||
{
|
||||
ComboFindTargetSmartStrategy strategy(botAI, dps);
|
||||
return TargetValue::FindTarget(&strategy);
|
||||
}
|
||||
@@ -258,24 +308,24 @@ Unit* DpsTargetValue::Calculate()
|
||||
|
||||
class FindMaxHpTargetStrategy : public FindTargetStrategy
|
||||
{
|
||||
public:
|
||||
FindMaxHpTargetStrategy(PlayerbotAI* botAI) : FindTargetStrategy(botAI), maxHealth(0) { }
|
||||
public:
|
||||
FindMaxHpTargetStrategy(PlayerbotAI* botAI) : FindTargetStrategy(botAI), maxHealth(0) {}
|
||||
|
||||
void CheckAttacker(Unit* attacker, ThreatMgr* threatMgr) override
|
||||
void CheckAttacker(Unit* attacker, ThreatMgr* threatMgr) override
|
||||
{
|
||||
if (Group* group = botAI->GetBot()->GetGroup())
|
||||
{
|
||||
if (Group* group = botAI->GetBot()->GetGroup())
|
||||
{
|
||||
ObjectGuid guid = group->GetTargetIcon(4);
|
||||
if (guid && attacker->GetGUID() == guid)
|
||||
return;
|
||||
}
|
||||
|
||||
if (!result || result->GetHealth() < attacker->GetHealth())
|
||||
result = attacker;
|
||||
ObjectGuid guid = group->GetTargetIcon(4);
|
||||
if (guid && attacker->GetGUID() == guid)
|
||||
return;
|
||||
}
|
||||
|
||||
protected:
|
||||
float maxHealth;
|
||||
if (!result || result->GetHealth() < attacker->GetHealth())
|
||||
result = attacker;
|
||||
}
|
||||
|
||||
protected:
|
||||
float maxHealth;
|
||||
};
|
||||
|
||||
Unit* DpsAoeTargetValue::Calculate()
|
||||
|
||||
Reference in New Issue
Block a user