… | |
… | |
34 | # seconds since 1970-01-01 00:00:00 UTC. |
34 | # seconds since 1970-01-01 00:00:00 UTC. |
35 | sub balance { |
35 | sub balance { |
36 | my ($who, $is_wiz) = @_; |
36 | my ($who, $is_wiz) = @_; |
37 | my $balance = $who->{bank_balance}; |
37 | my $balance = $who->{bank_balance}; |
38 | |
38 | |
|
|
39 | unless ($is_wiz) { |
39 | return "Sorry, you have no balance." |
40 | return "Sorry, you have no balance." |
40 | unless $balance; |
41 | unless $balance; |
|
|
42 | } else { |
|
|
43 | return $who->name." has no balance." |
|
|
44 | unless $balance; |
|
|
45 | } |
41 | |
46 | |
42 | my $imperials = calc_exchange_rate $balance, "silver", "imperial"; |
47 | my $imperials = calc_exchange_rate $balance, "silver", "imperial"; |
43 | my $platinum = calc_exchange_rate $imperials - (int $imperials), "imperial", "platina"; |
48 | my $platinum = calc_exchange_rate $imperials - (int $imperials), "imperial", "platina"; |
44 | my $gold = calc_exchange_rate $platinum - (int $platinum), "platina", "gold"; |
49 | my $gold = calc_exchange_rate $platinum - (int $platinum), "platina", "gold"; |
45 | my $silver = calc_exchange_rate $gold - (int $gold), "gold", "silver"; |
50 | my $silver = calc_exchange_rate $gold - (int $gold), "gold", "silver"; |
46 | |
51 | |
47 | return "You have " |
52 | my $account_info = |
48 | . (int $imperials) . " imperials, " |
53 | (int $imperials) . " imperials, " |
49 | . (int $platinum) . " platinum, " |
54 | . (int $platinum) . " platinum, " |
50 | . (int $gold) . " gold and about " |
55 | . (int $gold) . " gold and about " |
51 | . (int $silver) ." silver coins."; |
56 | . (int $silver) ." silver coins."; |
|
|
57 | |
|
|
58 | return "You have $account_info" |
|
|
59 | unless $is_wiz; |
|
|
60 | |
|
|
61 | return $who->name." has $account_info"; |
52 | } |
62 | } |
53 | |
63 | |
54 | sub transaction { |
64 | sub transaction { |
55 | my ($who, $action, $amount, $currency) = @_; |
65 | my ($who, $action, $amount, $currency) = @_; |
56 | my $pay = $amount * $unit{$currency}; |
66 | my $pay = $amount * $unit{$currency}; |
… | |
… | |
148 | } |
158 | } |
149 | } else { |
159 | } else { |
150 | $who->message ("$name says: ".balance ($who, 0), cf::NDI_WHITE); |
160 | $who->message ("$name says: ".balance ($who, 0), cf::NDI_WHITE); |
151 | } |
161 | } |
152 | |
162 | |
|
|
163 | } elsif ($cmd eq "balance" and !$arguments) { |
|
|
164 | $who->message ("$name says: Balance of whom?", cf::NDI_WHITE); |
|
|
165 | |
153 | } elsif ($cmd eq "deposit" and $currency) { |
166 | } elsif ($cmd eq "deposit" and $currency) { |
154 | $who->message ("$name says: " . (transaction $who, "deposit", $amount, $currency), cf::NDI_WHITE); |
167 | $who->message ("$name says: " . (transaction $who, "deposit", $amount, $currency), cf::NDI_WHITE); |
155 | $who->message ("$name says: " . (balance $who), cf::NDI_WHITE); |
168 | $who->message ("$name says: " . (balance $who), cf::NDI_WHITE); |
156 | |
169 | |
157 | } elsif ($cmd eq "deposit" and $amount and $currency eq "") { |
170 | } elsif ($cmd eq "deposit" and $amount and $currency eq "") { |