ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/ext/NPC_Dialogue.pm
(Generate patch)

Comparing deliantra/server/ext/NPC_Dialogue.pm (file contents):
Revision 1.15 by root, Tue Oct 13 00:24:14 2009 UTC vs.
Revision 1.21 by root, Fri Mar 19 22:16:27 2010 UTC

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
98can be seen by all NPCs (so better name your flags uniquely). This is 100can be seen by all NPCs (so better name your flags uniquely). This is
99useful for storing e.g. quest information. See C<@setflag> and C<@ifflag>. 101useful 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
105The environment is that standard "map scripting environment", which is 107The environment is that standard "map scripting environment", which is
106limited in the type of constructs allowed (no loops, for example). 108limited in the type of constructs allowed (no loops, for example).
156If the check fails, the match is skipped. 158If the check fails, the match is skipped.
157 159
158=item @find match expression 160=item @find match expression
159 161
160Like C<@check> in that it executes a match expression, but instead of 162Like C<@check> in that it executes a match expression, but instead of
161failing, it gathers all objects matched into the C<@find> array variable. 163failing, it gathers all objects into an array and provides a reference to
164the array in the C<$find> variable.
162 165
163When you want to skip the match when no objects have been found, combine 166When you want to skip the match when no objects have been found, combine
164C<@find> with C<@cond>: 167C<@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
181See C<@ifstate> for an example. 184See C<@ifstate> for an example.
182 185
183=item @ifstate state value 186=item @ifstate state value
184 187
185Requires that the named C<state> has the given C<value>, otherwise this 188Requires that the named C<state> has the given C<value>, otherwise this
186topic is skipped. For more complex comparisons, see C<@cond> with 189topic is skipped. For more complex comparisons, see C<@cond> with
187C<$state>. Example: 190C<$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?
199associated with a specific player and can be seen by all NPCs. with 202associated with a specific player and can be seen by all NPCs. with
200respect to a particular player, which makes them suitable to store quest 203respect to a particular player, which makes them suitable to store quest
201markers and other information (e.g. reputation/alignment). Flags are 204markers and other information (e.g. reputation/alignment). Flags are
202persistent over the lifetime of a player, so be careful :) 205persistent over the lifetime of a player, so be careful :)
203 206
207Perversely enough, using C<@setfflag> without a C<value> clears the flag
208as if it was never set, so always provide a flag value (e.g. C<1>) when
209you want to set the flag.
210
204See C<@ifflag> for an example. 211See C<@ifflag> for an example.
205 212
206=item @ifflag flag value 213=item @ifflag flag value
207 214
208Requires that the named C<flag> has the given C<value>, otherwise this 215Requires that the named C<flag> has the given C<value>, otherwise this
209topic is skipped. For more complex comparisons, see C<@cond> with 216topic is skipped. For more complex comparisons, see C<@cond> with
210C<$flag>. Example: 217C<$flag>.
218
219If no C<value> is given, then the ifflag succeeds when the flag is true.
220
221Example:
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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines