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

Prevent repeated move packets #3944

Merged
merged 3 commits into from
Jan 13, 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
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
1 change: 1 addition & 0 deletions src/AI/CoreLogic.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1427,6 +1427,7 @@ sub processAutoStorage {
getNPCInfo($config{storageAuto_npc}, $realpos);

ai_talkNPC($realpos->{pos}{x}, $realpos->{pos}{y}, $config{'storageAuto_npc_steps'});
AI::args->{'is_storageAuto'} = 1;
}

#delete $ai_v{temp}{storage_opened};
Expand Down
23 changes: 12 additions & 11 deletions src/Task/MapRoute.pm
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use Log qw(message debug warning error);
use Network;
use Plugins;
use Misc qw(canUseTeleport portalExists);
use Utils qw(timeOut blockDistance existsInList);
use Utils qw(timeOut blockDistance existsInList calcPosFromPathfinding);
use Utils::PathFinding;
use Utils::Exceptions;
use AI qw(ai_useTeleport);
Expand Down Expand Up @@ -170,7 +170,8 @@ sub iterate {
} elsif ( $self->{mapSolution}[0]{steps} ) {
my $min_npc_dist = 8;
my $max_npc_dist = 10;
my $dist_to_npc = blockDistance($self->{actor}{pos}, $self->{mapSolution}[0]{pos});
my $realPos = calcPosFromPathfinding($field, $self->{actor});
my $dist_to_npc = blockDistance($realPos, $self->{mapSolution}[0]{pos});

if (!exists $self->{mapSolution}[0]{retry} || !defined $self->{mapSolution}[0]{retry}) {
$self->{mapSolution}[0]{retry} = 0;
Expand All @@ -193,17 +194,17 @@ sub iterate {
delete $self->{mapSolution}[0]{error};

} else {


if (!exists $self->{mapSolution}[0]{plugin_retry}) {
$self->{mapSolution}[0]{plugin_retry} = 0;
}
my %plugin_args = (
x => $self->{mapSolution}[0]{pos}{x},
y => $self->{mapSolution}[0]{pos}{y},
steps => $self->{mapSolution}[0]{steps},
portal => $self->{mapSolution}[0]{portal},
plugin_retry => $self->{mapSolution}[0]{plugin_retry}
'x' => $self->{mapSolution}[0]{pos}{x},
'y' => $self->{mapSolution}[0]{pos}{y},
'steps' => $self->{mapSolution}[0]{steps},
'portal' => $self->{mapSolution}[0]{portal},
'plugin_retry' => $self->{mapSolution}[0]{plugin_retry},
'return' => 0
);
$plugin_args{plugin_retry} = 0 if (!defined $plugin_args{plugin_retry});
$plugin_args{return} = 0;

Plugins::callHook('npc_teleport_missing' => \%plugin_args);

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 "[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 "[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
27 changes: 27 additions & 0 deletions src/Task/TalkNPC.pm
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,33 @@ sub iterate {
return unless ($self->addSteps($self->{sequence}));
$self->{stage} = TALKING_TO_NPC;
$self->{time} = time;
} else {

if (!exists $self->{plugin_retry}) {
$self->{plugin_retry} = 0;
}
my %plugin_args = (
'x' => $self->{x},
'y' => $self->{y},
'nameID' => $self->{nameID},
'sequence' => $self->{sequence},
'plugin_retry' => $self->{plugin_retry},
'return' => 0
);

Plugins::callHook('TalkNPC_npc_missing' => \%plugin_args);

if ($plugin_args{return}) {
$self->{plugin_retry}++;
$self->{x} = $plugin_args{x};
$self->{y} = $plugin_args{y};
$self->{nameID} = $plugin_args{nameID};
$self->{sequence} = $plugin_args{sequence};
warning "[TalkNPC] Could not find NPC, retry set by hookcall.\n", 'ai_npcTalk';

} else {
$self->setError(NPC_NOT_FOUND, TF("Could not find an NPC."));
}
}
}

Expand Down
Loading