From ffb0b260d37e166b9255446f1045c97ca5eaa5d2 Mon Sep 17 00:00:00 2001 From: Yunfan Li Date: Tue, 30 May 2023 17:10:22 +0800 Subject: [PATCH] distance and reach related --- src/strategy/actions/ReachTargetActions.cpp | 27 +++------------------ src/strategy/triggers/RangeTriggers.cpp | 2 +- src/strategy/values/DistanceValue.cpp | 8 +++--- 3 files changed, 9 insertions(+), 28 deletions(-) diff --git a/src/strategy/actions/ReachTargetActions.cpp b/src/strategy/actions/ReachTargetActions.cpp index e9b76ded..146ef379 100644 --- a/src/strategy/actions/ReachTargetActions.cpp +++ b/src/strategy/actions/ReachTargetActions.cpp @@ -10,27 +10,7 @@ bool ReachTargetAction::Execute(Event event) { - Unit* target = AI_VALUE(Unit*, GetTargetName()); - if (!target) - return false; - - UpdateMovementState(); - - float combatReach = bot->GetCombatReach() + target->GetCombatReach() + 4.0f / 3.0f; - if (distance < std::max(5.0f, combatReach)) - { - // return MoveTo(target, 0.0f); - return ChaseTo(target, 0.0f, bot->GetAngle(target)); - } - else - { - combatReach = bot->GetCombatReach() + target->GetCombatReach(); - bool inLos = bot->IsWithinLOSInMap(target); - bool isFriend = bot->IsFriendlyTo(target); - float chaseDist = inLos ? distance : isFriend ? distance / 2 : distance; - return ChaseTo(target, chaseDist - sPlayerbotAIConfig->contactDistance, bot->GetAngle(target)); - // return MoveTo(target, chaseDist - sPlayerbotAIConfig->contactDistance); - } + return MoveTo(AI_VALUE(Unit*, GetTargetName()), distance); } bool ReachTargetAction::isUseful() @@ -39,8 +19,7 @@ bool ReachTargetAction::isUseful() if (bot->IsNonMeleeSpellCast(true)) return false; - Unit* target = AI_VALUE(Unit*, GetTargetName()); - return target && (!bot->IsWithinDistInMap(target, distance) || (bot->IsWithinDistInMap(target, distance) && !bot->IsWithinLOSInMap(target))); + return AI_VALUE2(float, "distance", GetTargetName()) > (distance + sPlayerbotAIConfig->contactDistance); } std::string const ReachTargetAction::GetTargetName() @@ -57,7 +36,7 @@ ReachSpellAction::ReachSpellAction(PlayerbotAI* botAI) : ReachTargetAction(botAI { } -ReachPartyMemberToHealAction::ReachPartyMemberToHealAction(PlayerbotAI* botAI) : ReachTargetAction(botAI, "reach party member to heal", botAI->GetRange("heal")) +ReachPartyMemberToHealAction::ReachPartyMemberToHealAction(PlayerbotAI* botAI) : ReachTargetAction(botAI, "reach party member to heal", botAI->GetRange("spell")) { } diff --git a/src/strategy/triggers/RangeTriggers.cpp b/src/strategy/triggers/RangeTriggers.cpp index 734cfc1f..49ea6af9 100644 --- a/src/strategy/triggers/RangeTriggers.cpp +++ b/src/strategy/triggers/RangeTriggers.cpp @@ -166,7 +166,7 @@ bool PartyMemberToHealOutOfSpellRangeTrigger::IsActive() } PartyMemberToHealOutOfSpellRangeTrigger::PartyMemberToHealOutOfSpellRangeTrigger(PlayerbotAI* botAI) : - OutOfRangeTrigger(botAI, "party member to heal out of spell range", botAI->GetRange("heal")) + OutOfRangeTrigger(botAI, "party member to heal out of spell range", botAI->GetRange("spell")) { } diff --git a/src/strategy/values/DistanceValue.cpp b/src/strategy/values/DistanceValue.cpp index f60e699d..3882eab0 100644 --- a/src/strategy/values/DistanceValue.cpp +++ b/src/strategy/values/DistanceValue.cpp @@ -61,9 +61,11 @@ float DistanceValue::Calculate() } else if (qualifier == "current target") { - Stance* stance = AI_VALUE(Stance*, "stance"); - WorldLocation loc = stance->GetLocation(); - return sServerFacade->GetDistance2d(botAI->GetBot(), loc.GetPositionX(), loc.GetPositionY()); + Unit* target = AI_VALUE(Unit*, qualifier); + if (!target || !target->IsInWorld()) + return 0.0f; + + return bot->GetDistance2d(target); } else {