| 1 |
root |
1.1 |
#! perl |
| 2 |
|
|
|
| 3 |
|
|
# additional support for cfplus client |
| 4 |
|
|
|
| 5 |
root |
1.4 |
use NPC_Dialogue; |
| 6 |
|
|
|
| 7 |
root |
1.1 |
cf::register_extcmd cfplus_support => sub { |
| 8 |
|
|
my ($pl, $data) = @_; |
| 9 |
|
|
|
| 10 |
|
|
my ($token, $client_version) = split / /, $data, 2; |
| 11 |
|
|
|
| 12 |
|
|
$pl->send ("ext $token 1"); |
| 13 |
|
|
}; |
| 14 |
|
|
|
| 15 |
root |
1.3 |
my %dialog; # currently active dialogs |
| 16 |
|
|
|
| 17 |
root |
1.5 |
my $timer = Event->timer (interval => 0.2, parked => 1, cb => sub { |
| 18 |
|
|
while (my ($token, $dialog) = each %dialog) { |
| 19 |
|
|
my (undef, $dx, $dy) = $dialog->{ob}->rangevector ($dialog->{npc}); |
| 20 |
|
|
next if (abs $dx) <= 2 && (abs $dy) <= 2; |
| 21 |
|
|
|
| 22 |
|
|
$dialog->{ob}->contr->send ("ext $token out_of_range"); |
| 23 |
|
|
delete $dialog{$token}; |
| 24 |
|
|
} |
| 25 |
|
|
|
| 26 |
|
|
$_[0]->w->stop unless keys %dialog; |
| 27 |
|
|
}); |
| 28 |
|
|
|
| 29 |
root |
1.3 |
sub dialog_tell { |
| 30 |
|
|
my ($token, $dialog, $msg) = @_; |
| 31 |
|
|
|
| 32 |
|
|
my $pl = $dialog->{ob}->contr; |
| 33 |
|
|
my ($reply, @kw) = $dialog->tell ($msg); |
| 34 |
|
|
$reply = "..." unless $reply; |
| 35 |
|
|
$pl->send ("ext $token msg " . join "\x00", $reply, @kw); |
| 36 |
root |
1.1 |
} |
| 37 |
|
|
|
| 38 |
|
|
# return "interesting" information about the given tile |
| 39 |
|
|
# currently only returns the npc_dialog title when a dialog is possible |
| 40 |
|
|
cf::register_extcmd lookat => sub { |
| 41 |
|
|
my ($pl, $data) = @_; |
| 42 |
|
|
|
| 43 |
|
|
my ($token, $dx, $dy) = split / /, $data; |
| 44 |
root |
1.3 |
my $near = (abs $dx) <= 2 && (abs $dy) <= 2; |
| 45 |
root |
1.1 |
|
| 46 |
|
|
my %res; |
| 47 |
|
|
|
| 48 |
|
|
if ($pl->cell_visible ($dx, $dy)) { |
| 49 |
|
|
for my $ob ($pl->ob->map->at ($pl->ob->x + $dx, $pl->ob->y + $dy)) { |
| 50 |
|
|
$res{npc_dialog} = $ob->name |
| 51 |
root |
1.3 |
if $near && NPC_Dialogue::has_dialogue $ob; |
| 52 |
root |
1.1 |
} |
| 53 |
|
|
} |
| 54 |
|
|
|
| 55 |
|
|
$pl->send ("ext $token " . join "\x00", %res); |
| 56 |
|
|
}; |
| 57 |
|
|
|
| 58 |
|
|
cf::register_extcmd npc_dialog_begin => sub { |
| 59 |
|
|
my ($pl, $data) = @_; |
| 60 |
|
|
|
| 61 |
|
|
my ($token, $dx, $dy) = split / /, $data; |
| 62 |
|
|
|
| 63 |
root |
1.2 |
return unless (abs $dx) <= 2 && (abs $dy) <= 2; |
| 64 |
root |
1.1 |
return unless $pl->cell_visible ($dx, $dy); |
| 65 |
|
|
|
| 66 |
|
|
for my $npc ($pl->ob->map->at ($pl->ob->x + $dx, $pl->ob->y + $dy)) { |
| 67 |
root |
1.3 |
if (NPC_Dialogue::has_dialogue $npc) { |
| 68 |
|
|
$dialog{$token} = new NPC_Dialogue ob => $pl->ob, npc => $npc; |
| 69 |
|
|
dialog_tell $token, $dialog{$token}, "hi"; |
| 70 |
root |
1.5 |
$timer->start; |
| 71 |
root |
1.1 |
return; |
| 72 |
|
|
} |
| 73 |
|
|
} |
| 74 |
|
|
|
| 75 |
|
|
$pl->send ("ext $token error"); |
| 76 |
|
|
}; |
| 77 |
|
|
|
| 78 |
|
|
cf::register_extcmd npc_dialog_tell => sub { |
| 79 |
|
|
my ($pl, $data) = @_; |
| 80 |
|
|
|
| 81 |
|
|
my ($token, $msg) = split / /, $data, 2; |
| 82 |
|
|
|
| 83 |
root |
1.3 |
dialog_tell $token, $dialog{$token}, $msg |
| 84 |
root |
1.1 |
if $dialog{$token}; |
| 85 |
|
|
}; |
| 86 |
|
|
|
| 87 |
|
|
cf::register_extcmd npc_dialog_end => sub { |
| 88 |
|
|
my ($pl, $token) = @_; |
| 89 |
|
|
|
| 90 |
|
|
delete $dialog{$token}; |
| 91 |
|
|
}; |
| 92 |
|
|
|
| 93 |
root |
1.3 |
sub on_logout { |
| 94 |
|
|
my ($pl, $host) = @_; |
| 95 |
|
|
|
| 96 |
|
|
delete $dialog{$_} for grep $pl->ob == $dialog{$_}{ob}, keys %dialog; |
| 97 |
|
|
|
| 98 |
|
|
0 |
| 99 |
|
|
} |
| 100 |
|
|
|
| 101 |
root |
1.2 |
|