diff --git a/src/AI/Attack.pm b/src/AI/Attack.pm index 11371fb152..9f6cb37338 100644 --- a/src/AI/Attack.pm +++ b/src/AI/Attack.pm @@ -87,6 +87,7 @@ sub process { ai_setSuspend(0); my $new_target = Actor::get($attackTarget); warning TF("Your target is not aggressive: %s, changing target to aggressive: %s.\n", $target, $new_target), 'ai_attack'; + $target->{droppedForAggressive} = 1; $char->attack($attackTarget); AI::Attack::process(); return; diff --git a/src/AI/CoreLogic.pm b/src/AI/CoreLogic.pm index 07aa918fbb..48ee9829cf 100644 --- a/src/AI/CoreLogic.pm +++ b/src/AI/CoreLogic.pm @@ -3158,6 +3158,7 @@ sub processAutoAttack { my @aggressives; my @partyMonsters; my @cleanMonsters; + my @droppedMonsters; # List aggressive monsters @aggressives = ai_getAggressives(1) if $attackOnRoute; @@ -3216,6 +3217,15 @@ sub processAutoAttack { } my $control = mon_control($monster->{name}, $monster->{nameID}); + # List dropped targets and already engaged targets + if( + $monster->{droppedForAggressive} || # check for dropped target + ($monster->{dmgFromYou} && $config{'attackAuto'} >= 1 && ($control->{attack_auto} == 1 || $control->{attack_auto} == 3)) # if received damage then check if we can continue the attack + ) { + push @droppedMonsters, $_; + next; + } + next unless (!AI::is(qw/sitAuto take items_gather items_take/) && $config{'attackAuto'} >= 2 && ($control->{attack_auto} == 1 || $control->{attack_auto} == 3) @@ -3251,6 +3261,7 @@ sub processAutoAttack { my $canSnipe = $config{attackCanSnipe}; $attackTarget = getBestTarget(\@aggressives, $checkLOS, $canSnipe) || getBestTarget(\@partyMonsters, $checkLOS, $canSnipe) || + getBestTarget(\@droppedMonsters, $checkLOS, $canSnipe) || getBestTarget(\@cleanMonsters, $checkLOS, $canSnipe); } diff --git a/src/Misc.pm b/src/Misc.pm index 7b7256cd22..88168b0e92 100644 --- a/src/Misc.pm +++ b/src/Misc.pm @@ -3722,15 +3722,16 @@ sub getBestTarget { my $name = lc $monster->{name}; my $dist = adjustedBlockDistance($myPos, $pos); + my $priority = $priority{$name} ? $priority{$name} : 0; - if (!defined($bestTarget) || ($priority{$name} > $highestPri)) { - $highestPri = $priority{$name}; + if (!defined($bestTarget) || ($priority > $highestPri)) { + $highestPri = $priority; $smallestDist = $dist; $bestTarget = $_; } - if ((!defined($bestTarget) || $priority{$name} == $highestPri) + if ((!defined($bestTarget) || $priority == $highestPri) && (!defined($smallestDist) || $dist < $smallestDist)) { - $highestPri = $priority{$name}; + $highestPri = $priority; $smallestDist = $dist; $bestTarget = $_; }