mirror of
https://codeberg.org/usrib/emeraldbank.git
synced 2024-12-22 22:22:25 +01:00
vendor upgrade system with old shops
This commit is contained in:
parent
f2f9cf9fc7
commit
c2b42ae51b
122
fancyshop.lua
122
fancyshop.lua
@ -27,6 +27,8 @@ local settings = minetest.settings
|
||||
|
||||
local shopcraft = core.settings:get_bool("emeraldbank.shop_craft") or true
|
||||
|
||||
local formspec_prefix = "emeraldbank:shop_formspec"
|
||||
|
||||
local display_node = (settings:get("fancy_vend.display_node") or "mcl_core:glass")
|
||||
local max_logs = (tonumber(settings:get("fancy_vend.log_max")) or 40)
|
||||
local autorotate_speed = (tonumber(settings:get("fancy_vend.autorotate_speed")) or 1)
|
||||
@ -1602,7 +1604,7 @@ minetest.register_craft({
|
||||
-- Vendor Upgrade System --
|
||||
---------------------------
|
||||
|
||||
local old_vendor_mods = string.split((minetest.setting_get("fancy_vend_old_vendor_mods") or ""), ",")
|
||||
local old_vendor_mods = string.split((minetest.setting_get("fancy_vend_old_vendor_mods") or "emeraldbank"), ",")
|
||||
local old_vendor_mods_table = {}
|
||||
|
||||
for i in pairs(old_vendor_mods) do
|
||||
@ -1621,70 +1623,86 @@ local base_upgrade_template = {
|
||||
sounds = mcl_sounds.node_sound_wood_defaults(),
|
||||
drop = drop_vendor,
|
||||
tiles = {
|
||||
"player_vend.png", "player_vend.png",
|
||||
"player_vend.png^mcl_core_emerald.png", "player_vend.png^mcl_core_emerald.png",
|
||||
"player_vend.png^mcl_core_emerald.png", "upgrade_front.png",
|
||||
"player_vend.png^mcl_core_emerald.png",
|
||||
"player_vend.png^mcl_core_emerald.png",
|
||||
"upgrade_front.png",
|
||||
},
|
||||
on_place = function(itemstack, placer, pointed_thing)
|
||||
return ItemStack(drop_vendor.." "..itemstack:get_count())
|
||||
end,
|
||||
allow_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
|
||||
local meta = minetest.get_meta(pos)
|
||||
if player:get_player_name() ~= meta:get_string("owner") then return 0 end
|
||||
return count
|
||||
end,
|
||||
allow_metadata_inventory_put = function(pos, listname, index, stack, player)
|
||||
local meta = minetest.get_meta(pos)
|
||||
if player:get_player_name() ~= meta:get_string("owner") then return 0 end
|
||||
return stack:get_count()
|
||||
end,
|
||||
allow_metadata_inventory_take = function(pos, listname, index, stack, player)
|
||||
local meta = minetest.get_meta(pos)
|
||||
if player:get_player_name() ~= meta:get_string("owner") then return 0 end
|
||||
return stack:get_count()
|
||||
end,
|
||||
return ItemStack(drop_vendor.." "..itemstack:get_count())
|
||||
end,
|
||||
allow_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
|
||||
local meta = minetest.get_meta(pos)
|
||||
if player:get_player_name() ~= meta:get_string("owner") then return 0 end
|
||||
return count
|
||||
end,
|
||||
allow_metadata_inventory_put = function(pos, listname, index, stack, player)
|
||||
local meta = minetest.get_meta(pos)
|
||||
if player:get_player_name() ~= meta:get_string("owner") then return 0 end
|
||||
return stack:get_count()
|
||||
end,
|
||||
allow_metadata_inventory_take = function(pos, listname, index, stack, player)
|
||||
local meta = minetest.get_meta(pos)
|
||||
if player:get_player_name() ~= meta:get_string("owner") then return 0 end
|
||||
return stack:get_count()
|
||||
end,
|
||||
}
|
||||
|
||||
local clear_craft_vendors = {}
|
||||
|
||||
if old_vendor_mods_table["emeraldbank"] then
|
||||
emeraldbank.shop_drop = drop_vendor
|
||||
emeraldbank.shop_empty_drop = drop_vendor
|
||||
else
|
||||
emeraldbank.shop_drop = "emeraldbank:shop"
|
||||
emeraldbank.shop_empty_drop = "emeraldbank:shop"
|
||||
local emeraldbank_template = table.copy(base_upgrade_template)
|
||||
emeraldbank_template.can_dig = function(pos, player)
|
||||
local pname = player:get_player_name()
|
||||
local is_admin = core.check_player_privs(pname, {admin_shop=true})
|
||||
local meta = core.get_meta(pos)
|
||||
local owner = meta:get_string("owner")
|
||||
local inv = meta:get_inventory()
|
||||
return inv:is_empty("stock") and (pname == owner or is_admin)
|
||||
end
|
||||
emeraldbank_template.on_rightclick = function(pos, node, clicker, itemstack)
|
||||
local meta = core.get_meta(pos)
|
||||
local nodename = core.get_node(pos).name
|
||||
local owner = meta:get_string("owner")
|
||||
local pname = clicker:get_player_name()
|
||||
emeraldbank.get_stonks(pos, clicker)
|
||||
core.show_formspec(pname, formspec_prefix..core.pos_to_string(pos), emeraldbank.get_shop_fs(pos, clicker))
|
||||
end
|
||||
minetest.override_item("emeraldbank:shop", emeraldbank_template)
|
||||
table.insert(clear_craft_vendors, "emeraldbank:shop")
|
||||
minetest.override_item("emeraldbank:shop_empty", emeraldbank_template)
|
||||
table.insert(clear_craft_vendors, "emeraldbank:shop_empty")
|
||||
end
|
||||
|
||||
if old_vendor_mods_table["currency"] then
|
||||
local currency_template = table.copy(base_upgrade_template)
|
||||
|
||||
currency_template.can_dig = function(pos, player)
|
||||
local meta = minetest.get_meta(pos)
|
||||
local inv = meta:get_inventory()
|
||||
return inv:is_empty("stock") and inv:is_empty("customers_gave") and inv:is_empty("owner_wants") and inv:is_empty("owner_gives") and (meta:get_string("owner") == player:get_player_name() or minetest.check_player_privs(player:get_player_name(), {protection_bypass=true}))
|
||||
end
|
||||
currency_template.on_rightclick = function(pos, node, clicker, itemstack)
|
||||
local meta = minetest.get_meta(pos)
|
||||
local list_name = "nodemeta:"..pos.x..','..pos.y..','..pos.z
|
||||
if clicker:get_player_name() == meta:get_string("owner") then
|
||||
minetest.show_formspec(clicker:get_player_name(),"fancy_vend:currency_shop_formspec",
|
||||
"size[8,9.5]"..
|
||||
"label[0,0;" .. "Customers gave:" .. "]"..
|
||||
"list["..list_name..";customers_gave;0,0.5;3,2;]"..
|
||||
"label[0,2.5;" .. "Your stock:" .. "]"..
|
||||
"list["..list_name..";stock;0,3;3,2;]"..
|
||||
"label[5,0;" .. "You want:" .. "]"..
|
||||
"list["..list_name..";owner_wants;5,0.5;3,2;]"..
|
||||
"label[5,2.5;" .. "In exchange, you give:" .. "]"..
|
||||
"list["..list_name..";owner_gives;5,3;3,2;]"..
|
||||
"list[current_player;main;0,5.5;8,4;]"
|
||||
local currency_template = table.copy(base_upgrade_template)
|
||||
|
||||
currency_template.can_dig = function(pos, player)
|
||||
local meta = minetest.get_meta(pos)
|
||||
local inv = meta:get_inventory()
|
||||
return inv:is_empty("stock") and inv:is_empty("customers_gave") and inv:is_empty("owner_wants") and inv:is_empty("owner_gives") and (meta:get_string("owner") == player:get_player_name() or minetest.check_player_privs(player:get_player_name(), {protection_bypass=true}))
|
||||
end
|
||||
currency_template.on_rightclick = function(pos, node, clicker, itemstack)
|
||||
local meta = minetest.get_meta(pos)
|
||||
local list_name = "nodemeta:"..pos.x..','..pos.y..','..pos.z
|
||||
if clicker:get_player_name() == meta:get_string("owner") then
|
||||
minetest.show_formspec(clicker:get_player_name(),"fancy_vend:currency_shop_formspec",
|
||||
"size[8,9.5]"..
|
||||
"label[0,0;" .. "Customers gave:" .. "]"..
|
||||
"list["..list_name..";customers_gave;0,0.5;3,2;]"..
|
||||
"label[0,2.5;" .. "Your stock:" .. "]"..
|
||||
"list["..list_name..";stock;0,3;3,2;]"..
|
||||
"label[5,0;" .. "You want:" .. "]"..
|
||||
"list["..list_name..";owner_wants;5,0.5;3,2;]"..
|
||||
"label[5,2.5;" .. "In exchange, you give:" .. "]"..
|
||||
"list["..list_name..";owner_gives;5,3;3,2;]"..
|
||||
"list[current_player;main;0,5.5;8,4;]"
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
minetest.register_node(":currency:shop", currency_template)
|
||||
minetest.register_node(":currency:shop", currency_template)
|
||||
|
||||
table.insert(clear_craft_vendors, "currency:shop")
|
||||
table.insert(clear_craft_vendors, "currency:shop")
|
||||
end
|
||||
|
||||
if old_vendor_mods_table["easyvend"] then
|
||||
|
Loading…
Reference in New Issue
Block a user