So I'm trying to figure out how to fix a bug in the item durability snippet. It's regarding buy and sell prices; I thought I had taken care of it, but I guess I didn't test it out enough. I'll stick to just selling things, for now.
So here's the problem; if an item has, say, 150 max durability, and the item is damaged at all, it will have a selling price (e.g. you get x coins!) of 0, even if it only has 1 point of durability damage. However, if the item has less than a max durability of 100, there is no issue; the code works fine as is.
I'm figuring it has something to do with how the percentage is figured out or something. I hate trying to work with int and float variables at the same time, but I don't really see any way around it. Here's the function for figuring out selling prices.
Code:
static int sell_price(struct obj_data *obj, int shop_nr, struct char_data *keeper, struct char_data *seller)
{
float sell_cost_modifier = SHOP_SELLPROFIT(shop_nr) * (1 - (GET_CHA(keeper) - GET_CHA(seller)) / (float)70);
float buy_cost_modifier = SHOP_BUYPROFIT(shop_nr) * (1 + (GET_CHA(keeper) - GET_CHA(seller)) / (float)70);
int itemcond = (100 / GET_OBJ_MAX_DURAB(obj)) * GET_OBJ_DURABILITY(obj);
float percent = 1, sellprice = 0;
if ((GET_OBJ_MAX_DURAB(obj) != 0) && (GET_OBJ_MAX_DURAB(obj) > GET_OBJ_DURABILITY(obj))) {
if (itemcond == 0)
percent = 0;
else if (itemcond <= 10)
percent = 0.1;
else if (itemcond <= 20)
percent = 0.2;
else if (itemcond <= 30)
percent = 0.3;
else if (itemcond <= 40)
percent = 0.4;
else if (itemcond <= 50)
percent = 0.5;
else if (itemcond <= 60)
percent = 0.6;
else if (itemcond <= 70)
percent = 0.7;
else if (itemcond <= 80)
percent = 0.8;
else if (itemcond <= 90)
percent = 0.9;
else if (itemcond <= 99)
percent = 0.99;
}
sellprice = GET_OBJ_COST(obj) * sell_cost_modifier * percent;
if (sell_cost_modifier > buy_cost_modifier)
sell_cost_modifier = buy_cost_modifier;
return (sellprice);
}
On a side note, been alpha testing out my mud and squashing quite a few bugs. Like regarding parry and dodge skills... turns out I messed that one up pretty bad. Oops! Anyways, any help on this would be greatly appreciated.