--- deliantra/server/ext/bank.ext 2009/09/02 00:05:56 1.9 +++ deliantra/server/ext/bank.ext 2010/03/09 14:48:17 1.10 @@ -43,6 +43,32 @@ : "You have $account_info." } +sub transaction_all { + my ($who, $action) = @_; + + my $money = $who->query_money; + + if ($action eq 'deposit') { + return "Sorry, you don't seem to have any money to deposit." + unless $money > 0; + + if ($who->pay_amount ($money)) { + $who->{bank_balance} += $money; + my $account_info = cf::cost_string_from_value $money; + return "$account_info received."; + } else { + return "Sorry, but we can't reach all your money. Something is wrong."; + } + + } elsif ($action eq 'withdraw') { + $who->pay_player ($who->{bank_balance}); + my $account_info = cf::cost_string_from_value $who->{bank_balance}; + $who->{bank_balance} = 0; + return "You withdrew $account_info."; + } + return "Sorry, we don't know what you mean by '$action'." +} + sub transaction { my ($who, $action, $amount, $currency) = @_; @@ -100,10 +126,10 @@ help "; } elsif ($command eq "deposit") { return "You can deposit some of the money you don't currently use in our bank. To do this, ask me to: - deposit \nSee help rates for our currencies."; + deposit \nOr, to deposit all your money: deposit all\nSee help rates for our currencies."; } elsif ($command eq "withdraw") { return "To get the money you stored in our system back, just say: - withdraw "; + withdraw \nOr withdraw all to withdraw all your money."; } elsif ($command eq "balance") { return "I can tell you how much money you are saving in our bank, just ask me about your balance."; } elsif ($command eq "rates") { @@ -151,13 +177,19 @@ } elsif ($cmd eq "deposit" and $currency) { $who->reply ($npc, transaction $who, "deposit", $amount, $currency); - + + } elsif ($cmd eq 'deposit' and $amount eq 'all') { + $who->reply ($npc, transaction_all $who, "deposit"); + } elsif ($cmd eq "deposit" and $amount and $currency eq "") { $who->reply ($npc, "deposit $amount of what: " . join ", ", cf::coin_names); } elsif ($cmd eq "deposit" and $amount eq "" and $currency eq "") { $who->reply ($npc, "How much do you want to deposit?"); + } elsif ($cmd eq 'withdraw' and $amount eq 'all') { + $who->reply ($npc, transaction_all $who, "withdraw"); + } elsif ($cmd eq "withdraw" and $currency) { $who->reply ($npc, transaction $who, "withdraw", $amount, $currency);