2015-09-01 17:15:24 +02:00
|
|
|
--
|
|
|
|
-- Gold and NPC Trading
|
|
|
|
-- By Kaadmy, for Pixture
|
|
|
|
--
|
|
|
|
|
|
|
|
gold = {}
|
|
|
|
|
2019-03-20 15:01:03 +01:00
|
|
|
local mapseed = minetest.get_mapgen_setting("seed")
|
|
|
|
gold.pr = PseudoRandom(mapseed+8732)
|
2015-09-01 17:15:24 +02:00
|
|
|
|
|
|
|
gold.trades = {}
|
2015-09-06 21:02:45 +02:00
|
|
|
gold.trade_names = {}
|
|
|
|
|
2017-05-12 04:29:55 +02:00
|
|
|
if minetest.get_modpath("mobs") ~= nil then
|
2015-09-06 21:02:45 +02:00
|
|
|
gold.trades["farmer"] = {
|
|
|
|
-- plants
|
2017-05-17 17:57:14 +02:00
|
|
|
{"gold:ingot_gold", "", "farming:wheat_1 6"},
|
|
|
|
{"gold:ingot_gold 3", "", "farming:cotton_1 4"},
|
|
|
|
{"gold:ingot_gold 5", "", "farming:cotton_1 8"},
|
|
|
|
{"gold:ingot_gold", "", "default:papyrus 4"},
|
|
|
|
{"gold:ingot_gold 4", "", "default:cactus 2"},
|
2015-09-06 21:02:45 +02:00
|
|
|
|
|
|
|
-- crafts
|
2017-05-17 17:57:14 +02:00
|
|
|
{"gold:ingot_gold 7", "", "farming:cotton_bale 3"},
|
2015-09-06 21:02:45 +02:00
|
|
|
|
|
|
|
-- materials
|
|
|
|
{"default:planks 3", "farming:cotton_bale 3", "bed:bed"},
|
|
|
|
|
|
|
|
-- tool repair
|
2017-05-17 17:57:14 +02:00
|
|
|
{"gold:ingot_gold 6", "default:shovel_stone", "default:shovel_stone"},
|
|
|
|
{"gold:ingot_gold 8", "default:shovel_steel", "default:shovel_steel"},
|
|
|
|
{"gold:ingot_gold 10", "default:shovel_carbonsteel", "default:shovel_carbonsteel"},
|
2015-09-06 21:02:45 +02:00
|
|
|
}
|
|
|
|
gold.trades["tavernkeeper"] = {
|
|
|
|
-- materials
|
2017-05-17 17:57:14 +02:00
|
|
|
{"gold:ingot_gold 2", "", "default:planks 12"},
|
|
|
|
{"gold:ingot_gold 2", "", "default:planks_birch 8"},
|
2015-09-06 21:02:45 +02:00
|
|
|
|
|
|
|
-- useables
|
2017-05-17 17:57:14 +02:00
|
|
|
{"gold:ingot_gold 9", "", "bed:bed"},
|
|
|
|
{"gold:ingot_gold 5", "", "default:chest"},
|
2015-09-06 21:02:45 +02:00
|
|
|
{"default:planks_birch 3", "mobs:wool 3", "bed:bed"},
|
|
|
|
|
|
|
|
-- filling buckets
|
2017-05-17 17:57:14 +02:00
|
|
|
{"gold:ingot_gold", "default:bucket", "default:bucket_water"},
|
2015-09-06 21:02:45 +02:00
|
|
|
}
|
|
|
|
gold.trades["blacksmith"] = {
|
|
|
|
-- smeltables
|
2017-05-17 17:57:14 +02:00
|
|
|
{"gold:ingot_gold", "", "default:lump_coal"},
|
|
|
|
{"gold:ingot_gold 3", "", "default:lump_iron"},
|
|
|
|
{"gold:ingot_gold 5", "", "default:dust_carbonsteel"},
|
2015-09-06 21:02:45 +02:00
|
|
|
|
|
|
|
-- materials
|
2017-05-17 17:57:14 +02:00
|
|
|
{"gold:ingot_gold 2", "", "default:cobble 10"},
|
|
|
|
{"gold:ingot_gold 3", "", "default:stone 10"},
|
|
|
|
{"gold:ingot_gold 5", "", "default:reinforced_cobble 10"},
|
|
|
|
{"gold:ingot_gold 25", "", "default:block_steel"},
|
|
|
|
{"gold:ingot_gold 6", "", "default:glass 5"},
|
2015-09-06 21:02:45 +02:00
|
|
|
|
|
|
|
-- usebles
|
2017-05-17 17:57:14 +02:00
|
|
|
{"gold:ingot_gold 7", "", "default:furnace"},
|
2015-09-06 21:02:45 +02:00
|
|
|
|
|
|
|
-- ingots
|
2017-05-17 17:57:14 +02:00
|
|
|
{"gold:ingot_gold 5", "", "default:ingot_steel"},
|
|
|
|
{"gold:ingot_gold 8", "", "default:ingot_carbonsteel"},
|
2015-09-06 21:02:45 +02:00
|
|
|
|
|
|
|
-- auto smelting
|
2017-05-17 17:57:14 +02:00
|
|
|
{"gold:ingot_gold 2", "default:lump_iron", "default:ingot_steel"},
|
|
|
|
{"gold:ingot_gold 4", "default:dust_carbonsteel", "default:ingot_carbonsteel"},
|
2015-09-06 21:02:45 +02:00
|
|
|
|
|
|
|
-- tool repair
|
2017-05-17 17:57:14 +02:00
|
|
|
{"gold:ingot_gold 8", "default:pick_stone", "default:pick_stone"},
|
|
|
|
{"gold:ingot_gold 12", "default:pick_steel", "default:pick_steel"},
|
|
|
|
{"gold:ingot_gold 16", "default:pick_carbonsteel", "default:pick_carbonsteel"},
|
2015-09-06 21:02:45 +02:00
|
|
|
}
|
|
|
|
gold.trades["butcher"] = {
|
|
|
|
-- materials
|
2017-05-17 17:57:14 +02:00
|
|
|
{"gold:ingot_gold 3", "", "default:planks_oak 10"},
|
2015-09-06 21:02:45 +02:00
|
|
|
|
|
|
|
-- cooked edibles
|
2017-05-17 17:57:14 +02:00
|
|
|
{"gold:ingot_gold 2", "", "mobs:meat"},
|
|
|
|
{"gold:ingot_gold 3", "", "mobs:pork"},
|
2015-09-06 21:02:45 +02:00
|
|
|
|
|
|
|
-- raw edibles
|
2017-05-17 17:57:14 +02:00
|
|
|
{"gold:ingot_gold 2", "", "mobs:meat_raw 2"},
|
|
|
|
{"gold:ingot_gold 3", "", "mobs:pork_raw 2"},
|
2015-09-06 21:02:45 +02:00
|
|
|
|
|
|
|
-- cooking edibles
|
2017-05-17 17:57:14 +02:00
|
|
|
{"gold:ingot_gold 1", "mobs:meat_raw", "mobs:meat"},
|
|
|
|
{"gold:ingot_gold 2", "mobs:pork_raw", "mobs:pork"},
|
2015-09-06 21:02:45 +02:00
|
|
|
|
|
|
|
-- tool repair
|
2017-05-17 17:57:14 +02:00
|
|
|
{"gold:ingot_gold 5", "default:spear_stone", "default:spear_stone"},
|
|
|
|
{"gold:ingot_gold 7", "default:spear_steel", "default:spear_steel"},
|
|
|
|
{"gold:ingot_gold 11", "default:spear_carbonsteel", "default:spear_carbonsteel"},
|
2015-09-06 21:02:45 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
-- trading currency
|
2017-05-12 04:29:55 +02:00
|
|
|
if minetest.get_modpath("jewels") ~= nil then -- jewels/gold
|
2015-09-06 21:02:45 +02:00
|
|
|
--farmer
|
2017-05-17 17:57:14 +02:00
|
|
|
table.insert(gold.trades["farmer"], {"gold:ingot_gold 16", "", "jewels:jewel"})
|
|
|
|
table.insert(gold.trades["farmer"], {"gold:ingot_gold 22", "", "jewels:jewel 2"})
|
|
|
|
table.insert(gold.trades["farmer"], {"gold:ingot_gold 34", "", "jewels:jewel 4"})
|
2015-09-06 21:02:45 +02:00
|
|
|
|
2017-05-17 17:57:14 +02:00
|
|
|
table.insert(gold.trades["farmer"], {"jewels:jewel", "", "gold:ingot_gold 14"})
|
|
|
|
table.insert(gold.trades["farmer"], {"jewels:jewel 2", "", "gold:ingot_gold 20"})
|
|
|
|
table.insert(gold.trades["farmer"], {"jewels:jewel 4", "", "gold:ingot_gold 32"})
|
2015-09-06 21:02:45 +02:00
|
|
|
|
2017-05-17 17:57:14 +02:00
|
|
|
table.insert(gold.trades["farmer"], {"default:planks 6", "", "gold:ingot_gold"})
|
2015-09-06 21:02:45 +02:00
|
|
|
|
|
|
|
-- tavern keeper
|
2017-05-17 17:57:14 +02:00
|
|
|
table.insert(gold.trades["tavernkeeper"], {"gold:ingot_gold 14", "", "jewels:jewel"})
|
|
|
|
table.insert(gold.trades["tavernkeeper"], {"gold:ingot_gold 20", "", "jewels:jewel 2"})
|
|
|
|
table.insert(gold.trades["tavernkeeper"], {"gold:ingot_gold 32", "", "jewels:jewel 4"})
|
2015-09-06 21:02:45 +02:00
|
|
|
|
|
|
|
-- blacksmith
|
|
|
|
table.insert(gold.trades["blacksmith"], {"default:ingot_steel 14", "", "jewels:jewel"})
|
|
|
|
table.insert(gold.trades["blacksmith"], {"default:ingot_steel 20", "", "jewels:jewel 2"})
|
|
|
|
table.insert(gold.trades["blacksmith"], {"default:ingot_steel 32", "", "jewels:jewel 4"})
|
|
|
|
end
|
|
|
|
|
|
|
|
-- butcher(no mod check)
|
2017-05-17 17:57:14 +02:00
|
|
|
table.insert(gold.trades["butcher"], {"mobs:meat_raw 3", "", "gold:ingot_gold"})
|
|
|
|
table.insert(gold.trades["butcher"], {"mobs:meat_raw 4", "", "gold:ingot_gold 2"})
|
|
|
|
table.insert(gold.trades["butcher"], {"mobs:meat_raw 5", "", "gold:ingot_gold 4"})
|
2015-09-06 21:02:45 +02:00
|
|
|
|
|
|
|
gold.trade_names["farmer"] = "Farmer"
|
|
|
|
gold.trade_names["tavernkeeper"] = "Tavern Keeper"
|
|
|
|
gold.trade_names["blacksmith"] = "Blacksmith"
|
|
|
|
gold.trade_names["butcher"] = "Butcher"
|
|
|
|
end
|
2015-09-01 17:15:24 +02:00
|
|
|
|
|
|
|
local form_trading = ""
|
|
|
|
|
2017-05-13 20:50:15 +02:00
|
|
|
form_trading = form_trading .. default.ui.get_page("default:2part")
|
2015-09-01 17:15:24 +02:00
|
|
|
|
|
|
|
form_trading = form_trading .. "list[current_player;gold_trade_out;3.75,2.25;1,1;]"
|
|
|
|
form_trading = form_trading .. "listring[current_player;gold_trade_out]"
|
|
|
|
|
|
|
|
form_trading = form_trading .. default.ui.get_hotbar_itemslot_bg(3.75, 2.25, 1, 1)
|
|
|
|
|
|
|
|
form_trading = form_trading .. "list[current_player;main;0.25,4.75;8,4;]"
|
|
|
|
form_trading = form_trading .. default.ui.get_hotbar_itemslot_bg(0.25, 4.75, 8, 1)
|
|
|
|
form_trading = form_trading .. default.ui.get_itemslot_bg(0.25, 5.75, 8, 3)
|
|
|
|
|
|
|
|
form_trading = form_trading .. "list[current_player;gold_trade_in;6.25,1.25;1,2;]"
|
|
|
|
form_trading = form_trading .. "listring[current_player;gold_trade_in]"
|
|
|
|
form_trading = form_trading .. default.ui.get_itemslot_bg(6.25, 1.25, 1, 2)
|
|
|
|
|
|
|
|
form_trading = form_trading .. "image[2.5,1.25;1,1;ui_arrow_bg.png^[transformR270]"
|
|
|
|
form_trading = form_trading .. "image[5,2.25;1,1;ui_arrow.png^[transformR90]"
|
|
|
|
|
|
|
|
form_trading = form_trading .. default.ui.button_exit(1.25, 3.25, 2, 1, "cancel", "Cancel")
|
|
|
|
form_trading = form_trading .. default.ui.button(5.25, 3.25, 2, 1, "trade", "Trade")
|
|
|
|
|
|
|
|
default.ui.register_page("gold_trading_book", form_trading)
|
|
|
|
|
|
|
|
function gold.trade(trade, trade_type, player)
|
|
|
|
local name = player:get_player_name()
|
|
|
|
local item = player:get_wielded_item()
|
|
|
|
|
|
|
|
if item:get_name() ~= "gold:trading_book" then return end
|
|
|
|
|
|
|
|
local inv = player:get_inventory()
|
2017-05-10 19:19:28 +02:00
|
|
|
|
2015-09-01 17:15:24 +02:00
|
|
|
if inv:get_size("gold_trade_wanted") ~= 2 then
|
|
|
|
inv:set_size("gold_trade_wanted", 2)
|
|
|
|
end
|
2017-05-10 19:19:28 +02:00
|
|
|
|
2015-09-01 17:15:24 +02:00
|
|
|
if inv:get_size("gold_trade_out") ~= 1 then
|
|
|
|
inv:set_size("gold_trade_out", 1)
|
|
|
|
end
|
|
|
|
|
|
|
|
if inv:get_size("gold_trade_in") ~= 2 then
|
|
|
|
inv:set_size("gold_trade_in", 2)
|
|
|
|
end
|
2017-05-10 19:19:28 +02:00
|
|
|
|
2015-09-01 17:15:24 +02:00
|
|
|
inv:set_stack("gold_trade_wanted", 1, trade[1])
|
|
|
|
inv:set_stack("gold_trade_wanted", 2, trade[2])
|
2017-05-10 19:19:28 +02:00
|
|
|
|
2017-05-12 04:29:55 +02:00
|
|
|
local meta = minetest.deserialize(item:get_metadata())
|
2015-09-01 17:15:24 +02:00
|
|
|
|
|
|
|
if not meta then meta = {} end
|
|
|
|
meta.trade = trade
|
|
|
|
|
|
|
|
local trade_name = gold.trade_names[trade_type]
|
|
|
|
|
|
|
|
local trade_wanted1 = inv:get_stack("gold_trade_wanted", 1)
|
|
|
|
local trade_wanted2 = inv:get_stack("gold_trade_wanted", 2)
|
|
|
|
|
|
|
|
local form = default.ui.get_page("gold_trading_book")
|
2017-05-12 04:29:55 +02:00
|
|
|
form = form .. "label[0.25,0.25;"..minetest.formspec_escape(trade_name).."]"
|
2015-09-01 17:15:24 +02:00
|
|
|
|
|
|
|
form = form .. default.ui.fake_itemstack(1.25, 1.25, trade_wanted1, "trade_wanted1")
|
|
|
|
form = form .. default.ui.fake_itemstack(1.25, 2.25, trade_wanted2, "trade_wanted2")
|
2017-05-14 23:50:37 +02:00
|
|
|
form = form .. default.ui.fake_itemstack(3.75, 1.25, ItemStack(trade[3]), "trade_result")
|
2015-09-01 17:15:24 +02:00
|
|
|
|
2017-05-12 04:29:55 +02:00
|
|
|
minetest.show_formspec(name, "gold:trading_book", form)
|
2015-09-01 17:15:24 +02:00
|
|
|
|
|
|
|
meta.trade_type = trade_type
|
|
|
|
|
2017-05-12 04:29:55 +02:00
|
|
|
item:set_metadata(minetest.serialize(meta))
|
2015-09-01 17:15:24 +02:00
|
|
|
player:set_wielded_item(item)
|
2015-10-03 23:02:14 +02:00
|
|
|
|
|
|
|
return true
|
2015-09-01 17:15:24 +02:00
|
|
|
end
|
|
|
|
|
2017-05-12 04:29:55 +02:00
|
|
|
minetest.register_on_player_receive_fields(
|
2015-09-01 17:15:24 +02:00
|
|
|
function(player, form_name, fields)
|
|
|
|
if form_name ~= "gold:trading_book" or fields.cancel then return end
|
|
|
|
|
|
|
|
local inv = player:get_inventory()
|
|
|
|
|
|
|
|
if fields.trade then
|
|
|
|
local item = player:get_wielded_item()
|
|
|
|
|
|
|
|
local trade_wanted1 = inv:get_stack("gold_trade_wanted", 1):to_string()
|
|
|
|
local trade_wanted2 = inv:get_stack("gold_trade_wanted", 2):to_string()
|
|
|
|
|
|
|
|
local trade_in1 = inv:get_stack("gold_trade_in", 1):to_string()
|
|
|
|
local trade_in2 = inv:get_stack("gold_trade_in", 2):to_string()
|
2017-05-10 19:19:28 +02:00
|
|
|
|
2015-09-01 17:15:24 +02:00
|
|
|
local matches = trade_wanted1 == trade_in1 and trade_wanted2 == trade_in2
|
|
|
|
|
2017-05-12 04:29:55 +02:00
|
|
|
local meta = minetest.deserialize(item:get_metadata())
|
2017-05-10 19:19:28 +02:00
|
|
|
|
2017-05-17 17:57:14 +02:00
|
|
|
local trade = {"gold:ingot_gold", "gold:ingot_gold", "default:stick"}
|
2015-09-01 17:15:24 +02:00
|
|
|
local trade_type = ""
|
2017-05-10 19:19:28 +02:00
|
|
|
|
2015-09-01 17:15:24 +02:00
|
|
|
if meta then
|
|
|
|
trade = meta.trade
|
|
|
|
trade_type = meta.trade_type
|
|
|
|
end
|
|
|
|
|
|
|
|
if matches then
|
|
|
|
if inv:room_for_item("gold_trade_out", trade[3]) then
|
|
|
|
inv:add_item("gold_trade_out", trade[3])
|
|
|
|
inv:set_stack("gold_trade_in", 1, "")
|
2017-05-10 19:19:28 +02:00
|
|
|
inv:set_stack("gold_trade_in", 2, "")
|
2015-09-01 17:15:24 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2017-05-10 19:19:28 +02:00
|
|
|
end)
|
2015-09-01 17:15:24 +02:00
|
|
|
|
2017-05-17 17:57:14 +02:00
|
|
|
-- Items
|
|
|
|
|
2017-05-12 04:29:55 +02:00
|
|
|
minetest.register_craftitem(
|
2015-09-01 17:15:24 +02:00
|
|
|
"gold:trading_book",
|
|
|
|
{
|
|
|
|
description = "Trading Book",
|
|
|
|
inventory_image = "default_book.png^gold_bookribbon.png",
|
|
|
|
stack_max = 1,
|
2017-05-10 19:19:28 +02:00
|
|
|
})
|
2015-09-01 17:15:24 +02:00
|
|
|
|
2017-05-12 04:29:55 +02:00
|
|
|
minetest.register_craftitem(
|
2017-05-17 17:57:14 +02:00
|
|
|
"gold:lump_gold",
|
|
|
|
{
|
|
|
|
description = "Gold Lump",
|
|
|
|
inventory_image = "gold_lump_gold.png",
|
|
|
|
})
|
|
|
|
|
|
|
|
minetest.register_craftitem(
|
|
|
|
"gold:ingot_gold",
|
2015-09-01 17:15:24 +02:00
|
|
|
{
|
2017-05-17 17:57:14 +02:00
|
|
|
description = "Gold Ingot",
|
|
|
|
inventory_image = "gold_ingot_gold.png",
|
2017-05-10 19:19:28 +02:00
|
|
|
})
|
2015-09-01 17:15:24 +02:00
|
|
|
|
2017-05-17 22:54:33 +02:00
|
|
|
-- Nodes
|
|
|
|
|
|
|
|
minetest.register_node(
|
|
|
|
"gold:stone_with_gold",
|
|
|
|
{
|
|
|
|
description = "Stone with Gold",
|
|
|
|
tiles ={"default_stone.png^gold_mineral_gold.png"},
|
|
|
|
groups = {cracky=1, stone=1},
|
|
|
|
drop = "gold:lump_gold",
|
|
|
|
is_ground_content = true,
|
|
|
|
sounds = default.node_sound_stone_defaults(),
|
|
|
|
})
|
|
|
|
|
|
|
|
-- Ores
|
|
|
|
|
|
|
|
minetest.register_ore(
|
|
|
|
{
|
|
|
|
ore_type = "scatter",
|
|
|
|
ore = "gold:stone_with_gold",
|
|
|
|
wherein = "default:stone",
|
|
|
|
clust_scarcity = 9*9*9,
|
|
|
|
clust_num_ores = 12,
|
|
|
|
clust_size = 6,
|
|
|
|
y_min = -60,
|
|
|
|
y_max = -45,
|
|
|
|
})
|
|
|
|
|
2017-05-17 17:57:14 +02:00
|
|
|
-- Crafting
|
|
|
|
|
2017-05-16 19:47:12 +02:00
|
|
|
crafting.register_craft(
|
2015-09-24 01:42:58 +02:00
|
|
|
{
|
|
|
|
output = "gold:trading_book",
|
2017-05-16 19:47:12 +02:00
|
|
|
items = {
|
|
|
|
"default:book",
|
2017-05-17 17:57:14 +02:00
|
|
|
"gold:ingot_gold",
|
2017-05-16 19:47:12 +02:00
|
|
|
}
|
2017-05-10 19:19:28 +02:00
|
|
|
})
|
2015-09-24 01:42:58 +02:00
|
|
|
|
2017-05-17 17:57:14 +02:00
|
|
|
minetest.register_craft(
|
|
|
|
{
|
|
|
|
type = "cooking",
|
|
|
|
output = "gold:ingot_gold",
|
|
|
|
recipe = "gold:lump_gold",
|
2017-05-17 22:54:33 +02:00
|
|
|
cooktime = 7,
|
2017-05-10 19:19:28 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
-- Achievements
|
|
|
|
|
|
|
|
achievements.register_achievement(
|
|
|
|
"trader",
|
|
|
|
{
|
|
|
|
title = "Trader",
|
|
|
|
description = "Craft a trading book.",
|
|
|
|
times = 1,
|
|
|
|
craftitem = "gold:trading_book",
|
|
|
|
})
|
|
|
|
|
|
|
|
achievements.register_achievement(
|
|
|
|
"gold_rush",
|
|
|
|
{
|
|
|
|
title = "Gold Rush",
|
|
|
|
description = "Dig 60 gold ore.",
|
|
|
|
times = 60,
|
2017-05-18 17:44:26 +02:00
|
|
|
dignode = "gold:stone_with_gold",
|
2017-05-10 19:19:28 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
default.log("mod:gold", "loaded")
|