80 lines
2.6 KiB
Lua
80 lines
2.6 KiB
Lua
--- Server Shops Deposit Logics
|
|
--
|
|
-- @topic deposit.lua
|
|
|
|
local ss = server_shop
|
|
local transaction = dofile(ss.modpath .. "/transaction.lua")
|
|
|
|
-- Einzahl-Slot für die Kassenreserve des Besitzers (unverändert)
|
|
core.create_detached_inventory(ss.modname .. ":cash_deposit", {
|
|
on_put = function(inv, listname, index, stack, player)
|
|
local pmeta = player:get_meta()
|
|
local pos = core.deserialize(pmeta:get_string(ss.modname .. ":pos"))
|
|
if not pos then return stack:get_count() end
|
|
|
|
if ss.is_shop_owner(pos, player) or ss.is_shop_admin(player) then
|
|
local value = transaction.calculate_currency_value(stack)
|
|
if value > 0 then
|
|
local shop_meta = core.get_meta(pos)
|
|
shop_meta:set_int("cash_reserve", shop_meta:get_int("cash_reserve") + value)
|
|
inv:set_stack(listname, index, nil)
|
|
ss.show_formspec(pos, player)
|
|
return 0
|
|
end
|
|
end
|
|
return stack:get_count()
|
|
end,
|
|
}):set_size("main", 1)
|
|
|
|
|
|
-- Einzahl-Slot für das Guthaben des Kunden (angepasst)
|
|
core.create_detached_inventory(ss.modname .. ":customer_deposit", {
|
|
on_put = function(inv, listname, index, stack, player)
|
|
local pmeta = player:get_meta()
|
|
local pos = core.deserialize(pmeta:get_string(ss.modname .. ":pos"))
|
|
local stack_name = stack:get_name()
|
|
|
|
if stack_name == "bank_accounts:debit_card" or stack_name == "bank_accounts:credit_card" then
|
|
local current_credit = pmeta:get_int(ss.modname .. ":session_credit") or 0
|
|
if current_credit > 0 then
|
|
local refund_stacks, remainder = transaction.calculate_refund(current_credit)
|
|
for _, r_stack in ipairs(refund_stacks) do
|
|
transaction.give_product(player, r_stack)
|
|
end
|
|
end
|
|
|
|
pmeta:set_string(ss.modname..":payment_method", stack_name)
|
|
pmeta:set_int(ss.modname..":session_credit", 0)
|
|
if pos then
|
|
ss.show_formspec(pos, player)
|
|
end
|
|
return stack:get_count()
|
|
end
|
|
|
|
local value = transaction.calculate_currency_value(stack)
|
|
if value > 0 then
|
|
pmeta:set_string(ss.modname..":payment_method", "cash")
|
|
pmeta:set_int(ss.modname .. ":session_credit", (pmeta:get_int(ss.modname .. ":session_credit") or 0) + value)
|
|
inv:set_stack(listname, index, nil)
|
|
|
|
if pos then
|
|
ss.show_formspec(pos, player)
|
|
end
|
|
return 0
|
|
end
|
|
|
|
return stack:get_count()
|
|
end,
|
|
on_take = function(inv, listname, index, stack, player)
|
|
local pmeta = player:get_meta()
|
|
local pos = core.deserialize(pmeta:get_string(ss.modname .. ":pos"))
|
|
|
|
if stack:get_name() == "bank_accounts:debit_card" or stack:get_name() == "bank_accounts:credit_card" then
|
|
pmeta:set_string(ss.modname..":payment_method", nil)
|
|
if pos then
|
|
ss.show_formspec(pos, player)
|
|
end
|
|
end
|
|
return stack
|
|
end,
|
|
}):set_size("main", 1)
|