#include "money.h" inherit "/std/room"; string bankprop; int account_cost, percentage; void create() { account_cost = 100; percentage = 90; bankprop = "bank"; ::create(); add_sign( "A sign giving instructions on how to use the bank.\n", "You can :-\n\n 'start account' at a cost of " + MONEY_HAND->money_value_string( account_cost ) + ",\n" + " 'finish account',\n " + "'deposit <number> <type> coins' (Bank claims " + (100 - percentage) + "% commision on deposits),\n " + "'withdraw <number> <type> coins',\n or " + "check your 'balance'.\n", 0, 0 ); } void init() { add_action( "balance", "balance" ); add_action( "withdraw", "withdraw" ); add_action( "do_start", "start", 1 ); add_action( "do_finish", "finish", 1 ); add_action( "deposit", "deposit" ); ::init(); } int balance() { int amt; if( !this_player()->query_property_exists( bankprop ) ) { notify_fail( "You do not have an account here.\n" ); return 0; } amt = this_player()->query_property( bankprop ); if( amt < 0 ) { write( "Your account is overdrawn by " + MONEY_HAND->money_value_string( -amt ) + ".\n" ); return 1; } if( amt == 0 ) { write( "Your account is empty.\n" ); return 1; } write( "You have " + MONEY_HAND->money_value_string( amt ) + " in your account.\n" ); return 1; } int withdraw( string str ) { int amt, i, val, total; string s1, type; mixed *values; if( !this_player()->query_property_exists( bankprop ) ) { notify_fail( "You do not have an account here.\n" ); return 0; } total = this_player()->query_property( bankprop ); notify_fail( "Syntax: " + query_verb() + " <amount> <type> coin[s]\n" ); if( !str ) return 0; if( sscanf( str, "%d %s coin%s", amt, type, s1 ) != 3 && sscanf( str, "%d %s", amt, type ) != 2 ) return 0; if( amt <= 0 ) { notify_fail( "You must withdraw something.\n" ); return 0; } values = (mixed *)MONEY_HAND->query_values(); if( (i = member_array( type, values )) == -1 ) { notify_fail( "This bank does not deal in " + type + " coins.\n" ); return 0; } val = amt * values[ i + 1 ]; if( val > total ) { write( "You do not have enough money in your account for that.\n" ); return 1; } this_player()->adjust_money( amt, type ); this_player()->add_property( bankprop, total - val ); write( "You withdraw " + amt + " " + type + " coins.\n" ); say( this_player()->query_cap_name() + " withdraws some money from " + this_player()->query_possessive() + " account.\n" ); return 1; } int deposit( string str ) { object *obs, cont; int i, amt, total; if( !this_player()->query_property_exists( bankprop ) ) { notify_fail( "You do not have an account here.\n" ); return 0; } total = this_player()->query_property( bankprop ); if( !str ) { notify_fail( "Syntax: " + query_verb() + " <money>\n" ); return 0; } cont = clone_object( "/std/container" ); obs = find_match( str, this_player() ); for( i = 0; i < sizeof( obs ); i++ ) if( obs[ i ]->query_property( "money" ) ) obs[ i ]->move( cont ); if( !sizeof( all_inventory( cont ) ) ) { cont->dest_me(); notify_fail( "You might want to deposit some money.\n" ); return 0; } obs = all_inventory( cont ); for( i = 0; i < sizeof( obs ); i++ ) amt += (int)obs[ i ]->query_value(); if( !amt ) { notify_fail( "Your money is not worth anything.\n" ); return 0; } amt = amt * percentage / 100; this_player()->add_property( bankprop, total + amt ); write( capitalize( (string)MONEY_HAND->money_value_string( amt ) ) + " deposited to give a total account of " + MONEY_HAND->money_value_string( total + amt ) + ".\n" ); say( this_player()->query_cap_name() + " deposits some money into " + this_player()->query_possessive() + " account.\n" ); return 1; } int do_start( string str ) { if( str != "account" ) { notify_fail( "Use '" + query_verb() + " account' to open an account here.\n" ); return 0; } if( this_player()->query_property_exists( bankprop ) ) { notify_fail( "You already have an account here.\n" ); return 0; } if( account_cost ) { if( this_player()->query_value() < account_cost ) { notify_fail( "You do not have enough money to open an account.\n" ); return 0; } write( "It will cost you " + MONEY_HAND->money_value_string( account_cost ) + " to open the account.\nDo you still want to ? " ); input_to( "check_open" ); return 1; } this_player()->add_property( bankprop, 1 ); write( "Account created.\n" ); return 1; } int check_open( string str ) { str = lower_case( str ); if( str[ 0 ] != 'y' && str[ 0 ] != 'n' ) { write( "I don't understand. Do you want to open an account ? " ); input_to( "check_open" ); return 1; } if( str[ 0 ] == 'n' ) { write( "Ok, not opening the account.\n" ); return 1; } this_player()->add_property( bankprop, 0 ); write( "Account created.\n" ); this_player()->pay_money( (mixed *)MONEY_HAND-> create_money_array( account_cost ) ); return 1; } int do_finish( string str ) { int amt, total; object ob; if( str != "account" ) { notify_fail( "Use 'close account' to close your account.\n" ); return 0; } if( !this_player()->query_property_exists( bankprop ) ) { notify_fail( "You do not have an account here!\n" ); return 0; } total = this_player()->query_property( bankprop ); if( (amt = total) ) { write( "You get " + MONEY_HAND->money_value_string( amt ) + " when you close " + "the account.\n" ); this_player()->adjust_money( MONEY_HAND->create_money_array( amt ) ); } else { write( "You close your account.\n" ); } say( this_player()->query_cap_name() + " closes " + this_player()->query_possessive() + " account.\n" ); this_player()->remove_property( bankprop ); return 1; } void set_percentage( int per ) { percentage = per; } int query_percentage() { return percentage; } void set_account_cost( int i ) { account_cost = i; } int query_account_cost() { return account_cost; } void set_bank_prop( string s ) { bankprop = s; } string query_bank_prop() { return bankprop; } mixed *stats() { return({ ({ "Percentage", percentage }), ({ "Account cost", account_cost }), ({ "Bank property", bankprop }) }); }