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

Comparing deliantra/maps/perl/ipo.ext (file contents):
Revision 1.4 by elmex, Wed Aug 9 11:54:02 2006 UTC vs.
Revision 1.12 by root, Fri Sep 8 17:39:31 2006 UTC

2 2
3my $price_fact = 50; 3my $price_fact = 50;
4 4
5sub set_package { 5sub set_package {
6 my ($pkg, $from, $to, $bagname, $weight) = @_; 6 my ($pkg, $from, $to, $bagname, $weight) = @_;
7
7 $pkg->set_name ("$bagname T: $to F: $from"); 8 $pkg->name ("$bagname T: $to F: $from");
8 $pkg->set_weight_limit ($weight); 9 $pkg->weight_limit ($weight);
9 $pkg->set_str (0); 10 $pkg->stats->Str (0);
10} 11}
11 12
12# prices in plat. 13# prices in plat.
13my %prices = ( 14my %prices = (
14 pen => [ 15 pen => [
15 40, 'stylus', 16 40, 'stylus',
16 sub { $_[0]->set_name ('IPO Writing Pen'); $_[0]->set_value (40 * $price_fact); } 17 sub { $_[0]->name ('IPO Writing Pen'); $_[0]->value (40 * $price_fact); }
17 ], 18 ],
18 literacy => [ 19 literacy => [
19 1000, 'scroll_literacy', 20 1000, 'scroll_literacy',
20 sub { $_[0]->set_value (1000 * $price_fact) } 21 sub { $_[0]->value (1000 * $price_fact) }
21 ], 22 ],
22 mailscroll => [ 23 mailscroll => [
23 1, 'scroll', 24 1, 'scroll',
24 sub { 25 sub {
25 $_[0]->set_name ("mailscroll T: $_[2] F: $_[1]"); 26 $_[0]->name ("mailscroll T: $_[2] F: $_[1]");
26 $_[0]->set_name_plural ("mailscrolls T: $_[2] F: $_[1]"); 27 $_[0]->name_pl ("mailscrolls T: $_[2] F: $_[1]");
27 $_[0]->set_value (1 * $price_fact); 28 $_[0]->value (1 * $price_fact);
28 }, 29 },
29 'plarg' 30 'plarg'
30 ], 31 ],
31 bag => [ 1, 'r_sack', sub { set_package (@_, bag => 5000) }, 'plarg' ], 32 bag => [ 1, 'r_sack', sub { set_package (@_, bag => 5000) }, 'plarg' ],
32 package => [ 5, 'r_sack', sub { set_package (@_, package => 50000) }, 'plarg' ], 33 package => [ 5, 'r_sack', sub { set_package (@_, package => 50000) }, 'plarg' ],
33 carton => [10, 'r_sack', sub { set_package (@_, carton => 100000) }, 'plarg' ], 34 carton => [10, 'r_sack', sub { set_package (@_, carton => 100000) }, 'plarg' ],
34 mailwarning => [ 35 mailwarning => [
35 0, 'diploma', 36 0, 'diploma',
36 sub { 37 sub {
37 $_[0]->set_name ("mailwarning T: $_[2] F: $_[1]"); 38 $_[0]->name ("mailwarning T: $_[2] F: $_[1]");
38 $_[0]->set_name_plural ("mailwarnings T: $_[2] F: $_[1]"); 39 $_[0]->name_pl ("mailwarnings T: $_[2] F: $_[1]");
39 $_[0]->set_value (0); 40 $_[0]->value (0);
40 }, 41 },
41 'plarg' 42 'plarg'
42 ], 43 ],
43); 44);
44 45
45my %mailtypes = ( 46my %mailtypes = (
46 1 => ['scroll', 'mailscroll'], 47 1 => ['scroll', 'mailscroll'],
47 2 => ['note', 'newspaper'], 48 2 => ['note', 'newspaper'],
48 3 => ['diploma', 'mailwarning'], 49 3 => ['diploma', 'mailwarning'],
49); 50);
51
52sub notify_players {
53 my (%sent_targets) = @_;
54
55 # lets message player ingame: this is a NEW feature from the perl IPO :-)
56 for (keys %sent_targets) {
57 if (my $player = cf::player::find $_) {
58 my $cnt = $sent_targets{$_};
59
60 if ($cnt == 1) {
61 $player->ob->message ("You've got new mail.");
62 } else {
63 $player->ob->message ("You've got $cnt new mails.");
64 }
65 }
66 }
67}
50 68
51sub create_object { 69sub create_object {
52 my ($name, $map, $x, $y, $cb, @a) = @_; 70 my ($name, $map, $x, $y, $cb, @a) = @_;
53 my $o = cf::object::new $name; 71 my $o = cf::object::new $name;
54 my $r = $cb->($o, @a); 72 my $r = $cb->($o, @a);
55 $map->insert_object ($o, $x, $y); 73 $map->insert_object ($o, $x, $y);
56 $r 74 $r
57} 75}
58 76
59# this handler handles to notice the player that he has got mail 77# this handler handles to notice the player that he has got mail
60sub on_login { 78cf::attach_to_players
79 on_login => sub {
61 my ($pl, $host) = @_; 80 my ($pl) = @_;
62 81
63 my $mails = CFMail::get_mail ($pl->ob->name); 82 my $mails = CFMail::get_mail ($pl->ob->name);
64 83
65 my $cnt = @{$mails || []}; 84 my $cnt = @{$mails || []};
66 85
67 if ($cnt == 1) { 86 if ($cnt == 1) {
68 $pl->ob->message ("You got one mail."); 87 $pl->ob->message ("You got one mail.");
69 } elsif ($cnt > 1) { 88 } elsif ($cnt > 1) {
70 $pl->ob->message ("You got $cnt mails."); 89 $pl->ob->message ("You got $cnt mails.");
71 } else { 90 } else {
72 $pl->ob->message ("You haven't got any mail."); 91 $pl->ob->message ("You haven't got any mail.");
92 }
73 } 93 },
74 94;
75 0
76}
77 95
78# this event handler handles receiving of mails 96# this event handler handles receiving of mails
79sub on_apply { 97cf::register_attachment ipo_mailbox =>
98 on_apply => sub {
80 my ($ev, $box, $pl) = @_; 99 my ($box, $pl) = @_;
81 100
82 my $cnt; 101 my $cnt;
83 my $mails = CFMail::get_mail ($pl->name) || []; 102 my $mails = CFMail::get_mail ($pl->name) || [];
84 103
85 # count the mails that are in the container 104 # count the mails that are in the container
86 # FIXME: the problem with on_apply is that it is called even when 105 # FIXME: the problem with on_apply is that it is called even when
87 # the player closes the container. so we get a 'You have X mails.' message 106 # the player closes the container. so we get a 'You have X mails.' message
88 # twice. - This bug existed also with the old python plugin 107 # twice. - This bug existed also with the old python plugin
89 108
90 my $plname = $pl->name; 109 my $plname = $pl->name;
91 for ($box->inv) { 110 for ($box->inv) {
92 $_->name =~ /\S+ F: \S+ T: \Q$plname\E/ 111 $_->name =~ /\S+ F: \S+ T: \Q$plname\E/
93 and $cnt++; 112 and $cnt++;
94 } 113 }
95 114
96 for (@$mails) { 115 for (@$mails) {
97 my ($type, $from, $msg) = @$_; 116 my ($type, $from, $msg) = @$_;
98 $type = $mailtypes{$type || 1} || ['scroll', 'mailscroll']; 117 $type = $mailtypes{$type || 1} || ['scroll', 'mailscroll'];
99 my $mail = cf::object::new $type->[0]; 118 my $mail = cf::object::new $type->[0];
100 $mail->set_name ("$type->[1] F: $from T: " .$pl->name); 119 $mail->name ("$type->[1] F: $from T: " .$pl->name);
101 $mail->set_name_plural ("$type->[1]s F: $from T: " .$pl->name); 120 $mail->name_pl ("$type->[1]s F: $from T: " .$pl->name);
102 $mail->set_message ($msg); 121 $mail->msg ($msg);
103 $mail->set_value (0); 122 $mail->value (0);
104 $mail->insert_in_ob ($box); 123 $mail->insert_in_ob ($box);
105 } 124 }
106 125
107 $cnt += @$mails; 126 $cnt += @$mails;
108 127
109 if ($cnt == 1) { 128 if ($cnt == 1) {
110 $pl->message ("You got one mail."); 129 $pl->message ("You got one mail.");
111 } elsif ($cnt > 1) { 130 } elsif ($cnt > 1) {
112 $pl->message ("You got $cnt mails."); 131 $pl->message ("You got $cnt mails.");
113 } else { 132 } else {
114 $pl->message ("You haven't got any mail."); 133 $pl->message ("You haven't got any mail.");
115 } 134 }
116 135
117 CFMail::clear_mail ($pl->name); 136 CFMail::clear_mail ($pl->name);
118 137 },
119 0;
120}
121
122# this event handler handles the sending of mails 138 # this event handler handles the sending of mails
123sub on_close { 139 on_close => sub {
124 my ($ev, $box, $pl) = @_; 140 my ($box, $pl) = @_;
125 141
126 my @mails; 142 my @mails;
127 143
128 my %sent_targets; 144 my %sent_targets;
129 145
130 for ($box->inv) { 146 for ($box->inv) {
131 if ($_->name =~ m/^mail(scroll|warning) T: (\S+) F: (\S+)/) { 147 if ($_->name =~ m/^mail(scroll|warning) T: (\S+) F: (\S+)/) {
132 CFMail::send_mail ($1 eq 'scroll' ? 1 : 3, $2, $3, $_->message); 148 CFMail::send_mail ($1 eq 'scroll' ? 1 : 3, $2, $3, $_->msg);
133 $pl->message ("Sent mail$1 to $2 (from $3)."); 149 $pl->message ("Sent mail$1 to $2 (from $3).");
134 $sent_targets{$2}++; 150 $sent_targets{$2}++;
135 push @mails, $_; 151 push @mails, $_;
136 152
137 } elsif ($_->name =~ m/^mail(scroll|warning) F: (\S+) T: (\S+)/) { 153 } elsif ($_->name =~ m/^mail(scroll|warning) F: (\S+) T: (\S+)/) {
138 # this is for mails that remain in the queue for the player 154 # this is for mails that remain in the queue for the player
139 CFMail::store_mail ($1 eq 'scroll' ? 1 : 3, $3, $2, $_->message); 155 CFMail::store_mail ($1 eq 'scroll' ? 1 : 3, $3, $2, $_->msg);
140 push @mails, $_; 156 push @mails, $_;
141 } 157 }
142 } 158 }
143 159
144 $_->remove for @mails; 160 $_->remove for @mails;
145 161
146 # lets message player ingame: this is a NEW feature from the perl IPO :-) 162 notify_players (%sent_targets);
147 for (keys %sent_targets) {
148 if (my $player = cf::player::find $_) {
149 my $cnt = $sent_targets{$_};
150
151 if ($cnt == 1) {
152 $player->ob->message ("You've got new mail.");
153 } else {
154 $player->ob->message ("You've got $cnt new mails.");
155 }
156 }
157 } 163 },
158 164;
159 0;
160}
161 165
162# this is the main command interface for the IPO NPC 166# this is the main command interface for the IPO NPC
163cf::register_script_function "ipo::command" => sub { 167cf::register_script_function "ipo::command" => sub {
164 my ($who, $msg, $npc) = @_; 168 my ($who, $msg, $npc) = @_;
165 my ($cmd, $arguments) = split /\s+/, $msg, 2; 169 my ($cmd, $arguments) = split /\s+/, $msg, 2;
180 create_object ($pr->[1], $who->map, $x, $y, $pr->[2], $who->name, $arguments); 184 create_object ($pr->[1], $who->map, $x, $y, $pr->[2], $who->name, $arguments);
181 $who->reply ($npc, "Here is your $cmd"); 185 $who->reply ($npc, "Here is your $cmd");
182 } 186 }
183 187
184 } elsif ($cmd eq 'receive') { 188 } elsif ($cmd eq 'receive') {
185 my $storage = cf::map::get_map ("/planes/IPO_storage"); 189 my $storage = cf::map::find ("/planes/IPO_storage");
186 unless ($storage) { 190 unless ($storage) {
187 $who->reply ($npc, "Sorry, our package delivery service is currently in strike. Please come back later."); 191 $who->reply ($npc, "Sorry, our package delivery service is currently in strike. Please come back later.");
188 return 1; 192 return 1;
189 } 193 }
190 194
207 unless ($arguments =~ /^\S+$/) { 211 unless ($arguments =~ /^\S+$/) {
208 $who->reply ($npc, "Send to who?"); 212 $who->reply ($npc, "Send to who?");
209 return 1; 213 return 1;
210 } 214 }
211 215
212 my $storage = cf::map::get_map ("/planes/IPO_storage"); 216 my $storage = cf::map::find ("/planes/IPO_storage");
213 unless ($storage) { 217 unless ($storage) {
214 $who->reply ($npc, "Sorry, our package delivery service is currently in strike. Please come back later."); 218 $who->reply ($npc, "Sorry, our package delivery service is currently in strike. Please come back later.");
215 return 1; 219 return 1;
216 } 220 }
217 221
218 my $cnt; 222 my $cnt;
219 for ($who->inv) { 223 for ($who->inv) {
220 if ($_->name () =~ /^(bag|package|carton) T: \Q$arguments\E F: (\S+)$/) { 224 if ($_->name () =~ /^(bag|package|carton) T: \Q$arguments\E F: (\S+)$/) {
221 $_->set_name ("$1 F: $2 T: $arguments"); 225 $_->name ("$1 F: $2 T: $arguments");
222 $_->teleport ($storage, 2, 2); 226 $_->teleport ($storage, 2, 2);
223 $cnt++; 227 $cnt++;
224 } 228 }
225 } 229 }
226 230
227 if ($cnt) { 231 if ($cnt) {
228 $who->reply ($npc, $cnt == 1 ? "Package sent to $arguments." : "Sent $cnt packages to $arguments\n"); 232 $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);
234 notify_players ($arguments => 1);
229 } else { 235 } else {
230 $who->reply ($npc, "Sorry, found no package to send to $arguments."); 236 $who->reply ($npc, "Sorry, found no package to send to $arguments.");
231 } 237 }
232 238
233 } else { 239 } else {
234 $who->reply ($npc, 240 $who->reply ($npc,
235 sprintf "How can I help you?\n" 241 sprintf "How can I help you?\n"
236 ."Here is a quick list of commands I understand:\n\n" 242 . "Here is a quick list of commands I understand:\n\n"
237 ."- pen (%s platinum)\n" 243 . "- pen (%s platinum)\n"
238 ."- literacy (%s platinum)\n" 244 . "- literacy (%s platinum)\n"
239 ."- mailscroll <friend> (%s platinum)\n" 245 . "- mailscroll <friend> (%s platinum)\n"
240 ."- bag <friend> (%s platinum)\n" 246 . "- bag <friend> (%s platinum)\n"
241 ."- package <friend> (%s platinum)\n" 247 . "- package <friend> (%s platinum)\n"
242 ."- carton <friend> (%s platinum)\n" 248 . "- carton <friend> (%s platinum)\n"
249 . "- send <friend> (send bags/packages/cartons)\n"
250 . "- receive (to receive packages for you)\n"
243 .($who->flag (cf::FLAG_WIZ) ? "- mailwarning <player>" : ""), 251 . ($who->flag (cf::FLAG_WIZ) ? "- mailwarning <player>" : ""),
244 40, 1000, 1, 1, 5, 10 252 40, 1000, 1, 1, 5, 10
245 ); 253 );
246 } 254 }
247 1 255 1
248}; 256};
249 257
250package CFMail; 258package CFMail;
259
251use POSIX qw/strftime/; 260use POSIX qw/strftime/;
252use CFDB; 261use CFDB;
253 262
254my $MAILDB = CFDB->new (db_file => cf::localdir . "/crossfiremail.perl"); 263my $MAILDB = CFDB->new (db_file => cf::localdir . "/crossfiremail.perl");
255 264

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines