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