Code: Select all
talkAuto_afterDeath 1
talkAuto_distance 5
talkAuto_npc comodo 188 162
talkAuto_npc_steps c r0 n
Code: Select all
############################################################
#
# autotalk
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
package autotalk;
use strict;
use Plugins;
use AI;
use Commands;
use Globals;
use Log;
use Utils;
Plugins::register('autotalk', 'talks to NPC after death or via command', \&unload);
my $mainLoopHook = Plugins::addHook('AI_pre', \&mainLoop);
my $hookCommandPost = Plugins::addHook('Command_post', \&onCommandPost);
my $queueNextLoop;
sub unload {
Plugins::delHook('AI_pre', $mainLoopHook);
Plugins::delHook('Command_post', $hookCommandPost);
}
sub onCommandPost {
my (undef, $args) = @_;
my ($cmd, $subcmd) = split(' ', $args->{input}, 2);
if ($cmd eq "autotalk") {
AI::queue('talkAuto');
$args->{return} = 1;
}
}
sub mainLoop {
if ($queueNextLoop) {
AI::queue('talkAuto');
$queueNextLoop = 0;
}
# Queue talkAuto after death
if (AI::action eq "dead" && !$::char->{dead}) {
if (!$::char->{resurrected}) {
$queueNextLoop = 1 if ($::config{'talkAuto_afterDeath'});
}
}
AUTOTALK: {
if (AI::action eq "talkAuto" && AI::args->{done}) {
# Autotalk finished
AI::dequeue;
} elsif (AI::action eq "talkAuto") {
# Main autotalk block
my $args = AI::args;
# Stop if talkAuto is not enabled, or if the specified NPC is invalid
$args->{npc} = {};
main::getNPCInfo($::config{'talkAuto_npc'}, $args->{npc});
if (!defined($args->{npc}{ok})) {
$args->{done} = 1;
return;
}
# Determine whether we have to move to the NPC
my $do_route;
if ($::field{'name'} ne $args->{npc}{map}) {
$do_route = 1;
} else {
my $distance = Utils::distance($args->{npc}{pos}, $::char->{pos_to});
if ($distance > $::config{'talkAuto_distance'}) {
$do_route = 1;
}
}
if ($do_route) {
Log::message "Calculating auto-talk route to: $::maps_lut{$args->{npc}{map}.'.rsw'}($args->{npc}{map}): $args->{npc}{pos}{x}, $args->{npc}{pos}{y}\n", "route";
main::ai_route($args->{npc}{map}, $args->{npc}{pos}{x}, $args->{npc}{pos}{y},
attackOnRoute => 1,
distFromGoal => $::config{'talkAuto_distance'},
noSitAuto => 1);
} else {
# Talk to NPC if we haven't done so
if (!defined($args->{queuedTalkSequence})) {
$args->{queuedTalkSequence} = 1;
if (defined $args->{npc}{id}) {
main::ai_talkNPC(ID => $args->{npc}{id}, $::config{'talkAuto_npc_steps'});
} else {
main::ai_talkNPC($args->{npc}{pos}{x}, $args->{npc}{pos}{y}, $::config{'talkAuto_npc_steps'});
}
return;
}
$args->{done} = 1;
}
}
} #END OF BLOCK AUTOTALK
}
return 1;