[Attack target] Valid target check

This commit is contained in:
Yunfan Li
2024-06-28 20:09:04 +08:00
parent 7395acb660
commit 6abc8d51e9
2 changed files with 7 additions and 18 deletions

View File

@@ -104,7 +104,7 @@ void AttackersValue::RemoveNonThreating(std::unordered_set<Unit*>& targets)
for(std::unordered_set<Unit *>::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<Unit *>::iterator tIter2 = tIter;
++tIter;
@@ -113,15 +113,6 @@ void AttackersValue::RemoveNonThreating(std::unordered_set<Unit*>& targets)
else
++tIter;
}
// Unit* unit = *tIter;
// if (!IsValidTarget(unit, bot) || !bot->IsWithinLOSInMap(unit))
// {
// std::unordered_set<Unit*>::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<Unit*>("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<ObjectGuid>("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<ObjectGuid>("pull target")->Get());
}
bool PossibleAddsValue::Calculate()

View File

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