… | |
… | |
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, |
… | |
… | |
125 | |
119 | |
126 | =item B<matching for an item name and removing the matched item> |
120 | =item B<matching for an item name and removing the matched item> |
127 | |
121 | |
128 | @match found earhorn |
122 | @match found earhorn |
129 | @cond grep $_->slaying =~ /Gramp's walking stick/, $who->inv |
123 | @cond grep $_->slaying =~ /Gramp's walking stick/, $who->inv |
130 | @eval my @g = grep { $_->slaying =~ /Gramp's walking stick/ } $who->inv; $g[0]->decrease_ob_nr (1); |
124 | @eval my @g = grep { $_->slaying =~ /Gramp's walking stick/ } $who->inv; $g[0]->decrease; |
131 | Thanks for the earhorn! |
125 | Thanks for the earhorn! |
132 | |
126 | |
133 | This example is a bit more complex. The C<@eval> statement will search |
127 | This example is a bit more complex. The C<@eval> statement will search |
134 | the players inventory for the same term as the C<@cond> and then |
128 | the players inventory for the same term as the C<@cond> and then |
135 | decreases the number of objects used there. |
129 | decreases the number of objects used there. |
… | |
… | |
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 if $self->{npc}->type == cf::MAGIC_EAR; |
|
|
351 | |
360 | return wantarray ? ($reply, @kw) : $reply; |
352 | return wantarray ? ($reply, @kw) : $reply; |
361 | } |
353 | } |
362 | } |
354 | } |
363 | } |
355 | } |
364 | |
356 | |