Skip to content
Open
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
22 changes: 20 additions & 2 deletions src/FileParsers.pm
Original file line number Diff line number Diff line change
Expand Up @@ -844,8 +844,9 @@ sub parsePortalsAirship {
$line =~ s/(.*)[\s\t]+#.*$/$1/;

#airpship "airplane_01","We are heading to Izlude.","izlude",200,73;
if ($line =~ /^airpship\s+"([\w-]+)"\s*,\s*(\d+)\s*,\s*(\d+)\s*,\s*"([^"]+)"\s*,\s*"([\w-]+)"\s*,\s*(\d+)\s*,\s*(\d+)\s*(,\s*(.+)\s*)?;$/) {
my ($source_map, $source_x, $source_y, $message, $dest_map, $dest_x, $dest_y, $steps) = ($1, $2, $3, $4, $5, $6, $7, $9);
#airpship "airplane_01",243,73,"Welcome to Rachel.","ra_fild12",292,204,"236-248,67-79",x;
if ($line =~ /^airpship\s+"([\w-]+)"\s*,\s*(\d+)\s*,\s*(\d+)\s*,\s*"([^"]+)"\s*,\s*"([\w-]+)"\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*"([^"]*)"\s*)?(?:,\s*(.+?)\s*)?;$/) {
my ($source_map, $source_x, $source_y, $message, $dest_map, $dest_x, $dest_y, $wait_area, $steps) = ($1, $2, $3, $4, $5, $6, $7, $8, $9);
my $portal = "$source_map $source_x $source_y";
my $dest = "$dest_map $dest_x $dest_y";
$$r_hash{$portal}{'source'}{'map'} = $source_map;
Expand All @@ -856,6 +857,23 @@ sub parsePortalsAirship {
$$r_hash{$portal}{'dest'}{$dest}{'y'} = $dest_y;
$$r_hash{$portal}{'dest'}{$dest}{'message'} = $message;
$$r_hash{$portal}{'dest'}{$dest}{enabled} = 1; # is available permanently (can be used when calculating a route)
if (defined $wait_area && $wait_area ne '') {
if ($wait_area =~ /^\s*(\d+)\s*-\s*(\d+)\s*,\s*(\d+)\s*-\s*(\d+)\s*$/) {
my ($x1, $x2, $y1, $y2) = ($1, $2, $3, $4);
($x1, $x2) = ($x2, $x1) if ($x1 > $x2);
($y1, $y2) = ($y2, $y1) if ($y1 > $y2);
$$r_hash{$portal}{'dest'}{$dest}{'wait_area'} = {
x1 => $x1,
x2 => $x2,
y1 => $y1,
y2 => $y2,
};
} elsif (!defined $steps || $steps eq '') {
# Backwards compatibility with quoted legacy steps:
# airpship "...", "...", "x";
$steps = $wait_area;
}
}
if (defined $steps && $steps) {
$$r_hash{$portal}{'dest'}{$dest}{'steps'} = $steps;
}
Expand Down
53 changes: 46 additions & 7 deletions src/Misc.pm
Original file line number Diff line number Diff line change
Expand Up @@ -5749,15 +5749,12 @@ sub autoNpcTalk {
my ($ID, $nameID) = @_;

return if (defined AI::findAction("NPC"));

my $routeIndex = AI::findAction("route");
return if (defined $routeIndex && AI::args($routeIndex)->getSubtask && UNIVERSAL::isa(AI::args($routeIndex)->getSubtask, 'Task::TalkNPC'));

my $routeIndex = AI::findAction("route", 1);
return if (defined $routeIndex && AI::args($routeIndex)->getSubtask && UNIVERSAL::isa(AI::args($routeIndex)->getSubtask, 'Task::TalkNPC'));
return if _routeActionHasTalkNpcSubtask(0) || _routeActionHasTalkNpcSubtask(1);

debug "An unexpected npc conversation has started, auto-creating a TalkNPC Task\n";
my $task = Task::TalkNPC->new(type => 'autotalk', nameID => $nameID, ID => $ID);
my $sequence = resolveAutoNpcTalkSequence($ID);
debug "[TalkNPC] AutoTalk resolved sequence '".($sequence // '')."'.\n", "ai_npcTalk";
my $task = Task::TalkNPC->new(type => 'autotalk', nameID => $nameID, ID => $ID, sequence => $sequence);
AI::queue("NPC", $task);
# TODO: The following npc_talk hook is only added on activation.
# Make the task module or AI listen to the hook instead
Expand All @@ -5768,6 +5765,48 @@ sub autoNpcTalk {
});
}

sub _routeActionHasTalkNpcSubtask {
my ($offset) = @_;
$offset = 0 if !defined $offset;

my $routeIndex = AI::findAction("route", $offset);
return 0 if !defined $routeIndex;

my $routeSubtask = AI::args($routeIndex)->getSubtask;
return ($routeSubtask && UNIVERSAL::isa($routeSubtask, 'Task::TalkNPC')) ? 1 : 0;
}

sub resolveAutoNpcTalkSequence {
my ($ID) = @_;

my $routeIndex = AI::findAction("mapRoute");
$routeIndex = AI::findAction("route") if (!defined $routeIndex);
return '' if (!defined $routeIndex);

my $routeTask = AI::args($routeIndex);
return '' if (!$routeTask || !UNIVERSAL::isa($routeTask, 'Task::MapRoute'));
return '' if (!$routeTask->{mapSolution} || ref($routeTask->{mapSolution}) ne 'ARRAY' || !@{$routeTask->{mapSolution}});
return '' if (!$routeTask->{mapSolution}[0]{steps});

my $solution = $routeTask->{mapSolution}[0];
my $actor = $npcsList->getByID($ID) || $portalsList->getByID($ID) || $monstersList->getByID($ID);
return '' if (!$actor);

my $pos = $actor->{pos} || $actor->{pos_to};
return '' if (!$pos || !$solution->{pos});
return '' if ($pos->{x} != $solution->{pos}{x} || $pos->{y} != $solution->{pos}{y});

return _stripLeadingPortalApproachStep($solution->{steps});
}

sub _stripLeadingPortalApproachStep {
my ($sequence) = @_;
$sequence = '' if !defined $sequence;
$sequence =~ s/^\s*k(?:\s+|$)//i;
$sequence =~ s/^\s+|\s+$//g;
return $sequence;
}

sub isTeleportItemEquipRequirementSatisfied {
my ($entry) = @_;
return 1 unless ($entry->{requiredEquipSlot} && defined $entry->{requiredEquipItemID});
Expand Down
3 changes: 3 additions & 0 deletions src/Task/CalcMapRoute.pm
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ sub iterate {
amount_of_tickets_used => 0
};
$value->{airship_message} = $entry->{dest}{$dest}{message};
$value->{wait_area} = $entry->{dest}{$dest}{wait_area};
$value->{is_airship} = 1;
$self->add_key_to_openList($key, $value);
}
Expand Down Expand Up @@ -442,6 +443,7 @@ sub searchStep {
$arg{teleportItemRequiredEquipItemID} = $closelist->{$this}{teleportItemRequiredEquipItemID};
$arg{is_airship} = $closelist->{$this}{is_airship} || 0;
$arg{airship_message} = $closelist->{$this}{airship_message};
$arg{wait_area} = $closelist->{$this}{wait_area};

unshift @{$self->{mapSolution}}, \%arg;
$this = $closelist->{$this}{parent};
Expand Down Expand Up @@ -516,6 +518,7 @@ sub searchStep {
amount_of_tickets_used => $closelist->{$parent}{amount_of_tickets_used}
};
$value->{airship_message} = $portals_airships{$child}{dest}{$subchild}{message};
$value->{wait_area} = $portals_airships{$child}{dest}{$subchild}{wait_area};
$value->{is_airship} = 1;
$self->add_key_to_openList($key, $value);
}
Expand Down
Loading
Loading