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

Comparing deliantra/server/ext/NPC_Dialogue.pm (file contents):
Revision 1.6 by elmex, Wed Aug 8 07:55:57 2007 UTC vs.
Revision 1.14 by root, Thu Jan 8 19:23:44 2009 UTC

11=cut 11=cut
12 12
13package NPC_Dialogue; 13package NPC_Dialogue;
14 14
15use strict; 15use strict;
16
17sub has_dialogue($) {
18 my ($ob) = @_;
19
20 $ob->msg =~ /^\@match /;
21}
22 16
23sub parse_message($) { 17sub parse_message($) {
24 map [split /\n/, $_, 2], 18 map [split /\n/, $_, 2],
25 grep length, 19 grep length,
26 split /^\@match /m, 20 split /^\@match /m,
121 115
122You may want to change the C<name> method there to something like C<title>, 116You may want to change the C<name> method there to something like C<title>,
123C<slaying> or any other method that is allowed to be called on a 117C<slaying> or any other method that is allowed to be called on a
124C<cf::object> here. 118C<cf::object> here.
125 119
120=item B<matching for an item name and removing the matched item>
121
122 @match found earhorn
123 @cond grep $_->slaying =~ /Gramp's walking stick/, $who->inv
124 @eval my @g = grep { $_->slaying =~ /Gramp's walking stick/ } $who->inv; $g[0]->decrease;
125 Thanks for the earhorn!
126
127This example is a bit more complex. The C<@eval> statement will search
128the players inventory for the same term as the C<@cond> and then
129decreases the number of objects used there.
130
131(See also the map: C<scorn/houses/cornerbrook.map> for an example how this is
132used in the real world :-)
133
126=back 134=back
127 135
128=item @eval perl 136=item @eval perl
129 137
130Like C<@cond>, but proceed regardless of the outcome. 138Like C<@cond>, but proceed regardless of the outcome.
193When the state argument is omitted the trigger is stateful and retains an 201When the state argument is omitted the trigger is stateful and retains an
194internal state per connected-id. There is a limitation to the use of this: The 202internal state per connected-id. There is a limitation to the use of this: The
195state won't be changed when the connection is triggered by other triggers. So 203state won't be changed when the connection is triggered by other triggers. So
196be careful when triggering the connection from other objects. 204be careful when triggering the connection from other objects.
197 205
198When a state argument is given it should be either 0 or 1. 1 will 'push' the connection 206When a state argument is given it should be a positive integer. Any value
199and 0 will 'release' the connection. This is useful for example when you want to 207C<!= 0> will 'push' the connection (in general, you should specify C<1>
200let a npc control a door. 208for this) and C<0> will 'release' the connection. This is useful for
209example when you want to let an NPC control a door.
201 210
202Trigger all objects with the given connected-id by 'releasing' the connection. 211Trigger all objects with the given connected-id by 'releasing' the connection.
212
213=item @playersound face-name
214
215Plays the given sound face (either an alias or sound file path) so that
216only the player talking to the npc can hear it.
217
218=item @npcsound face-name
219
220Plays the given sound face (either an alias or sound file path) as if
221the npc had made that sound, i.e. it will be located at the npc and all
222players near enough can hear it.
203 223
204=item @addtopic topic 224=item @addtopic topic
205 225
206Adds the given topic names (separated by C<|>) to the list of topics 226Adds the given topic names (separated by C<|>) to the list of topics
207returned. 227returned.
249 or next topic; 269 or next topic;
250 270
251 } elsif ($cmd eq "comment") { 271 } elsif ($cmd eq "comment") {
252 # nop 272 # nop
253 273
274 } elsif ($cmd eq "playersound") {
275 $self->{ob}->contr->play_sound (cf::sound::find $args);
276
277 } elsif ($cmd eq "npcsound") {
278 $self->{npc}->play_sound (cf::sound::find $args);
279
254 } elsif ($cmd eq "cond") { 280 } elsif ($cmd eq "cond") {
255 cf::safe_eval $args, %vars 281 cf::safe_eval $args, %vars
256 or next topic; 282 or next topic;
257 283
258 } elsif ($cmd eq "eval") { 284 } elsif ($cmd eq "eval") {
282 $state->{$name} eq $value 308 $state->{$name} eq $value
283 or next topic; 309 or next topic;
284 310
285 } elsif ($cmd eq "trigger") { 311 } elsif ($cmd eq "trigger") {
286 my ($con, $state) = split /\s+/, $args, 2; 312 my ($con, $state) = split /\s+/, $args, 2;
287 $con = $con * 1;
288 313
289 if (defined $state) { 314 if (defined $state) {
290 $self->{npc}->map->trigger ($args, $state); 315 $self->{npc}->map->trigger ($con, $state, $self->{npc}, $self->{ob});
291 } else { 316 } else {
292 my $rvalue = \$self->{npc}{dialog_trigger}{$con}; 317 my $rvalue = \$self->{npc}{dialog_trigger}{$con+0};
293 $self->{npc}->map->trigger ($con, $$rvalue = !$$rvalue); 318 $self->{npc}->map->trigger ($con, $$rvalue = !$$rvalue, $self->{npc}, $self->{ob});
294 } 319 }
295 320
296 } elsif ($cmd eq "addtopic") { 321 } elsif ($cmd eq "addtopic") {
297 push @kw, split /\|/, $args; 322 push @kw, split /\|/, $args;
298 $self->{add_topic}->(split /\s*\|\s*/, $args) if $self->{add_topic}; 323 $self->{add_topic}->(split /\s*\|\s*/, $args) if $self->{add_topic};
306 } 331 }
307 } 332 }
308 333
309 delete $self->{npc}{$self->{ob}->name}{dialog_state} unless %$state; 334 delete $self->{npc}{$self->{ob}->name}{dialog_state} unless %$state;
310 delete $self->{ob}{dialog_flag} unless %$flag; 335 delete $self->{ob}{dialog_flag} unless %$flag;
311
312 # combine lines into paragraphs
313 $reply =~ s/(?<=\S)\n(?=\w)/ /g;
314 $reply =~ s/\n\n/\n/g;
315 336
316 # ignores flags and npc from replies 337 # ignores flags and npc from replies
317 $reply = join "\n", (map $_->[1], @replies), $reply; 338 $reply = join "\n", (map $_->[1], @replies), $reply;
318 339
319 # now mark up all matching keywords 340 # now mark up all matching keywords
324 last; 345 last;
325 } 346 }
326 } 347 }
327 } 348 }
328 349
350 $self->{npc}->use_trigger ($self->{ob})
351 if $self->{npc}->type == cf::MAGIC_EAR;
352
329 return wantarray ? ($reply, @kw) : $reply; 353 return wantarray ? ($reply, @kw) : $reply;
330 } 354 }
331 } 355 }
332 } 356 }
333 357

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines