Skip to content

Commit

Permalink
fix(attack): updating get target algorithm (#3954)
Browse files Browse the repository at this point in the history
- fix pick target by distance
- fix not pick target when it was dropped
  • Loading branch information
alisonrag authored Jan 16, 2025
1 parent 174131c commit 1e2bebf
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/AI/Attack.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
11 changes: 11 additions & 0 deletions src/AI/CoreLogic.pm
Original file line number Diff line number Diff line change
Expand Up @@ -3158,6 +3158,7 @@ sub processAutoAttack {
my @aggressives;
my @partyMonsters;
my @cleanMonsters;
my @droppedMonsters;

# List aggressive monsters
@aggressives = ai_getAggressives(1) if $attackOnRoute;
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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);
}

Expand Down
9 changes: 5 additions & 4 deletions src/Misc.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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 = $_;
}
Expand Down

0 comments on commit 1e2bebf

Please sign in to comment.