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

Comparing deliantra/maps/perl/bank.ext (file contents):
Revision 1.20 by root, Wed Jul 19 08:52:57 2006 UTC vs.
Revision 1.22 by elmex, Mon Aug 14 07:11:10 2006 UTC

26 my ($value, $from_cur, $to_cur) = @_; 26 my ($value, $from_cur, $to_cur) = @_;
27 27
28 $value * $unit{$from_cur} / $unit{$to_cur} 28 $value * $unit{$from_cur} / $unit{$to_cur}
29} 29}
30 30
31sub amount_str {
32 my $amount = shift;
33
34 my $royalties = calc_exchange_rate $amount, "silver", "royalty";
35 my $platinum = calc_exchange_rate $royalties - (int $royalties), "royalty", "platina";
36 my $gold = calc_exchange_rate $platinum - (int $platinum), "platina", "gold";
37 my $silver = calc_exchange_rate $gold - (int $gold), "gold", "silver";
38
39 (int $royalties) . " royalties, "
40 . (int $platinum) . " platinum, "
41 . (int $gold) . " gold and about "
42 . (int $silver) ." silver coins.";
43
44}
45
31# Calculates and returns how much money someone has starting with the 46# Calculates and returns how much money someone has starting with the
32# highest value currency going down. Think of it like having the date 47# highest value currency going down. Think of it like having the date
33# and time in the format of 2006-05-19 03:21:31 UTC instead of 1148001691 48# and time in the format of 2006-05-19 03:21:31 UTC instead of 1148001691
34# seconds since 1970-01-01 00:00:00 UTC. 49# seconds since 1970-01-01 00:00:00 UTC.
35sub balance { 50sub balance {
42 } else { 57 } else {
43 return $who->name." has no balance." 58 return $who->name." has no balance."
44 unless $balance >= 1; 59 unless $balance >= 1;
45 } 60 }
46 61
47 my $royalties = calc_exchange_rate $balance, "silver", "royalty"; 62 my $account_info = amount_str ($balance);
48 my $platinum = calc_exchange_rate $royalties - (int $royalties), "royalty", "platina";
49 my $gold = calc_exchange_rate $platinum - (int $platinum), "platina", "gold";
50 my $silver = calc_exchange_rate $gold - (int $gold), "gold", "silver";
51
52 my $account_info =
53 (int $royalties) . " royalties, "
54 . (int $platinum) . " platinum, "
55 . (int $gold) . " gold and about "
56 . (int $silver) ." silver coins.";
57 63
58 return "You have $account_info" 64 return "You have $account_info"
59 unless $is_wiz; 65 unless $is_wiz;
60 66
61 return $who->name." has $account_info"; 67 return $who->name." has $account_info";
140 } 146 }
141 return $exchange_rates."This may change a bit with the stock markets but don't expect it to be much."; 147 return $exchange_rates."This may change a bit with the stock markets but don't expect it to be much.";
142 } 148 }
143} 149}
144 150
145sub on_say { 151cf::register_script_function "bank::command" => sub {
146 my ($event, $ob, $who, $msg) = @_; 152 my ($who, $msg, $npc) = @_;
153
147 my ($cmd, $arguments) = split /\s+/, $msg, 2; 154 my ($cmd, $arguments) = split /\s+/, $msg, 2;
148 my ($amount, $currency) = split /\s+/, $arguments, 2; 155 my ($amount, $currency) = split /\s+/, $arguments, 2;
149 my $name = $ob->name;
150 my $service_charge = 5; 156 my $service_charge = 5;
151 my @units = sort keys %unit; 157 my @units = sort keys %unit;
152 my $units = join ", ", @units; 158 my $units = join ", ", @units;
153 my $fees = - ($service_charge / 100) + 1; 159 my $fees = - ($service_charge / 100) + 1;
154 160
160 } 166 }
161 167
162 if ($cmd eq "balance") { 168 if ($cmd eq "balance") {
163 if ($who->flag (cf::FLAG_WIZ)) { 169 if ($who->flag (cf::FLAG_WIZ)) {
164 if (my $player = cf::player::find $arguments) { 170 if (my $player = cf::player::find $arguments) {
165 $who->reply ("$name says: " . balance ($player->ob, 1)); 171 $who->reply ($npc, balance $player->ob, 1);
166 } 172 }
167 } else { 173 } else {
168 $who->reply ("$name says: " . balance ($who, 0)); 174 $who->reply ($npc, balance $who, 0);
169 } 175 }
170 176
171 } elsif ($cmd eq "balance" and !$arguments) { 177 } elsif ($cmd eq "balance" and !$arguments) {
172 $who->reply ("$name says: Balance of whom?"); 178 $who->reply ($npc, "Balance of whom?");
173 179
174 } elsif ($cmd eq "deposit" and $currency) { 180 } elsif ($cmd eq "deposit" and $currency) {
175 $who->reply ("$name says: " . (transaction $who, "deposit", $amount, $currency)); 181 $who->reply ($npc, transaction $who, "deposit", $amount, $currency);
176 $who->reply ("$name says: " . (balance $who)); 182 $who->reply ($npc, balance $who);
177 183
178 } elsif ($cmd eq "deposit" and $amount and $currency eq "") { 184 } elsif ($cmd eq "deposit" and $amount and $currency eq "") {
179 $who->reply ("$name says: Deposit $amount of what: $units"); 185 $who->reply ($npc, "deposit $amount of what: $units");
180 186
181 } elsif ($cmd eq "deposit" and $amount eq "" and $currency eq "") { 187 } elsif ($cmd eq "deposit" and $amount eq "" and $currency eq "") {
182 $who->reply ("$name says: How much do you want to deposit?"); 188 $who->reply ($npc, "How much do you want to deposit?");
183 189
184 } elsif ($cmd eq "withdraw" and $currency) { 190 } elsif ($cmd eq "withdraw" and $currency) {
185 $who->reply ("$name says: " . (transaction $who, "withdraw", $amount, $currency)); 191 $who->reply ($npc, transaction $who, "withdraw", $amount, $currency);
186 $who->reply ("$name says: " . (balance $who)); 192 $who->reply ($npc, balance $who);
187 193
188 } elsif ($cmd eq "withdraw" and $amount and $currency eq "") { 194 } elsif ($cmd eq "withdraw" and $amount and $currency eq "") {
189 $who->reply ("$name says: Withdraw $amount of what: $units"); 195 $who->reply ($npc, "Withdraw $amount of what: $units");
190 196
191 } elsif ($cmd eq "withdraw" and $amount eq "" and $currency eq "") { 197 } elsif ($cmd eq "withdraw" and $amount eq "" and $currency eq "") {
192 $who->reply ("$name says: How much do you want to withdraw?"); 198 $who->reply ($npc, "How much do you want to withdraw?");
193 199
194 } elsif ($cmd eq "exchange") { 200 } elsif ($cmd eq "exchange") {
195 $who->reply ("$name says: This function is not yet implemented. Ask me again later."); 201 $who->reply ($npc, "This function is not yet implemented. Ask me again later.");
196 202
197 } elsif ($cmd eq "help" or $cmd eq "yes" and $arguments eq "") { 203 } elsif ($cmd eq "help" or $cmd eq "yes" and $arguments eq "") {
198 $who->reply ("$name says: " . (help $arguments)); 204 $who->reply ($npc, help $arguments);
199 205
200 } elsif ($cmd eq "help" or $cmd eq "yes" and $arguments ne "") { 206 } elsif ($cmd eq "help" or $cmd eq "yes" and $arguments ne "") {
201 $who->reply ("$name says: " . (help)); 207 $who->reply ($npc, help);
202 208
203 } else { 209 } else {
204 $who->reply ("$name says: Do you need help?"); 210 $who->reply ($npc, "Do you need help?");
205 } 211 }
206} 212}
207 213

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines