#! perl my $price_fact = 50; sub set_package { my ($pkg, $to, $from, $bagname, $weight) = @_; $pkg->set_name ("$bagname T: $to F: $from"); $pkg->set_weight_limit ($weight); $pkg->set_str (0); } # prices in plat. my %prices = ( pen => [ 40, 'stylus', sub { $_[0]->set_name ('IPO Writing Pen'); $_[0]->set_value (40 * $price_fact); }, 'plarg' ], literacy => [ 1000, 'scroll_literacy', sub { $_[0]->set_value (1000 * $price_fact) } ], mailscroll => [ 1, 'scroll', sub { $_[0]->set_name ("mailscroll T: $_[2] F: $_[1]"); $_[0]->set_name_plural ("mailscrolls T: $_[2] F: $_[1]"); $_[0]->set_value (1 * $price_fact); }, 'plarg' ], bag => [ 1, 'r_sack', sub { set_package (@_, bag => 5000) }, 'plarg' ], package => [ 5, 'r_sack', sub { set_package (@_, package => 50000) }, 'plarg' ], carton => [10, 'r_sack', sub { set_package (@_, carton => 100000) }, 'plarg' ], mailwarning => [ 0, 'diploma', sub { $_[0]->set_name ("mailwarning T: $_[2] F: $_[1]"); $_[0]->set_name_plural ("mailwarnings T: $_[2] F: $_[1]"); $_[0]->set_value (0); }, 'plarg' ], ); sub create_object { my ($name, $map, $x, $y, $cb, @a) = @_; my $o = cf::object::new $name; my $r = $cb->($o, @a); $map->insert_object ($o, $x, $y); $r } cf::register_script_function "ipo::command" => sub { my ($who, $msg, $npc) = @_; my ($cmd, $arguments) = split /\s+/, $msg, 2; $cmd = lc $cmd; my $pl = cf::player::find $who->name; my ($x, $y) = ($pl->ob->x, $pl->ob->y); if (my $pr = $prices{$cmd}) { if ($cmd eq 'mailwarning' and !$who->flag (cf::FLAG_WIZ)) { 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'"); } else { create_object ($pr->[1], $who->map, $x, $y, $pr->[2], $who->name, $arguments); $who->reply ($npc, "Here is your $cmd"); } } elsif ($cmd eq 'receive') { my $storage = cf::map::get_map ("/planes/IPO_storage"); unless ($storage) { $who->reply ($npc, "Sorry, our package delivery service is currently in strike. Please come back later."); return 1; } 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++; } } 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."); } } elsif ($cmd eq 'send') { unless ($arguments =~ /^\S+$/) { $who->reply ($npc, "Send to who?"); return 1; } my $storage = cf::map::get_map ("/planes/IPO_storage"); unless ($storage) { $who->reply ($npc, "Sorry, our package delivery service is currently in strike. Please come back later."); return 1; } my $cnt; for ($who->inv) { if ($_->name () =~ /^\S+ T: \Q$arguments\E F: (\S+)$/) { $_->set_name ("$1 F: $2 T: $arguments"); $_->teleport ($storage, 2, 2); $cnt++; } } if ($cnt) { $who->reply ($npc, $cnt == 1 ? "Package sent to $arguments." : "Sent $cnt packages to $arguments\n"); } else { $who->reply ($npc, "Sorry, found no package to send to $arguments."); } } else { $who->reply ($npc, "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" .($who->flag (cf::FLAG_WIZ) ? "- mailwarning " : "") ); } 1 }