ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/maps/perl/ipo.ext
Revision: 1.1
Committed: Thu Jul 20 22:06:28 2006 UTC (17 years, 10 months ago) by elmex
Branch: MAIN
Log Message:
post office works again

File Contents

# User Rev Content
1 elmex 1.1 #! perl
2    
3     my $price_fact = 50;
4    
5     sub set_package {
6     my ($pkg, $to, $from, $bagname, $weight) = @_;
7     $pkg->set_name ("$bagname T: $to F: $from");
8     $pkg->set_weight_limit ($weight);
9     $pkg->set_str (0);
10     }
11    
12     # prices in plat.
13     my %prices = (
14     pen => [
15     40, 'stylus',
16     sub { $_[0]->set_name ('IPO Writing Pen'); $_[0]->set_value (40 * $price_fact); }, 'plarg'
17     ],
18     literacy => [
19     1000, 'scroll_literacy',
20     sub { $_[0]->set_value (1000 * $price_fact) }
21     ],
22     mailscroll => [
23     1, 'scroll',
24     sub {
25     $_[0]->set_name ("mailscroll T: $_[2] F: $_[1]");
26     $_[0]->set_name_plural ("mailscrolls T: $_[2] F: $_[1]");
27     $_[0]->set_value (1 * $price_fact);
28     },
29     'plarg'
30     ],
31     bag => [ 1, 'r_sack', sub { set_package (@_, bag => 5000) }, 'plarg' ],
32     package => [ 5, 'r_sack', sub { set_package (@_, package => 50000) }, 'plarg' ],
33     carton => [10, 'r_sack', sub { set_package (@_, carton => 100000) }, 'plarg' ],
34     mailwarning => [
35     0, 'diploma',
36     sub {
37     $_[0]->set_name ("mailwarning T: $_[2] F: $_[1]");
38     $_[0]->set_name_plural ("mailwarnings T: $_[2] F: $_[1]");
39     $_[0]->set_value (0);
40     },
41     'plarg'
42     ],
43     );
44    
45     sub create_object {
46     my ($name, $map, $x, $y, $cb, @a) = @_;
47     my $o = cf::object::new $name;
48     my $r = $cb->($o, @a);
49     $map->insert_object ($o, $x, $y);
50     $r
51     }
52    
53     cf::register_script_function "ipo::command" => sub {
54     my ($who, $msg, $npc) = @_;
55     my ($cmd, $arguments) = split /\s+/, $msg, 2;
56     $cmd = lc $cmd;
57    
58     my $pl = cf::player::find $who->name;
59     my ($x, $y) = ($pl->ob->x, $pl->ob->y);
60    
61     if (my $pr = $prices{$cmd}) {
62     if ($cmd eq 'mailwarning' and !$who->flag (cf::FLAG_WIZ)) {
63     return 1;
64     }
65    
66     $who->pay_amount ($pr->[0] * $price_fact);
67     if ($pr->[3] && not cf::player::exists $arguments) {
68     $who->reply ($npc, "Sorry, there is no '$arguments'");
69     } else {
70     create_object ($pr->[1], $who->map, $x, $y, $pr->[2], $who->name, $arguments);
71     $who->reply ($npc, "Here is your $cmd");
72     }
73    
74     } elsif ($cmd eq 'receive') {
75     my $storage = cf::map::get_map ("/planes/IPO_storage");
76     unless ($storage) {
77     $who->reply ($npc, "Sorry, our package delivery service is currently in strike. Please come back later.");
78     return 1;
79     }
80    
81     my $plname = $who->name;
82     my $cnt;
83     for ($storage->at (2, 2)) {
84     if ($_->name () =~ /^\S+ F: \S+ T: \Q$plname\E$/) {
85     $_->insert_in_ob ($who);
86     $cnt++;
87     }
88     }
89    
90     if ($cnt) {
91     $who->reply ($npc, $cnt == 1 ? "Here is your pakage." : "Here are your packages.");
92     } else {
93     $who->reply ($npc, "Sorry, no deliverys for you sir.");
94     }
95    
96     } elsif ($cmd eq 'send') {
97     unless ($arguments =~ /^\S+$/) {
98     $who->reply ($npc, "Send to who?");
99     return 1;
100     }
101    
102     my $storage = cf::map::get_map ("/planes/IPO_storage");
103     unless ($storage) {
104     $who->reply ($npc, "Sorry, our package delivery service is currently in strike. Please come back later.");
105     return 1;
106     }
107    
108     my $cnt;
109     for ($who->inv) {
110     if ($_->name () =~ /^\S+ T: \Q$arguments\E F: (\S+)$/) {
111     $_->set_name ("$1 F: $2 T: $arguments");
112     $_->teleport ($storage, 2, 2);
113     $cnt++;
114     }
115     }
116    
117     if ($cnt) {
118     $who->reply ($npc, $cnt == 1 ? "Package sent to $arguments." : "Sent $cnt packages to $arguments\n");
119     } else {
120     $who->reply ($npc, "Sorry, found no package to send to $arguments.");
121     }
122    
123     } else {
124     $who->reply ($npc,
125     "How can I help you?\n"
126     ."Here is a quick list of commands I understand:\n\n"
127     ."- pen (%s platinum)\n"
128     ."- literacy (%s platinum)\n"
129     ."- mailscroll <friend> (%s platinum)\n"
130     ."- bag <friend> (%s platinum)\n"
131     ."- package <friend> (%s platinum)\n"
132     .($who->flag (cf::FLAG_WIZ) ? "- mailwarning <player>" : "")
133     );
134     }
135     1
136     }