--- deliantra/server/ext/ipo.ext 2006/12/21 22:41:34 1.2 +++ deliantra/server/ext/ipo.ext 2008/09/22 01:33:09 1.15 @@ -14,18 +14,18 @@ my %prices = ( pen => [ 40, 'stylus', - sub { $_[0]->name ('IPO Writing Pen'); $_[0]->value (40 * $price_fact); } + sub { $_[0]->name ('IPO Writing Pen'); $_[0]->value (0); } ], literacy => [ 1000, 'scroll_literacy', - sub { $_[0]->value (1000 * $price_fact) } + sub { $_[0]->value (0) } ], mailscroll => [ - 1, 'scroll', + 1, 'mailscroll_empty', sub { $_[0]->name ("mailscroll T: $_[2] F: $_[1]"); $_[0]->name_pl ("mailscrolls T: $_[2] F: $_[1]"); - $_[0]->value (1 * $price_fact); + $_[0]->value (0); }, 'plarg' ], @@ -54,7 +54,7 @@ # lets message player ingame: this is a NEW feature from the perl IPO :-) for (keys %sent_targets) { - if (my $player = cf::player::find $_) { + if (my $player = cf::player::find_active $_) { my $cnt = $sent_targets{$_}; if ($cnt == 1) { @@ -70,7 +70,7 @@ my ($name, $map, $x, $y, $cb, @a) = @_; my $o = cf::object::new $name; my $r = $cb->($o, @a); - $map->insert_object ($o, $x, $y); + $map->insert ($o, $x, $y); $r } @@ -120,7 +120,7 @@ $mail->name_pl ("$type->[1]s F: $from T: " .$pl->name); $mail->msg ($msg); $mail->value (0); - $mail->insert_in_ob ($box); + $box->insert ($mail); } $cnt += @$mails; @@ -169,7 +169,7 @@ my ($cmd, $arguments) = split /\s+/, $msg, 2; $cmd = lc $cmd; - my $pl = cf::player::find $who->name; + my $pl = cf::player::find_active $who->name; my ($x, $y) = ($pl->ob->x, $pl->ob->y); if (my $pr = $prices{$cmd}) { @@ -177,34 +177,44 @@ return 1; } - $who->pay_amount ($pr->[0] * $price_fact); - if ($pr->[3] && not cf::player::exists $arguments) { - $who->reply ($npc, "Sorry, there is no '$arguments'"); + if ($who->pay_amount ($pr->[0] * $price_fact)) { + cf::async { + if ($pr->[3] && not cf::player::exists $arguments) { + $who->reply ($npc, "Sorry, there is no '$arguments'"); + } else { + create_object ($pr->[1], $who->map, $x, $y, $pr->[2], $who->name, $arguments); + $who->reply ($npc, "Here is your $cmd"); + } + } } else { - create_object ($pr->[1], $who->map, $x, $y, $pr->[2], $who->name, $arguments); - $who->reply ($npc, "Here is your $cmd"); + $who->reply ($npc, "Sorry, you don't have enough money."); } } elsif ($cmd eq 'receive') { - my $storage = cf::map::find ("/planes/IPO_storage"); - unless ($storage) { - $who->reply ($npc, "Sorry, our package delivery service is currently in strike. Please come back later."); - return 1; - } + cf::async { + $Coro::current->{desc} = "ipo receive"; - my $plname = $who->name; - my $cnt; - for ($storage->at (2, 2)) { - if ($_->name () =~ /^\S+ F: \S+ T: \Q$plname\E$/) { - $_->insert_in_ob ($who); - $cnt++; + my $storage = cf::map::find ("/planes/IPO_storage"); + unless ($storage) { + $who->reply ($npc, "Sorry, our package delivery service is currently in strike. Please come back later."); + return 1; } - } + $storage->load; - if ($cnt) { - $who->reply ($npc, $cnt == 1 ? "Here is your pakage." : "Here are your packages."); - } else { - $who->reply ($npc, "Sorry, no deliverys for you sir."); + my $plname = $who->name; + my $cnt; + for ($storage->at (2, 2)) { + if ($_->name () =~ /^\S+ F: \S+ T: \Q$plname\E$/) { + $who->insert ($_); + $cnt++; + } + } + + if ($cnt) { + $who->reply ($npc, $cnt == 1 ? "Here is your package." : "Here are your packages."); + } else { + $who->reply ($npc, "Sorry, no deliveries for you sir."); + } } } elsif ($cmd eq 'send') { @@ -213,42 +223,47 @@ return 1; } - my $storage = cf::map::find ("/planes/IPO_storage"); - unless ($storage) { - $who->reply ($npc, "Sorry, our package delivery service is currently in strike. Please come back later."); - return 1; - } + cf::async { + $Coro::current->{desc} = "ipo send"; - my $cnt; - for ($who->inv) { - if ($_->name () =~ /^(bag|package|carton) T: \Q$arguments\E F: (\S+)$/) { - $_->name ("$1 F: $2 T: $arguments"); - $_->teleport ($storage, 2, 2); - $cnt++; + my $storage = cf::map::find ("/planes/IPO_storage"); + unless ($storage) { + $who->reply ($npc, "Sorry, our package delivery service is currently in strike. Please come back later."); + return 1; } - } + $storage->load; - if ($cnt) { - $who->reply ($npc, $cnt == 1 ? "Package sent to $arguments." : "Sent $cnt packages to $arguments\n"); - CFMail::send_mail (1, $arguments, $who->name, "You got $cnt packages from " . $who->name); - notify_players ($arguments => 1); - } else { - $who->reply ($npc, "Sorry, found no package to send to $arguments."); + my $cnt; + for ($who->inv) { + if ($_->name () =~ /^(bag|package|carton) T: \Q$arguments\E F: (\S+)$/) { + $_->name ("$1 F: $2 T: $arguments"); + $storage->insert ($_, 2, 2); + $cnt++; + } + } + + if ($cnt) { + $who->reply ($npc, $cnt == 1 ? "Package sent to $arguments." : "Sent $cnt packages to $arguments\n"); + CFMail::send_mail (1, $arguments, $who->name, "You got $cnt packages from " . $who->name); + notify_players ($arguments => 1); + } else { + $who->reply ($npc, "Sorry, found no package to send to $arguments."); + } } } else { $who->reply ($npc, sprintf "How can I help you?\n" . "Here is a quick list of commands I understand:\n\n" - . "- pen (%s platinum)\n" - . "- literacy (%s platinum)\n" - . "- mailscroll (%s platinum)\n" - . "- bag (%s platinum)\n" - . "- package (%s platinum)\n" - . "- carton (%s platinum)\n" - . "- send (send bags/packages/cartons)\n" - . "- receive (to receive packages for you)\n" - . ($who->flag (cf::FLAG_WIZ) ? "- mailwarning " : ""), + . " - pen (%s platinum)\n" + . " - literacy (%s platinum)\n" + . " - mailscroll (%s platinum)\n" + . " - bag (%s platinum)\n" + . " - package (%s platinum)\n" + . " - carton (%s platinum)\n" + . " - send (send bags/packages/cartons)\n" + . " - receive (to receive packages for you)\n" + . ($who->flag (cf::FLAG_WIZ) ? " - mailwarning \n" : ""), 40, 1000, 1, 1, 5, 10 ); } @@ -260,7 +275,7 @@ use POSIX qw/strftime/; use CFDB; -my $MAILDB = CFDB->new (db_file => cf::localdir . "/crossfiremail.perl"); +my $MAILDB = CFDB->new (db_file => "$LOCALDIR/crossfiremail"); sub get_mail { my ($toname) = @_; @@ -282,8 +297,9 @@ sub send_mail { my ($type, $toname, $fromname, $message) = @_; my $time = strftime ("%a, %d %b %Y %H:%M:%S CEST", localtime (time)); - my $msg = "From: $fromname\nTo: $toname\nDate: $time\n\n$message\n"; + my $msg = "From: $fromname\rTo: $toname\rDate: $time\n\n$message\n"; store_mail ($type, $toname, $fromname, $msg); } 1; +