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.4 by root, Sat Jun 16 14:35:41 2007 UTC vs.
Revision 1.12 by root, Thu Dec 18 02:49:22 2008 UTC

4 4
5=head1 DESCRIPTION 5=head1 DESCRIPTION
6 6
7NPC dialogue support module. 7NPC dialogue support module.
8 8
9=over 4
10
9=cut 11=cut
10 12
11package NPC_Dialogue; 13package NPC_Dialogue;
12 14
13use strict; 15use strict;
14
15sub has_dialogue($) {
16 my ($ob) = @_;
17
18 $ob->msg =~ /^\@match /;
19}
20 16
21sub parse_message($) { 17sub parse_message($) {
22 map [split /\n/, $_, 2], 18 map [split /\n/, $_, 2],
23 grep length, 19 grep length,
24 split /^\@match /m, 20 split /^\@match /m,
105=back 101=back
106 102
107The environment is that standard "map scripting environment", which is 103The environment is that standard "map scripting environment", which is
108limited in the type of constructs allowed (no loops, for example). 104limited in the type of constructs allowed (no loops, for example).
109 105
106Here is a example:
107
108=over 4
109
110=item B<matching for an item name>
111
112 @match hi
113 @cond grep $_->name =~ /royalty/, $who->inv
114 You got royalties there! Wanna have!
115
116You may want to change the C<name> method there to something like C<title>,
117C<slaying> or any other method that is allowed to be called on a
118C<cf::object> here.
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
134=back
135
110=item @eval perl 136=item @eval perl
111 137
112Like C<@cond>, but proceed regardless of the outcome. 138Like C<@cond>, but proceed regardless of the outcome.
113 139
114=item @msg perl 140=item @msg perl
180When 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 either 0 or 1. 1 will 'push' the connection
181and 0 will 'release' the connection. This is useful for example when you want to 207and 0 will 'release' the connection. This is useful for example when you want to
182let a npc control a door. 208let a npc control a door.
183 209
184Trigger all objects with the given connected-id by 'releasing' the connection. 210Trigger all objects with the given connected-id by 'releasing' the connection.
211
212=item @playersound face-name
213
214Plays the given sound face (either an alias or sound file path) so that
215only the player talking to the npc can hear it.
216
217=item @npcsound face-name
218
219Plays the given sound face (either an alias or sound file path) as if
220the npc had made that sound, i.e. it will be located at the npc and all
221players near enough can hear it.
185 222
186=item @addtopic topic 223=item @addtopic topic
187 224
188Adds the given topic names (separated by C<|>) to the list of topics 225Adds the given topic names (separated by C<|>) to the list of topics
189returned. 226returned.
231 or next topic; 268 or next topic;
232 269
233 } elsif ($cmd eq "comment") { 270 } elsif ($cmd eq "comment") {
234 # nop 271 # nop
235 272
273 } elsif ($cmd eq "playersound") {
274 $self->{ob}->contr->play_sound (cf::sound::find $args);
275
276 } elsif ($cmd eq "npcsound") {
277 $self->{npc}->play_sound (cf::sound::find $args);
278
236 } elsif ($cmd eq "cond") { 279 } elsif ($cmd eq "cond") {
237 cf::safe_eval $args, %vars 280 cf::safe_eval $args, %vars
238 or next topic; 281 or next topic;
239 282
240 } elsif ($cmd eq "eval") { 283 } elsif ($cmd eq "eval") {
288 } 331 }
289 } 332 }
290 333
291 delete $self->{npc}{$self->{ob}->name}{dialog_state} unless %$state; 334 delete $self->{npc}{$self->{ob}->name}{dialog_state} unless %$state;
292 delete $self->{ob}{dialog_flag} unless %$flag; 335 delete $self->{ob}{dialog_flag} unless %$flag;
293
294 # combine lines into paragraphs
295 $reply =~ s/(?<=\S)\n(?=\w)/ /g;
296 $reply =~ s/\n\n/\n/g;
297 336
298 # ignores flags and npc from replies 337 # ignores flags and npc from replies
299 $reply = join "\n", (map $_->[1], @replies), $reply; 338 $reply = join "\n", (map $_->[1], @replies), $reply;
300 339
301 # now mark up all matching keywords 340 # now mark up all matching keywords
306 last; 345 last;
307 } 346 }
308 } 347 }
309 } 348 }
310 349
350 $self->{npc}->use_trigger if $self->{npc}->type == cf::MAGIC_EAR;
351
311 return wantarray ? ($reply, @kw) : $reply; 352 return wantarray ? ($reply, @kw) : $reply;
312 } 353 }
313 } 354 }
314 } 355 }
315 356

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines