void do_change (CHAR_DATA *ch, char *argument)
{
CHAR_DATA *banker;
char buf [MAX_STRING_LENGTH];
char arg1 [MAX_INPUT_LENGTH];
char arg2 [MAX_INPUT_LENGTH];
int amount = 0;
int change = 0;
int silver;
int copper;
if ( !( banker = find_banker( ch ) ) )
{
send_to_char( "You're not in a bank!\n\r", ch );
return;
}
if ( IS_NPC( ch ) )
{
sprintf( buf, "Sorry, %s, we don't do business with mobs.", ch->short_descr );
do_say( banker, buf );
return;
}
if ( argument[0] == '\0' )
{
sprintf( buf, "%s How much silver or copper do you wish to exchange?", ch->name );
do_tell( banker, buf );
return;
}
argument = one_argument( argument, arg1 );
argument = one_argument( argument, arg2 );
/* Call for changing Silver */
if ( !str_cmp( arg2, "silver" ) )
{
if ( str_cmp(arg1, "all") && !is_number( arg1 ) )
{
sprintf( buf, "%s How much silver do you wish to change?", ch->name );
do_tell( banker, buf );
return;
}
}
if ( !str_cmp( arg1, "all" ) )
{
amount = ch->silver/100;
change = ch->silver%100;
}
else
{
amount = atoi( arg1 )/100;
change = atoi( arg1 )%100;
}
if ( amount > ch->silver )
{
sprintf( buf, "%s Sorry, but you don't have that much silver to change.", ch->name );
do_tell( banker, buf );
return;
}
if ( change > 99 )
{
//If you have over 100 silver after you get your change,
//convert the other extra silver to gold, and get the difference
change -=100;
silver++;
}
else
{
ch->gold += amount;
ch->silver = change;
set_char_color( AT_PLAIN, ch );
ch_printf( ch, "You exchanged your silver for %d gold coins.\n\r", amount );
sprintf( buf, "$n changes some currency.\n\r" );
act( AT_PLAIN, buf, ch, NULL, NULL, TO_ROOM );
save_char_obj( ch );
return;
}
/* Call for changing Copper */
if ( !str_cmp( arg2, "copper" ) )
{
if ( str_cmp(arg1, "all") && !is_number( arg1 ) )
{
sprintf( buf, "%s How much copper do you wish to change?", ch->name );
do_tell( banker, buf );
return;
}
}
if ( !str_cmp( arg1, "all" ) )
{
amount = ch->copper/100;
change = ch->copper%100;
}
else
{
amount = atoi( arg1 )/100;
change = atoi( arg1 )%100;
}
if ( amount > ch->copper )
{
sprintf( buf, "%s Sorry, but you don't have that much silver to change.", ch->name );
do_tell( banker, buf );
return;
}
if ( change > 99 )
{
//If you have over 100 copper after you get your change,
//convert the other extra copper to silver, and get the difference
change -=100;
copper++;
}
else
{
ch->silver += amount;
ch->copper = change;
set_char_color( AT_PLAIN, ch );
ch_printf( ch, "You exchanged your copper for %d silver coins.\n\r", amount );
sprintf( buf, "$n changes some currency.\n\r" );
act( AT_PLAIN, buf, ch, NULL, NULL, TO_ROOM );
save_char_obj( ch );
return;
}
}
Now that I cleaned up the types and put the amount > ch->silver check into the right spot this might be a bit easier to read. Sorry, still sorta new at this. Anyways I recompiled and tested out. All the calls for changing silver work fine cept for the "all" argument. Simply typing "change all" will now only call to silver, so I believe my issues are in the beginings argument code. Doing tests on it now.
-Toy |