… | |
… | |
82 | |
82 | |
83 | =item $who - The cf::object::player object that initiated the dialogue. |
83 | =item $who - The cf::object::player object that initiated the dialogue. |
84 | |
84 | |
85 | =item $npc - The NPC (or magic_ear etc.) object that is being talked to. |
85 | =item $npc - The NPC (or magic_ear etc.) object that is being talked to. |
86 | |
86 | |
|
|
87 | =item $map - The map the NPC (not the player) is on. |
|
|
88 | |
87 | =item $msg - The actual message as passed to this method. |
89 | =item $msg - The actual message as passed to this method. |
88 | |
90 | |
89 | =item $match - An arrayref with previous results from C<@parse>. |
91 | =item $match - An arrayref with previous results from C<@parse>. |
90 | |
92 | |
91 | =item $state - A hashref that stores state variables associated |
93 | =item $state - A hashref that stores state variables associated |
… | |
… | |
96 | |
98 | |
97 | =item $flag - A hashref that stores flags associated with the player and |
99 | =item $flag - A hashref that stores flags associated with the player and |
98 | can be seen by all NPCs (so better name your flags uniquely). This is |
100 | can be seen by all NPCs (so better name your flags uniquely). This is |
99 | useful for storing e.g. quest information. See C<@setflag> and C<@ifflag>. |
101 | useful for storing e.g. quest information. See C<@setflag> and C<@ifflag>. |
100 | |
102 | |
101 | =item @find - see @find, below. |
103 | =item $find - see @find, below. |
102 | |
104 | |
103 | =back |
105 | =back |
104 | |
106 | |
105 | The environment is that standard "map scripting environment", which is |
107 | The environment is that standard "map scripting environment", which is |
106 | limited in the type of constructs allowed (no loops, for example). |
108 | limited in the type of constructs allowed (no loops, for example). |
… | |
… | |
156 | If the check fails, the match is skipped. |
158 | If the check fails, the match is skipped. |
157 | |
159 | |
158 | =item @find match expression |
160 | =item @find match expression |
159 | |
161 | |
160 | Like C<@check> in that it executes a match expression, but instead of |
162 | Like C<@check> in that it executes a match expression, but instead of |
161 | failing, it gathers all objects matched into the C<@find> array variable. |
163 | failing, it gathers all objects into an array and provides a reference to |
|
|
164 | the array in the C<$find> variable. |
162 | |
165 | |
163 | When you want to skip the match when no objects have been found, combine |
166 | When you want to skip the match when no objects have been found, combine |
164 | C<@find> with C<@cond>: |
167 | C<@find> with C<@cond>: |
165 | |
168 | |
166 | @match see my spellbook |
169 | @match see my spellbook |
167 | @find type=SPELLBOOK in inv |
170 | @find type=SPELLBOOK in inv |
168 | @cond @find |
171 | @cond @$find |
169 | It looks dirty. |
172 | It looks dirty. |
170 | @match see my spellbook |
173 | @match see my spellbook |
171 | I can't see any, where do you have it? |
174 | I can't see any, where do you have it? |
172 | |
175 | |
173 | =item @setstate state value |
176 | =item @setstate state value |
… | |
… | |
181 | See C<@ifstate> for an example. |
184 | See C<@ifstate> for an example. |
182 | |
185 | |
183 | =item @ifstate state value |
186 | =item @ifstate state value |
184 | |
187 | |
185 | Requires that the named C<state> has the given C<value>, otherwise this |
188 | Requires that the named C<state> has the given C<value>, otherwise this |
186 | topic is skipped. For more complex comparisons, see C<@cond> with |
189 | topic is skipped. For more complex comparisons, see C<@cond> with |
187 | C<$state>. Example: |
190 | C<$state>. Example: |
188 | |
191 | |
189 | @match quest |
192 | @match quest |
190 | @setstate question quest |
193 | @setstate question quest |
191 | Do you really want to help find the magic amulet of Beeblebrox? |
194 | Do you really want to help find the magic amulet of Beeblebrox? |
… | |
… | |
287 | my @find; |
290 | my @find; |
288 | |
291 | |
289 | my %vars = ( |
292 | my %vars = ( |
290 | who => $self->{ob}, |
293 | who => $self->{ob}, |
291 | npc => $self->{npc}, |
294 | npc => $self->{npc}, |
|
|
295 | map => $self->{npc}->map, |
292 | state => $state, |
296 | state => $state, |
293 | flag => $flag, |
297 | flag => $flag, |
294 | msg => $msg, |
298 | msg => $msg, |
295 | match => \@match, |
299 | match => \@match, |
|
|
300 | find => \@find, |
296 | ); |
301 | ); |
297 | |
302 | |
298 | local $self->{ob}{record_replies} = \@replies; |
303 | local $self->{ob}{record_replies} = \@replies; |
299 | |
304 | |
300 | # now execute @-commands (which can result in a no-match) |
305 | # now execute @-commands (which can result in a no-match) |
… | |
… | |
339 | } elsif ($cmd eq "msg") { |
344 | } elsif ($cmd eq "msg") { |
340 | push @replies, [$self->{npc}, (scalar cf::safe_eval $args, %vars)]; |
345 | push @replies, [$self->{npc}, (scalar cf::safe_eval $args, %vars)]; |
341 | |
346 | |
342 | } elsif ($cmd eq "setflag") { |
347 | } elsif ($cmd eq "setflag") { |
343 | my ($name, $value) = split /\s+/, $args, 2; |
348 | my ($name, $value) = split /\s+/, $args, 2; |
344 | $value ? $flag->{$name} = $value |
349 | defined $value ? $flag->{$name} = $value |
345 | : delete $flag->{$name}; |
350 | : delete $flag->{$name}; |
346 | |
351 | |
347 | } elsif ($cmd eq "setstate") { |
352 | } elsif ($cmd eq "setstate") { |
348 | my ($name, $value) = split /\s+/, $args, 2; |
353 | my ($name, $value) = split /\s+/, $args, 2; |
349 | $value ? $state->{$name} = $value |
354 | defined $value ? $state->{$name} = $value |
350 | : delete $state->{$name}; |
355 | : delete $state->{$name}; |
351 | |
356 | |
352 | } elsif ($cmd eq "ifflag") { |
357 | } elsif ($cmd eq "ifflag") { |
353 | my ($name, $value) = split /\s+/, $args, 2; |
358 | my ($name, $value) = split /\s+/, $args, 2; |
354 | $flag->{$name} eq $value |
359 | defined $value ? $flag->{$name} eq $value |
|
|
360 | : $flag->{$name} |
355 | or next topic; |
361 | or next topic; |
356 | |
362 | |
357 | } elsif ($cmd eq "ifstate") { |
363 | } elsif ($cmd eq "ifstate") { |
358 | my ($name, $value) = split /\s+/, $args, 2; |
364 | my ($name, $value) = split /\s+/, $args, 2; |
359 | $state->{$name} eq $value |
365 | defined $value ? $state->{$name} eq $value |
|
|
366 | : $state->{$name} |
360 | or next topic; |
367 | or next topic; |
361 | |
368 | |
362 | } elsif ($cmd eq "trigger") { |
369 | } elsif ($cmd eq "trigger") { |
363 | my ($con, $state) = split /\s+/, $args, 2; |
370 | my ($con, $state) = split /\s+/, $args, 2; |
364 | |
371 | |