[Attack Target] Prioritized targets

This commit is contained in:
Yunfan Li
2024-05-28 11:25:07 +08:00
parent 43c0435e78
commit d5d1bb3904
5 changed files with 75 additions and 7 deletions

View File

@@ -36,7 +36,8 @@ bool AttackMyTargetAction::Execute(Event event)
return false;
}
botAI->GetAiObjectContext()->GetValue<GuidVector>("prioritized targets")->Set({guid});
bool result = Attack(botAI->GetUnit(guid));
if (result)
context->GetValue<ObjectGuid>("pull target")->Set(guid);

View File

@@ -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;
}

View File

@@ -37,4 +37,10 @@ class PossibleAddsValue : public BoolCalculatedValue
bool Calculate() override;
};
class PrioritizedTargetsValue : public ManualSetValue<GuidVector>
{
public:
PrioritizedTargetsValue(PlayerbotAI* botAI, std::string const name = "prioritized targets"): ManualSetValue(botAI, GuidVector(), name) {}
};
#endif

View File

@@ -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<GuidVector>("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<GuidVector>("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<GuidVector>("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<GuidVector>("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<GuidVector>("prioritized targets")->Get();
for (ObjectGuid targetGuid : prioritizedTargets) {
if (targetGuid && attacker->GetGUID() == targetGuid) {
result = attacker;
return;
}
}
if (!attacker->IsAlive()) {
return;

View File

@@ -112,6 +112,7 @@ class ValueContext : public NamedObjectContext<UntypedValue>
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<UntypedValue>
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); }