Selling Price Higher for Discounted Items

When switching from buying to selling, some items are discounted while others increase in price. I notice it is happening in the video for Sam as well. The sword price goes from $40.13 for buying and $47.84 for selling. This happens if you have discounts on your individual items that would make them cheaper to buy than to sell. Putting it here because it confused me for a while, and is something to consider for your game since players could buy an item and sell it for more giving them infinite gold.
A fix would be to multiply the selling price by the discount price and then by the selling price. (Note that I am rounding my floats into ints but otherwise the code is the same.

4 Likes

Good catch.

I didn’t notice it in my own project because I’m used to old school RPGs where vendors give you a HUGE haircut on the price when they buy it back… so I’d instinctively set sellingPercentage to 10. :slight_smile:

I think the current commit is ok, the tutor sets “buyingDiscountPercentage”, which means it may be used in case the Player is buying.
Considering using “buyingDiscountPercentage” for general usage is your choice.

Thanks for the fix! I had thought I had just done something wrong until I read this.

1 Like

Also after we refactor GetPrice, the buying mode is also bugged. If a shopkeeper is selling a sword for 10 gold with a 50% discount at level 1, and then selling another sword for 10 gold with a 25% discount at level 2, the selling price for the swords is correct, however, the buying price is 50% of 10 which is 5, and then 25% of 5 which is 3.75. So it takes both of the swords discounts into account which makes the buying price sometimes less than the selling price.
So I fixed it by changing: prices[config.item] *= (1 - config.buyingDiscountPercentage / 100); into prices[config.item] = config.item.GetPrice() * (1 - config.buyingDiscountPercentage / 100);

2 Likes

Privacy & Terms