--- deliantra/server/ext/NPC_Dialogue.pm 2009/01/08 19:23:44 1.14 +++ deliantra/server/ext/NPC_Dialogue.pm 2009/10/26 02:48:02 1.16 @@ -98,6 +98,8 @@ can be seen by all NPCs (so better name your flags uniquely). This is useful for storing e.g. quest information. See C<@setflag> and C<@ifflag>. +=item @find - see @find, below. + =back The environment is that standard "map scripting environment", which is @@ -140,7 +142,33 @@ =item @msg perl Like C<@cond>, but the return value will be stringified and prepended to -the message. +the reply message. + +=item @check match expression + +Executes a match expression (see +http://pod.tst.eu/http://cvs.schmorp.de/deliantra/server/lib/cf/match.pm) +to see if it matches. + +C is the npc object, C, C and C are the +player communicating with the NPC. + +If the check fails, the match is skipped. + +=item @find match expression + +Like C<@check> in that it executes a match expression, but instead of +failing, it gathers all objects matched into the C<@find> array variable. + +When you want to skip the match when no objects have been found, combine +C<@find> with C<@cond>: + + @match see my spellbook + @find type=SPELLBOOK in inv + @cond @find + It looks dirty. + @match see my spellbook + I can't see any, where do you have it? =item @setstate state value @@ -173,13 +201,21 @@ markers and other information (e.g. reputation/alignment). Flags are persistent over the lifetime of a player, so be careful :) +Perversely enough, using C<@setfflag> without a C clears the flag +as if it was never set, so always provide a flag value (e.g. C<1>) when +you want to set the flag. + See C<@ifflag> for an example. =item @ifflag flag value Requires that the named C has the given C, otherwise this -topic is skipped. For more complex comparisons, see C<@cond> with -C<$flag>. Example: +topic is skipped. For more complex comparisons, see C<@cond> with +C<$flag>. + +If no C is given, then the ifflag succeeds when the flag is true. + +Example: @match I want to do the quest! @setflag kings_quest 1 @@ -248,6 +284,8 @@ my $state = $self->{npc}{$self->{ob}->name}{dialog_state} ||= {}; my $flag = $self->{ob}{dialog_flag} ||= {}; + my @find; + my %vars = ( who => $self->{ob}, npc => $self->{npc}, @@ -285,6 +323,19 @@ cf::safe_eval $args, %vars; warn "\@eval evaluation error: $@\n" if $@; + } elsif ($cmd eq "check") { + eval { + cf::match::match $args, $self->{ob}, $self->{npc}, $self->{ob} + or next topic; + }; + warn "\@check evaluation error: $@\n" if $@; + + } elsif ($cmd eq "find") { + @find = eval { + cf::match::match $args, $self->{ob}, $self->{npc}, $self->{ob} + }; + warn "\@find evaluation error: $@\n" if $@; + } elsif ($cmd eq "msg") { push @replies, [$self->{npc}, (scalar cf::safe_eval $args, %vars)];