… | |
… | |
41 | $is_wiz |
41 | $is_wiz |
42 | ? $who->name . " has $account_info." |
42 | ? $who->name . " has $account_info." |
43 | : "You have $account_info." |
43 | : "You have $account_info." |
44 | } |
44 | } |
45 | |
45 | |
|
|
46 | sub transaction_all { |
|
|
47 | my ($who, $action) = @_; |
|
|
48 | |
|
|
49 | my $money = $who->query_money; |
|
|
50 | |
|
|
51 | if ($action eq 'deposit') { |
|
|
52 | return "Sorry, you don't seem to have any money to deposit." |
|
|
53 | unless $money > 0; |
|
|
54 | |
|
|
55 | if ($who->pay_amount ($money)) { |
|
|
56 | $who->{bank_balance} += $money; |
|
|
57 | my $account_info = cf::cost_string_from_value $money; |
|
|
58 | return "$account_info received."; |
|
|
59 | } else { |
|
|
60 | return "Sorry, but we can't reach all your money. Something is wrong."; |
|
|
61 | } |
|
|
62 | |
|
|
63 | } elsif ($action eq 'withdraw') { |
|
|
64 | $who->pay_player ($who->{bank_balance}); |
|
|
65 | my $account_info = cf::cost_string_from_value $who->{bank_balance}; |
|
|
66 | $who->{bank_balance} = 0; |
|
|
67 | return "You withdrew $account_info."; |
|
|
68 | } |
|
|
69 | return "Sorry, we don't know what you mean by '$action'." |
|
|
70 | } |
|
|
71 | |
46 | sub transaction { |
72 | sub transaction { |
47 | my ($who, $action, $amount, $currency) = @_; |
73 | my ($who, $action, $amount, $currency) = @_; |
48 | |
74 | |
49 | my $coin = cf::coin_from_name $currency |
75 | my $coin = cf::coin_from_name $currency |
50 | or return "We don't trade in that currency.\n"; |
76 | or return "We don't trade in that currency.\n"; |
… | |
… | |
98 | balance |
124 | balance |
99 | help rates |
125 | help rates |
100 | help <deposit|withdraw|balance>"; |
126 | help <deposit|withdraw|balance>"; |
101 | } elsif ($command eq "deposit") { |
127 | } elsif ($command eq "deposit") { |
102 | return "You can deposit some of the money you don't currently use in our bank. To do this, ask me to: |
128 | return "You can deposit some of the money you don't currently use in our bank. To do this, ask me to: |
103 | deposit <amount> <currency>\nSee help rates for our currencies."; |
129 | deposit <amount> <currency>\nOr, to deposit all your money: deposit all\nSee help rates for our currencies."; |
104 | } elsif ($command eq "withdraw") { |
130 | } elsif ($command eq "withdraw") { |
105 | return "To get the money you stored in our system back, just say: |
131 | return "To get the money you stored in our system back, just say: |
106 | withdraw <amount> <currency>"; |
132 | withdraw <amount> <currency>\nOr withdraw all to withdraw all your money."; |
107 | } elsif ($command eq "balance") { |
133 | } elsif ($command eq "balance") { |
108 | return "I can tell you how much money you are saving in our bank, just ask me about your balance."; |
134 | return "I can tell you how much money you are saving in our bank, just ask me about your balance."; |
109 | } elsif ($command eq "rates") { |
135 | } elsif ($command eq "rates") { |
110 | my @coins = cf::coin_archetypes; |
136 | my @coins = cf::coin_archetypes; |
111 | my $exchange_rates = "Here is a list of exchange rates:\n\n"; |
137 | my $exchange_rates = "Here is a list of exchange rates:\n\n"; |
… | |
… | |
149 | } elsif ($cmd eq "balance" and !$arguments) { |
175 | } elsif ($cmd eq "balance" and !$arguments) { |
150 | $who->reply ($npc, "Balance of whom?"); |
176 | $who->reply ($npc, "Balance of whom?"); |
151 | |
177 | |
152 | } elsif ($cmd eq "deposit" and $currency) { |
178 | } elsif ($cmd eq "deposit" and $currency) { |
153 | $who->reply ($npc, transaction $who, "deposit", $amount, $currency); |
179 | $who->reply ($npc, transaction $who, "deposit", $amount, $currency); |
154 | |
180 | |
|
|
181 | } elsif ($cmd eq 'deposit' and $amount eq 'all') { |
|
|
182 | $who->reply ($npc, transaction_all $who, "deposit"); |
|
|
183 | |
155 | } elsif ($cmd eq "deposit" and $amount and $currency eq "") { |
184 | } elsif ($cmd eq "deposit" and $amount and $currency eq "") { |
156 | $who->reply ($npc, "deposit $amount of what: " . join ", ", cf::coin_names); |
185 | $who->reply ($npc, "deposit $amount of what: " . join ", ", cf::coin_names); |
157 | |
186 | |
158 | } elsif ($cmd eq "deposit" and $amount eq "" and $currency eq "") { |
187 | } elsif ($cmd eq "deposit" and $amount eq "" and $currency eq "") { |
159 | $who->reply ($npc, "How much do you want to deposit?"); |
188 | $who->reply ($npc, "How much do you want to deposit?"); |
160 | |
189 | |
|
|
190 | } elsif ($cmd eq 'withdraw' and $amount eq 'all') { |
|
|
191 | $who->reply ($npc, transaction_all $who, "withdraw"); |
|
|
192 | |
161 | } elsif ($cmd eq "withdraw" and $currency) { |
193 | } elsif ($cmd eq "withdraw" and $currency) { |
162 | $who->reply ($npc, transaction $who, "withdraw", $amount, $currency); |
194 | $who->reply ($npc, transaction $who, "withdraw", $amount, $currency); |
163 | |
195 | |
164 | } elsif ($cmd eq "withdraw" and $amount and $currency eq "") { |
196 | } elsif ($cmd eq "withdraw" and $amount and $currency eq "") { |
165 | $who->reply ($npc, "Withdraw $amount of what: " . join ", ", cf::coin_names); |
197 | $who->reply ($npc, "Withdraw $amount of what: " . join ", ", cf::coin_names); |