… | |
… | |
19 | literacy => [ |
19 | literacy => [ |
20 | 1000, 'scroll_literacy', |
20 | 1000, 'scroll_literacy', |
21 | sub { $_[0]->value (1000 * $price_fact) } |
21 | sub { $_[0]->value (1000 * $price_fact) } |
22 | ], |
22 | ], |
23 | mailscroll => [ |
23 | mailscroll => [ |
24 | 1, 'scroll', |
24 | 1, 'mailscroll_empty', |
25 | sub { |
25 | sub { |
26 | $_[0]->name ("mailscroll T: $_[2] F: $_[1]"); |
26 | $_[0]->name ("mailscroll T: $_[2] F: $_[1]"); |
27 | $_[0]->name_pl ("mailscrolls T: $_[2] F: $_[1]"); |
27 | $_[0]->name_pl ("mailscrolls T: $_[2] F: $_[1]"); |
28 | $_[0]->value (1 * $price_fact); |
28 | $_[0]->value (1 * $price_fact); |
29 | }, |
29 | }, |
… | |
… | |
52 | sub notify_players { |
52 | sub notify_players { |
53 | my (%sent_targets) = @_; |
53 | my (%sent_targets) = @_; |
54 | |
54 | |
55 | # lets message player ingame: this is a NEW feature from the perl IPO :-) |
55 | # lets message player ingame: this is a NEW feature from the perl IPO :-) |
56 | for (keys %sent_targets) { |
56 | for (keys %sent_targets) { |
57 | if (my $player = cf::player::find $_) { |
57 | if (my $player = cf::player::find_active $_) { |
58 | my $cnt = $sent_targets{$_}; |
58 | my $cnt = $sent_targets{$_}; |
59 | |
59 | |
60 | if ($cnt == 1) { |
60 | if ($cnt == 1) { |
61 | $player->ob->message ("You've got new mail."); |
61 | $player->ob->message ("You've got new mail."); |
62 | } else { |
62 | } else { |
… | |
… | |
68 | |
68 | |
69 | sub create_object { |
69 | sub create_object { |
70 | my ($name, $map, $x, $y, $cb, @a) = @_; |
70 | my ($name, $map, $x, $y, $cb, @a) = @_; |
71 | my $o = cf::object::new $name; |
71 | my $o = cf::object::new $name; |
72 | my $r = $cb->($o, @a); |
72 | my $r = $cb->($o, @a); |
73 | $map->insert_object ($o, $x, $y); |
73 | $map->insert ($o, $x, $y); |
74 | $r |
74 | $r |
75 | } |
75 | } |
76 | |
76 | |
77 | # this handler notifies the player of new mail |
77 | # this handler notifies the player of new mail |
78 | cf::player->attach ( |
78 | cf::player->attach ( |
… | |
… | |
118 | my $mail = cf::object::new $type->[0]; |
118 | my $mail = cf::object::new $type->[0]; |
119 | $mail->name ("$type->[1] F: $from T: " .$pl->name); |
119 | $mail->name ("$type->[1] F: $from T: " .$pl->name); |
120 | $mail->name_pl ("$type->[1]s F: $from T: " .$pl->name); |
120 | $mail->name_pl ("$type->[1]s F: $from T: " .$pl->name); |
121 | $mail->msg ($msg); |
121 | $mail->msg ($msg); |
122 | $mail->value (0); |
122 | $mail->value (0); |
123 | $mail->insert_in_ob ($box); |
123 | $box->insert ($mail); |
124 | } |
124 | } |
125 | |
125 | |
126 | $cnt += @$mails; |
126 | $cnt += @$mails; |
127 | |
127 | |
128 | if ($cnt == 1) { |
128 | if ($cnt == 1) { |
… | |
… | |
167 | cf::register_script_function "ipo::command" => sub { |
167 | cf::register_script_function "ipo::command" => sub { |
168 | my ($who, $msg, $npc) = @_; |
168 | my ($who, $msg, $npc) = @_; |
169 | my ($cmd, $arguments) = split /\s+/, $msg, 2; |
169 | my ($cmd, $arguments) = split /\s+/, $msg, 2; |
170 | $cmd = lc $cmd; |
170 | $cmd = lc $cmd; |
171 | |
171 | |
172 | my $pl = cf::player::find $who->name; |
172 | my $pl = cf::player::find_active $who->name; |
173 | my ($x, $y) = ($pl->ob->x, $pl->ob->y); |
173 | my ($x, $y) = ($pl->ob->x, $pl->ob->y); |
174 | |
174 | |
175 | if (my $pr = $prices{$cmd}) { |
175 | if (my $pr = $prices{$cmd}) { |
176 | if ($cmd eq 'mailwarning' and !$who->flag (cf::FLAG_WIZ)) { |
176 | if ($cmd eq 'mailwarning' and !$who->flag (cf::FLAG_WIZ)) { |
177 | return 1; |
177 | return 1; |
… | |
… | |
184 | create_object ($pr->[1], $who->map, $x, $y, $pr->[2], $who->name, $arguments); |
184 | create_object ($pr->[1], $who->map, $x, $y, $pr->[2], $who->name, $arguments); |
185 | $who->reply ($npc, "Here is your $cmd"); |
185 | $who->reply ($npc, "Here is your $cmd"); |
186 | } |
186 | } |
187 | |
187 | |
188 | } elsif ($cmd eq 'receive') { |
188 | } elsif ($cmd eq 'receive') { |
|
|
189 | cf::async { |
|
|
190 | $Coro::current->{desc} = "ipo receive"; |
|
|
191 | |
189 | my $storage = cf::map::find ("/planes/IPO_storage"); |
192 | my $storage = cf::map::find ("/planes/IPO_storage"); |
190 | unless ($storage) { |
193 | unless ($storage) { |
191 | $who->reply ($npc, "Sorry, our package delivery service is currently in strike. Please come back later."); |
194 | $who->reply ($npc, "Sorry, our package delivery service is currently in strike. Please come back later."); |
192 | return 1; |
195 | return 1; |
193 | } |
196 | } |
|
|
197 | $storage->load; |
194 | |
198 | |
195 | my $plname = $who->name; |
199 | my $plname = $who->name; |
196 | my $cnt; |
200 | my $cnt; |
197 | for ($storage->at (2, 2)) { |
201 | for ($storage->at (2, 2)) { |
198 | if ($_->name () =~ /^\S+ F: \S+ T: \Q$plname\E$/) { |
202 | if ($_->name () =~ /^\S+ F: \S+ T: \Q$plname\E$/) { |
199 | $_->insert_in_ob ($who); |
203 | $who->insert ($_); |
200 | $cnt++; |
204 | $cnt++; |
201 | } |
205 | } |
202 | } |
206 | } |
203 | |
207 | |
204 | if ($cnt) { |
208 | if ($cnt) { |
205 | $who->reply ($npc, $cnt == 1 ? "Here is your pakage." : "Here are your packages."); |
209 | $who->reply ($npc, $cnt == 1 ? "Here is your package." : "Here are your packages."); |
206 | } else { |
210 | } else { |
207 | $who->reply ($npc, "Sorry, no deliverys for you sir."); |
211 | $who->reply ($npc, "Sorry, no deliveries for you sir."); |
|
|
212 | } |
208 | } |
213 | } |
209 | |
214 | |
210 | } elsif ($cmd eq 'send') { |
215 | } elsif ($cmd eq 'send') { |
211 | unless ($arguments =~ /^\S+$/) { |
216 | unless ($arguments =~ /^\S+$/) { |
212 | $who->reply ($npc, "Send to who?"); |
217 | $who->reply ($npc, "Send to who?"); |
213 | return 1; |
218 | return 1; |
214 | } |
219 | } |
215 | |
220 | |
|
|
221 | cf::async { |
|
|
222 | $Coro::current->{desc} = "ipo send"; |
|
|
223 | |
216 | my $storage = cf::map::find ("/planes/IPO_storage"); |
224 | my $storage = cf::map::find ("/planes/IPO_storage"); |
217 | unless ($storage) { |
225 | unless ($storage) { |
218 | $who->reply ($npc, "Sorry, our package delivery service is currently in strike. Please come back later."); |
226 | $who->reply ($npc, "Sorry, our package delivery service is currently in strike. Please come back later."); |
219 | return 1; |
227 | return 1; |
220 | } |
228 | } |
|
|
229 | $storage->load; |
221 | |
230 | |
222 | my $cnt; |
231 | my $cnt; |
223 | for ($who->inv) { |
232 | for ($who->inv) { |
224 | if ($_->name () =~ /^(bag|package|carton) T: \Q$arguments\E F: (\S+)$/) { |
233 | if ($_->name () =~ /^(bag|package|carton) T: \Q$arguments\E F: (\S+)$/) { |
225 | $_->name ("$1 F: $2 T: $arguments"); |
234 | $_->name ("$1 F: $2 T: $arguments"); |
226 | $_->teleport ($storage, 2, 2); |
235 | $storage->insert ($_, 2, 2); |
|
|
236 | $who->esrv_del_item ($_->count); |
227 | $cnt++; |
237 | $cnt++; |
228 | } |
238 | } |
229 | } |
239 | } |
230 | |
240 | |
231 | if ($cnt) { |
241 | if ($cnt) { |
232 | $who->reply ($npc, $cnt == 1 ? "Package sent to $arguments." : "Sent $cnt packages to $arguments\n"); |
242 | $who->reply ($npc, $cnt == 1 ? "Package sent to $arguments." : "Sent $cnt packages to $arguments\n"); |
233 | CFMail::send_mail (1, $arguments, $who->name, "You got $cnt packages from " . $who->name); |
243 | CFMail::send_mail (1, $arguments, $who->name, "You got $cnt packages from " . $who->name); |
234 | notify_players ($arguments => 1); |
244 | notify_players ($arguments => 1); |
235 | } else { |
245 | } else { |
236 | $who->reply ($npc, "Sorry, found no package to send to $arguments."); |
246 | $who->reply ($npc, "Sorry, found no package to send to $arguments."); |
|
|
247 | } |
237 | } |
248 | } |
238 | |
249 | |
239 | } else { |
250 | } else { |
240 | $who->reply ($npc, |
251 | $who->reply ($npc, |
241 | sprintf "How can I help you?\n" |
252 | sprintf "How can I help you?\n" |
… | |
… | |
258 | package CFMail; |
269 | package CFMail; |
259 | |
270 | |
260 | use POSIX qw/strftime/; |
271 | use POSIX qw/strftime/; |
261 | use CFDB; |
272 | use CFDB; |
262 | |
273 | |
263 | my $MAILDB = CFDB->new (db_file => cf::localdir . "/crossfiremail"); |
274 | my $MAILDB = CFDB->new (db_file => "$LOCALDIR/crossfiremail"); |
264 | |
275 | |
265 | sub get_mail { |
276 | sub get_mail { |
266 | my ($toname) = @_; |
277 | my ($toname) = @_; |
267 | $MAILDB->get ($toname); |
278 | $MAILDB->get ($toname); |
268 | } |
279 | } |