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

🔨 refactor(attack): improve code #3880

Merged
merged 2 commits into from
Sep 17, 2024
Merged
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
16 changes: 11 additions & 5 deletions src/AI/Attack.pm
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,9 @@ use Utils::PathFinding;
sub process {
Benchmark::begin("ai_attack") if DEBUG;
my $args = AI::args;
my $action = AI::action;

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)) {
iurynogueira marked this conversation as resolved.
Show resolved Hide resolved
my $ID;
my $ataqArgs;
if (AI::action eq "attack") {
Expand Down Expand Up @@ -205,6 +202,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
Loading