Skip to content

Commit

Permalink
Add hook call to talknpc and fix maproute pos check
Browse files Browse the repository at this point in the history
  • Loading branch information
Henrybk committed Jan 13, 2025
1 parent 6766f5f commit fb66c70
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 11 deletions.
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
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

0 comments on commit fb66c70

Please sign in to comment.