… | |
… | |
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, |
… | |
… | |
207 | When the state argument is omitted the trigger is stateful and retains an |
201 | When the state argument is omitted the trigger is stateful and retains an |
208 | internal state per connected-id. There is a limitation to the use of this: The |
202 | internal state per connected-id. There is a limitation to the use of this: The |
209 | state won't be changed when the connection is triggered by other triggers. So |
203 | state won't be changed when the connection is triggered by other triggers. So |
210 | be careful when triggering the connection from other objects. |
204 | be careful when triggering the connection from other objects. |
211 | |
205 | |
212 | 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 a positive integer. Any value |
213 | and 0 will 'release' the connection. This is useful for example when you want to |
207 | C<!= 0> will 'push' the connection (in general, you should specify C<1> |
214 | let a npc control a door. |
208 | for this) and C<0> will 'release' the connection. This is useful for |
|
|
209 | example when you want to let an NPC control a door. |
215 | |
210 | |
216 | Trigger all objects with the given connected-id by 'releasing' the connection. |
211 | Trigger all objects with the given connected-id by 'releasing' the connection. |
217 | |
212 | |
218 | =item @playersound face-name |
213 | =item @playersound face-name |
219 | |
214 | |
… | |
… | |
313 | $state->{$name} eq $value |
308 | $state->{$name} eq $value |
314 | or next topic; |
309 | or next topic; |
315 | |
310 | |
316 | } elsif ($cmd eq "trigger") { |
311 | } elsif ($cmd eq "trigger") { |
317 | my ($con, $state) = split /\s+/, $args, 2; |
312 | my ($con, $state) = split /\s+/, $args, 2; |
318 | $con = $con * 1; |
|
|
319 | |
313 | |
320 | if (defined $state) { |
314 | if (defined $state) { |
321 | $self->{npc}->map->trigger ($args, $state); |
315 | $self->{npc}->map->trigger ($con, $state, $self->{npc}, $self->{ob}); |
322 | } else { |
316 | } else { |
323 | my $rvalue = \$self->{npc}{dialog_trigger}{$con}; |
317 | my $rvalue = \$self->{npc}{dialog_trigger}{$con+0}; |
324 | $self->{npc}->map->trigger ($con, $$rvalue = !$$rvalue); |
318 | $self->{npc}->map->trigger ($con, $$rvalue = !$$rvalue, $self->{npc}, $self->{ob}); |
325 | } |
319 | } |
326 | |
320 | |
327 | } elsif ($cmd eq "addtopic") { |
321 | } elsif ($cmd eq "addtopic") { |
328 | push @kw, split /\|/, $args; |
322 | push @kw, split /\|/, $args; |
329 | $self->{add_topic}->(split /\s*\|\s*/, $args) if $self->{add_topic}; |
323 | $self->{add_topic}->(split /\s*\|\s*/, $args) if $self->{add_topic}; |
… | |
… | |
337 | } |
331 | } |
338 | } |
332 | } |
339 | |
333 | |
340 | delete $self->{npc}{$self->{ob}->name}{dialog_state} unless %$state; |
334 | delete $self->{npc}{$self->{ob}->name}{dialog_state} unless %$state; |
341 | delete $self->{ob}{dialog_flag} unless %$flag; |
335 | delete $self->{ob}{dialog_flag} unless %$flag; |
342 | |
|
|
343 | # combine lines into paragraphs |
|
|
344 | $reply =~ s/(?<=\S)\n(?=\w)/ /g; |
|
|
345 | $reply =~ s/\n\n/\n/g; |
|
|
346 | |
336 | |
347 | # ignores flags and npc from replies |
337 | # ignores flags and npc from replies |
348 | $reply = join "\n", (map $_->[1], @replies), $reply; |
338 | $reply = join "\n", (map $_->[1], @replies), $reply; |
349 | |
339 | |
350 | # now mark up all matching keywords |
340 | # now mark up all matching keywords |
… | |
… | |
355 | last; |
345 | last; |
356 | } |
346 | } |
357 | } |
347 | } |
358 | } |
348 | } |
359 | |
349 | |
|
|
350 | $self->{npc}->use_trigger ($self->{ob}) |
|
|
351 | if $self->{npc}->type == cf::MAGIC_EAR; |
|
|
352 | |
360 | return wantarray ? ($reply, @kw) : $reply; |
353 | return wantarray ? ($reply, @kw) : $reply; |
361 | } |
354 | } |
362 | } |
355 | } |
363 | } |
356 | } |
364 | |
357 | |