ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/ext/ipo.ext
(Generate patch)

Comparing deliantra/server/ext/ipo.ext (file contents):
Revision 1.2 by root, Thu Dec 21 22:41:34 2006 UTC vs.
Revision 1.16 by sf-marcmagus, Sun Oct 11 21:39:08 2009 UTC

1#! perl 1#! perl
2
3my $price_fact = 50;
4 2
5sub set_package { 3sub set_package {
6 my ($pkg, $from, $to, $bagname, $weight) = @_; 4 my ($pkg, $from, $to, $bagname, $weight) = @_;
7 5
8 $pkg->name ("$bagname T: $to F: $from"); 6 $pkg->name ("$bagname T: $to F: $from");
9 $pkg->weight_limit ($weight); 7 $pkg->weight_limit ($weight);
10 $pkg->stats->Str (0); 8 $pkg->stats->Str (0);
11} 9}
12 10
13# prices in plat. 11# prices [in silver]
14my %prices = ( 12my %prices = (
15 pen => [ 13 pen => [
16 40, 'stylus', 14 10000, 'stylus',
17 sub { $_[0]->name ('IPO Writing Pen'); $_[0]->value (40 * $price_fact); } 15 sub { $_[0]->name ('IPO Writing Pen'); $_[0]->value (0); }
18 ], 16 ],
19 literacy => [ 17 literacy => [
20 1000, 'scroll_literacy', 18 10000, 'scroll_literacy',
21 sub { $_[0]->value (1000 * $price_fact) } 19 sub { $_[0]->value (0) }
22 ], 20 ],
23 mailscroll => [ 21 mailscroll => [
24 1, 'scroll', 22 50, 'mailscroll_empty',
25 sub { 23 sub {
26 $_[0]->name ("mailscroll T: $_[2] F: $_[1]"); 24 $_[0]->name ("mailscroll T: $_[2] F: $_[1]");
27 $_[0]->name_pl ("mailscrolls T: $_[2] F: $_[1]"); 25 $_[0]->name_pl ("mailscrolls T: $_[2] F: $_[1]");
28 $_[0]->value (1 * $price_fact); 26 $_[0]->value (0);
29 }, 27 },
30 'plarg' 28 'plarg'
31 ], 29 ],
32 bag => [ 1, 'r_sack', sub { set_package (@_, bag => 5000) }, 'plarg' ], 30 bag => [ 100, 'r_sack', sub { set_package (@_, bag => 5000) }, 'plarg' ],
33 package => [ 5, 'r_sack', sub { set_package (@_, package => 50000) }, 'plarg' ], 31 package => [ 1000, 'r_sack', sub { set_package (@_, package => 50000) }, 'plarg' ],
34 carton => [10, 'r_sack', sub { set_package (@_, carton => 100000) }, 'plarg' ], 32 carton => [ 2000, 'r_sack', sub { set_package (@_, carton => 100000) }, 'plarg' ],
35 mailwarning => [ 33 mailwarning => [
36 0, 'diploma', 34 0, 'diploma',
37 sub { 35 sub {
38 $_[0]->name ("mailwarning T: $_[2] F: $_[1]"); 36 $_[0]->name ("mailwarning T: $_[2] F: $_[1]");
39 $_[0]->name_pl ("mailwarnings T: $_[2] F: $_[1]"); 37 $_[0]->name_pl ("mailwarnings T: $_[2] F: $_[1]");
52sub notify_players { 50sub notify_players {
53 my (%sent_targets) = @_; 51 my (%sent_targets) = @_;
54 52
55 # lets message player ingame: this is a NEW feature from the perl IPO :-) 53 # lets message player ingame: this is a NEW feature from the perl IPO :-)
56 for (keys %sent_targets) { 54 for (keys %sent_targets) {
57 if (my $player = cf::player::find $_) { 55 if (my $player = cf::player::find_active $_) {
58 my $cnt = $sent_targets{$_}; 56 my $cnt = $sent_targets{$_};
59 57
60 if ($cnt == 1) { 58 if ($cnt == 1) {
61 $player->ob->message ("You've got new mail."); 59 $player->ob->message ("You've got new mail.");
62 } else { 60 } else {
68 66
69sub create_object { 67sub create_object {
70 my ($name, $map, $x, $y, $cb, @a) = @_; 68 my ($name, $map, $x, $y, $cb, @a) = @_;
71 my $o = cf::object::new $name; 69 my $o = cf::object::new $name;
72 my $r = $cb->($o, @a); 70 my $r = $cb->($o, @a);
73 $map->insert_object ($o, $x, $y); 71 $map->insert ($o, $x, $y);
74 $r 72 $r
75} 73}
76 74
77# this handler notifies the player of new mail 75# this handler notifies the player of new mail
78cf::player->attach ( 76cf::player->attach (
118 my $mail = cf::object::new $type->[0]; 116 my $mail = cf::object::new $type->[0];
119 $mail->name ("$type->[1] F: $from T: " .$pl->name); 117 $mail->name ("$type->[1] F: $from T: " .$pl->name);
120 $mail->name_pl ("$type->[1]s F: $from T: " .$pl->name); 118 $mail->name_pl ("$type->[1]s F: $from T: " .$pl->name);
121 $mail->msg ($msg); 119 $mail->msg ($msg);
122 $mail->value (0); 120 $mail->value (0);
123 $mail->insert_in_ob ($box); 121 $box->insert ($mail);
124 } 122 }
125 123
126 $cnt += @$mails; 124 $cnt += @$mails;
127 125
128 if ($cnt == 1) { 126 if ($cnt == 1) {
167cf::register_script_function "ipo::command" => sub { 165cf::register_script_function "ipo::command" => sub {
168 my ($who, $msg, $npc) = @_; 166 my ($who, $msg, $npc) = @_;
169 my ($cmd, $arguments) = split /\s+/, $msg, 2; 167 my ($cmd, $arguments) = split /\s+/, $msg, 2;
170 $cmd = lc $cmd; 168 $cmd = lc $cmd;
171 169
172 my $pl = cf::player::find $who->name; 170 my $pl = cf::player::find_active $who->name;
173 my ($x, $y) = ($pl->ob->x, $pl->ob->y); 171 my ($x, $y) = ($pl->ob->x, $pl->ob->y);
174 172
175 if (my $pr = $prices{$cmd}) { 173 if (my $pr = $prices{$cmd}) {
176 if ($cmd eq 'mailwarning' and !$who->flag (cf::FLAG_WIZ)) { 174 if ($cmd eq 'mailwarning' and !$who->flag (cf::FLAG_WIZ)) {
177 return 1; 175 return 1;
178 } 176 }
179 177
180 $who->pay_amount ($pr->[0] * $price_fact); 178 if ($who->pay_amount ($pr->[0])) {
179 cf::async {
181 if ($pr->[3] && not cf::player::exists $arguments) { 180 if ($pr->[3] && not cf::player::exists $arguments) {
182 $who->reply ($npc, "Sorry, there is no '$arguments'"); 181 $who->reply ($npc, "Sorry, there is no '$arguments'");
182 } else {
183 create_object ($pr->[1], $who->map, $x, $y, $pr->[2], $who->name, $arguments);
184 $who->reply ($npc, "Here is your $cmd");
185 }
186 }
183 } else { 187 } else {
184 create_object ($pr->[1], $who->map, $x, $y, $pr->[2], $who->name, $arguments); 188 $who->reply ($npc, "Sorry, you don't have enough money.");
185 $who->reply ($npc, "Here is your $cmd");
186 } 189 }
187 190
188 } elsif ($cmd eq 'receive') { 191 } elsif ($cmd eq 'receive') {
192 cf::async {
193 $Coro::current->{desc} = "ipo receive";
194
189 my $storage = cf::map::find ("/planes/IPO_storage"); 195 my $storage = cf::map::find ("/planes/IPO_storage");
190 unless ($storage) { 196 unless ($storage) {
191 $who->reply ($npc, "Sorry, our package delivery service is currently in strike. Please come back later."); 197 $who->reply ($npc, "Sorry, our package delivery service is currently in strike. Please come back later.");
192 return 1; 198 return 1;
193 } 199 }
200 $storage->load;
194 201
195 my $plname = $who->name; 202 my $plname = $who->name;
196 my $cnt; 203 my $cnt;
197 for ($storage->at (2, 2)) { 204 for ($storage->at (2, 2)) {
198 if ($_->name () =~ /^\S+ F: \S+ T: \Q$plname\E$/) { 205 if ($_->name () =~ /^\S+ F: \S+ T: \Q$plname\E$/) {
199 $_->insert_in_ob ($who); 206 $who->insert ($_);
200 $cnt++; 207 $cnt++;
201 } 208 }
202 } 209 }
203 210
204 if ($cnt) { 211 if ($cnt) {
205 $who->reply ($npc, $cnt == 1 ? "Here is your pakage." : "Here are your packages."); 212 $who->reply ($npc, $cnt == 1 ? "Here is your package." : "Here are your packages.");
206 } else { 213 } else {
207 $who->reply ($npc, "Sorry, no deliverys for you sir."); 214 $who->reply ($npc, "Sorry, no deliveries for you sir.");
215 }
208 } 216 }
209 217
210 } elsif ($cmd eq 'send') { 218 } elsif ($cmd eq 'send') {
211 unless ($arguments =~ /^\S+$/) { 219 unless ($arguments =~ /^\S+$/) {
212 $who->reply ($npc, "Send to who?"); 220 $who->reply ($npc, "Send to who?");
213 return 1; 221 return 1;
214 } 222 }
215 223
224 cf::async {
225 $Coro::current->{desc} = "ipo send";
226
216 my $storage = cf::map::find ("/planes/IPO_storage"); 227 my $storage = cf::map::find ("/planes/IPO_storage");
217 unless ($storage) { 228 unless ($storage) {
218 $who->reply ($npc, "Sorry, our package delivery service is currently in strike. Please come back later."); 229 $who->reply ($npc, "Sorry, our package delivery service is currently in strike. Please come back later.");
219 return 1; 230 return 1;
220 } 231 }
232 $storage->load;
221 233
222 my $cnt; 234 my $cnt;
223 for ($who->inv) { 235 for ($who->inv) {
224 if ($_->name () =~ /^(bag|package|carton) T: \Q$arguments\E F: (\S+)$/) { 236 if ($_->name () =~ /^(bag|package|carton) T: \Q$arguments\E F: (\S+)$/) {
225 $_->name ("$1 F: $2 T: $arguments"); 237 $_->name ("$1 F: $2 T: $arguments");
226 $_->teleport ($storage, 2, 2); 238 $storage->insert ($_, 2, 2);
227 $cnt++; 239 $cnt++;
228 } 240 }
229 } 241 }
230 242
231 if ($cnt) { 243 if ($cnt) {
232 $who->reply ($npc, $cnt == 1 ? "Package sent to $arguments." : "Sent $cnt packages to $arguments\n"); 244 $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); 245 CFMail::send_mail (1, $arguments, $who->name, "You got $cnt packages from " . $who->name);
234 notify_players ($arguments => 1); 246 notify_players ($arguments => 1);
235 } else { 247 } else {
236 $who->reply ($npc, "Sorry, found no package to send to $arguments."); 248 $who->reply ($npc, "Sorry, found no package to send to $arguments.");
249 }
237 } 250 }
238 251
239 } else { 252 } else {
240 $who->reply ($npc, 253 $who->reply ($npc,
241 sprintf "How can I help you?\n" 254 sprintf "How can I help you?\n"
242 . "Here is a quick list of commands I understand:\n\n" 255 . "Here is a quick list of commands I understand:\n\n"
243 . "- pen (%s platinum)\n" 256 . " - pen (%s)\n"
244 . "- literacy (%s platinum)\n" 257 . " - literacy (%s)\n"
245 . "- mailscroll <friend> (%s platinum)\n" 258 . " - mailscroll <friend> (%s)\n"
246 . "- bag <friend> (%s platinum)\n" 259 . " - bag <friend> (%s)\n"
247 . "- package <friend> (%s platinum)\n" 260 . " - package <friend> (%s)\n"
248 . "- carton <friend> (%s platinum)\n" 261 . " - carton <friend> (%s)\n"
249 . "- send <friend> (send bags/packages/cartons)\n" 262 . " - send <friend> (send bags/packages/cartons)\n"
250 . "- receive (to receive packages for you)\n" 263 . " - receive (to receive packages for you)\n"
251 . ($who->flag (cf::FLAG_WIZ) ? "- mailwarning <player>" : ""), 264 . ($who->flag (cf::FLAG_WIZ) ? " - mailwarning <player>\n" : ""),
252 40, 1000, 1, 1, 5, 10 265 cf::cost_string_from_value($prices{'pen'}[0]),
266 cf::cost_string_from_value($prices{'literacy'}[0]),
267 cf::cost_string_from_value($prices{'mailscroll'}[0]),
268 cf::cost_string_from_value($prices{'bag'}[0]),
269 cf::cost_string_from_value($prices{'package'}[0]),
270 cf::cost_string_from_value($prices{'carton'}[0])
253 ); 271 );
254 } 272 }
255 1 273 1
256}; 274};
257 275
258package CFMail; 276package CFMail;
259 277
260use POSIX qw/strftime/; 278use POSIX qw/strftime/;
261use CFDB; 279use CFDB;
262 280
263my $MAILDB = CFDB->new (db_file => cf::localdir . "/crossfiremail.perl"); 281my $MAILDB = CFDB->new (db_file => "$LOCALDIR/crossfiremail");
264 282
265sub get_mail { 283sub get_mail {
266 my ($toname) = @_; 284 my ($toname) = @_;
267 $MAILDB->get ($toname); 285 $MAILDB->get ($toname);
268} 286}
280} 298}
281 299
282sub send_mail { 300sub send_mail {
283 my ($type, $toname, $fromname, $message) = @_; 301 my ($type, $toname, $fromname, $message) = @_;
284 my $time = strftime ("%a, %d %b %Y %H:%M:%S CEST", localtime (time)); 302 my $time = strftime ("%a, %d %b %Y %H:%M:%S CEST", localtime (time));
285 my $msg = "From: $fromname\nTo: $toname\nDate: $time\n\n$message\n"; 303 my $msg = "From: $fromname\rTo: $toname\rDate: $time\n\n$message\n";
286 store_mail ($type, $toname, $fromname, $msg); 304 store_mail ($type, $toname, $fromname, $msg);
287} 305}
288 306
2891; 3071;
308

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines