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