diff --git a/src/AI/CoreLogic.pm b/src/AI/CoreLogic.pm index 4f4fd918c9..07aa918fbb 100644 --- a/src/AI/CoreLogic.pm +++ b/src/AI/CoreLogic.pm @@ -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}; diff --git a/src/Task/MapRoute.pm b/src/Task/MapRoute.pm index 830f104af6..045fd7d30b 100644 --- a/src/Task/MapRoute.pm +++ b/src/Task/MapRoute.pm @@ -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); @@ -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; @@ -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); diff --git a/src/Task/TalkNPC.pm b/src/Task/TalkNPC.pm index b2b7898b41..e9f3a591c6 100644 --- a/src/Task/TalkNPC.pm +++ b/src/Task/TalkNPC.pm @@ -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.")); + } } }