This is how I am designing the merchant system. Please let me know if you have a better idea or believe that I forgot something:
- 1. The table structure:
- "Field"
"id" - standard auto increment
"merchant_id" - merchant_id that matches the merchant_id found in the spawns table
"item_id" - item id
"quantity" - quantity that the NPC will carry
"low_buy_multiplier" - see below
"high_buy_multiplier" - see below
"low_sell_multiplier" - see below
"high_sell_multiplier" - see below
"multiplier_faction_id" - see below
"min_faction" - see below
"max_faction" - see below
- "Field"
An example:
- item base price = 50 copper
low_buy_multiplier = .5
high_buy_multiplier = 10
low_sell_multiplier = 1
high_sell_multiplier = 5
min_faction -20000;
max_faction 50000;
Lets assume that a player's faction level with the given merchant is 15000. The calculation below would determine the price that the player could BUY if for from the merchant:
- float diff_low = 15000 - (-20000);
float total_diff = 50000 - (-20000);
float buy_multiplier = 10 - .5;
float total1 = (diff_low/total_diff);
float final_buy_multiplier = total1*buy_multiplier + total1*.5;
Now lets calculate how much he could SELL it for:
- float diff_low = 15000 - (-20000);
float total_diff = 50000 - (-20000);
float sell_multiplier = 5 - 1;
float total1 = (diff_low/total_diff);
float final_sell_multiplier = total1*sell_multiplier + total1*1;
One additional thing - the system would keep track of how much the player paid for an item so that they could not make money by buying and selling the items to different merchants. The max price for which they could sell an item would be the price they bought it for, even if the multipliers would have allowed them a better rate.
I know it is complicated, but I think it is fairly straightforward once you actually start messing with it. And it should allow for some good customizations.