… | |
… | |
2 | |
2 | |
3 | # additional support for cfplus client |
3 | # additional support for cfplus client |
4 | |
4 | |
5 | use NPC_Dialogue; |
5 | use NPC_Dialogue; |
6 | |
6 | |
|
|
7 | =head1 CF+ protocol extensions |
|
|
8 | |
|
|
9 | This module implements protocol extensions for use by the CF+ client, but |
|
|
10 | can be used by other clients as well. It uses the C<extcmd> mechanism |
|
|
11 | exclusively. |
|
|
12 | |
|
|
13 | =over 4 |
|
|
14 | |
|
|
15 | =item ... = extcmd cfplus_support { version => $client_version } |
|
|
16 | |
|
|
17 | Registers the client the the server. the client should send the highest |
|
|
18 | version of the protocol it supports itself, and the server returns the |
|
|
19 | highest version of the protocol it supports in the C<version> key itself. |
|
|
20 | |
|
|
21 | =cut |
|
|
22 | |
7 | cf::register_extcmd cfplus_support => sub { |
23 | cf::register_extcmd cfplus_support => sub { |
8 | my ($pl, $msg) = @_; |
24 | my ($pl, $msg) = @_; |
9 | |
25 | |
10 | # $msg->{version} |
26 | # $msg->{version} |
11 | |
27 | |
12 | (version => 1) |
28 | (version => 2) |
13 | }; |
29 | }; |
14 | |
30 | |
15 | my %dialog; # currently active dialogs |
31 | my %dialog; # currently active dialogs |
16 | |
32 | |
17 | my $timer = Event->timer (interval => 0.2, parked => 1, cb => sub { |
33 | my $timer = Event->timer (interval => 0.2, parked => 1, cb => sub { |
… | |
… | |
34 | $reply = "..." unless $reply; |
50 | $reply = "..." unless $reply; |
35 | |
51 | |
36 | $pl->ext_reply ($id => msgtype => "reply", msg => $reply, add_topics => \@kw); |
52 | $pl->ext_reply ($id => msgtype => "reply", msg => $reply, add_topics => \@kw); |
37 | } |
53 | } |
38 | |
54 | |
|
|
55 | =item ... = extcmd lookat { dx => $dx, dy => $dy } |
|
|
56 | |
|
|
57 | "Looks at" the mapspace displaced (dx|dy) relative to the player |
39 | # return "interesting" information about the given tile |
58 | and returns "interesting" information about it. |
40 | # currently only returns the npc_dialog title when a dialog is possible |
59 | |
|
|
60 | Keys it can return include: |
|
|
61 | |
|
|
62 | npc_dialog => $name |
|
|
63 | There is an npc or other object that can "talk" to the player. |
|
|
64 | |
|
|
65 | =cut |
|
|
66 | |
41 | cf::register_extcmd lookat => sub { |
67 | cf::register_extcmd lookat => sub { |
42 | my ($pl, $msg) = @_; |
68 | my ($pl, $msg) = @_; |
43 | my ($dx, $dy) = @$msg{qw(dx dy)}; |
69 | my ($dx, $dy) = @$msg{qw(dx dy)}; |
44 | |
70 | |
45 | my $near = (abs $dx) <= 2 && (abs $dy) <= 2; |
71 | my $near = (abs $dx) <= 2 && (abs $dy) <= 2; |
… | |
… | |
53 | } |
79 | } |
54 | } |
80 | } |
55 | |
81 | |
56 | %res |
82 | %res |
57 | }; |
83 | }; |
|
|
84 | |
|
|
85 | =item ... = extcmd npc_dialog_begin { msgid => $id, dx => $dx, dy => $dy } |
|
|
86 | |
|
|
87 | Tries to start a dialogue with the mapspace specified by $dx and $dy (see |
|
|
88 | C<extcmd lookat>). The $msgid will be used as a handle for all future |
|
|
89 | messages related to this dialog interaction. |
|
|
90 | |
|
|
91 | It either replies with an error reply or starts a dialog by telling |
|
|
92 | the npc "hi" and returning a reply strcuture as with C<extcmd |
|
|
93 | npc_dialog_tell>. |
|
|
94 | |
|
|
95 | =cut |
58 | |
96 | |
59 | cf::register_extcmd npc_dialog_begin => sub { |
97 | cf::register_extcmd npc_dialog_begin => sub { |
60 | my ($pl, $msg) = @_; |
98 | my ($pl, $msg) = @_; |
61 | my ($id, $dx, $dy) = @$msg{qw(msgid dx dy)}; |
99 | my ($id, $dx, $dy) = @$msg{qw(msgid dx dy)}; |
62 | |
100 | |
… | |
… | |
73 | } |
111 | } |
74 | |
112 | |
75 | (msgtype => "error", msg => "nothing to talk to found") |
113 | (msgtype => "error", msg => "nothing to talk to found") |
76 | }; |
114 | }; |
77 | |
115 | |
|
|
116 | =item ... = extcmd npc_dialog_tell { msgid => $id, msg => $text } |
|
|
117 | |
|
|
118 | Tells the NPC the given $text message and returns a reply structure which |
|
|
119 | can have the following keys: |
|
|
120 | |
|
|
121 | msgtype => "reply" |
|
|
122 | msg => $reply_text, |
|
|
123 | add_topics => [additional topic strings] |
|
|
124 | del_topics => [invalidated topic strings] |
|
|
125 | |
|
|
126 | =cut |
|
|
127 | |
78 | cf::register_extcmd npc_dialog_tell => sub { |
128 | cf::register_extcmd npc_dialog_tell => sub { |
79 | my ($pl, $msg) = @_; |
129 | my ($pl, $msg) = @_; |
80 | |
130 | |
81 | dialog_tell $msg->{msgid}, $dialog{$msg->{msgid}}, $msg->{msg} |
131 | dialog_tell $msg->{msgid}, $dialog{$msg->{msgid}}, $msg->{msg} |
82 | if $dialog{$msg->{msgid}}; |
132 | if $dialog{$msg->{msgid}}; |
83 | |
133 | |
84 | () |
134 | () |
85 | }; |
135 | }; |
|
|
136 | |
|
|
137 | =item extcmd npc_dialog_end { msgid => $id } |
|
|
138 | |
|
|
139 | Finishes the dialog, invalidating the handle. |
|
|
140 | |
|
|
141 | =cut |
86 | |
142 | |
87 | cf::register_extcmd npc_dialog_end => sub { |
143 | cf::register_extcmd npc_dialog_end => sub { |
88 | my ($pl, $msg) = @_; |
144 | my ($pl, $msg) = @_; |
89 | |
145 | |
90 | delete $dialog{$msg->{msgid}}; |
146 | delete $dialog{$msg->{msgid}}; |
… | |
… | |
98 | |
154 | |
99 | delete $dialog{$_} for grep $pl->ob == $dialog{$_}{ob}, keys %dialog; |
155 | delete $dialog{$_} for grep $pl->ob == $dialog{$_}{ob}, keys %dialog; |
100 | }, |
156 | }, |
101 | ; |
157 | ; |
102 | |
158 | |
|
|
159 | cf::register_extcmd editor_support => sub { |
|
|
160 | my ($pl, $msg) = @_; |
|
|
161 | |
|
|
162 | ( |
|
|
163 | cvs_root => $cf::CFG{editor_cvs_root}, |
|
|
164 | upload => $cf::CFG{editor_upload}, |
|
|
165 | ) |
|
|
166 | }; |
|
|
167 | |
103 | sub unload { |
168 | sub unload { |
104 | while (my ($id, $dialog) = each %dialog) { |
169 | while (my ($id, $dialog) = each %dialog) { |
105 | $dialog->{ob}->contr->ext_reply ($id => msgtype => "error", msg => "npc dialogue module was reloaded"); |
170 | $dialog->{ob}->contr->ext_reply ($id => msgtype => "error", msg => "npc dialogue module was reloaded"); |
106 | } |
171 | } |
107 | |
172 | |
108 | %dialog = (); |
173 | %dialog = (); |
109 | } |
174 | } |
110 | |
175 | |
|
|
176 | =back |
111 | |
177 | |
|
|
178 | =cut |
|
|
179 | |