… | |
… | |
25 | $_[0] |
25 | $_[0] |
26 | } |
26 | } |
27 | |
27 | |
28 | sub new { |
28 | sub new { |
29 | my ($class, %arg) = @_; |
29 | my ($class, %arg) = @_; |
|
|
30 | |
|
|
31 | $arg{ob} = $arg{pl}->ob; |
30 | |
32 | |
31 | my $self = bless { |
33 | my $self = bless { |
32 | %arg, |
34 | %arg, |
33 | }, $class; |
35 | }, $class; |
34 | |
36 | |
… | |
… | |
164 | |
166 | |
165 | @match hi |
167 | @match hi |
166 | @ifflag kings_quest |
168 | @ifflag kings_quest |
167 | Hi, I was told you want to do the kings quest? |
169 | Hi, I was told you want to do the kings quest? |
168 | |
170 | |
169 | =item @trigger connected-id |
171 | =item @trigger connected-id [state] |
170 | |
172 | |
171 | Trigger all objects with the given connected-id. The trigger is stateful |
173 | Trigger all objects with the given connected-id. |
172 | and retains state per connected-id. |
174 | |
|
|
175 | When the state argument is omitted the trigger is stateful and retains an |
|
|
176 | internal state per connected-id. There is a limitation to the use of this: The |
|
|
177 | state won't be changed when the connection is triggered by other triggers. So |
|
|
178 | be careful when triggering the connection from other objects. |
|
|
179 | |
|
|
180 | When a state argument is given it should be either 0 or 1. 1 will 'push' the connection |
|
|
181 | and 0 will 'release' the connection. This is useful for example when you want to |
|
|
182 | let a npc control a door. |
|
|
183 | |
|
|
184 | Trigger all objects with the given connected-id by 'releasing' the connection. |
173 | |
185 | |
174 | =item @addtopic topic |
186 | =item @addtopic topic |
175 | |
187 | |
176 | Adds the given topic names (separated by C<|>) to the list of topics |
188 | Adds the given topic names (separated by C<|>) to the list of topics |
177 | returned. |
189 | returned. |
… | |
… | |
186 | my $lcmsg = lc $msg; |
198 | my $lcmsg = lc $msg; |
187 | |
199 | |
188 | topic: |
200 | topic: |
189 | for my $match (@{ $self->{match} }) { |
201 | for my $match (@{ $self->{match} }) { |
190 | for (split /\|/, $match->[0]) { |
202 | for (split /\|/, $match->[0]) { |
191 | if ($_ eq "*" || $lcmsg eq lc) { |
203 | if ($_ eq "*" || $lcmsg =~ /\b\Q$_\E\b/i) { |
192 | my $reply = $match->[1]; |
204 | my $reply = $match->[1]; |
193 | my @kw; |
205 | my @kw; |
194 | |
206 | |
195 | my @replies; |
207 | my @replies; |
196 | my @match; # @match/@parse command results |
208 | my @match; # @match/@parse command results |
… | |
… | |
251 | my ($name, $value) = split /\s+/, $args, 2; |
263 | my ($name, $value) = split /\s+/, $args, 2; |
252 | $state->{$name} eq $value |
264 | $state->{$name} eq $value |
253 | or next topic; |
265 | or next topic; |
254 | |
266 | |
255 | } elsif ($cmd eq "trigger") { |
267 | } elsif ($cmd eq "trigger") { |
|
|
268 | my ($con, $state) = split /\s+/, $args, 2; |
|
|
269 | $con = $con * 1; |
|
|
270 | |
|
|
271 | if (defined $state) { |
|
|
272 | $self->{npc}->map->trigger ($args, $state); |
|
|
273 | } else { |
256 | my $rvalue = \$self->{npc}{dialog_trigger}{$args*1}; |
274 | my $rvalue = \$self->{npc}{dialog_trigger}{$con}; |
257 | $self->{npc}->map->trigger ($args, $$rvalue = !$$rvalue); |
275 | $self->{npc}->map->trigger ($con, $$rvalue = !$$rvalue); |
|
|
276 | } |
258 | |
277 | |
259 | } elsif ($cmd eq "addtopic") { |
278 | } elsif ($cmd eq "addtopic") { |
260 | push @kw, split /\|/, $args; |
279 | push @kw, split /\|/, $args; |
261 | $self->{add_topic}->(split /\s*\|\s*/, $args) if $self->{add_topic}; |
280 | $self->{add_topic}->(split /\s*\|\s*/, $args) if $self->{add_topic}; |
262 | |
281 | |