Schedules: Allow to set trade list as a schedule property.

Trade: Trading list now supports setting maximum sell count, buy count and how much to keep (in case of sell).
Add price for empty bucket.
This commit is contained in:
Hector Franqui 2017-09-21 18:53:43 -04:00
parent c94edbc649
commit d55ffd06fc
3 changed files with 597 additions and 561 deletions

55
npc.lua
View File

@ -420,11 +420,7 @@ function npc.initialize(entity, pos, is_lua_entity, npc_stats, occupation_name)
-- It is mostly related to its occupation. -- It is mostly related to its occupation.
-- If empty, the NPC will revert to casual trading -- If empty, the NPC will revert to casual trading
-- If not, it will try to sell those that it have, and buy the ones it not. -- If not, it will try to sell those that it have, and buy the ones it not.
trade_list = { trade_list = {},
sell = {},
buy = {},
both = {}
},
-- Custom trade allows to specify more than one payment -- Custom trade allows to specify more than one payment
-- and a custom prompt (instead of the usual buy or sell prompts) -- and a custom prompt (instead of the usual buy or sell prompts)
custom_trades = {} custom_trades = {}
@ -521,21 +517,21 @@ function npc.initialize(entity, pos, is_lua_entity, npc_stats, occupation_name)
-- TODO: Remove this - do inside occupation -- TODO: Remove this - do inside occupation
-- Dedicated trade test -- Dedicated trade test
ent.trader_data.trade_list.both = { -- ent.trader_data.trade_list = {
["default:tree"] = {}, -- ["default:tree"] = {},
["default:cobble"] = {}, -- ["default:cobble"] = {},
["default:wood"] = {}, -- ["default:wood"] = {},
["default:diamond"] = {}, -- ["default:diamond"] = {},
["default:mese_crystal"] = {}, -- ["default:mese_crystal"] = {},
["flowers:rose"] = {}, -- ["flowers:rose"] = {},
["advanced_npc:marriage_ring"] = {}, -- ["advanced_npc:marriage_ring"] = {},
["flowers:geranium"] = {}, -- ["flowers:geranium"] = {},
["mobs:meat"] = {}, -- ["mobs:meat"] = {},
["mobs:leather"] = {}, -- ["mobs:leather"] = {},
["default:sword_stone"] = {}, -- ["default:sword_stone"] = {},
["default:shovel_stone"] = {}, -- ["default:shovel_stone"] = {},
["default:axe_stone"] = {} -- ["default:axe_stone"] = {}
} -- }
-- Generate trade offers -- Generate trade offers
npc.trade.generate_trade_offers_by_status(ent) npc.trade.generate_trade_offers_by_status(ent)
@ -564,10 +560,11 @@ function npc.generate_trade_list_from_inventory(self)
for i = 1, #self.inventory do for i = 1, #self.inventory do
list[npc.get_item_name(self.inventory[i])] = {} list[npc.get_item_name(self.inventory[i])] = {}
end end
self.trader_data.trade_list.both = list self.trader_data.trade_list = list
end end
function npc.set_trading_status(self, status) function npc.set_trading_status(self, status)
minetest.log("Trader_data: "..dump(self.trader_data))
-- Set status -- Set status
self.trader_data.trader_status = status self.trader_data.trader_status = status
-- Re-generate trade offers -- Re-generate trade offers
@ -879,7 +876,8 @@ npc.schedule_properties = {
trader_status = "trader_status", trader_status = "trader_status",
can_receive_gifts = "can_receive_gifts", can_receive_gifts = "can_receive_gifts",
flag = "flag", flag = "flag",
enable_gift_items_hints = "enable_gift_items_hints" enable_gift_items_hints = "enable_gift_items_hints",
set_trade_list = "set_trade_list"
} }
local function get_time_in_hours() local function get_time_in_hours()
@ -1048,7 +1046,18 @@ function npc.schedule_change_property(self, property, args)
end end
elseif property == npc.schedule_properties.enable_gift_item_hints then elseif property == npc.schedule_properties.enable_gift_item_hints then
self.gift_data.enable_gift_items_hints = args.value self.gift_data.enable_gift_items_hints = args.value
end elseif property == npc.schedule_properties.set_trade_list then
-- Insert items
for i = 1, #args.items do
-- Insert entry into trade list
self.trader_data.trade_list[args.items[i].name] = {
max_item_buy_count = args.items[i].buy,
max_item_sell_count = args.items[i].sell,
amount_to_keep = args.items[i].keep
}
end
end
end end
function npc.add_schedule_check(self) function npc.add_schedule_check(self)

View File

@ -37,6 +37,7 @@ npc.trade.prices.table["default:shovel_stone"] = {tier = npc.trade.prices.curre
npc.trade.prices.table["default:axe_stone"] = {tier = npc.trade.prices.currency.tier3.string, count = 6} npc.trade.prices.table["default:axe_stone"] = {tier = npc.trade.prices.currency.tier3.string, count = 6}
npc.trade.prices.table["default:hoe_stone"] = {tier = npc.trade.prices.currency.tier3.string, count = 6} npc.trade.prices.table["default:hoe_stone"] = {tier = npc.trade.prices.currency.tier3.string, count = 6}
npc.trade.prices.table["default:pick_stone"] = {tier = npc.trade.prices.currency.tier3.string, count = 7} npc.trade.prices.table["default:pick_stone"] = {tier = npc.trade.prices.currency.tier3.string, count = 7}
npc.trade.prices.table["bucket:bucket_empty"] = {tier = npc.trade.prices.currency.tier3.string, count = 10}
npc.trade.prices.table["farming:cotton"] = {tier = npc.trade.prices.currency.tier3.string, count = 15} npc.trade.prices.table["farming:cotton"] = {tier = npc.trade.prices.currency.tier3.string, count = 15}
npc.trade.prices.table["farming:bread"] = {tier = npc.trade.prices.currency.tier3.string, count = 20} npc.trade.prices.table["farming:bread"] = {tier = npc.trade.prices.currency.tier3.string, count = 20}

File diff suppressed because it is too large Load Diff