1 | #! perl |
1 | #! perl |
2 | #CONVERSION: PARTIAL |
|
|
3 | |
2 | |
4 | my $price_fact = 50; |
3 | my $price_fact = 50; |
5 | |
4 | |
6 | sub set_package { |
5 | sub set_package { |
7 | my ($pkg, $from, $to, $bagname, $weight) = @_; |
6 | my ($pkg, $from, $to, $bagname, $weight) = @_; |
|
|
7 | |
8 | $pkg->set_name ("$bagname T: $to F: $from"); |
8 | $pkg->name ("$bagname T: $to F: $from"); |
9 | $pkg->set_weight_limit ($weight); |
9 | $pkg->weight_limit ($weight); |
10 | $pkg->set_str (0); |
10 | $pkg->stats->Str (0); |
11 | } |
11 | } |
12 | |
12 | |
13 | # prices in plat. |
13 | # prices in plat. |
14 | my %prices = ( |
14 | my %prices = ( |
15 | pen => [ |
15 | pen => [ |
16 | 40, 'stylus', |
16 | 40, 'stylus', |
17 | 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); } |
18 | ], |
18 | ], |
19 | literacy => [ |
19 | literacy => [ |
20 | 1000, 'scroll_literacy', |
20 | 1000, 'scroll_literacy', |
21 | sub { $_[0]->set_value (1000 * $price_fact) } |
21 | sub { $_[0]->value (1000 * $price_fact) } |
22 | ], |
22 | ], |
23 | mailscroll => [ |
23 | mailscroll => [ |
24 | 1, 'scroll', |
24 | 1, 'scroll', |
25 | sub { |
25 | sub { |
26 | $_[0]->set_name ("mailscroll T: $_[2] F: $_[1]"); |
26 | $_[0]->name ("mailscroll T: $_[2] F: $_[1]"); |
27 | $_[0]->set_name_plural ("mailscrolls T: $_[2] F: $_[1]"); |
27 | $_[0]->name_pl ("mailscrolls T: $_[2] F: $_[1]"); |
28 | $_[0]->set_value (1 * $price_fact); |
28 | $_[0]->value (1 * $price_fact); |
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' ], |
34 | carton => [10, 'r_sack', sub { set_package (@_, carton => 100000) }, 'plarg' ], |
34 | carton => [10, 'r_sack', sub { set_package (@_, carton => 100000) }, 'plarg' ], |
35 | mailwarning => [ |
35 | mailwarning => [ |
36 | 0, 'diploma', |
36 | 0, 'diploma', |
37 | sub { |
37 | sub { |
38 | $_[0]->set_name ("mailwarning T: $_[2] F: $_[1]"); |
38 | $_[0]->name ("mailwarning T: $_[2] F: $_[1]"); |
39 | $_[0]->set_name_plural ("mailwarnings T: $_[2] F: $_[1]"); |
39 | $_[0]->name_pl ("mailwarnings T: $_[2] F: $_[1]"); |
40 | $_[0]->set_value (0); |
40 | $_[0]->value (0); |
41 | }, |
41 | }, |
42 | 'plarg' |
42 | 'plarg' |
43 | ], |
43 | ], |
44 | ); |
44 | ); |
45 | |
45 | |
… | |
… | |
92 | } |
92 | } |
93 | }, |
93 | }, |
94 | ; |
94 | ; |
95 | |
95 | |
96 | # this event handler handles receiving of mails |
96 | # this event handler handles receiving of mails |
97 | sub on_apply { |
97 | cf::register_attachment ipo_mailbox => |
|
|
98 | on_apply => sub { |
98 | my ($ev, $box, $pl) = @_; |
99 | my ($box, $pl) = @_; |
99 | |
100 | |
100 | my $cnt; |
101 | my $cnt; |
101 | my $mails = CFMail::get_mail ($pl->name) || []; |
102 | my $mails = CFMail::get_mail ($pl->name) || []; |
102 | |
103 | |
103 | # count the mails that are in the container |
104 | # count the mails that are in the container |
104 | # 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 |
105 | # 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 |
106 | # twice. - This bug existed also with the old python plugin |
107 | # twice. - This bug existed also with the old python plugin |
107 | |
108 | |
108 | my $plname = $pl->name; |
109 | my $plname = $pl->name; |
109 | for ($box->inv) { |
110 | for ($box->inv) { |
110 | $_->name =~ /\S+ F: \S+ T: \Q$plname\E/ |
111 | $_->name =~ /\S+ F: \S+ T: \Q$plname\E/ |
111 | and $cnt++; |
112 | and $cnt++; |
112 | } |
113 | } |
113 | |
114 | |
114 | for (@$mails) { |
115 | for (@$mails) { |
115 | my ($type, $from, $msg) = @$_; |
116 | my ($type, $from, $msg) = @$_; |
116 | $type = $mailtypes{$type || 1} || ['scroll', 'mailscroll']; |
117 | $type = $mailtypes{$type || 1} || ['scroll', 'mailscroll']; |
117 | my $mail = cf::object::new $type->[0]; |
118 | my $mail = cf::object::new $type->[0]; |
118 | $mail->set_name ("$type->[1] F: $from T: " .$pl->name); |
119 | $mail->name ("$type->[1] F: $from T: " .$pl->name); |
119 | $mail->set_name_plural ("$type->[1]s F: $from T: " .$pl->name); |
120 | $mail->name_pl ("$type->[1]s F: $from T: " .$pl->name); |
120 | $mail->set_message ($msg); |
121 | $mail->msg ($msg); |
121 | $mail->set_value (0); |
122 | $mail->value (0); |
122 | $mail->insert_in_ob ($box); |
123 | $mail->insert_in_ob ($box); |
123 | } |
124 | } |
124 | |
125 | |
125 | $cnt += @$mails; |
126 | $cnt += @$mails; |
126 | |
127 | |
127 | if ($cnt == 1) { |
128 | if ($cnt == 1) { |
128 | $pl->message ("You got one mail."); |
129 | $pl->message ("You got one mail."); |
129 | } elsif ($cnt > 1) { |
130 | } elsif ($cnt > 1) { |
130 | $pl->message ("You got $cnt mails."); |
131 | $pl->message ("You got $cnt mails."); |
131 | } else { |
132 | } else { |
132 | $pl->message ("You haven't got any mail."); |
133 | $pl->message ("You haven't got any mail."); |
133 | } |
134 | } |
134 | |
135 | |
135 | CFMail::clear_mail ($pl->name); |
136 | CFMail::clear_mail ($pl->name); |
136 | |
137 | }, |
137 | 0; |
|
|
138 | } |
|
|
139 | |
|
|
140 | # this event handler handles the sending of mails |
138 | # this event handler handles the sending of mails |
141 | sub on_close { |
139 | on_close => sub { |
142 | my ($ev, $box, $pl) = @_; |
140 | my ($box, $pl) = @_; |
143 | |
141 | |
144 | my @mails; |
142 | my @mails; |
145 | |
143 | |
146 | my %sent_targets; |
144 | my %sent_targets; |
147 | |
145 | |
148 | for ($box->inv) { |
146 | for ($box->inv) { |
149 | if ($_->name =~ m/^mail(scroll|warning) T: (\S+) F: (\S+)/) { |
147 | if ($_->name =~ m/^mail(scroll|warning) T: (\S+) F: (\S+)/) { |
150 | CFMail::send_mail ($1 eq 'scroll' ? 1 : 3, $2, $3, $_->message); |
148 | CFMail::send_mail ($1 eq 'scroll' ? 1 : 3, $2, $3, $_->msg); |
151 | $pl->message ("Sent mail$1 to $2 (from $3)."); |
149 | $pl->message ("Sent mail$1 to $2 (from $3)."); |
152 | $sent_targets{$2}++; |
150 | $sent_targets{$2}++; |
153 | push @mails, $_; |
151 | push @mails, $_; |
154 | |
152 | |
155 | } elsif ($_->name =~ m/^mail(scroll|warning) F: (\S+) T: (\S+)/) { |
153 | } elsif ($_->name =~ m/^mail(scroll|warning) F: (\S+) T: (\S+)/) { |
156 | # 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 |
157 | CFMail::store_mail ($1 eq 'scroll' ? 1 : 3, $3, $2, $_->message); |
155 | CFMail::store_mail ($1 eq 'scroll' ? 1 : 3, $3, $2, $_->msg); |
158 | push @mails, $_; |
156 | push @mails, $_; |
159 | } |
157 | } |
160 | } |
158 | } |
161 | |
159 | |
162 | $_->remove for @mails; |
160 | $_->remove for @mails; |
163 | |
161 | |
164 | notify_players (%sent_targets); |
162 | notify_players (%sent_targets); |
165 | |
163 | }, |
166 | 0; |
164 | ; |
167 | } |
|
|
168 | |
165 | |
169 | # this is the main command interface for the IPO NPC |
166 | # this is the main command interface for the IPO NPC |
170 | cf::register_script_function "ipo::command" => sub { |
167 | cf::register_script_function "ipo::command" => sub { |
171 | my ($who, $msg, $npc) = @_; |
168 | my ($who, $msg, $npc) = @_; |
172 | my ($cmd, $arguments) = split /\s+/, $msg, 2; |
169 | my ($cmd, $arguments) = split /\s+/, $msg, 2; |
… | |
… | |
187 | 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); |
188 | $who->reply ($npc, "Here is your $cmd"); |
185 | $who->reply ($npc, "Here is your $cmd"); |
189 | } |
186 | } |
190 | |
187 | |
191 | } elsif ($cmd eq 'receive') { |
188 | } elsif ($cmd eq 'receive') { |
192 | my $storage = cf::map::get_map ("/planes/IPO_storage"); |
189 | my $storage = cf::map::find ("/planes/IPO_storage"); |
193 | unless ($storage) { |
190 | unless ($storage) { |
194 | $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."); |
195 | return 1; |
192 | return 1; |
196 | } |
193 | } |
197 | |
194 | |
… | |
… | |
214 | unless ($arguments =~ /^\S+$/) { |
211 | unless ($arguments =~ /^\S+$/) { |
215 | $who->reply ($npc, "Send to who?"); |
212 | $who->reply ($npc, "Send to who?"); |
216 | return 1; |
213 | return 1; |
217 | } |
214 | } |
218 | |
215 | |
219 | my $storage = cf::map::get_map ("/planes/IPO_storage"); |
216 | my $storage = cf::map::find ("/planes/IPO_storage"); |
220 | unless ($storage) { |
217 | unless ($storage) { |
221 | $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."); |
222 | return 1; |
219 | return 1; |
223 | } |
220 | } |
224 | |
221 | |
225 | my $cnt; |
222 | my $cnt; |
226 | for ($who->inv) { |
223 | for ($who->inv) { |
227 | if ($_->name () =~ /^(bag|package|carton) T: \Q$arguments\E F: (\S+)$/) { |
224 | if ($_->name () =~ /^(bag|package|carton) T: \Q$arguments\E F: (\S+)$/) { |
228 | $_->set_name ("$1 F: $2 T: $arguments"); |
225 | $_->name ("$1 F: $2 T: $arguments"); |
229 | $_->teleport ($storage, 2, 2); |
226 | $_->teleport ($storage, 2, 2); |
230 | $cnt++; |
227 | $cnt++; |
231 | } |
228 | } |
232 | } |
229 | } |
233 | |
230 | |
… | |
… | |
240 | } |
237 | } |
241 | |
238 | |
242 | } else { |
239 | } else { |
243 | $who->reply ($npc, |
240 | $who->reply ($npc, |
244 | sprintf "How can I help you?\n" |
241 | sprintf "How can I help you?\n" |
245 | ."Here is a quick list of commands I understand:\n\n" |
242 | . "Here is a quick list of commands I understand:\n\n" |
246 | ."- pen (%s platinum)\n" |
243 | . "- pen (%s platinum)\n" |
247 | ."- literacy (%s platinum)\n" |
244 | . "- literacy (%s platinum)\n" |
248 | ."- mailscroll <friend> (%s platinum)\n" |
245 | . "- mailscroll <friend> (%s platinum)\n" |
249 | ."- bag <friend> (%s platinum)\n" |
246 | . "- bag <friend> (%s platinum)\n" |
250 | ."- package <friend> (%s platinum)\n" |
247 | . "- package <friend> (%s platinum)\n" |
251 | ."- carton <friend> (%s platinum)\n" |
248 | . "- carton <friend> (%s platinum)\n" |
252 | ."- send <friend> (send bags/packages/cartons)\n" |
249 | . "- send <friend> (send bags/packages/cartons)\n" |
253 | ."- receive (to receive packages for you)\n" |
250 | . "- receive (to receive packages for you)\n" |
254 | .($who->flag (cf::FLAG_WIZ) ? "- mailwarning <player>" : ""), |
251 | . ($who->flag (cf::FLAG_WIZ) ? "- mailwarning <player>" : ""), |
255 | 40, 1000, 1, 1, 5, 10 |
252 | 40, 1000, 1, 1, 5, 10 |
256 | ); |
253 | ); |
257 | } |
254 | } |
258 | 1 |
255 | 1 |
259 | }; |
256 | }; |
260 | |
257 | |
261 | package CFMail; |
258 | package CFMail; |
|
|
259 | |
262 | use POSIX qw/strftime/; |
260 | use POSIX qw/strftime/; |
263 | use CFDB; |
261 | use CFDB; |
264 | |
262 | |
265 | my $MAILDB = CFDB->new (db_file => cf::localdir . "/crossfiremail.perl"); |
263 | my $MAILDB = CFDB->new (db_file => cf::localdir . "/crossfiremail.perl"); |
266 | |
264 | |