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.1 by root, Fri Dec 15 19:29:18 2006 UTC vs.
Revision 1.5 by root, Sat Jun 16 14:35:41 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}
65=cut 53=cut
66 54
67cf::register_extcmd lookat => sub { 55cf::register_extcmd lookat => sub {
68 my ($pl, $msg) = @_; 56 my ($pl, $msg) = @_;
69 my ($dx, $dy) = @$msg{qw(dx dy)}; 57 my ($dx, $dy) = @$msg{qw(dx dy)};
58
59 return unless $pl->ob && $pl->ob->map;
70 60
71 my $near = (abs $dx) <= 2 && (abs $dy) <= 2; 61 my $near = (abs $dx) <= 2 && (abs $dy) <= 2;
72 62
73 my %res; 63 my %res;
74 64
75 if ($pl->cell_visible ($dx, $dy)) { 65 if ($pl->cell_visible ($dx, $dy)) {
76 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)) {
77 $res{npc_dialog} = $ob->name 67 $res{npc_dialog} = $ob->name
78 if $near && NPC_Dialogue::has_dialogue $ob; 68 if $near && NPC_Dialogue::has_dialogue $ob && !$pl->{npc_dialog};
79 } 69 }
80 } 70 }
81 71
82 %res 72 %res
83}; 73};
87Tries 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
88C<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
89messages related to this dialog interaction. 79messages related to this dialog interaction.
90 80
91It 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
92the npc "hi" and returning a reply strcuture as with C<extcmd 82the npc "hi" and returning a reply structure as with C<extcmd
93npc_dialog_tell>. 83npc_dialog_tell>.
94 84
95=cut 85=cut
96 86
97cf::register_extcmd npc_dialog_begin => sub { 87cf::register_extcmd npc_dialog_begin => sub {
98 my ($pl, $msg) = @_; 88 my ($pl, $msg) = @_;
99 my ($id, $dx, $dy) = @$msg{qw(msgid dx dy)}; 89 my ($id, $dx, $dy) = @$msg{qw(msgid dx dy)};
100 90
91 return unless $pl->ob && $pl->ob->map;
101 return unless (abs $dx) <= 2 && (abs $dy) <= 2; 92 return unless (abs $dx) <= 2 && (abs $dy) <= 2;
102 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
103 95
104 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)) {
105 if (NPC_Dialogue::has_dialogue $npc) { 97 if (NPC_Dialogue::has_dialogue $npc) {
98 $pl->attach ("npc_dialog_active");
106 $dialog{$id} = new NPC_Dialogue ob => $pl->ob, npc => $npc; 99 $pl->{npc_dialog} = new NPC_Dialogue pl => $pl, npc => $npc;
107 dialog_tell $id, $dialog{$id}, "hi"; 100 dialog_tell $id, $pl->{npc_dialog}, "hi";
108 $timer->start;
109 return; 101 return;
110 } 102 }
111 } 103 }
112 104
113 (msgtype => "error", msg => "nothing to talk to found") 105 (msgtype => "error", msg => "nothing to talk to found")
126=cut 118=cut
127 119
128cf::register_extcmd npc_dialog_tell => sub { 120cf::register_extcmd npc_dialog_tell => sub {
129 my ($pl, $msg) = @_; 121 my ($pl, $msg) = @_;
130 122
123 if (my $dialog = $pl->{npc_dialog}) {
131 dialog_tell $msg->{msgid}, $dialog{$msg->{msgid}}, $msg->{msg} 124 dialog_tell $msg->{msgid}, $dialog, $msg->{msg};
132 if $dialog{$msg->{msgid}}; 125 }
133 126
134 () 127 ()
135}; 128};
136 129
137=item extcmd npc_dialog_end { msgid => $id } 130=item extcmd npc_dialog_end { msgid => $id }
141=cut 134=cut
142 135
143cf::register_extcmd npc_dialog_end => sub { 136cf::register_extcmd npc_dialog_end => sub {
144 my ($pl, $msg) = @_; 137 my ($pl, $msg) = @_;
145 138
146 delete $dialog{$msg->{msgid}}; 139 if (my $dialog = delete $pl->{npc_dialog}) {
140 $pl->detach ("ncpa_dialog_active");
141 }
147 142
148 () 143 ()
149}; 144};
150
151cf::attach_to_players
152 on_logout => sub {
153 my ($pl) = @_;
154
155 delete $dialog{$_} for grep $pl->ob == $dialog{$_}{ob}, keys %dialog;
156 },
157;
158 145
159=item ... = extcmd editor_support 146=item ... = extcmd editor_support
160 147
161Returns 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
162upload maps from/to the server. 149upload maps from/to the server.
189 176
190 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)
191}; 178};
192 179
193sub unload { 180sub unload {
194 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");
195 $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 }
196 } 186 }
197
198 %dialog = ();
199} 187}
200 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
201=back 226=back
202 227
203=cut 228=cut
204 229

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines