Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(attack): updating get target algorithm #3954

Merged
merged 1 commit into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading