Skip to content

Commit

Permalink
attack improve code
Browse files Browse the repository at this point in the history
  • Loading branch information
iurynogueira authored Sep 17, 2024
1 parent 726a805 commit 144f0b5
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/AI/Attack.pm
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,7 @@ sub process {
Benchmark::begin("ai_attack") if DEBUG;
my $args = AI::args;

if (
(AI::action eq "attack" && $args->{ID})
|| (AI::action eq "route" && AI::action (1) eq "attack" && $args->{attackID})
|| (AI::action eq "move" && AI::action (2) eq "attack" && $args->{attackID})
) {
if (shouldAttack($action, $args)) {

Check failure on line 42 in src/AI/Attack.pm

View workflow job for this annotation

GitHub Actions / test ubuntu-20.04 (perl 5.12) x64

Global symbol "$action" requires explicit package name

Check failure on line 42 in src/AI/Attack.pm

View workflow job for this annotation

GitHub Actions / test ubuntu-22.04 (perl latest) x64

Global symbol "$action" requires explicit package name (did you forget to declare "my $action"?)
my $ID;
my $ataqArgs;
if (AI::action eq "attack") {
Expand Down Expand Up @@ -205,6 +201,15 @@ sub process {
Benchmark::end("ai_attack") if DEBUG;
}

sub shouldAttack {
my ($action, $args) = @_;
return (
($action eq "attack" && $args->{ID})
|| ($action eq "route" && AI::action(1) eq "attack" && $args->{attackID})
|| ($action eq "move" && AI::action(2) eq "attack" && $args->{attackID})
);
}

sub shouldGiveUp {
my ($args, $ID) = @_;
return !$config{attackNoGiveup} && (timeOut($args->{ai_attack_giveup}) || $args->{unstuck}{count} > 5);
Expand Down

0 comments on commit 144f0b5

Please sign in to comment.