From 46e585f85477228463656f3f8941c72cffb4e49f Mon Sep 17 00:00:00 2001 From: Yunfan Li Date: Tue, 4 Jun 2024 22:15:27 +0800 Subject: [PATCH] [Attack target] Fix attack --- src/strategy/values/DpsTargetValue.cpp | 115 +++++++++---------------- src/strategy/values/TargetValue.cpp | 18 ++++ src/strategy/values/TargetValue.h | 2 + 3 files changed, 60 insertions(+), 75 deletions(-) diff --git a/src/strategy/values/DpsTargetValue.cpp b/src/strategy/values/DpsTargetValue.cpp index 4011c4f6..fc8f6ce1 100644 --- a/src/strategy/values/DpsTargetValue.cpp +++ b/src/strategy/values/DpsTargetValue.cpp @@ -13,24 +13,17 @@ class FindLeastHpTargetStrategy : public FindTargetStrategy void CheckAttacker(Unit* attacker, ThreatMgr* threatMgr) override { - if (Group* group = botAI->GetBot()->GetGroup()) - { - ObjectGuid guid = group->GetTargetIcon(4); - if (guid && attacker->GetGUID() == guid) { - result = attacker; - return; - } - } - GuidVector prioritizedTargets = botAI->GetAiObjectContext()->GetValue("prioritized targets")->Get(); - for (ObjectGuid targetGuid : prioritizedTargets) { - if (targetGuid && attacker->GetGUID() == targetGuid) { - result = attacker; - return; - } - } if (!attacker->IsAlive()) { return; } + if (foundHighPriority) { + return; + } + if (IsHighPriority(attacker)) { + result = attacker; + foundHighPriority = true; + return; + } if (!result || result->GetHealth() > attacker->GetHealth()) result = attacker; } @@ -46,24 +39,17 @@ class FindMaxThreatGapTargetStrategy : public FindTargetStrategy void CheckAttacker(Unit* attacker, ThreatMgr* threatMgr) override { - if (Group* group = botAI->GetBot()->GetGroup()) - { - ObjectGuid guid = group->GetTargetIcon(4); - if (guid && attacker->GetGUID() == guid) { - result = attacker; - return; - } - } - GuidVector prioritizedTargets = botAI->GetAiObjectContext()->GetValue("prioritized targets")->Get(); - for (ObjectGuid targetGuid : prioritizedTargets) { - if (targetGuid && attacker->GetGUID() == targetGuid) { - result = attacker; - return; - } - } 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; @@ -85,24 +71,17 @@ class CasterFindTargetSmartStrategy : public FindTargetStrategy void CheckAttacker(Unit* attacker, ThreatMgr* threatMgr) override { - if (Group* group = botAI->GetBot()->GetGroup()) - { - ObjectGuid guid = group->GetTargetIcon(4); - if (guid && attacker->GetGUID() == guid) { - result = attacker; - return; - } - } - GuidVector prioritizedTargets = botAI->GetAiObjectContext()->GetValue("prioritized targets")->Get(); - for (ObjectGuid targetGuid : prioritizedTargets) { - if (targetGuid && attacker->GetGUID() == targetGuid) { - result = attacker; - return; - } - } 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)) { @@ -159,24 +138,17 @@ class NonCasterFindTargetSmartStrategy : public FindTargetStrategy void CheckAttacker(Unit* attacker, ThreatMgr* threatMgr) override { - if (Group* group = botAI->GetBot()->GetGroup()) - { - ObjectGuid guid = group->GetTargetIcon(4); - if (guid && attacker->GetGUID() == guid) { - result = attacker; - return; - } - } - GuidVector prioritizedTargets = botAI->GetAiObjectContext()->GetValue("prioritized targets")->Get(); - for (ObjectGuid targetGuid : prioritizedTargets) { - if (targetGuid && attacker->GetGUID() == targetGuid) { - result = attacker; - return; - } - } 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)) { @@ -221,24 +193,17 @@ class ComboFindTargetSmartStrategy : public FindTargetStrategy void CheckAttacker(Unit* attacker, ThreatMgr* threatMgr) override { - if (Group* group = botAI->GetBot()->GetGroup()) - { - ObjectGuid guid = group->GetTargetIcon(4); - if (guid && attacker->GetGUID() == guid) { - result = attacker; - return; - } - } - GuidVector prioritizedTargets = botAI->GetAiObjectContext()->GetValue("prioritized targets")->Get(); - for (ObjectGuid targetGuid : prioritizedTargets) { - if (targetGuid && attacker->GetGUID() == targetGuid) { - result = attacker; - return; - } - } 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)) { diff --git a/src/strategy/values/TargetValue.cpp b/src/strategy/values/TargetValue.cpp index 44ee831a..ad709394 100644 --- a/src/strategy/values/TargetValue.cpp +++ b/src/strategy/values/TargetValue.cpp @@ -100,6 +100,24 @@ void FindTargetStrategy::GetPlayerCount(Unit* creature, uint32* tankCount, uint3 dpsCountCache[creature] = *dpsCount; } +bool FindTargetStrategy::IsHighPriority(Unit* attacker) +{ + if (Group* group = botAI->GetBot()->GetGroup()) + { + ObjectGuid guid = group->GetTargetIcon(4); + if (guid && attacker->GetGUID() == guid) { + return true; + } + } + GuidVector prioritizedTargets = botAI->GetAiObjectContext()->GetValue("prioritized targets")->Get(); + for (ObjectGuid targetGuid : prioritizedTargets) { + if (targetGuid && attacker->GetGUID() == targetGuid) { + return true; + } + } + return false; +} + WorldPosition LastLongMoveValue::Calculate() { LastMovement& lastMove = *context->GetValue("last movement"); diff --git a/src/strategy/values/TargetValue.h b/src/strategy/values/TargetValue.h index 215977bd..b4ed6af6 100644 --- a/src/strategy/values/TargetValue.h +++ b/src/strategy/values/TargetValue.h @@ -21,12 +21,14 @@ class FindTargetStrategy Unit* GetResult(); virtual void CheckAttacker(Unit* attacker, ThreatMgr* threatMgr) = 0; void GetPlayerCount(Unit* creature, uint32* tankCount, uint32* dpsCount); + bool IsHighPriority(Unit* attacker); protected: Unit* result; PlayerbotAI* botAI; std::map tankCountCache; std::map dpsCountCache; + bool foundHighPriority = false; }; class FindNonCcTargetStrategy : public FindTargetStrategy