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.8 by root, Fri Aug 25 17:08:20 2006 UTC vs.
Revision 1.9 by root, Sun Aug 27 15:23:30 2006 UTC

1#! perl 1#! perl
2#CONVERSION: PARTIAL, MISSING ON_APPLY
3 2
4my $price_fact = 50; 3my $price_fact = 50;
5 4
6sub set_package { 5sub set_package {
7 my ($pkg, $from, $to, $bagname, $weight) = @_; 6 my ($pkg, $from, $to, $bagname, $weight) = @_;
92 } 91 }
93 }, 92 },
94; 93;
95 94
96# this event handler handles receiving of mails 95# this event handler handles receiving of mails
97sub on_apply { 96cf::register_attachment ipo_mailbox =>
97 on_apply => sub {
98 my ($ev, $box, $pl) = @_; 98 my ($box, $pl) = @_;
99 99
100 my $cnt; 100 my $cnt;
101 my $mails = CFMail::get_mail ($pl->name) || []; 101 my $mails = CFMail::get_mail ($pl->name) || [];
102 102
103 # count the mails that are in the container 103 # count the mails that are in the container
104 # FIXME: the problem with on_apply is that it is called even when 104 # 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 105 # 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 106 # twice. - This bug existed also with the old python plugin
107 107
108 my $plname = $pl->name; 108 my $plname = $pl->name;
109 for ($box->inv) { 109 for ($box->inv) {
110 $_->name =~ /\S+ F: \S+ T: \Q$plname\E/ 110 $_->name =~ /\S+ F: \S+ T: \Q$plname\E/
111 and $cnt++; 111 and $cnt++;
112 } 112 }
113 113
114 for (@$mails) { 114 for (@$mails) {
115 my ($type, $from, $msg) = @$_; 115 my ($type, $from, $msg) = @$_;
116 $type = $mailtypes{$type || 1} || ['scroll', 'mailscroll']; 116 $type = $mailtypes{$type || 1} || ['scroll', 'mailscroll'];
117 my $mail = cf::object::new $type->[0]; 117 my $mail = cf::object::new $type->[0];
118 $mail->set_name ("$type->[1] F: $from T: " .$pl->name); 118 $mail->set_name ("$type->[1] F: $from T: " .$pl->name);
119 $mail->set_name_plural ("$type->[1]s F: $from T: " .$pl->name); 119 $mail->set_name_plural ("$type->[1]s F: $from T: " .$pl->name);
120 $mail->set_message ($msg); 120 $mail->set_message ($msg);
121 $mail->set_value (0); 121 $mail->set_value (0);
122 $mail->insert_in_ob ($box); 122 $mail->insert_in_ob ($box);
123 } 123 }
124 124
125 $cnt += @$mails; 125 $cnt += @$mails;
126 126
127 if ($cnt == 1) { 127 if ($cnt == 1) {
128 $pl->message ("You got one mail."); 128 $pl->message ("You got one mail.");
129 } elsif ($cnt > 1) { 129 } elsif ($cnt > 1) {
130 $pl->message ("You got $cnt mails."); 130 $pl->message ("You got $cnt mails.");
131 } else { 131 } else {
132 $pl->message ("You haven't got any mail."); 132 $pl->message ("You haven't got any mail.");
133 } 133 }
134 134
135 CFMail::clear_mail ($pl->name); 135 CFMail::clear_mail ($pl->name);
136 136 },
137 0;
138}
139
140# this event handler handles the sending of mails 137 # this event handler handles the sending of mails
141sub on_close { 138 on_close => sub {
142 my ($ev, $box, $pl) = @_; 139 my ($box, $pl) = @_;
143 140
144 my @mails; 141 my @mails;
145 142
146 my %sent_targets; 143 my %sent_targets;
147 144
148 for ($box->inv) { 145 for ($box->inv) {
149 if ($_->name =~ m/^mail(scroll|warning) T: (\S+) F: (\S+)/) { 146 if ($_->name =~ m/^mail(scroll|warning) T: (\S+) F: (\S+)/) {
150 CFMail::send_mail ($1 eq 'scroll' ? 1 : 3, $2, $3, $_->message); 147 CFMail::send_mail ($1 eq 'scroll' ? 1 : 3, $2, $3, $_->message);
151 $pl->message ("Sent mail$1 to $2 (from $3)."); 148 $pl->message ("Sent mail$1 to $2 (from $3).");
152 $sent_targets{$2}++; 149 $sent_targets{$2}++;
153 push @mails, $_; 150 push @mails, $_;
154 151
155 } elsif ($_->name =~ m/^mail(scroll|warning) F: (\S+) T: (\S+)/) { 152 } elsif ($_->name =~ m/^mail(scroll|warning) F: (\S+) T: (\S+)/) {
156 # this is for mails that remain in the queue for the player 153 # this is for mails that remain in the queue for the player
157 CFMail::store_mail ($1 eq 'scroll' ? 1 : 3, $3, $2, $_->message); 154 CFMail::store_mail ($1 eq 'scroll' ? 1 : 3, $3, $2, $_->message);
158 push @mails, $_; 155 push @mails, $_;
159 } 156 }
160 } 157 }
161 158
162 $_->remove for @mails; 159 $_->remove for @mails;
163 160
164 notify_players (%sent_targets); 161 notify_players (%sent_targets);
165 162 },
166 0; 163;
167}
168 164
169# this is the main command interface for the IPO NPC 165# this is the main command interface for the IPO NPC
170cf::register_script_function "ipo::command" => sub { 166cf::register_script_function "ipo::command" => sub {
171 my ($who, $msg, $npc) = @_; 167 my ($who, $msg, $npc) = @_;
172 my ($cmd, $arguments) = split /\s+/, $msg, 2; 168 my ($cmd, $arguments) = split /\s+/, $msg, 2;
240 } 236 }
241 237
242 } else { 238 } else {
243 $who->reply ($npc, 239 $who->reply ($npc,
244 sprintf "How can I help you?\n" 240 sprintf "How can I help you?\n"
245 ."Here is a quick list of commands I understand:\n\n" 241 . "Here is a quick list of commands I understand:\n\n"
246 ."- pen (%s platinum)\n" 242 . "- pen (%s platinum)\n"
247 ."- literacy (%s platinum)\n" 243 . "- literacy (%s platinum)\n"
248 ."- mailscroll <friend> (%s platinum)\n" 244 . "- mailscroll <friend> (%s platinum)\n"
249 ."- bag <friend> (%s platinum)\n" 245 . "- bag <friend> (%s platinum)\n"
250 ."- package <friend> (%s platinum)\n" 246 . "- package <friend> (%s platinum)\n"
251 ."- carton <friend> (%s platinum)\n" 247 . "- carton <friend> (%s platinum)\n"
252 ."- send <friend> (send bags/packages/cartons)\n" 248 . "- send <friend> (send bags/packages/cartons)\n"
253 ."- receive (to receive packages for you)\n" 249 . "- receive (to receive packages for you)\n"
254 .($who->flag (cf::FLAG_WIZ) ? "- mailwarning <player>" : ""), 250 . ($who->flag (cf::FLAG_WIZ) ? "- mailwarning <player>" : ""),
255 40, 1000, 1, 1, 5, 10 251 40, 1000, 1, 1, 5, 10
256 ); 252 );
257 } 253 }
258 1 254 1
259}; 255};
260 256
261package CFMail; 257package CFMail;
258
262use POSIX qw/strftime/; 259use POSIX qw/strftime/;
263use CFDB; 260use CFDB;
264 261
265my $MAILDB = CFDB->new (db_file => cf::localdir . "/crossfiremail.perl"); 262my $MAILDB = CFDB->new (db_file => cf::localdir . "/crossfiremail.perl");
266 263

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines