shops get emeralds from bank

This commit is contained in:
Freeman 2023-11-05 17:37:43 +01:00
parent b1ba61501f
commit dac343c284

@ -615,6 +615,7 @@ local function run_inv_checks(pos, player, lots)
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
local inv = meta:get_inventory() local inv = meta:get_inventory()
local player_inv = player:get_inventory() local player_inv = player:get_inventory()
local player_emeralds = emeraldbank.get_emeralds(player:get_player_name())
local ct = {} local ct = {}
@ -624,6 +625,9 @@ local function run_inv_checks(pos, player, lots)
-- Perform inventory checks -- Perform inventory checks
ct.player_has, ct.player_item_table = inv_contains_items(player_inv, "main", settings.input_item, input_qty, settings.accept_worn_input) ct.player_has, ct.player_item_table = inv_contains_items(player_inv, "main", settings.input_item, input_qty, settings.accept_worn_input)
if settings.input_item == "mcl_core:emerald" then
ct.player_has = player_emeralds >= input_qty
end
ct.vendor_has, ct.vendor_item_table = inv_contains_items(inv, "main", settings.output_item, output_qty, settings.accept_worn_output) ct.vendor_has, ct.vendor_item_table = inv_contains_items(inv, "main", settings.output_item, output_qty, settings.accept_worn_output)
ct.player_fits = free_slots(player_inv, "main", settings.output_item, output_qty) ct.player_fits = free_slots(player_inv, "main", settings.output_item, output_qty)
ct.vendor_fits = free_slots(inv, "main", settings.input_item, input_qty) ct.vendor_fits = free_slots(inv, "main", settings.input_item, input_qty)
@ -656,6 +660,8 @@ local function make_purchase(pos, player, lots)
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
local inv = meta:get_inventory() local inv = meta:get_inventory()
local player_inv = player:get_inventory() local player_inv = player:get_inventory()
local name = player:get_player_name()
local player_emeralds = emeraldbank.get_emeralds(name)
local status, errorcode = get_vendor_status(pos) local status, errorcode = get_vendor_status(pos)
-- Double check settings, vendors which were incorrectly set up before this bug fix won't matter anymore -- Double check settings, vendors which were incorrectly set up before this bug fix won't matter anymore
@ -673,9 +679,13 @@ local function make_purchase(pos, player, lots)
if ct.player_has then if ct.player_has then
if ct.player_fits then if ct.player_fits then
if settings.admin_vendor then if settings.admin_vendor then
minetest.log("action", player:get_player_name().." trades "..settings.input_item_qty.." "..settings.input_item.." for "..settings.output_item_qty.." "..settings.output_item.." using vendor at "..minetest.pos_to_string(pos)) minetest.log("action", name.." trades "..settings.input_item_qty.." "..settings.input_item.." for "..settings.output_item_qty.." "..settings.output_item.." using vendor at "..minetest.pos_to_string(pos))
if settings.input_item == "mcl_core:emerald" then
emeraldbank.add_emeralds(player, - input_qty)
else
inv_remove(player_inv, "main", ct.player_item_table, settings.input_item, input_qty) inv_remove(player_inv, "main", ct.player_item_table, settings.input_item, input_qty)
end
inv_insert(player_inv, "main", ItemStack(settings.output_item), output_qty, nil) inv_insert(player_inv, "main", ItemStack(settings.output_item), output_qty, nil)
if minetest.get_modpath("digilines") then if minetest.get_modpath("digilines") then
@ -685,10 +695,14 @@ local function make_purchase(pos, player, lots)
return true, "Trade successful" return true, "Trade successful"
elseif ct.vendor_has then elseif ct.vendor_has then
if ct.vendor_fits then if ct.vendor_fits then
minetest.log("action", player:get_player_name().." trades "..settings.input_item_qty.." "..settings.input_item.." for "..settings.output_item_qty.." "..settings.output_item.." using vendor at "..minetest.pos_to_string(pos)) minetest.log("action", name.." trades "..settings.input_item_qty.." "..settings.input_item.." for "..settings.output_item_qty.." "..settings.output_item.." using vendor at "..minetest.pos_to_string(pos))
inv_remove(inv, "main", ct.vendor_item_table, settings.output_item, output_qty) inv_remove(inv, "main", ct.vendor_item_table, settings.output_item, output_qty)
if settings.input_item == "mcl_core:emerald" then
emeraldbank.add_emeralds(player, - input_qty)
else
inv_remove(player_inv, "main", ct.player_item_table, settings.input_item, input_qty) inv_remove(player_inv, "main", ct.player_item_table, settings.input_item, input_qty)
end
inv_insert(player_inv, "main", ItemStack(settings.output_item), output_qty, ct.vendor_item_table) inv_insert(player_inv, "main", ItemStack(settings.output_item), output_qty, ct.vendor_item_table)
inv_insert(inv, "main", ItemStack(settings.input_item), input_qty, ct.player_item_table, pos, (minetest.get_modpath("pipeworks") and settings.currency_eject)) inv_insert(inv, "main", ItemStack(settings.input_item), input_qty, ct.player_item_table, pos, (minetest.get_modpath("pipeworks") and settings.currency_eject))
@ -1455,6 +1469,7 @@ player_depo.tiles = {
"player_depo.png^mcl_core_emerald.png", "player_depo.png^mcl_core_emerald.png", "player_depo.png^mcl_core_emerald.png", "player_depo.png^mcl_core_emerald.png",
"player_depo.png^mcl_core_emerald.png", "player_depo_front.png", "player_depo.png^mcl_core_emerald.png", "player_depo_front.png",
} }
player_depo.groups.not_in_creative_inventory = 1 player_depo.groups.not_in_creative_inventory = 1
local admin_vendor = table.copy(vendor_template) local admin_vendor = table.copy(vendor_template)