--- deliantra/server/ext/NPC_Dialogue.pm 2007/08/26 04:07:40 1.8 +++ deliantra/server/ext/NPC_Dialogue.pm 2009/01/08 19:23:44 1.14 @@ -14,12 +14,6 @@ use strict; -sub has_dialogue($) { - my ($ob) = @_; - - $ob->msg =~ /^\@match /; -} - sub parse_message($) { map [split /\n/, $_, 2], grep length, @@ -127,7 +121,7 @@ @match found earhorn @cond grep $_->slaying =~ /Gramp's walking stick/, $who->inv - @eval my @g = grep { $_->slaying =~ /Gramp's walking stick/ } $who->inv; $g[0]->decrease_ob_nr (1); + @eval my @g = grep { $_->slaying =~ /Gramp's walking stick/ } $who->inv; $g[0]->decrease; Thanks for the earhorn! This example is a bit more complex. The C<@eval> statement will search @@ -209,9 +203,10 @@ state won't be changed when the connection is triggered by other triggers. So be careful when triggering the connection from other objects. -When a state argument is given it should be either 0 or 1. 1 will 'push' the connection -and 0 will 'release' the connection. This is useful for example when you want to -let a npc control a door. +When a state argument is given it should be a positive integer. Any value +C will 'push' the connection (in general, you should specify C<1> +for this) and C<0> will 'release' the connection. This is useful for +example when you want to let an NPC control a door. Trigger all objects with the given connected-id by 'releasing' the connection. @@ -315,13 +310,12 @@ } elsif ($cmd eq "trigger") { my ($con, $state) = split /\s+/, $args, 2; - $con = $con * 1; if (defined $state) { - $self->{npc}->map->trigger ($args, $state); + $self->{npc}->map->trigger ($con, $state, $self->{npc}, $self->{ob}); } else { - my $rvalue = \$self->{npc}{dialog_trigger}{$con}; - $self->{npc}->map->trigger ($con, $$rvalue = !$$rvalue); + my $rvalue = \$self->{npc}{dialog_trigger}{$con+0}; + $self->{npc}->map->trigger ($con, $$rvalue = !$$rvalue, $self->{npc}, $self->{ob}); } } elsif ($cmd eq "addtopic") { @@ -340,10 +334,6 @@ delete $self->{npc}{$self->{ob}->name}{dialog_state} unless %$state; delete $self->{ob}{dialog_flag} unless %$flag; - # combine lines into paragraphs - $reply =~ s/(?<=\S)\n(?=\w)/ /g; - $reply =~ s/\n\n/\n/g; - # ignores flags and npc from replies $reply = join "\n", (map $_->[1], @replies), $reply; @@ -357,6 +347,9 @@ } } + $self->{npc}->use_trigger ($self->{ob}) + if $self->{npc}->type == cf::MAGIC_EAR; + return wantarray ? ($reply, @kw) : $reply; } }