Skip to content

Commit

Permalink
Prevent repeated move packets
Browse files Browse the repository at this point in the history
  • Loading branch information
Henrybk committed Jan 11, 2025
1 parent 6917fa0 commit 6766f5f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 10 deletions.
26 changes: 16 additions & 10 deletions src/AI/Attack.pm
Original file line number Diff line number Diff line change
Expand Up @@ -523,17 +523,23 @@ sub main {

# Here we check if we have finished moving to the meeting position to attack our target, only checks this if attackWaitApproachFinish is set to 1 in config
# If so sets sentApproach to 0
if (
$config{"attackWaitApproachFinish"} &&
($canAttack == 0 || $canAttack == -1) &&
$args->{sentApproach}
) {
if (!timeOut($char->{time_move}, $char->{time_move_calc})) {
debug TF("[Out of Range - Still Approaching - Waiting] %s (%d %d), target %s (%d %d), distance %d, maxDistance %d, dmgFromYou %d.\n", $char, $realMyPos->{x}, $realMyPos->{y}, $target, $realMonsterPos->{x}, $realMonsterPos->{y}, $realMonsterDist, $args->{attackMethod}{maxDistance}, $target->{dmgFromYou}), 'ai_attack';
return;
if ($args->{sentApproach}) {
if ($config{"attackWaitApproachFinish"}) {
if (!timeOut($char->{time_move}, $char->{time_move_calc})) {
debug TF("[attackWaitApproachFinish - Waiting] %s (%d %d), target %s (%d %d), distance %d, maxDistance %d, dmgFromYou %d.\n", $char, $realMyPos->{x}, $realMyPos->{y}, $target, $realMonsterPos->{x}, $realMonsterPos->{y}, $realMonsterDist, $args->{attackMethod}{maxDistance}, $target->{dmgFromYou}), 'ai_attack';
return;
} else {
debug TF("[attackWaitApproachFinish - Ended Approaching] %s (%d %d), target %s (%d %d), distance %d, maxDistance %d, dmgFromYou %d.\n", $char, $realMyPos->{x}, $realMyPos->{y}, $target, $realMonsterPos->{x}, $realMonsterPos->{y}, $realMonsterDist, $args->{attackMethod}{maxDistance}, $target->{dmgFromYou}), 'ai_attack';
$args->{sentApproach} = 0;
}
} else {
debug TF("[Out of Range - Ended Approaching] %s (%d %d), target %s (%d %d), distance %d, maxDistance %d, dmgFromYou %d.\n", $char, $realMyPos->{x}, $realMyPos->{y}, $target, $realMonsterPos->{x}, $realMonsterPos->{y}, $realMonsterDist, $args->{attackMethod}{maxDistance}, $target->{dmgFromYou}), 'ai_attack';
$args->{sentApproach} = 0;
if ($canAttack == 2) {
debug TF("[Approaching - Can now attack] %s (%d %d), target %s (%d %d), distance %d, maxDistance %d, dmgFromYou %d.\n", $char, $realMyPos->{x}, $realMyPos->{y}, $target, $realMonsterPos->{x}, $realMonsterPos->{y}, $realMonsterDist, $args->{attackMethod}{maxDistance}, $target->{dmgFromYou}), 'ai_attack';
$args->{sentApproach} = 0;
} elsif (timeOut($char->{time_move}, $char->{time_move_calc})) {
debug TF("[Approaching - Ended] Still no LOS/Range - %s (%d %d), target %s (%d %d), distance %d, maxDistance %d, dmgFromYou %d.\n", $char, $realMyPos->{x}, $realMyPos->{y}, $target, $realMonsterPos->{x}, $realMonsterPos->{y}, $realMonsterDist, $args->{attackMethod}{maxDistance}, $target->{dmgFromYou}), 'ai_attack';
$args->{sentApproach} = 0;
}
}
}

Expand Down
10 changes: 10 additions & 0 deletions src/Task/Route.pm
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,16 @@ sub iterate {
return;
}
}

if ($current_pos_to->{x} == $self->{next_pos}{x} && $current_pos_to->{y} == $self->{next_pos}{y}) {
debug "[Test] [Route] Not sending next step ($self->{next_pos}{x}, $self->{next_pos}{y}) because our pos_to is the same as it.\n", "route";
if ($self->{lastStep} == 1 && !$self->{sendAttackWithMove} && $self->{meetingSubRoute}) {
debug "[Test] [Route] Also ending task now ang giving back control to AI::Attack.\n", "route";
Plugins::callHook('route', {status => 'success'});
$self->setDone();
}
return;
}

if ($self->{start} || ($self->{last_pos}{x} != $current_pos->{x} || $self->{last_pos}{y} != $current_pos->{y})) {
$self->{time_step} = time;
Expand Down

0 comments on commit 6766f5f

Please sign in to comment.