Well, here is how I would do it.
There is a certain structure to each command, in which you take the characters data and what they put as input, which looks like:
void do_commandname( CHAR_DATA *ch, char *argument )
{
/* command stuff here */
}
Also, in order to add a command, you must add it in tables.c and do something such as DECLARE_DO_FUN( do_haggle ); in mud.h.
In this case, I think a better solution would be this. Modify do_buy and do_sell, and just add in a haggle function. That way you just call it from either do_sell or do_buy, and it automatically haggles.
Here's some code to give you some structure:
int haggle( CHAR_DATA *ch, CHAR_DATA *keeper, OBJ_INDEX_DATA * obj, bool is_selling )
{
int endprice = obj->price;
if ( !ch || !keeper || !obj )
return 100;
if ( ch->pcdata->learned[gsn_haggle] )
{
if ( is_selling == TRUE )
{
/* equations go here */
endprice += (int)(ch->pcdata->learned[gsn_haggle]/10);
if ( get_curr_int(ch) > get_curr_int(keeper) )
endprice += endprice*1.5;
if ( get_curr_lck(ch) > number_range( 5, 50 ) )
endprice += endprice*2;
}
else /* buying */
{
if ( get_curr_cha(ch) > get_curr_wis(keeper) )
endprice = endprice-(endprice*.5);
endprice = endprice-(ch->pcdata->learned[gsn_haggle]/10);
}
}
return endprice;
}
There is a VERY basic example. I wouldnt really support using that function, as it definitely needs a way to balance the cost of things. However, it does illustrate my thinking. The function returns the final cost of the object. But you will need to jump into the do_buy and do_sell code a lot more to get a good haggle function.
To call it from do_buy or do_sell, you just need to do something such as:
For do_buy:
buyprice = haggle( ch, keeper, obj, FALSE );
For do_sell:
sellprice = haggle(ch, keeper, obj, TRUE );
This code is also implying that you added haggle as a skill.
Hopefully that helpped you, maybe it didn't. Good luck :) |