From 6abc8d51e972991874c01629dbeec1067d5fe100 Mon Sep 17 00:00:00 2001 From: Yunfan Li Date: Fri, 28 Jun 2024 20:09:04 +0800 Subject: [PATCH] [Attack target] Valid target check --- src/strategy/values/AttackersValue.cpp | 21 ++++++--------------- src/strategy/values/InvalidTargetValue.cpp | 4 +--- 2 files changed, 7 insertions(+), 18 deletions(-) diff --git a/src/strategy/values/AttackersValue.cpp b/src/strategy/values/AttackersValue.cpp index 41ff417e..7ae853be 100644 --- a/src/strategy/values/AttackersValue.cpp +++ b/src/strategy/values/AttackersValue.cpp @@ -104,7 +104,7 @@ void AttackersValue::RemoveNonThreating(std::unordered_set& targets) for(std::unordered_set::iterator tIter = targets.begin(); tIter != targets.end();) { Unit* unit = *tIter; - if(bot->GetMapId() != unit->GetMapId() || !hasRealThreat(unit) || !IsValidTarget(unit, bot) || !bot->IsWithinLOSInMap(unit)) + if(bot->GetMapId() != unit->GetMapId() || !hasRealThreat(unit) || !IsValidTarget(unit, bot)) { std::unordered_set::iterator tIter2 = tIter; ++tIter; @@ -113,15 +113,6 @@ void AttackersValue::RemoveNonThreating(std::unordered_set& targets) else ++tIter; } - // Unit* unit = *tIter; - // if (!IsValidTarget(unit, bot) || !bot->IsWithinLOSInMap(unit)) - // { - // std::unordered_set::iterator tIter2 = tIter; - // ++tIter; - // targets.erase(tIter2); - // } - // else - // ++tIter; } bool AttackersValue::hasRealThreat(Unit *attacker) @@ -160,7 +151,7 @@ bool AttackersValue::IsPossibleTarget(Unit* attacker, Player* bot, float range) // bool inCannon = botAI->IsInVehicle(false, true); // bool enemy = botAI->GetAiObjectContext()->GetValue("enemy player target")->Get(); - return attacker && + return attacker && attacker->IsVisible() && attacker->IsInWorld() && attacker->GetMapId() == bot->GetMapId() && !attacker->isDead() && @@ -183,10 +174,10 @@ bool AttackersValue::IsPossibleTarget(Unit* attacker, Player* bot, float range) bool AttackersValue::IsValidTarget(Unit *attacker, Player *bot) { - return attacker->IsVisible() && - IsPossibleTarget(attacker, bot) && - (attacker->GetThreatMgr().getCurrentVictim() || attacker->GetGuidValue(UNIT_FIELD_TARGET) || - attacker->GetGUID().IsPlayer() || attacker->GetGUID() == GET_PLAYERBOT_AI(bot)->GetAiObjectContext()->GetValue("pull target")->Get()); + return bot->IsWithinLOSInMap(attacker) && + IsPossibleTarget(attacker, bot); + // (attacker->GetThreatMgr().getCurrentVictim() || attacker->GetGuidValue(UNIT_FIELD_TARGET) || + // attacker->GetGUID().IsPlayer() || attacker->GetGUID() == GET_PLAYERBOT_AI(bot)->GetAiObjectContext()->GetValue("pull target")->Get()); } bool PossibleAddsValue::Calculate() diff --git a/src/strategy/values/InvalidTargetValue.cpp b/src/strategy/values/InvalidTargetValue.cpp index d2499c52..c940424a 100644 --- a/src/strategy/values/InvalidTargetValue.cpp +++ b/src/strategy/values/InvalidTargetValue.cpp @@ -27,9 +27,7 @@ bool InvalidTargetValue::Calculate() target->isFeared() || target->HasUnitState(UNIT_STATE_ISOLATED) || target->IsFriendlyTo(bot) || - !AttackersValue::IsValidTarget(target, bot) || - // !bot->IsWithinDistInMap(target, sPlayerbotAIConfig->sightDistance) || - !bot->IsWithinLOSInMap(target); + !AttackersValue::IsValidTarget(target, bot); } return !target;