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.1 by root, Fri Dec 15 19:29:18 2006 UTC vs.
Revision 1.14 by elmex, Thu Apr 24 11:05:51 2008 UTC

12 12
13# prices in plat. 13# prices in plat.
14my %prices = ( 14my %prices = (
15 pen => [ 15 pen => [
16 40, 'stylus', 16 40, 'stylus',
17 sub { $_[0]->name ('IPO Writing Pen'); $_[0]->value (40 * $price_fact); } 17 sub { $_[0]->name ('IPO Writing Pen'); $_[0]->value (0); }
18 ], 18 ],
19 literacy => [ 19 literacy => [
20 1000, 'scroll_literacy', 20 1000, 'scroll_literacy',
21 sub { $_[0]->value (1000 * $price_fact) } 21 sub { $_[0]->value (0) }
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 (0);
29 }, 29 },
30 'plarg' 30 'plarg'
31 ], 31 ],
32 bag => [ 1, 'r_sack', sub { set_package (@_, bag => 5000) }, 'plarg' ], 32 bag => [ 1, 'r_sack', sub { set_package (@_, bag => 5000) }, 'plarg' ],
33 package => [ 5, 'r_sack', sub { set_package (@_, package => 50000) }, 'plarg' ], 33 package => [ 5, 'r_sack', sub { set_package (@_, package => 50000) }, 'plarg' ],
52sub notify_players { 52sub 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
69sub create_object { 69sub 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 handles to notice the player that he has got mail 77# this handler notifies the player of new mail
78cf::attach_to_players 78cf::player->attach (
79 on_login => sub { 79 on_login => sub {
80 my ($pl) = @_; 80 my ($pl) = @_;
81 81
82 my $mails = CFMail::get_mail ($pl->ob->name); 82 my $mails = CFMail::get_mail ($pl->ob->name);
83 83
89 $pl->ob->message ("You got $cnt mails."); 89 $pl->ob->message ("You got $cnt mails.");
90 } else { 90 } else {
91 $pl->ob->message ("You haven't got any mail."); 91 $pl->ob->message ("You haven't got any mail.");
92 } 92 }
93 }, 93 },
94; 94);
95 95
96# this event handler handles receiving of mails 96# this event handler handles receiving of mails
97cf::register_attachment ipo_mailbox => 97cf::object::attachment ipo_mailbox =>
98 on_apply => sub { 98 on_apply => sub {
99 my ($box, $pl) = @_; 99 my ($box, $pl) = @_;
100 100
101 my $cnt; 101 my $cnt;
102 my $mails = CFMail::get_mail ($pl->name) || []; 102 my $mails = CFMail::get_mail ($pl->name) || [];
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) {
167cf::register_script_function "ipo::command" => sub { 167cf::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;
178 } 178 }
179 179
180 $who->pay_amount ($pr->[0] * $price_fact); 180 if ($who->pay_amount ($pr->[0] * $price_fact)) {
181 cf::async {
181 if ($pr->[3] && not cf::player::exists $arguments) { 182 if ($pr->[3] && not cf::player::exists $arguments) {
182 $who->reply ($npc, "Sorry, there is no '$arguments'"); 183 $who->reply ($npc, "Sorry, there is no '$arguments'");
184 } else {
185 create_object ($pr->[1], $who->map, $x, $y, $pr->[2], $who->name, $arguments);
186 $who->reply ($npc, "Here is your $cmd");
187 }
188 }
183 } else { 189 } else {
184 create_object ($pr->[1], $who->map, $x, $y, $pr->[2], $who->name, $arguments); 190 $who->reply ($npc, "Sorry, you don't have enough money.");
185 $who->reply ($npc, "Here is your $cmd");
186 } 191 }
187 192
188 } elsif ($cmd eq 'receive') { 193 } elsif ($cmd eq 'receive') {
194 cf::async {
195 $Coro::current->{desc} = "ipo receive";
196
189 my $storage = cf::map::find ("/planes/IPO_storage"); 197 my $storage = cf::map::find ("/planes/IPO_storage");
190 unless ($storage) { 198 unless ($storage) {
191 $who->reply ($npc, "Sorry, our package delivery service is currently in strike. Please come back later."); 199 $who->reply ($npc, "Sorry, our package delivery service is currently in strike. Please come back later.");
192 return 1; 200 return 1;
193 } 201 }
202 $storage->load;
194 203
195 my $plname = $who->name; 204 my $plname = $who->name;
196 my $cnt; 205 my $cnt;
197 for ($storage->at (2, 2)) { 206 for ($storage->at (2, 2)) {
198 if ($_->name () =~ /^\S+ F: \S+ T: \Q$plname\E$/) { 207 if ($_->name () =~ /^\S+ F: \S+ T: \Q$plname\E$/) {
199 $_->insert_in_ob ($who); 208 $who->insert ($_);
200 $cnt++; 209 $cnt++;
201 } 210 }
202 } 211 }
203 212
204 if ($cnt) { 213 if ($cnt) {
205 $who->reply ($npc, $cnt == 1 ? "Here is your pakage." : "Here are your packages."); 214 $who->reply ($npc, $cnt == 1 ? "Here is your package." : "Here are your packages.");
206 } else { 215 } else {
207 $who->reply ($npc, "Sorry, no deliverys for you sir."); 216 $who->reply ($npc, "Sorry, no deliveries for you sir.");
217 }
208 } 218 }
209 219
210 } elsif ($cmd eq 'send') { 220 } elsif ($cmd eq 'send') {
211 unless ($arguments =~ /^\S+$/) { 221 unless ($arguments =~ /^\S+$/) {
212 $who->reply ($npc, "Send to who?"); 222 $who->reply ($npc, "Send to who?");
213 return 1; 223 return 1;
214 } 224 }
215 225
226 cf::async {
227 $Coro::current->{desc} = "ipo send";
228
216 my $storage = cf::map::find ("/planes/IPO_storage"); 229 my $storage = cf::map::find ("/planes/IPO_storage");
217 unless ($storage) { 230 unless ($storage) {
218 $who->reply ($npc, "Sorry, our package delivery service is currently in strike. Please come back later."); 231 $who->reply ($npc, "Sorry, our package delivery service is currently in strike. Please come back later.");
219 return 1; 232 return 1;
220 } 233 }
234 $storage->load;
221 235
222 my $cnt; 236 my $cnt;
223 for ($who->inv) { 237 for ($who->inv) {
224 if ($_->name () =~ /^(bag|package|carton) T: \Q$arguments\E F: (\S+)$/) { 238 if ($_->name () =~ /^(bag|package|carton) T: \Q$arguments\E F: (\S+)$/) {
225 $_->name ("$1 F: $2 T: $arguments"); 239 $_->name ("$1 F: $2 T: $arguments");
226 $_->teleport ($storage, 2, 2); 240 $storage->insert ($_, 2, 2);
227 $cnt++; 241 $cnt++;
228 } 242 }
229 } 243 }
230 244
231 if ($cnt) { 245 if ($cnt) {
232 $who->reply ($npc, $cnt == 1 ? "Package sent to $arguments." : "Sent $cnt packages to $arguments\n"); 246 $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); 247 CFMail::send_mail (1, $arguments, $who->name, "You got $cnt packages from " . $who->name);
234 notify_players ($arguments => 1); 248 notify_players ($arguments => 1);
235 } else { 249 } else {
236 $who->reply ($npc, "Sorry, found no package to send to $arguments."); 250 $who->reply ($npc, "Sorry, found no package to send to $arguments.");
251 }
237 } 252 }
238 253
239 } else { 254 } else {
240 $who->reply ($npc, 255 $who->reply ($npc,
241 sprintf "How can I help you?\n" 256 sprintf "How can I help you?\n"
258package CFMail; 273package CFMail;
259 274
260use POSIX qw/strftime/; 275use POSIX qw/strftime/;
261use CFDB; 276use CFDB;
262 277
263my $MAILDB = CFDB->new (db_file => cf::localdir . "/crossfiremail.perl"); 278my $MAILDB = CFDB->new (db_file => "$LOCALDIR/crossfiremail");
264 279
265sub get_mail { 280sub get_mail {
266 my ($toname) = @_; 281 my ($toname) = @_;
267 $MAILDB->get ($toname); 282 $MAILDB->get ($toname);
268} 283}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines