… | |
… | |
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? |
… | |
… | |
199 | associated with a specific player and can be seen by all NPCs. with |
202 | associated with a specific player and can be seen by all NPCs. with |
200 | respect to a particular player, which makes them suitable to store quest |
203 | respect to a particular player, which makes them suitable to store quest |
201 | markers and other information (e.g. reputation/alignment). Flags are |
204 | markers and other information (e.g. reputation/alignment). Flags are |
202 | persistent over the lifetime of a player, so be careful :) |
205 | persistent over the lifetime of a player, so be careful :) |
203 | |
206 | |
|
|
207 | Perversely enough, using C<@setfflag> without a C<value> clears the flag |
|
|
208 | as if it was never set, so always provide a flag value (e.g. C<1>) when |
|
|
209 | you want to set the flag. |
|
|
210 | |
204 | See C<@ifflag> for an example. |
211 | See C<@ifflag> for an example. |
205 | |
212 | |
206 | =item @ifflag flag value |
213 | =item @ifflag flag value |
207 | |
214 | |
208 | Requires that the named C<flag> has the given C<value>, otherwise this |
215 | Requires that the named C<flag> has the given C<value>, otherwise this |
209 | topic is skipped. For more complex comparisons, see C<@cond> with |
216 | topic is skipped. For more complex comparisons, see C<@cond> with |
210 | C<$flag>. Example: |
217 | C<$flag>. |
|
|
218 | |
|
|
219 | If no C<value> is given, then the ifflag succeeds when the flag is true. |
|
|
220 | |
|
|
221 | Example: |
211 | |
222 | |
212 | @match I want to do the quest! |
223 | @match I want to do the quest! |
213 | @setflag kings_quest 1 |
224 | @setflag kings_quest 1 |
214 | Then seek out Bumblebee in Navar, he will tell you... |
225 | Then seek out Bumblebee in Navar, he will tell you... |
215 | @match I did the quest |
226 | @match I did the quest |
… | |
… | |
279 | my @find; |
290 | my @find; |
280 | |
291 | |
281 | my %vars = ( |
292 | my %vars = ( |
282 | who => $self->{ob}, |
293 | who => $self->{ob}, |
283 | npc => $self->{npc}, |
294 | npc => $self->{npc}, |
|
|
295 | map => $self->{npc}->map, |
284 | state => $state, |
296 | state => $state, |
285 | flag => $flag, |
297 | flag => $flag, |
286 | msg => $msg, |
298 | msg => $msg, |
287 | match => \@match, |
299 | match => \@match, |
|
|
300 | find => \@find, |
288 | ); |
301 | ); |
289 | |
302 | |
290 | local $self->{ob}{record_replies} = \@replies; |
303 | local $self->{ob}{record_replies} = \@replies; |
291 | |
304 | |
292 | # now execute @-commands (which can result in a no-match) |
305 | # now execute @-commands (which can result in a no-match) |
… | |
… | |
331 | } elsif ($cmd eq "msg") { |
344 | } elsif ($cmd eq "msg") { |
332 | push @replies, [$self->{npc}, (scalar cf::safe_eval $args, %vars)]; |
345 | push @replies, [$self->{npc}, (scalar cf::safe_eval $args, %vars)]; |
333 | |
346 | |
334 | } elsif ($cmd eq "setflag") { |
347 | } elsif ($cmd eq "setflag") { |
335 | my ($name, $value) = split /\s+/, $args, 2; |
348 | my ($name, $value) = split /\s+/, $args, 2; |
336 | $value ? $flag->{$name} = $value |
349 | defined $value ? $flag->{$name} = $value |
337 | : delete $flag->{$name}; |
350 | : delete $flag->{$name}; |
338 | |
351 | |
339 | } elsif ($cmd eq "setstate") { |
352 | } elsif ($cmd eq "setstate") { |
340 | my ($name, $value) = split /\s+/, $args, 2; |
353 | my ($name, $value) = split /\s+/, $args, 2; |
341 | $value ? $state->{$name} = $value |
354 | defined $value ? $state->{$name} = $value |
342 | : delete $state->{$name}; |
355 | : delete $state->{$name}; |
343 | |
356 | |
344 | } elsif ($cmd eq "ifflag") { |
357 | } elsif ($cmd eq "ifflag") { |
345 | my ($name, $value) = split /\s+/, $args, 2; |
358 | my ($name, $value) = split /\s+/, $args, 2; |
346 | $flag->{$name} eq $value |
359 | defined $value ? $flag->{$name} eq $value |
|
|
360 | : $flag->{$name} |
347 | or next topic; |
361 | or next topic; |
348 | |
362 | |
349 | } elsif ($cmd eq "ifstate") { |
363 | } elsif ($cmd eq "ifstate") { |
350 | my ($name, $value) = split /\s+/, $args, 2; |
364 | my ($name, $value) = split /\s+/, $args, 2; |
351 | $state->{$name} eq $value |
365 | defined $value ? $state->{$name} eq $value |
|
|
366 | : $state->{$name} |
352 | or next topic; |
367 | or next topic; |
353 | |
368 | |
354 | } elsif ($cmd eq "trigger") { |
369 | } elsif ($cmd eq "trigger") { |
355 | my ($con, $state) = split /\s+/, $args, 2; |
370 | my ($con, $state) = split /\s+/, $args, 2; |
356 | |
371 | |