… | |
… | |
55 | $currency = $amount > 1 ? $coin->name_pl : $coin->name; |
55 | $currency = $amount > 1 ? $coin->name_pl : $coin->name; |
56 | |
56 | |
57 | my $pay = $amount * $coin->value; |
57 | my $pay = $amount * $coin->value; |
58 | |
58 | |
59 | # First check for possible overflow and user stupidity |
59 | # First check for possible overflow and user stupidity |
60 | if ($amount > 2**30) { |
60 | if ($pay > 2**30) { |
61 | return "Sorry, we do not handle that kind of money for one $action."; |
61 | return "Sorry, we do not handle that amount of money for one $action."; |
62 | } elsif ($amount == 0) { |
62 | } elsif ($pay == 0) { |
63 | return "You can not $action nothing."; |
63 | return "You can not $action nothing."; |
64 | } elsif ($amount < 0) { |
64 | } elsif ($pay < 0) { |
65 | return "You can not $action negative values."; |
65 | return "You can not $action negative values."; |
66 | } |
66 | } |
67 | |
67 | |
68 | # Here we handle the transactions |
68 | # Here we handle the transactions |
69 | if ($action eq "deposit") { |
69 | if ($action eq "deposit") { |
… | |
… | |
90 | sub help { |
90 | sub help { |
91 | my ($command) = @_; |
91 | my ($command) = @_; |
92 | |
92 | |
93 | if ($command eq "") { |
93 | if ($command eq "") { |
94 | return "You can: |
94 | return "You can: |
|
|
95 | |
95 | deposit <amount> <currency> |
96 | deposit <amount> <currency> |
96 | withdraw <amount> <currency> |
97 | withdraw <amount> <currency> |
97 | balance |
98 | balance |
98 | help rates |
99 | help rates |
99 | help <deposit|withdraw|balance>"; |
100 | help <deposit|withdraw|balance>"; |
… | |
… | |
105 | withdraw <amount> <currency>"; |
106 | withdraw <amount> <currency>"; |
106 | } elsif ($command eq "balance") { |
107 | } elsif ($command eq "balance") { |
107 | return "I can tell you how much money you are saving in our bank, just ask me about your balance."; |
108 | return "I can tell you how much money you are saving in our bank, just ask me about your balance."; |
108 | } elsif ($command eq "rates") { |
109 | } elsif ($command eq "rates") { |
109 | my @coins = cf::coin_archetypes; |
110 | my @coins = cf::coin_archetypes; |
110 | my $exchange_rates = "Here is a list of exchange rates:\n\n\n"; |
111 | my $exchange_rates = "Here is a list of exchange rates:\n\n"; |
111 | |
112 | |
112 | for my $f (0 .. $#coins) { |
113 | for my $f (0 .. $#coins) { |
113 | for my $t ($f + 1 .. $#coins) { |
114 | for my $t ($f + 1 .. $#coins) { |
114 | $exchange_rates .= |
115 | $exchange_rates .= |
115 | sprintf "One %s is %d %s.\n\n", |
116 | sprintf " One %s is %d %s.\n", |
116 | $coins[$f]->name, |
117 | $coins[$f]->name, |
117 | (calc_exchange_rate 1, $coins[$f], $coins[$t]), |
118 | (calc_exchange_rate 1, $coins[$f], $coins[$t]), |
118 | $coins[$t]->name_pl; |
119 | $coins[$t]->name_pl; |
119 | } |
120 | } |
120 | } |
121 | } |
121 | |
122 | |
122 | return "$exchange_rates\n\nThis may change a bit with the stock markets but don't expect it to be much."; |
123 | return "$exchange_rates\nThis may change a bit with the stock markets but don't expect it to be much."; |
123 | } |
124 | } |
124 | } |
125 | } |
125 | |
126 | |
126 | cf::register_script_function "bank::command" => sub { |
127 | cf::register_script_function "bank::command" => sub { |
127 | my ($who, $msg, $npc) = @_; |
128 | my ($who, $msg, $npc) = @_; |