Trade: Added dedicated trader's formspec.
This commit is contained in:
parent
d8b90d95c3
commit
fcc1968179
24
npc.lua
24
npc.lua
@ -377,6 +377,16 @@ local function choose_spawn_items(self)
|
|||||||
-- For test
|
-- For test
|
||||||
npc.add_item_to_inventory(self, "default:tree", 10)
|
npc.add_item_to_inventory(self, "default:tree", 10)
|
||||||
npc.add_item_to_inventory(self, "default:cobble", 10)
|
npc.add_item_to_inventory(self, "default:cobble", 10)
|
||||||
|
npc.add_item_to_inventory(self, "default:diamond", 2)
|
||||||
|
npc.add_item_to_inventory(self, "default:mese_crystal", 2)
|
||||||
|
npc.add_item_to_inventory(self, "flowers:rose", 2)
|
||||||
|
npc.add_item_to_inventory(self, "advanced_npc:marriage_ring", 2)
|
||||||
|
npc.add_item_to_inventory(self, "flowers:geranium", 2)
|
||||||
|
npc.add_item_to_inventory(self, "mobs:meat", 2)
|
||||||
|
npc.add_item_to_inventory(self, "mobs:leather", 2)
|
||||||
|
npc.add_item_to_inventory(self, "default:sword_stone", 2)
|
||||||
|
npc.add_item_to_inventory(self, "default:shovel_stone", 2)
|
||||||
|
npc.add_item_to_inventory(self, "default:axe_stone", 2)
|
||||||
|
|
||||||
minetest.log("Initial inventory: "..dump(self.inventory))
|
minetest.log("Initial inventory: "..dump(self.inventory))
|
||||||
end
|
end
|
||||||
@ -534,7 +544,17 @@ local function npc_spawn(self, pos)
|
|||||||
ent.trader_data.trade_list.both = {
|
ent.trader_data.trade_list.both = {
|
||||||
["default:tree"] = {},
|
["default:tree"] = {},
|
||||||
["default:cobble"] = {},
|
["default:cobble"] = {},
|
||||||
["default:wood"] = {}
|
["default:wood"] = {},
|
||||||
|
["default:diamond"] = {},
|
||||||
|
["default:mese_crystal"] = {},
|
||||||
|
["flowers:rose"] = {},
|
||||||
|
["advanced_npc:marriage_ring"] = {},
|
||||||
|
["flowers:geranium"] = {},
|
||||||
|
["mobs:meat"] = {},
|
||||||
|
["mobs:leather"] = {},
|
||||||
|
["default:sword_stone"] = {},
|
||||||
|
["default:shovel_stone"] = {},
|
||||||
|
["default:axe_stone"] = {}
|
||||||
}
|
}
|
||||||
|
|
||||||
npc.trade.generate_trade_offers_by_status(ent)
|
npc.trade.generate_trade_offers_by_status(ent)
|
||||||
@ -675,7 +695,7 @@ mobs:register_mob("advanced_npc:npc", {
|
|||||||
-- Reset timer
|
-- Reset timer
|
||||||
self.trader_data.change_offers_timer = 0
|
self.trader_data.change_offers_timer = 0
|
||||||
-- Re-select casual trade offers
|
-- Re-select casual trade offers
|
||||||
select_casual_trade_offers(self)
|
npc.trade.generate_trade_offers_by_status(self)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Timer function for gifts
|
-- Timer function for gifts
|
||||||
|
@ -43,6 +43,7 @@ npc.trade.prices.table["farming:bread"] = {tier = npc.trade.prices.curre
|
|||||||
-- Tier 2 items: medium priced items
|
-- Tier 2 items: medium priced items
|
||||||
|
|
||||||
-- Tier 1 items: expensive items
|
-- Tier 1 items: expensive items
|
||||||
|
npc.trade.prices.table["default:mese_crystal"] = {tier = npc.trade.prices.currency.tier1.string, count = 45}
|
||||||
npc.trade.prices.table["default:diamond"] = {tier = npc.trade.prices.currency.tier1.string, count = 90}
|
npc.trade.prices.table["default:diamond"] = {tier = npc.trade.prices.currency.tier1.string, count = 90}
|
||||||
npc.trade.prices.table["advanced_npc:marriage_ring"] = {tier = npc.trade.prices.currency.tier1.string, count = 100}
|
npc.trade.prices.table["advanced_npc:marriage_ring"] = {tier = npc.trade.prices.currency.tier1.string, count = 100}
|
||||||
|
|
||||||
|
@ -58,6 +58,7 @@ npc.trade.DEDICATED_TRADER_PROMPT = {
|
|||||||
action_type = "function",
|
action_type = "function",
|
||||||
response_id = 1,
|
response_id = 1,
|
||||||
action = function(self, player)
|
action = function(self, player)
|
||||||
|
npc.trade.show_dedicated_trade_formspec(self, player, npc.trade.OFFER_SELL)
|
||||||
end
|
end
|
||||||
},
|
},
|
||||||
[2] = {
|
[2] = {
|
||||||
@ -65,7 +66,7 @@ npc.trade.DEDICATED_TRADER_PROMPT = {
|
|||||||
action_type = "function",
|
action_type = "function",
|
||||||
response_id = 2,
|
response_id = 2,
|
||||||
action = function(self, player)
|
action = function(self, player)
|
||||||
|
npc.trade.show_dedicated_trade_formspec(self, player, npc.trade.OFFER_BUY)
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -107,6 +108,50 @@ function npc.trade.show_trade_offer_formspec(self, player, offer_type)
|
|||||||
minetest.show_formspec(player:get_player_name(), "advanced_npc:trade_offer", formspec)
|
minetest.show_formspec(player:get_player_name(), "advanced_npc:trade_offer", formspec)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
function npc.trade.show_dedicated_trade_formspec(self, player, offers_type)
|
||||||
|
|
||||||
|
-- Choose the correct offers
|
||||||
|
local offers = self.trader_data.buy_offers
|
||||||
|
local menu_offer_type = "sell"
|
||||||
|
if offers_type == npc.trade.OFFER_SELL then
|
||||||
|
offers = self.trader_data.sell_offers
|
||||||
|
menu_offer_type = "buy"
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Create a grid with the items for trade offer
|
||||||
|
local max_columns = 4
|
||||||
|
local current_x = 0.2
|
||||||
|
local current_y = 0.5
|
||||||
|
local current_col = 1
|
||||||
|
local current_row = 1
|
||||||
|
local formspec = "size[8.9,8.2]"..
|
||||||
|
default.gui_bg..
|
||||||
|
default.gui_bg_img..
|
||||||
|
default.gui_slots..
|
||||||
|
"label[0.2,0.05;Click on the price button to "..menu_offer_type.." item]"
|
||||||
|
for i = 1, #offers do
|
||||||
|
local price_item_name = minetest.registered_items[npc.get_item_name(offers[i].price)].description
|
||||||
|
formspec = formspec..
|
||||||
|
"box["..current_x..","..current_y..";2,2.3;#212121]"..
|
||||||
|
"item_image["..(current_x + 0.45)..","..(current_y + 0.15)..";1.3,1.3;"..npc.get_item_name(offers[i].item).."]"..
|
||||||
|
"item_image_button["..(current_x + 1.15)..","..(current_y + 1.4)..";1,1;"..offers[i].price..";price"..i..";]"..
|
||||||
|
"label["..(current_x + 0.15)..","..(current_y + 1.7)..";Price]"
|
||||||
|
current_x = current_x + 2.1
|
||||||
|
current_col = current_col + 1
|
||||||
|
if current_col > 4 then
|
||||||
|
current_col = 1
|
||||||
|
current_x = 0.2
|
||||||
|
current_y = current_y + 2.4
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
formspec = formspec .. "button_exit[2.5,7.9;3.9,0.5;exit;Nevermind]"
|
||||||
|
|
||||||
|
minetest.show_formspec(player:get_player_name(), "advanced_npc:dedicated_trading_offers", formspec)
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
function npc.trade.get_random_trade_status()
|
function npc.trade.get_random_trade_status()
|
||||||
local chance = math.random(1,10)
|
local chance = math.random(1,10)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user