… | |
… | |
11 | =cut |
11 | =cut |
12 | |
12 | |
13 | package NPC_Dialogue; |
13 | package NPC_Dialogue; |
14 | |
14 | |
15 | use strict; |
15 | use strict; |
16 | |
|
|
17 | sub has_dialogue($) { |
|
|
18 | my ($ob) = @_; |
|
|
19 | |
|
|
20 | $ob->msg =~ /^\@match /; |
|
|
21 | } |
|
|
22 | |
16 | |
23 | sub parse_message($) { |
17 | sub 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 | |
122 | You may want to change the C<name> method there to something like C<title>, |
116 | You may want to change the C<name> method there to something like C<title>, |
123 | C<slaying> or any other method that is allowed to be called on a |
117 | C<slaying> or any other method that is allowed to be called on a |
124 | C<cf::object> here. |
118 | C<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 | |
|
|
127 | This example is a bit more complex. The C<@eval> statement will search |
|
|
128 | the players inventory for the same term as the C<@cond> and then |
|
|
129 | decreases the number of objects used there. |
|
|
130 | |
|
|
131 | (See also the map: C<scorn/houses/cornerbrook.map> for an example how this is |
|
|
132 | used in the real world :-) |
|
|
133 | |
126 | =back |
134 | =back |
127 | |
135 | |
128 | =item @eval perl |
136 | =item @eval perl |
129 | |
137 | |
130 | Like C<@cond>, but proceed regardless of the outcome. |
138 | Like C<@cond>, but proceed regardless of the outcome. |
… | |
… | |
198 | When a state argument is given it should be either 0 or 1. 1 will 'push' the connection |
206 | When a state argument is given it should be either 0 or 1. 1 will 'push' the connection |
199 | and 0 will 'release' the connection. This is useful for example when you want to |
207 | and 0 will 'release' the connection. This is useful for example when you want to |
200 | let a npc control a door. |
208 | let a npc control a door. |
201 | |
209 | |
202 | Trigger all objects with the given connected-id by 'releasing' the connection. |
210 | Trigger all objects with the given connected-id by 'releasing' the connection. |
|
|
211 | |
|
|
212 | =item @playersound face-name |
|
|
213 | |
|
|
214 | Plays the given sound face (either an alias or sound file path) so that |
|
|
215 | only the player talking to the npc can hear it. |
|
|
216 | |
|
|
217 | =item @npcsound face-name |
|
|
218 | |
|
|
219 | Plays the given sound face (either an alias or sound file path) as if |
|
|
220 | the npc had made that sound, i.e. it will be located at the npc and all |
|
|
221 | players near enough can hear it. |
203 | |
222 | |
204 | =item @addtopic topic |
223 | =item @addtopic topic |
205 | |
224 | |
206 | Adds the given topic names (separated by C<|>) to the list of topics |
225 | Adds the given topic names (separated by C<|>) to the list of topics |
207 | returned. |
226 | returned. |
… | |
… | |
249 | or next topic; |
268 | or next topic; |
250 | |
269 | |
251 | } elsif ($cmd eq "comment") { |
270 | } elsif ($cmd eq "comment") { |
252 | # nop |
271 | # nop |
253 | |
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 | |
254 | } elsif ($cmd eq "cond") { |
279 | } elsif ($cmd eq "cond") { |
255 | cf::safe_eval $args, %vars |
280 | cf::safe_eval $args, %vars |
256 | or next topic; |
281 | or next topic; |
257 | |
282 | |
258 | } elsif ($cmd eq "eval") { |
283 | } elsif ($cmd eq "eval") { |
… | |
… | |
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 |