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.7 by elmex, Tue Jun 19 18:14:36 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);
38
52 $reply = "..." unless $reply; 39 $reply = "..." unless defined $reply;
40 return if $reply eq ""; # NPC doesn't want to say, or wants to say something later
53 41
54 $pl->ext_reply ($id => msgtype => "reply", msg => $reply, add_topics => \@kw); 42 $pl->ext_reply ($id => msgtype => "reply", msg => $reply, add_topics => \@kw);
55} 43}
56 44
57=item ... = extcmd lookat { dx => $dx, dy => $dy } 45=item ... = extcmd lookat { dx => $dx, dy => $dy }
77 my %res; 65 my %res;
78 66
79 if ($pl->cell_visible ($dx, $dy)) { 67 if ($pl->cell_visible ($dx, $dy)) {
80 for my $ob ($pl->ob->map->at ($pl->ob->x + $dx, $pl->ob->y + $dy)) { 68 for my $ob ($pl->ob->map->at ($pl->ob->x + $dx, $pl->ob->y + $dy)) {
81 $res{npc_dialog} = $ob->name 69 $res{npc_dialog} = $ob->name
82 if $near && NPC_Dialogue::has_dialogue $ob; 70 if $near && NPC_Dialogue::has_dialogue $ob && !$pl->{npc_dialog};
83 } 71 }
84 } 72 }
85 73
86 %res 74 %res
87}; 75};
91Tries to start a dialogue with the mapspace specified by $dx and $dy (see 79Tries 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 80C<extcmd lookat>). The $msgid will be used as a handle for all future
93messages related to this dialog interaction. 81messages related to this dialog interaction.
94 82
95It either replies with an error reply or starts a dialog by telling 83It either replies with an error reply or starts a dialog by telling
96the npc "hi" and returning a reply strcuture as with C<extcmd 84the npc "hi" and returning a reply structure as with C<extcmd
97npc_dialog_tell>. 85npc_dialog_tell>.
98 86
99=cut 87=cut
100 88
101cf::register_extcmd npc_dialog_begin => sub { 89cf::register_extcmd npc_dialog_begin => sub {
103 my ($id, $dx, $dy) = @$msg{qw(msgid dx dy)}; 91 my ($id, $dx, $dy) = @$msg{qw(msgid dx dy)};
104 92
105 return unless $pl->ob && $pl->ob->map; 93 return unless $pl->ob && $pl->ob->map;
106 return unless (abs $dx) <= 2 && (abs $dy) <= 2; 94 return unless (abs $dx) <= 2 && (abs $dy) <= 2;
107 return unless $pl->cell_visible ($dx, $dy); 95 return unless $pl->cell_visible ($dx, $dy);
96 return if $pl->{npc_dialog}; # only one dialog at a time
108 97
109 for my $npc ($pl->ob->map->at ($pl->ob->x + $dx, $pl->ob->y + $dy)) { 98 for my $npc ($pl->ob->map->at ($pl->ob->x + $dx, $pl->ob->y + $dy)) {
110 if (NPC_Dialogue::has_dialogue $npc) { 99 if (NPC_Dialogue::has_dialogue $npc) {
100 $pl->attach ("npc_dialog_active");
111 $dialog{$id} = new NPC_Dialogue ob => $pl->ob, npc => $npc; 101 $pl->{npc_dialog} = new NPC_Dialogue pl => $pl, npc => $npc, id => $id;
112 dialog_tell $id, $dialog{$id}, "hi"; 102 dialog_tell $id, $pl->{npc_dialog}, "hi";
113 $timer->start;
114 return; 103 return;
115 } 104 }
116 } 105 }
117 106
118 (msgtype => "error", msg => "nothing to talk to found") 107 (msgtype => "error", msg => "nothing to talk to found")
131=cut 120=cut
132 121
133cf::register_extcmd npc_dialog_tell => sub { 122cf::register_extcmd npc_dialog_tell => sub {
134 my ($pl, $msg) = @_; 123 my ($pl, $msg) = @_;
135 124
125 if (my $dialog = $pl->{npc_dialog}) {
136 dialog_tell $msg->{msgid}, $dialog{$msg->{msgid}}, $msg->{msg} 126 dialog_tell $msg->{msgid}, $dialog, $msg->{msg};
137 if $dialog{$msg->{msgid}}; 127 }
138 128
139 () 129 ()
140}; 130};
141 131
142=item extcmd npc_dialog_end { msgid => $id } 132=item extcmd npc_dialog_end { msgid => $id }
146=cut 136=cut
147 137
148cf::register_extcmd npc_dialog_end => sub { 138cf::register_extcmd npc_dialog_end => sub {
149 my ($pl, $msg) = @_; 139 my ($pl, $msg) = @_;
150 140
151 delete $dialog{$msg->{msgid}}; 141 if (my $dialog = delete $pl->{npc_dialog}) {
142 $pl->detach ("ncpa_dialog_active");
143 }
152 144
153 () 145 ()
154}; 146};
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 147
164=item ... = extcmd editor_support 148=item ... = extcmd editor_support
165 149
166Returns the value required by clients that have an editor to download and 150Returns the value required by clients that have an editor to download and
167upload maps from/to the server. 151upload maps from/to the server.
194 178
195 map +($_ => $cf::CFG{"editor_$_"}), qw(servertype gameserver testserver cvs_root lib_root builder_ui) 179 map +($_ => $cf::CFG{"editor_$_"}), qw(servertype gameserver testserver cvs_root lib_root builder_ui)
196}; 180};
197 181
198sub unload { 182sub unload {
199 while (my ($id, $dialog) = each %dialog) { 183 for my $pl (cf::player::list) {
184 if (my $dialog = delete $pl->{npc_dialog}) {
185 $pl->detach ("npc_dialog_active");
200 $dialog->{ob}->contr->ext_reply ($id => msgtype => "error", msg => "npc dialogue module was reloaded"); 186 $pl->ext_reply ($dialog->{id} => msgtype => "error", msg => "npc dialogue module was reloaded");
187 }
201 } 188 }
202
203 %dialog = ();
204} 189}
205 190
191cf::player::attachment npc_dialog_active =>
192 on_logout => sub {
193 my ($pl) = @_;
194
195 delete $pl->{npc_dialog};
196 $pl->detach ("npc_dialog_active");
197 },
198 on_move => sub {
199 my ($pl, $dir) = @_;
200
201 if (my $dialog = $pl->{npc_dialog}) {
202 warn "on_move<@_>\n";#d#
203 warn $pl->ob;
204 warn $dialog;
205 warn $dialog->{npc};
206 warn $dialog->{npc}->is_valid;
207
208 my (undef, $dx, $dy) = $pl->ob->rangevector ($dialog->{npc});
209
210 return if (abs $dx) <= 2 && (abs $dy) <= 2;
211
212 $pl->ext_reply ($dialog->{id} => msgtype => "error", msg => "out of range");
213 }
214
215 delete $pl->{npc_dialog};
216 $pl->detach ("npc_dialog_active");
217 },
218;
219
220cf::player->attach (
221 on_login => sub {
222 my ($pl) = @_;
223
224 delete $pl->{npc_dialog};
225 },
226);
227
206=back 228=back
207 229
208=cut 230=cut
209 231

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines