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.1 by root, Fri Dec 15 19:29:18 2006 UTC vs.
Revision 1.6 by elmex, Wed Aug 8 07:55:57 2007 UTC

3NPC_Dialogue 3NPC_Dialogue
4 4
5=head1 DESCRIPTION 5=head1 DESCRIPTION
6 6
7NPC dialogue support module. 7NPC dialogue support module.
8
9=over 4
8 10
9=cut 11=cut
10 12
11package NPC_Dialogue; 13package NPC_Dialogue;
12 14
26} 28}
27 29
28sub new { 30sub new {
29 my ($class, %arg) = @_; 31 my ($class, %arg) = @_;
30 32
33 $arg{ob} = $arg{pl}->ob;
34
31 my $self = bless { 35 my $self = bless {
32 %arg, 36 %arg,
33 }, $class; 37 }, $class;
34 38
35 $self->{match} ||= [parse_message $self->{npc}->msg]; 39 $self->{match} ||= [parse_message $self->{npc}->msg];
102 106
103=back 107=back
104 108
105The environment is that standard "map scripting environment", which is 109The environment is that standard "map scripting environment", which is
106limited in the type of constructs allowed (no loops, for example). 110limited in the type of constructs allowed (no loops, for example).
111
112Here is a example:
113
114=over 4
115
116=item B<matching for an item name>
117
118 @match hi
119 @cond grep $_->name =~ /royalty/, $who->inv
120 You got royalties there! Wanna have!
121
122You may want to change the C<name> method there to something like C<title>,
123C<slaying> or any other method that is allowed to be called on a
124C<cf::object> here.
125
126=back
107 127
108=item @eval perl 128=item @eval perl
109 129
110Like C<@cond>, but proceed regardless of the outcome. 130Like C<@cond>, but proceed regardless of the outcome.
111 131
164 184
165 @match hi 185 @match hi
166 @ifflag kings_quest 186 @ifflag kings_quest
167 Hi, I was told you want to do the kings quest? 187 Hi, I was told you want to do the kings quest?
168 188
169=item @trigger connected-id 189=item @trigger connected-id [state]
170 190
171Trigger all objects with the given connected-id. The trigger is stateful 191Trigger all objects with the given connected-id.
172and retains state per connected-id. 192
193When the state argument is omitted the trigger is stateful and retains an
194internal state per connected-id. There is a limitation to the use of this: The
195state won't be changed when the connection is triggered by other triggers. So
196be careful when triggering the connection from other objects.
197
198When a state argument is given it should be either 0 or 1. 1 will 'push' the connection
199and 0 will 'release' the connection. This is useful for example when you want to
200let a npc control a door.
201
202Trigger all objects with the given connected-id by 'releasing' the connection.
173 203
174=item @addtopic topic 204=item @addtopic topic
175 205
176Adds the given topic names (separated by C<|>) to the list of topics 206Adds the given topic names (separated by C<|>) to the list of topics
177returned. 207returned.
186 my $lcmsg = lc $msg; 216 my $lcmsg = lc $msg;
187 217
188 topic: 218 topic:
189 for my $match (@{ $self->{match} }) { 219 for my $match (@{ $self->{match} }) {
190 for (split /\|/, $match->[0]) { 220 for (split /\|/, $match->[0]) {
191 if ($_ eq "*" || $lcmsg eq lc) { 221 if ($_ eq "*" || $lcmsg =~ /\b\Q$_\E\b/i) {
192 my $reply = $match->[1]; 222 my $reply = $match->[1];
193 my @kw; 223 my @kw;
194 224
195 my @replies; 225 my @replies;
196 my @match; # @match/@parse command results 226 my @match; # @match/@parse command results
251 my ($name, $value) = split /\s+/, $args, 2; 281 my ($name, $value) = split /\s+/, $args, 2;
252 $state->{$name} eq $value 282 $state->{$name} eq $value
253 or next topic; 283 or next topic;
254 284
255 } elsif ($cmd eq "trigger") { 285 } elsif ($cmd eq "trigger") {
286 my ($con, $state) = split /\s+/, $args, 2;
287 $con = $con * 1;
288
289 if (defined $state) {
290 $self->{npc}->map->trigger ($args, $state);
291 } else {
256 my $rvalue = \$self->{npc}{dialog_trigger}{$args*1}; 292 my $rvalue = \$self->{npc}{dialog_trigger}{$con};
257 $self->{npc}->map->trigger ($args, $$rvalue = !$$rvalue); 293 $self->{npc}->map->trigger ($con, $$rvalue = !$$rvalue);
294 }
258 295
259 } elsif ($cmd eq "addtopic") { 296 } elsif ($cmd eq "addtopic") {
260 push @kw, split /\|/, $args; 297 push @kw, split /\|/, $args;
261 $self->{add_topic}->(split /\s*\|\s*/, $args) if $self->{add_topic}; 298 $self->{add_topic}->(split /\s*\|\s*/, $args) if $self->{add_topic};
262 299

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines