/
LIB3/
LIB3/D/ADMIN/
LIB3/D/ADMIN/OBJ/
LIB3/D/ADMIN/ROOM/W/
LIB3/D/HOME/
LIB3/D/HOME/CITY/ARENA/
LIB3/D/HOME/CITY/ITEMS/
LIB3/D/HOME/CITY/POSTOFFI/
LIB3/DOC/
LIB3/GLOBAL/SPECIAL/
LIB3/GLOBAL/VIRTUAL/
LIB3/NET/
LIB3/NET/CONFIG/
LIB3/NET/DAEMON/CHARS/
LIB3/NET/GOPHER/
LIB3/NET/INHERIT/
LIB3/NET/OBJ/
LIB3/NET/SAVE/
LIB3/NET/VIRTUAL/
LIB3/OBJ/B_DAY/
LIB3/OBJ/HANDLERS/TERM_TYP/
LIB3/PLAYERS/B/
LIB3/PLAYERS/N/
LIB3/ROOM/
LIB3/SAVE/
LIB3/SAVE/BOARDS/
LIB3/SAVE/ENVIRON/
LIB3/SAVE/POST/
LIB3/STD/COMMANDS/SHADOWS/
LIB3/STD/CREATOR/
LIB3/STD/DOM/
LIB3/STD/EFFECTS/
LIB3/STD/EFFECTS/HEALING/
LIB3/STD/EFFECTS/OTHER/
LIB3/STD/EFFECTS/POISONS/
LIB3/STD/ENVIRON/
LIB3/STD/GUILDS/
LIB3/STD/LIQUIDS/
LIB3/STD/ROOM/
LIB3/STD/TRIGGER/SHADOW/
LIB3/W/
LIB3/W/BANNOR/
LIB3/W/NEWSTYLE/
#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 }) });
}