--- deliantra/server/ext/bank.ext 2008/04/10 15:35:16 1.5 +++ 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) = @_; @@ -57,11 +83,11 @@ my $pay = $amount * $coin->value; # First check for possible overflow and user stupidity - if ($amount > 2**30) { - return "Sorry, we do not handle that kind of money for one $action."; - } elsif ($amount == 0) { + if ($pay > 2**30) { + return "Sorry, we do not handle that amount of money for one $action."; + } elsif ($pay == 0) { return "You can not $action nothing."; - } elsif ($amount < 0) { + } elsif ($pay < 0) { return "You can not $action negative values."; } @@ -92,6 +118,7 @@ if ($command eq "") { return "You can: + deposit withdraw balance @@ -99,27 +126,27 @@ 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") { my @coins = cf::coin_archetypes; - my $exchange_rates = "Here is a list of exchange rates:\n\n\n"; + my $exchange_rates = "Here is a list of exchange rates:\n\n"; for my $f (0 .. $#coins) { for my $t ($f + 1 .. $#coins) { $exchange_rates .= - sprintf "One %s is %d %s.\n\n", + sprintf " One %s is %d %s.\n", $coins[$f]->name, (calc_exchange_rate 1, $coins[$f], $coins[$t]), $coins[$t]->name_pl; } } - return "$exchange_rates\n\nThis may change a bit with the stock markets but don't expect it to be much."; + return "$exchange_rates\nThis may change a bit with the stock markets but don't expect it to be much."; } } @@ -135,10 +162,10 @@ if ($who->flag (cf::FLAG_WIZ) && $arguments =~ /\S/) { cf::async { if (my $player = cf::player::find $arguments) { - $who->contr->send_msg ( - $ext::chat::SAY_CHANNEL, "Nancy says: " . balance ($player->ob, 1), + $who->reply ($npc, + "Nancy says: " . balance ($player->ob, 1), cf::NDI_BROWN | cf::NDI_REPLY - ) if $who->contr; + ); } }; } else { @@ -150,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);