… | |
… | |
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 | |
… | |
… | |
26 | } |
28 | } |
27 | |
29 | |
28 | sub new { |
30 | sub 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 | |
105 | The environment is that standard "map scripting environment", which is |
109 | The environment is that standard "map scripting environment", which is |
106 | limited in the type of constructs allowed (no loops, for example). |
110 | limited in the type of constructs allowed (no loops, for example). |
|
|
111 | |
|
|
112 | Here 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 | |
|
|
122 | You may want to change the C<name> method there to something like C<title>, |
|
|
123 | C<slaying> or any other method that is allowed to be called on a |
|
|
124 | C<cf::object> here. |
|
|
125 | |
|
|
126 | =item B<matching for an item name and removing the matched item> |
|
|
127 | |
|
|
128 | @match found earhorn |
|
|
129 | @cond grep $_->slaying =~ /Gramp's walking stick/, $who->inv |
|
|
130 | @eval my @g = grep { $_->slaying =~ /Gramp's walking stick/ } $who->inv; $g[0]->decrease; |
|
|
131 | Thanks for the earhorn! |
|
|
132 | |
|
|
133 | This example is a bit more complex. The C<@eval> statement will search |
|
|
134 | the players inventory for the same term as the C<@cond> and then |
|
|
135 | decreases the number of objects used there. |
|
|
136 | |
|
|
137 | (See also the map: C<scorn/houses/cornerbrook.map> for an example how this is |
|
|
138 | used in the real world :-) |
|
|
139 | |
|
|
140 | =back |
107 | |
141 | |
108 | =item @eval perl |
142 | =item @eval perl |
109 | |
143 | |
110 | Like C<@cond>, but proceed regardless of the outcome. |
144 | Like C<@cond>, but proceed regardless of the outcome. |
111 | |
145 | |
… | |
… | |
179 | and 0 will 'release' the connection. This is useful for example when you want to |
213 | and 0 will 'release' the connection. This is useful for example when you want to |
180 | let a npc control a door. |
214 | let a npc control a door. |
181 | |
215 | |
182 | Trigger all objects with the given connected-id by 'releasing' the connection. |
216 | Trigger all objects with the given connected-id by 'releasing' the connection. |
183 | |
217 | |
|
|
218 | =item @playersound face-name |
|
|
219 | |
|
|
220 | Plays the given sound face (either an alias or sound file path) so that |
|
|
221 | only the player talking to the npc can hear it. |
|
|
222 | |
|
|
223 | =item @npcsound face-name |
|
|
224 | |
|
|
225 | Plays the given sound face (either an alias or sound file path) as if |
|
|
226 | the npc had made that sound, i.e. it will be located at the npc and all |
|
|
227 | players near enough can hear it. |
|
|
228 | |
184 | =item @addtopic topic |
229 | =item @addtopic topic |
185 | |
230 | |
186 | Adds the given topic names (separated by C<|>) to the list of topics |
231 | Adds the given topic names (separated by C<|>) to the list of topics |
187 | returned. |
232 | returned. |
188 | |
233 | |
… | |
… | |
196 | my $lcmsg = lc $msg; |
241 | my $lcmsg = lc $msg; |
197 | |
242 | |
198 | topic: |
243 | topic: |
199 | for my $match (@{ $self->{match} }) { |
244 | for my $match (@{ $self->{match} }) { |
200 | for (split /\|/, $match->[0]) { |
245 | for (split /\|/, $match->[0]) { |
201 | if ($_ eq "*" || $lcmsg eq lc) { |
246 | if ($_ eq "*" || $lcmsg =~ /\b\Q$_\E\b/i) { |
202 | my $reply = $match->[1]; |
247 | my $reply = $match->[1]; |
203 | my @kw; |
248 | my @kw; |
204 | |
249 | |
205 | my @replies; |
250 | my @replies; |
206 | my @match; # @match/@parse command results |
251 | my @match; # @match/@parse command results |
… | |
… | |
228 | @match = $msg =~ /$args/i |
273 | @match = $msg =~ /$args/i |
229 | or next topic; |
274 | or next topic; |
230 | |
275 | |
231 | } elsif ($cmd eq "comment") { |
276 | } elsif ($cmd eq "comment") { |
232 | # nop |
277 | # nop |
|
|
278 | |
|
|
279 | } elsif ($cmd eq "playersound") { |
|
|
280 | $self->{ob}->contr->play_sound (cf::sound::find $args); |
|
|
281 | |
|
|
282 | } elsif ($cmd eq "npcsound") { |
|
|
283 | $self->{npc}->play_sound (cf::sound::find $args); |
233 | |
284 | |
234 | } elsif ($cmd eq "cond") { |
285 | } elsif ($cmd eq "cond") { |
235 | cf::safe_eval $args, %vars |
286 | cf::safe_eval $args, %vars |
236 | or next topic; |
287 | or next topic; |
237 | |
288 | |