Trade: A list of buyable items is now calculated with the maximum amount buyable (given the currency), the minimum buyable amount and the minimum price.

Port casual trading to use this system.
Refactor the offer function to also support dedicated trading.
This commit is contained in:
zorman2000
2017-01-29 20:08:34 -05:00
parent 25f1fcbfa8
commit d7a8de5b86
2 changed files with 18 additions and 43 deletions

View File

@ -87,7 +87,7 @@ function npc.trade.prices.get_items_for_currency_count(tier, count, price_factor
if price.tier == tier and price.count <= count then
result[item_name] = {price = price}
minetest.log("Item name: "..dump(item_name)..", Price: "..dump(price))
--minetest.log("Item name: "..dump(item_name)..", Price: "..dump(price))
local min_buying_item_count = 1
-- Calculate price NPC is going to buy for
@ -111,11 +111,11 @@ function npc.trade.prices.get_items_for_currency_count(tier, count, price_factor
--minetest.log("Maximum item buy quantity: "..dump(max_buying_item_count))
result[item_name].min_buyable_item_count = min_buying_item_count
result[item_name].min_buyable_item_price = min_buying_item_count * buying_price_count
result[item_name].min_buyable_item_price = buying_price_count
result[item_name].max_buyable_item_count = max_buying_item_count
end
end
--minetest.log("Final result: "..dump(result))
minetest.log("Final result: "..dump(result))
return result
end