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.4 by root, Mon Apr 2 18:04:45 2007 UTC vs.
Revision 1.5 by root, Sat Jun 16 14:35:41 2007 UTC

28 ( 28 (
29 version => 2, 29 version => 2,
30 ) 30 )
31}; 31};
32 32
33my %dialog; # currently active dialogs
34
35my $timer = Event->timer (interval => 0.2, parked => 1, data => cf::WF_AUTOCANCEL, cb => sub {
36 while (my ($id, $dialog) = each %dialog) {
37 my (undef, $dx, $dy) = $dialog->{ob}->rangevector ($dialog->{npc});
38 next if (abs $dx) <= 2 && (abs $dy) <= 2;
39
40 $dialog->{ob}->contr->ext_reply ($id => msgtype => "error", msg => "out of range");
41 delete $dialog{$id};
42 }
43
44 $_[0]->w->stop unless keys %dialog;
45});
46
47sub dialog_tell { 33sub dialog_tell {
48 my ($id, $dialog, $msg) = @_; 34 my ($id, $dialog, $msg) = @_;
49 35
50 my $pl = $dialog->{ob}->contr; 36 my $pl = $dialog->{pl};
51 my ($reply, @kw) = $dialog->tell ($msg); 37 my ($reply, @kw) = $dialog->tell ($msg);
52 $reply = "..." unless $reply; 38 $reply = "..." unless $reply;
53 39
54 $pl->ext_reply ($id => msgtype => "reply", msg => $reply, add_topics => \@kw); 40 $pl->ext_reply ($id => msgtype => "reply", msg => $reply, add_topics => \@kw);
55} 41}
77 my %res; 63 my %res;
78 64
79 if ($pl->cell_visible ($dx, $dy)) { 65 if ($pl->cell_visible ($dx, $dy)) {
80 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)) {
81 $res{npc_dialog} = $ob->name 67 $res{npc_dialog} = $ob->name
82 if $near && NPC_Dialogue::has_dialogue $ob; 68 if $near && NPC_Dialogue::has_dialogue $ob && !$pl->{npc_dialog};
83 } 69 }
84 } 70 }
85 71
86 %res 72 %res
87}; 73};
91Tries 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
92C<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
93messages related to this dialog interaction. 79messages related to this dialog interaction.
94 80
95It 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
96the npc "hi" and returning a reply strcuture as with C<extcmd 82the npc "hi" and returning a reply structure as with C<extcmd
97npc_dialog_tell>. 83npc_dialog_tell>.
98 84
99=cut 85=cut
100 86
101cf::register_extcmd npc_dialog_begin => sub { 87cf::register_extcmd npc_dialog_begin => sub {
103 my ($id, $dx, $dy) = @$msg{qw(msgid dx dy)}; 89 my ($id, $dx, $dy) = @$msg{qw(msgid dx dy)};
104 90
105 return unless $pl->ob && $pl->ob->map; 91 return unless $pl->ob && $pl->ob->map;
106 return unless (abs $dx) <= 2 && (abs $dy) <= 2; 92 return unless (abs $dx) <= 2 && (abs $dy) <= 2;
107 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
108 95
109 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)) {
110 if (NPC_Dialogue::has_dialogue $npc) { 97 if (NPC_Dialogue::has_dialogue $npc) {
98 $pl->attach ("npc_dialog_active");
111 $dialog{$id} = new NPC_Dialogue ob => $pl->ob, npc => $npc; 99 $pl->{npc_dialog} = new NPC_Dialogue pl => $pl, npc => $npc;
112 dialog_tell $id, $dialog{$id}, "hi"; 100 dialog_tell $id, $pl->{npc_dialog}, "hi";
113 $timer->start;
114 return; 101 return;
115 } 102 }
116 } 103 }
117 104
118 (msgtype => "error", msg => "nothing to talk to found") 105 (msgtype => "error", msg => "nothing to talk to found")
131=cut 118=cut
132 119
133cf::register_extcmd npc_dialog_tell => sub { 120cf::register_extcmd npc_dialog_tell => sub {
134 my ($pl, $msg) = @_; 121 my ($pl, $msg) = @_;
135 122
123 if (my $dialog = $pl->{npc_dialog}) {
136 dialog_tell $msg->{msgid}, $dialog{$msg->{msgid}}, $msg->{msg} 124 dialog_tell $msg->{msgid}, $dialog, $msg->{msg};
137 if $dialog{$msg->{msgid}}; 125 }
138 126
139 () 127 ()
140}; 128};
141 129
142=item extcmd npc_dialog_end { msgid => $id } 130=item extcmd npc_dialog_end { msgid => $id }
146=cut 134=cut
147 135
148cf::register_extcmd npc_dialog_end => sub { 136cf::register_extcmd npc_dialog_end => sub {
149 my ($pl, $msg) = @_; 137 my ($pl, $msg) = @_;
150 138
151 delete $dialog{$msg->{msgid}}; 139 if (my $dialog = delete $pl->{npc_dialog}) {
140 $pl->detach ("ncpa_dialog_active");
141 }
152 142
153 () 143 ()
154}; 144};
155
156cf::player->attach (
157 on_logout => sub {
158 my ($pl) = @_;
159
160 delete $dialog{$_} for grep $pl->ob == $dialog{$_}{ob}, keys %dialog;
161 },
162);
163 145
164=item ... = extcmd editor_support 146=item ... = extcmd editor_support
165 147
166Returns 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
167upload maps from/to the server. 149upload maps from/to the server.
194 176
195 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)
196}; 178};
197 179
198sub unload { 180sub unload {
199 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");
200 $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 }
201 } 186 }
202
203 %dialog = ();
204} 187}
205 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
206=back 226=back
207 227
208=cut 228=cut
209 229

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines