… | |
… | |
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 | |
|
|
31 | sub 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. |
35 | sub balance { |
50 | sub 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"; |
… | |
… | |
88 | } else { |
94 | } else { |
89 | return "You don't have enough money with you."; |
95 | return "You don't have enough money with you."; |
90 | } |
96 | } |
91 | } elsif ($action eq "withdraw") { |
97 | } elsif ($action eq "withdraw") { |
92 | if ($pay <= $who->{bank_balance}) { |
98 | if ($pay <= $who->{bank_balance}) { |
|
|
99 | my $paid = $who->pay_player_arch ( |
|
|
100 | $currency eq 'royalty' ? 'royalty' : $currency . "coin", |
|
|
101 | $amount |
|
|
102 | ); |
|
|
103 | if ($paid) { |
93 | $who->{bank_balance} -= $pay; |
104 | $who->{bank_balance} -= $pay; |
94 | if ($currency eq "royalty") { |
|
|
95 | my $money = cf::object::new "royalty"; |
|
|
96 | $money->set_property (1, 24, $amount); |
|
|
97 | $money->take ($who); |
|
|
98 | } else { |
105 | } else { |
99 | my $money = cf::object::new $currency . "coin"; |
106 | $amount = 0; |
100 | $money->set_property (1, 24, $amount); |
|
|
101 | $money->take ($who); |
|
|
102 | } |
107 | } |
103 | return "Withdrew $amount $currency"; |
108 | return "Withdrew $amount $currency"; |
104 | } else { |
109 | } else { |
105 | return "You don't have that much money on your bank account."; |
110 | return "You don't have that much money on your bank account."; |
106 | } |
111 | } |
… | |
… | |
141 | } |
146 | } |
142 | 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."; |
143 | } |
148 | } |
144 | } |
149 | } |
145 | |
150 | |
146 | sub on_say { |
151 | cf::register_script_function "bank::command" => sub { |
147 | my ($event, $ob, $who, $msg) = @_; |
152 | my ($who, $msg, $npc) = @_; |
|
|
153 | |
148 | my ($cmd, $arguments) = split /\s+/, $msg, 2; |
154 | my ($cmd, $arguments) = split /\s+/, $msg, 2; |
149 | my ($amount, $currency) = split /\s+/, $arguments, 2; |
155 | my ($amount, $currency) = split /\s+/, $arguments, 2; |
150 | my $name = $ob->name; |
|
|
151 | my $service_charge = 5; |
156 | my $service_charge = 5; |
152 | my @units = sort keys %unit; |
157 | my @units = sort keys %unit; |
153 | my $units = join ", ", @units; |
158 | my $units = join ", ", @units; |
154 | my $fees = - ($service_charge / 100) + 1; |
159 | my $fees = - ($service_charge / 100) + 1; |
155 | |
160 | |
… | |
… | |
161 | } |
166 | } |
162 | |
167 | |
163 | if ($cmd eq "balance") { |
168 | if ($cmd eq "balance") { |
164 | if ($who->flag (cf::FLAG_WIZ)) { |
169 | if ($who->flag (cf::FLAG_WIZ)) { |
165 | if (my $player = cf::player::find $arguments) { |
170 | if (my $player = cf::player::find $arguments) { |
166 | $who->message ("$name says: ".balance ($player->ob, 1), cf::NDI_WHITE); |
171 | $who->reply ($npc, balance $player->ob, 1); |
167 | } |
172 | } |
168 | } else { |
173 | } else { |
169 | $who->message ("$name says: ".balance ($who, 0), cf::NDI_WHITE); |
174 | $who->reply ($npc, balance $who, 0); |
170 | } |
175 | } |
171 | |
176 | |
172 | } elsif ($cmd eq "balance" and !$arguments) { |
177 | } elsif ($cmd eq "balance" and !$arguments) { |
173 | $who->message ("$name says: Balance of whom?", cf::NDI_WHITE); |
178 | $who->reply ($npc, "Balance of whom?"); |
174 | |
179 | |
175 | } elsif ($cmd eq "deposit" and $currency) { |
180 | } elsif ($cmd eq "deposit" and $currency) { |
176 | $who->message ("$name says: " . (transaction $who, "deposit", $amount, $currency), cf::NDI_WHITE); |
181 | $who->reply ($npc, transaction $who, "deposit", $amount, $currency); |
177 | $who->message ("$name says: " . (balance $who), cf::NDI_WHITE); |
182 | $who->reply ($npc, balance $who); |
178 | |
183 | |
179 | } elsif ($cmd eq "deposit" and $amount and $currency eq "") { |
184 | } elsif ($cmd eq "deposit" and $amount and $currency eq "") { |
180 | $who->message ("$name says: Deposit $amount of what: $units", cf::NDI_WHITE); |
185 | $who->reply ($npc, "deposit $amount of what: $units"); |
181 | |
186 | |
182 | } elsif ($cmd eq "deposit" and $amount eq "" and $currency eq "") { |
187 | } elsif ($cmd eq "deposit" and $amount eq "" and $currency eq "") { |
183 | $who->message ("$name says: How much do you want to deposit?", cf::NDI_WHITE); |
188 | $who->reply ($npc, "How much do you want to deposit?"); |
184 | |
189 | |
185 | } elsif ($cmd eq "withdraw" and $currency) { |
190 | } elsif ($cmd eq "withdraw" and $currency) { |
186 | $who->message ("$name says: " . (transaction $who, "withdraw", $amount, $currency), cf::NDI_WHITE); |
191 | $who->reply ($npc, transaction $who, "withdraw", $amount, $currency); |
187 | $who->message ("$name says: " . (balance $who), cf::NDI_WHITE); |
192 | $who->reply ($npc, balance $who); |
188 | |
193 | |
189 | } elsif ($cmd eq "withdraw" and $amount and $currency eq "") { |
194 | } elsif ($cmd eq "withdraw" and $amount and $currency eq "") { |
190 | $who->message ("$name says: Withdraw $amount of what: $units", cf::NDI_WHITE); |
195 | $who->reply ($npc, "Withdraw $amount of what: $units"); |
191 | |
196 | |
192 | } elsif ($cmd eq "withdraw" and $amount eq "" and $currency eq "") { |
197 | } elsif ($cmd eq "withdraw" and $amount eq "" and $currency eq "") { |
193 | $who->message ("$name says: How much do you want to withdraw?", cf::NDI_WHITE); |
198 | $who->reply ($npc, "How much do you want to withdraw?"); |
194 | |
199 | |
195 | } elsif ($cmd eq "exchange") { |
200 | } elsif ($cmd eq "exchange") { |
196 | $who->message ("$name says: This function is not yet implemented. Ask me again later.", cf::NDI_WHITE); |
201 | $who->reply ($npc, "This function is not yet implemented. Ask me again later."); |
197 | |
202 | |
198 | } elsif ($cmd eq "help" or $cmd eq "yes" and $arguments eq "") { |
203 | } elsif ($cmd eq "help" or $cmd eq "yes" and $arguments eq "") { |
199 | $who->message ("$name says: " . (help $arguments), cf::NDI_WHITE); |
204 | $who->reply ($npc, help $arguments); |
200 | |
205 | |
201 | } elsif ($cmd eq "help" or $cmd eq "yes" and $arguments ne "") { |
206 | } elsif ($cmd eq "help" or $cmd eq "yes" and $arguments ne "") { |
202 | $who->message ("$name says: " . (help), cf::NDI_WHITE); |
207 | $who->reply ($npc, help); |
203 | |
208 | |
204 | } else { |
209 | } else { |
205 | $who->message ("$name says: Do you need help?", cf::NDI_WHITE); |
210 | $who->reply ($npc, "Do you need help?"); |
206 | } |
211 | } |
207 | } |
212 | } |
208 | |
213 | |