ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/ext/cfplus.ext
(Generate patch)

Comparing deliantra/server/ext/cfplus.ext (file contents):
Revision 1.2 by root, Sat Dec 16 17:16:51 2006 UTC vs.
Revision 1.6 by root, Tue Jun 19 17:32:56 2007 UTC

23cf::register_extcmd cfplus_support => sub { 23cf::register_extcmd cfplus_support => sub {
24 my ($pl, $msg) = @_; 24 my ($pl, $msg) = @_;
25 25
26 # $msg->{version} 26 # $msg->{version}
27 27
28 (
28 (version => 2) 29 version => 2,
29};
30
31my %dialog; # currently active dialogs
32
33my $timer = Event->timer (interval => 0.2, parked => 1, data => cf::WF_AUTOCANCEL, cb => sub {
34 while (my ($id, $dialog) = each %dialog) {
35 my (undef, $dx, $dy) = $dialog->{ob}->rangevector ($dialog->{npc});
36 next if (abs $dx) <= 2 && (abs $dy) <= 2;
37
38 $dialog->{ob}->contr->ext_reply ($id => msgtype => "error", msg => "out of range");
39 delete $dialog{$id};
40 } 30 )
41
42 $_[0]->w->stop unless keys %dialog;
43}); 31};
44 32
45sub dialog_tell { 33sub dialog_tell {
46 my ($id, $dialog, $msg) = @_; 34 my ($id, $dialog, $msg) = @_;
47 35
48 my $pl = $dialog->{ob}->contr; 36 my $pl = $dialog->{pl};
49 my ($reply, @kw) = $dialog->tell ($msg); 37 my ($reply, @kw) = $dialog->tell ($msg);
50 $reply = "..." unless $reply; 38 $reply = "..." unless $reply;
51 39
52 $pl->ext_reply ($id => msgtype => "reply", msg => $reply, add_topics => \@kw); 40 $pl->ext_reply ($id => msgtype => "reply", msg => $reply, add_topics => \@kw);
53} 41}
75 my %res; 63 my %res;
76 64
77 if ($pl->cell_visible ($dx, $dy)) { 65 if ($pl->cell_visible ($dx, $dy)) {
78 for my $ob ($pl->ob->map->at ($pl->ob->x + $dx, $pl->ob->y + $dy)) { 66 for my $ob ($pl->ob->map->at ($pl->ob->x + $dx, $pl->ob->y + $dy)) {
79 $res{npc_dialog} = $ob->name 67 $res{npc_dialog} = $ob->name
80 if $near && NPC_Dialogue::has_dialogue $ob; 68 if $near && NPC_Dialogue::has_dialogue $ob && !$pl->{npc_dialog};
81 } 69 }
82 } 70 }
83 71
84 %res 72 %res
85}; 73};
89Tries to start a dialogue with the mapspace specified by $dx and $dy (see 77Tries to start a dialogue with the mapspace specified by $dx and $dy (see
90C<extcmd lookat>). The $msgid will be used as a handle for all future 78C<extcmd lookat>). The $msgid will be used as a handle for all future
91messages related to this dialog interaction. 79messages related to this dialog interaction.
92 80
93It either replies with an error reply or starts a dialog by telling 81It either replies with an error reply or starts a dialog by telling
94the npc "hi" and returning a reply strcuture as with C<extcmd 82the npc "hi" and returning a reply structure as with C<extcmd
95npc_dialog_tell>. 83npc_dialog_tell>.
96 84
97=cut 85=cut
98 86
99cf::register_extcmd npc_dialog_begin => sub { 87cf::register_extcmd npc_dialog_begin => sub {
101 my ($id, $dx, $dy) = @$msg{qw(msgid dx dy)}; 89 my ($id, $dx, $dy) = @$msg{qw(msgid dx dy)};
102 90
103 return unless $pl->ob && $pl->ob->map; 91 return unless $pl->ob && $pl->ob->map;
104 return unless (abs $dx) <= 2 && (abs $dy) <= 2; 92 return unless (abs $dx) <= 2 && (abs $dy) <= 2;
105 return unless $pl->cell_visible ($dx, $dy); 93 return unless $pl->cell_visible ($dx, $dy);
94 return if $pl->{npc_dialog}; # only one dialog at a time
106 95
107 for my $npc ($pl->ob->map->at ($pl->ob->x + $dx, $pl->ob->y + $dy)) { 96 for my $npc ($pl->ob->map->at ($pl->ob->x + $dx, $pl->ob->y + $dy)) {
108 if (NPC_Dialogue::has_dialogue $npc) { 97 if (NPC_Dialogue::has_dialogue $npc) {
98 $pl->attach ("npc_dialog_active");
109 $dialog{$id} = new NPC_Dialogue ob => $pl->ob, npc => $npc; 99 $pl->{npc_dialog} = new NPC_Dialogue pl => $pl, npc => $npc, id => $id;
110 dialog_tell $id, $dialog{$id}, "hi"; 100 dialog_tell $id, $pl->{npc_dialog}, "hi";
111 $timer->start;
112 return; 101 return;
113 } 102 }
114 } 103 }
115 104
116 (msgtype => "error", msg => "nothing to talk to found") 105 (msgtype => "error", msg => "nothing to talk to found")
129=cut 118=cut
130 119
131cf::register_extcmd npc_dialog_tell => sub { 120cf::register_extcmd npc_dialog_tell => sub {
132 my ($pl, $msg) = @_; 121 my ($pl, $msg) = @_;
133 122
123 if (my $dialog = $pl->{npc_dialog}) {
134 dialog_tell $msg->{msgid}, $dialog{$msg->{msgid}}, $msg->{msg} 124 dialog_tell $msg->{msgid}, $dialog, $msg->{msg};
135 if $dialog{$msg->{msgid}}; 125 }
136 126
137 () 127 ()
138}; 128};
139 129
140=item extcmd npc_dialog_end { msgid => $id } 130=item extcmd npc_dialog_end { msgid => $id }
144=cut 134=cut
145 135
146cf::register_extcmd npc_dialog_end => sub { 136cf::register_extcmd npc_dialog_end => sub {
147 my ($pl, $msg) = @_; 137 my ($pl, $msg) = @_;
148 138
149 delete $dialog{$msg->{msgid}}; 139 if (my $dialog = delete $pl->{npc_dialog}) {
140 $pl->detach ("ncpa_dialog_active");
141 }
150 142
151 () 143 ()
152}; 144};
153
154cf::attach_to_players
155 on_logout => sub {
156 my ($pl) = @_;
157
158 delete $dialog{$_} for grep $pl->ob == $dialog{$_}{ob}, keys %dialog;
159 },
160;
161 145
162=item ... = extcmd editor_support 146=item ... = extcmd editor_support
163 147
164Returns the value required by clients that have an editor to download and 148Returns the value required by clients that have an editor to download and
165upload maps from/to the server. 149upload maps from/to the server.
192 176
193 map +($_ => $cf::CFG{"editor_$_"}), qw(servertype gameserver testserver cvs_root lib_root builder_ui) 177 map +($_ => $cf::CFG{"editor_$_"}), qw(servertype gameserver testserver cvs_root lib_root builder_ui)
194}; 178};
195 179
196sub unload { 180sub unload {
197 while (my ($id, $dialog) = each %dialog) { 181 for my $pl (cf::player::list) {
182 if (my $dialog = delete $pl->{npc_dialog}) {
183 $pl->detach ("npc_dialog_active");
198 $dialog->{ob}->contr->ext_reply ($id => msgtype => "error", msg => "npc dialogue module was reloaded"); 184 $pl->ext_reply ($dialog->{id} => msgtype => "error", msg => "npc dialogue module was reloaded");
185 }
199 } 186 }
200
201 %dialog = ();
202} 187}
203 188
189cf::player::attachment npc_dialog_active =>
190 on_logout => sub {
191 my ($pl) = @_;
192
193 delete $pl->{npc_dialog};
194 $pl->detach ("npc_dialog_active");
195 },
196 on_move => sub {
197 my ($pl, $dir) = @_;
198
199 if (my $dialog = $pl->{npc_dialog}) {
200 warn "on_move<@_>\n";#d#
201 warn $pl->ob;
202 warn $dialog;
203 warn $dialog->{npc};
204 warn $dialog->{npc}->is_valid;
205
206 my (undef, $dx, $dy) = $pl->ob->rangevector ($dialog->{npc});
207
208 return if (abs $dx) <= 2 && (abs $dy) <= 2;
209
210 $pl->ext_reply ($dialog->{id} => msgtype => "error", msg => "out of range");
211 }
212
213 delete $pl->{npc_dialog};
214 $pl->detach ("npc_dialog_active");
215 },
216;
217
218cf::player->attach (
219 on_login => sub {
220 my ($pl) = @_;
221
222 delete $pl->{npc_dialog};
223 },
224);
225
204=back 226=back
205 227
206=cut 228=cut
207 229

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines