From d5d1bb39042b0dac123dae48b51ac28c5c5ee2a6 Mon Sep 17 00:00:00 2001 From: Yunfan Li Date: Tue, 28 May 2024 11:25:07 +0800 Subject: [PATCH] [Attack Target] Prioritized targets --- src/strategy/actions/AttackAction.cpp | 3 +- src/strategy/values/AttackersValue.cpp | 16 +++++++- src/strategy/values/AttackersValue.h | 6 +++ src/strategy/values/DpsTargetValue.cpp | 55 +++++++++++++++++++++++--- src/strategy/values/ValueContext.h | 2 + 5 files changed, 75 insertions(+), 7 deletions(-) diff --git a/src/strategy/actions/AttackAction.cpp b/src/strategy/actions/AttackAction.cpp index 20e496c3..58ebd02f 100644 --- a/src/strategy/actions/AttackAction.cpp +++ b/src/strategy/actions/AttackAction.cpp @@ -36,7 +36,8 @@ bool AttackMyTargetAction::Execute(Event event) return false; } - + + botAI->GetAiObjectContext()->GetValue("prioritized targets")->Set({guid}); bool result = Attack(botAI->GetUnit(guid)); if (result) context->GetValue("pull target")->Set(guid); diff --git a/src/strategy/values/AttackersValue.cpp b/src/strategy/values/AttackersValue.cpp index d6442363..f33abb56 100644 --- a/src/strategy/values/AttackersValue.cpp +++ b/src/strategy/values/AttackersValue.cpp @@ -23,6 +23,20 @@ GuidVector AttackersValue::Calculate() if (Group* group = bot->GetGroup()) AddAttackersOf(group, targets); + // prioritize target + GuidVector prioritizedTargets = AI_VALUE(GuidVector, "prioritized targets"); + for (ObjectGuid target : prioritizedTargets) { + Unit* unit = botAI->GetUnit(target); + if (unit) { + targets.insert(unit); + } + } + ObjectGuid skullGuid = bot->GetGroup()->GetTargetIcon(4); + Unit* skullTarget = botAI->GetUnit(skullGuid); + if (skullTarget) { + targets.insert(skullTarget); + } + RemoveNonThreating(targets); for (Unit* unit : targets) @@ -30,7 +44,7 @@ GuidVector AttackersValue::Calculate() if (bot->duel && bot->duel->Opponent) result.push_back(bot->duel->Opponent->GetGUID()); - + return result; } diff --git a/src/strategy/values/AttackersValue.h b/src/strategy/values/AttackersValue.h index b3bb38b4..3a4ae20a 100644 --- a/src/strategy/values/AttackersValue.h +++ b/src/strategy/values/AttackersValue.h @@ -37,4 +37,10 @@ class PossibleAddsValue : public BoolCalculatedValue bool Calculate() override; }; +class PrioritizedTargetsValue : public ManualSetValue +{ + public: + PrioritizedTargetsValue(PlayerbotAI* botAI, std::string const name = "prioritized targets"): ManualSetValue(botAI, GuidVector(), name) {} +}; + #endif diff --git a/src/strategy/values/DpsTargetValue.cpp b/src/strategy/values/DpsTargetValue.cpp index f16a3f84..4011c4f6 100644 --- a/src/strategy/values/DpsTargetValue.cpp +++ b/src/strategy/values/DpsTargetValue.cpp @@ -16,8 +16,17 @@ class FindLeastHpTargetStrategy : public FindTargetStrategy if (Group* group = botAI->GetBot()->GetGroup()) { ObjectGuid guid = group->GetTargetIcon(4); - if (guid && attacker->GetGUID() == guid) + 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; @@ -40,8 +49,17 @@ class FindMaxThreatGapTargetStrategy : public FindTargetStrategy if (Group* group = botAI->GetBot()->GetGroup()) { ObjectGuid guid = group->GetTargetIcon(4); - if (guid && attacker->GetGUID() == guid) + 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; @@ -70,8 +88,17 @@ class CasterFindTargetSmartStrategy : public FindTargetStrategy if (Group* group = botAI->GetBot()->GetGroup()) { ObjectGuid guid = group->GetTargetIcon(4); - if (guid && attacker->GetGUID() == guid) + 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; @@ -135,8 +162,17 @@ class NonCasterFindTargetSmartStrategy : public FindTargetStrategy if (Group* group = botAI->GetBot()->GetGroup()) { ObjectGuid guid = group->GetTargetIcon(4); - if (guid && attacker->GetGUID() == guid) + 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; @@ -188,8 +224,17 @@ class ComboFindTargetSmartStrategy : public FindTargetStrategy if (Group* group = botAI->GetBot()->GetGroup()) { ObjectGuid guid = group->GetTargetIcon(4); - if (guid && attacker->GetGUID() == guid) + 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; diff --git a/src/strategy/values/ValueContext.h b/src/strategy/values/ValueContext.h index 72e65185..4298b44e 100644 --- a/src/strategy/values/ValueContext.h +++ b/src/strategy/values/ValueContext.h @@ -112,6 +112,7 @@ class ValueContext : public NamedObjectContext creators["possible targets no los"] = &ValueContext::possible_targets_no_los; creators["possible triggers"] = &ValueContext::possible_triggers; creators["possible adds"] = &ValueContext::possible_adds; + creators["prioritized targets"] = &ValueContext::prioritized_targets; creators["all targets"] = &ValueContext::all_targets; creators["possible rpg targets"] = &ValueContext::possible_rpg_targets; creators["nearest adds"] = &ValueContext::nearest_adds; @@ -382,6 +383,7 @@ class ValueContext : public NamedObjectContext static UntypedValue* possible_triggers(PlayerbotAI* botAI) { return new PossibleTriggersValue(botAI); } static UntypedValue* possible_targets_no_los(PlayerbotAI* botAI) { return new PossibleTargetsValue(botAI, "possible targets", sPlayerbotAIConfig->sightDistance, true); } static UntypedValue* possible_adds(PlayerbotAI* botAI) { return new PossibleAddsValue(botAI); } + static UntypedValue* prioritized_targets(PlayerbotAI* botAI) { return new PrioritizedTargetsValue(botAI); } static UntypedValue* all_targets(PlayerbotAI* botAI) { return new AllTargetsValue(botAI); } static UntypedValue* nearest_adds(PlayerbotAI* botAI) { return new NearestAddsValue(botAI); } static UntypedValue* party_member_without_aura(PlayerbotAI* botAI) { return new PartyMemberWithoutAuraValue(botAI); }