1
0
mirror of https://github.com/MinetestForFun/minercantile.git synced 2024-12-23 00:00:21 +01:00

add coins and add alias to maptools coins

add and compress textures
and more changes
This commit is contained in:
crabman77 2016-06-10 19:16:33 +02:00
parent a5f384fc6a
commit 9fb020b39a
10 changed files with 124 additions and 101 deletions

View File

@ -1,13 +1,35 @@
--[[
"maptools:copper_coin"
"maptools:silver_coin"
"maptools:gold_coin"
100 pc = 1pa, 100pa = 1po local convertion = { ["minercantile:copper_coin"]=1, ["minercantile:silver_coin"]=100, ["minercantile:gold_coin"]=10000}
--]]
local convertion = { ["maptools:copper_coin"]=1, ["maptools:silver_coin"]=100, ["maptools:gold_coin"]=10000} minetest.register_craftitem("minercantile:copper_coin", {
description = "Copper Coin",
inventory_image = "minercantile_copper_coin.png",
wield_scale = {x = 0.5, y = 0.5, z = 0.25},
stack_max = 10000,
groups = {not_in_creative_inventory = 0},
})
minetest.register_craftitem("minercantile:silver_coin", {
description = "Silver Coin",
inventory_image = "minercantile_silver_coin.png",
wield_scale = {x = 0.5, y = 0.5, z = 0.25},
stack_max = 10000,
groups = {not_in_creative_inventory = 0},
})
minetest.register_craftitem("minercantile:gold_coin", {
description = "Gold Coin",
inventory_image = "minercantile_gold_coin.png",
wield_scale = {x = 0.5, y = 0.5, z = 0.25},
stack_max = 10000,
groups = {not_in_creative_inventory = 0},
})
minetest.register_alias("maptools:copper_coin", "minercantile:copper_coin")
minetest.register_alias("maptools:silver_coin", "minercantile:silver_coin")
minetest.register_alias("maptools:gold_coin", "minercantile:gold_coin")
local function get_bancomatic_formspec(pos, name) local function get_bancomatic_formspec(pos, name)
local spos = pos.x .. "," .. pos.y .. "," .. pos.z local spos = pos.x .. "," .. pos.y .. "," .. pos.z
@ -16,12 +38,12 @@ local function get_bancomatic_formspec(pos, name)
"label[0,0;Your money:"..minercantile.wallet.get_money(name).."$]" .. "label[0,0;Your money:"..minercantile.wallet.get_money(name).."$]" ..
"label[2,1;Put your coins to convert on your wallet]" .. "label[2,1;Put your coins to convert on your wallet]" ..
"image[0,1.5;1,1;maptools_gold_coin.png]" .. "image[0,1.5;1,1;minercantile_gold_coin.png]" ..
"label[1,1.7;= "..convertion["maptools:gold_coin"].."$]" .. "label[1,1.7;= "..convertion["minercantile:gold_coin"].."$]" ..
"image[0,2.5;1,1;maptools_silver_coin.png]" .. "image[0,2.5;1,1;minercantile_silver_coin.png]" ..
"label[1,2.7;= "..convertion["maptools:silver_coin"].."$]" .. "label[1,2.7;= "..convertion["minercantile:silver_coin"].."$]" ..
"image[0,3.5;1,1;maptools_copper_coin.png]" .. "image[0,3.5;1,1;minercantile_copper_coin.png]" ..
"label[1,3.7;= "..convertion["maptools:copper_coin"].."$]" .. "label[1,3.7;= "..convertion["minercantile:copper_coin"].."$]" ..
"list[nodemeta:" .. spos .. ";main;3.5,2.5;1,1;]" .. "list[nodemeta:" .. spos .. ";main;3.5,2.5;1,1;]" ..
"list[current_player;main;0,4.85;8,1;]" .. "list[current_player;main;0,4.85;8,1;]" ..
@ -33,7 +55,6 @@ local function get_bancomatic_formspec(pos, name)
end end
--change money. --change money.
minetest.register_node("minercantile:bancomatic", { minetest.register_node("minercantile:bancomatic", {
description = "Bancomatic", description = "Bancomatic",
@ -58,7 +79,7 @@ minetest.register_node("minercantile:bancomatic", {
local inv = meta:get_inventory() local inv = meta:get_inventory()
inv:set_size("main", 1 * 1) inv:set_size("main", 1 * 1)
end, end,
can_dig = function(pos,player) can_dig = function(pos, player)
local name = player:get_player_name() local name = player:get_player_name()
return (minetest.check_player_privs(name, {protection_bypass = true}) or minetest.check_player_privs(name, {server = true})) return (minetest.check_player_privs(name, {protection_bypass = true}) or minetest.check_player_privs(name, {server = true}))
end, end,
@ -67,7 +88,7 @@ minetest.register_node("minercantile:bancomatic", {
end, end,
allow_metadata_inventory_put = function(pos, listname, index, stack, player) allow_metadata_inventory_put = function(pos, listname, index, stack, player)
local item = stack:get_name() local item = stack:get_name()
if item == "maptools:copper_coin" or item == "maptools:silver_coin" or item == "maptools:gold_coin" then if item == "minercantile:copper_coin" or item == "minercantile:silver_coin" or item == "minercantile:gold_coin" then
return stack:get_count() return stack:get_count()
end end
return 0 return 0
@ -77,7 +98,7 @@ minetest.register_node("minercantile:bancomatic", {
end, end,
on_metadata_inventory_put = function(pos, listname, index, stack, player) on_metadata_inventory_put = function(pos, listname, index, stack, player)
local item = stack:get_name() local item = stack:get_name()
if item == "maptools:copper_coin" or item == "maptools:silver_coin" or item == "maptools:gold_coin" then if item == "minercantile:copper_coin" or item == "minercantile:silver_coin" or item == "minercantile:gold_coin" then
local name = player:get_player_name() local name = player:get_player_name()
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
local inv = meta:get_inventory() local inv = meta:get_inventory()

View File

@ -1,3 +1,2 @@
default default
unified_inventory? unified_inventory?
maptools?

View File

@ -13,7 +13,7 @@ minercantile.stock = {} -- table saved money, items list
minercantile.shop = {} minercantile.shop = {}
minercantile.shop.items_inventory = {} minercantile.shop.items_inventory = {}
minercantile.stock.items = {} minercantile.stock.items = {}
minercantile.stock.money = 800000 minercantile.stock.money = 8000
minercantile.stock.transac_b = 0 minercantile.stock.transac_b = 0
minercantile.stock.transac_s = 0 minercantile.stock.transac_s = 0
@ -28,7 +28,6 @@ dofile(minetest.get_modpath("minercantile") .. "/change.lua")
dofile(minetest.get_modpath("minercantile") .. "/shop.lua") dofile(minetest.get_modpath("minercantile") .. "/shop.lua")
--load items base and available --load items base and available
minercantile.load_stock_base() minercantile.load_stock_base()
minetest.after(1, function() minetest.after(1, function()
@ -36,4 +35,5 @@ minetest.after(1, function()
minercantile.load_stock() minercantile.load_stock()
end end
) )
minetest.log("action", "[minercantile] Loaded") minetest.log("action", "[minercantile] Loaded")

123
shop.lua
View File

@ -28,9 +28,9 @@ function minercantile.shop.give_money(money, saving)
end end
end end
function minercantile.shop.get_nb(item) function minercantile.shop.get_nb(itname)
if minercantile.stock.items[item] then if minercantile.stock.items[itname] then
return minercantile.stock.items[item].nb return minercantile.stock.items[itname].nb
end end
return 0 return 0
end end
@ -52,16 +52,16 @@ function minercantile.shop.set_transac_s()
minercantile.stock.transac_s = minercantile.stock.transac_s + 1 minercantile.stock.transac_s = minercantile.stock.transac_s + 1
end end
function minercantile.shop.is_available(item) function minercantile.shop.is_available(itname)
if minercantile.registered_items[item] then if minercantile.registered_items[itname] then
return true return true
end end
return false return false
end end
function minercantile.shop.get_item_def(item) function minercantile.shop.get_item_def(itname)
if minercantile.registered_items[item] then if minercantile.registered_items[itname] then
return minercantile.registered_items[item] return minercantile.registered_items[itname]
end end
return nil return nil
end end
@ -100,6 +100,14 @@ function minercantile.load_stock_base()
file:close() file:close()
if data and type(data) == "table" then if data and type(data) == "table" then
minercantile.stock_base = table.copy(data) minercantile.stock_base = table.copy(data)
if minercantile.stock_base.money then
minercantile.stock.money = minercantile.stock_base.money
end
if minercantile.stock_base.items then
for itname, def in pairs(minercantile.stock_base.items) do
minercantile.stock.items[itname] = table.copy(def)
end
end
end end
end end
end end
@ -126,7 +134,9 @@ function minercantile.load_stock()
minercantile.stock.money = data.money minercantile.stock.money = data.money
end end
if data.items then if data.items then
minercantile.stock.items = table.copy(data.items) for itname, def in pairs(data.items) do
minercantile.stock.items[itname] = table.copy(def)
end
end end
if data.transac_b then if data.transac_b then
minercantile.stock.transac_b = data.transac_b minercantile.stock.transac_b = data.transac_b
@ -134,11 +144,6 @@ function minercantile.load_stock()
if data.transac_s then if data.transac_s then
minercantile.stock.transac_s = data.transac_s minercantile.stock.transac_s = data.transac_s
end end
return
end
else
if minercantile.stock_base then
minercantile.stock.items = table.copy(minercantile.stock_base)
end end
end end
end end
@ -161,19 +166,19 @@ end
-- sell fonction -- sell fonction
function minercantile.shop.get_buy_price(item) function minercantile.shop.get_buy_price(itname)
if item == "maptools:copper_coin" or item == "maptools:silver_coin" or item == "maptools:gold_coin" then -- dont's buy/sell coins if itname == "minercantile:copper_coin" or itname == "minercantile:silver_coin" or itname == "minercantile:gold_coin" then -- dont's buy/sell coins
return nil return nil
end end
local price = nil local price = nil
local money = minercantile.shop.get_money() local money = minercantile.shop.get_money()
if not minercantile.stock.items[item] then if not minercantile.stock.items[itname] then
minercantile.stock.items[item] = {nb=math.random(500, 1000)} minercantile.stock.items[itname] = {nb=0}
end end
local nb = minercantile.stock.items[item].nb local nb = minercantile.stock.items[itname].nb
if minercantile.stock.items[item].price ~= nil then -- if defined price if minercantile.stock.items[itname].price ~= nil then -- if defined price
price = math.ceil(minercantile.stock.items[item].price) price = math.ceil(minercantile.stock.items[itname].price)
else else
price = math.ceil((money/10)/(math.log(nb+2000-99)*10)*1000000/(math.pow((nb+2000-99),(2.01)))) price = math.ceil((money/10)/(math.log(nb+2000-99)*10)*1000000/(math.pow((nb+2000-99),(2.01))))
end end
@ -183,20 +188,20 @@ end
-- sell fonction -- sell fonction
function minercantile.shop.get_sell_price(item, wear) function minercantile.shop.get_sell_price(itname, wear)
if item == "maptools:copper_coin" or item == "maptools:silver_coin" or item == "maptools:gold_coin" then -- dont's buy/sell coins if itname == "minercantile:copper_coin" or itname == "minercantile:silver_coin" or itname == "minercantile:gold_coin" then -- dont's buy/sell coins
return nil return nil
end end
local price = nil local price = nil
local money = minercantile.shop.get_money() local money = minercantile.shop.get_money()
if not minercantile.stock.items[item] then if not minercantile.stock.items[itname] then
minercantile.stock.items[item] = {nb=0} minercantile.stock.items[itname] = {nb=0}
end end
local nb = minercantile.stock.items[item].nb local nb = minercantile.stock.items[itname].nb
if minercantile.stock.items[item].price ~= nil then -- if defined price if minercantile.stock.items[itname].price ~= nil then -- if defined price
price = math.floor(minercantile.stock.items[item].price) price = math.floor(minercantile.stock.items[itname].price)
else else
price = math.floor((money/10)/(math.log(nb+2000+99)*10)*1000000/(math.pow((nb+2000+99),(2.01)))) price = math.floor((money/10)/(math.log(nb+2000+99)*10)*1000000/(math.pow((nb+2000+99),(2.01))))
end end
@ -240,13 +245,13 @@ local function get_shop_inventory_by_page(name)
if page > nb_pages then page = nb_pages end if page > nb_pages then page = nb_pages end
local index = (page*32)-32 local index = (page*32)-32
for i=1, 32 do for i=1, 32 do
local item = shop_buy[name].items_list[index+i] local itname = shop_buy[name].items_list[index+i]
if not item then break end if not itname then break end
local nb = minercantile.shop.get_nb(item) local nb = minercantile.shop.get_nb(itname)
if nb > 0 then if nb > 0 then
local price = minercantile.shop.get_buy_price(item) local price = minercantile.shop.get_buy_price(itname)
if price and price > 0 then if price and price > 0 then
table.insert(inv_list, {name=item, nb=nb, price=price}) table.insert(inv_list, {name=itname, nb=nb, price=price})
end end
end end
end end
@ -256,13 +261,13 @@ local function get_shop_inventory_by_page(name)
if page > nb_pages then page = nb_pages end if page > nb_pages then page = nb_pages end
local index = (page*32)-32 local index = (page*32)-32
for i=1, 32 do for i=1, 32 do
local item = shop_buy[name].items_type[index+i] local itname = shop_buy[name].items_type[index+i]
if item then if itname then
local nb = minercantile.shop.get_nb(item) local nb = minercantile.shop.get_nb(itname)
if nb > 0 then if nb > 0 then
local price = minercantile.shop.get_buy_price(item) local price = minercantile.shop.get_buy_price(itname)
if price and price > 0 then if price and price > 0 then
table.insert(inv_list, {name=item,nb=nb,price=price}) table.insert(inv_list, {name=itname,nb=nb,price=price})
end end
end end
end end
@ -274,7 +279,7 @@ end
--buy --buy
function minercantile.shop.buy(name, item, nb, price) function minercantile.shop.buy(name, itname, nb, price)
local player = minetest.get_player_by_name(name) local player = minetest.get_player_by_name(name)
if not player then return false end if not player then return false end
local player_inv = player:get_inventory() local player_inv = player:get_inventory()
@ -285,9 +290,9 @@ function minercantile.shop.buy(name, item, nb, price)
return false return false
end end
local items_nb = minercantile.stock.items[item].nb local items_nb = minercantile.stock.items[itname].nb
if items_nb < 1 then if items_nb < 1 then
minetest.show_formspec(name, "minercantile:confirmed", "size[6,3]bgcolor[#2A2A2A;]label[2.6,0;Shop]label[1,1;Sorry, shop have 0 item ".. item.."]button[1.3,2.1;1.5,1;return_buy;Return]button_exit[3.3,2.1;1.5,1;close;Close]") minetest.show_formspec(name, "minercantile:confirmed", "size[6,3]bgcolor[#2A2A2A;]label[2.6,0;Shop]label[1,1;Sorry, shop have 0 item ".. itname.."]button[1.3,2.1;1.5,1;return_buy;Return]button_exit[3.3,2.1;1.5,1;close;Close]")
return false return false
end end
@ -305,20 +310,20 @@ function minercantile.shop.buy(name, item, nb, price)
end end
local sell_price = player_can_buy * price local sell_price = player_can_buy * price
local stack = ItemStack(item.." "..player_can_buy) local stack = ItemStack(itname.." "..player_can_buy)
--player_inv:room_for_item("main", stack) --player_inv:room_for_item("main", stack)
local nn = player_inv:add_item("main", stack) local nn = player_inv:add_item("main", stack)
local count = nn:get_count() local count = nn:get_count()
if count > 0 then if count > 0 then
minetest.spawn_item(player:getpos(), {name=item, count=count, wear=0, metadata=""}) minetest.spawn_item(player:getpos(), {name=itname, count=count, wear=0, metadata=""})
end end
minercantile.stock.items[item].nb = minercantile.stock.items[item].nb - player_can_buy minercantile.stock.items[itname].nb = minercantile.stock.items[itname].nb - player_can_buy
minercantile.shop.set_transac_b() minercantile.shop.set_transac_b()
minercantile.shop.give_money(sell_price, true) minercantile.shop.give_money(sell_price, true)
minercantile.wallet.take_money(name, sell_price, " Buy "..player_can_buy .." "..item..", price "..sell_price) minercantile.wallet.take_money(name, sell_price, " Buy "..player_can_buy .." "..itname..", price "..sell_price)
minetest.show_formspec(name, "minercantile:confirmed", "size[6,3]bgcolor[#2A2A2A;]label[2.6,0;Shop]label[1.3,0.8;You buy "..player_can_buy .." "..item.."]label[1.3,1.3;price "..sell_price.."$]button[1.3,2.1;1.5,1;return_buy;Return]button_exit[3.3,2.1;1.5,1;close;Close]") minetest.show_formspec(name, "minercantile:confirmed", "size[6,3]bgcolor[#2A2A2A;]label[2.6,0;Shop]label[1.3,0.8;You buy "..player_can_buy .." "..itname.."]label[1.3,1.3;price "..sell_price.."$]button[1.3,2.1;1.5,1;return_buy;Return]button_exit[3.3,2.1;1.5,1;close;Close]")
return true return true
end end
@ -363,7 +368,7 @@ end
local function get_formspec_buy_items(name) local function get_formspec_buy_items(name)
local itname = shop_buy[name].item local itname = shop_buy[name].itname
local max = shop_buy[name].max local max = shop_buy[name].max
local nb = shop_buy[name].nb local nb = shop_buy[name].nb
local price = shop_buy[name].price local price = shop_buy[name].price
@ -563,18 +568,18 @@ function minercantile.get_formspec_shop_admin_shop(pos, node_name, name)
local isnode = minetest.get_node_or_nil(pos) local isnode = minetest.get_node_or_nil(pos)
if not isnode or isnode.name ~= node_name then return end if not isnode or isnode.name ~= node_name then return end
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
local shop_type = meta:get_int("shop_type") or 1 local shop_type = meta:get_int("shop_type")
table.insert(formspec, "label[1,1;Shop Type:]") table.insert(formspec, "label[1,1;Shop Type:]")
table.insert(formspec, "dropdown[3,1;3,1;select_type;"..table.concat(minercantile.shop.shop_type, ",")..";"..shop_type.."]") table.insert(formspec, "dropdown[3,1;3,1;select_type;"..table.concat(minercantile.shop.shop_type, ",")..";"..shop_type.."]")
local isopen = meta:get_int("open") or 0 local isopen = meta:get_int("open")
if isopen == 1 then if isopen == 1 then
table.insert(formspec, "label[1,2;Is Open: Yes]button[3.5,1.8;1.5,1;open_close;No]") table.insert(formspec, "label[1,2;Is Open: Yes]button[3.5,1.8;1.5,1;open_close;No]")
else else
table.insert(formspec, "label[1,2;Is Open: No]button[3.5,1.8;1.5,1;open_close;Yes]") table.insert(formspec, "label[1,2;Is Open: No]button[3.5,1.8;1.5,1;open_close;Yes]")
end end
local always_open = meta:get_int("always_open") or 0 local always_open = meta:get_int("always_open")
if always_open == 1 then if always_open == 1 then
table.insert(formspec, "label[1,3;Open 24/24: Yes]button[3.5,2.8;1.5,1;always_open;No]") table.insert(formspec, "label[1,3;Open 24/24: Yes]button[3.5,2.8;1.5,1;always_open;No]")
else else
@ -602,11 +607,11 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
for b, n in pairs(fields) do for b, n in pairs(fields) do
if string.find(b, "buttonchoice_") then if string.find(b, "buttonchoice_") then
if not shop_buy[name] then return end if not shop_buy[name] then return end
local item = string.sub(b, 14) local itname = string.sub(b, 14)
shop_buy[name].item = item shop_buy[name].itname = itname
shop_buy[name].max = tonumber(n)/4 shop_buy[name].max = math.floor(minercantile.shop.get_nb(itname)/4)
shop_buy[name].nb = 1 shop_buy[name].nb = 1
shop_buy[name].price = minercantile.shop.get_buy_price(item) shop_buy[name].price = minercantile.shop.get_buy_price(itname)
minetest.show_formspec(name, "minercantile:shop_buy_items", get_formspec_buy_items(name)) minetest.show_formspec(name, "minercantile:shop_buy_items", get_formspec_buy_items(name))
return return
end end
@ -634,7 +639,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
end end
if shop_buy[name].nb > 99 then if shop_buy[name].nb > 99 then
shop_buy[name].nb = 99 shop_buy[name].nb = 99
end end
if shop_buy[name].nb > shop_buy[name].max then if shop_buy[name].nb > shop_buy[name].max then
shop_buy[name].nb = shop_buy[name].max shop_buy[name].nb = shop_buy[name].max
end end
@ -645,7 +650,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
show_formspec_to_buy(name) show_formspec_to_buy(name)
return return
elseif fields["confirm"] then elseif fields["confirm"] then
minercantile.shop.buy(name, shop_buy[name].item, shop_buy[name].nb, shop_buy[name].price) minercantile.shop.buy(name, shop_buy[name].itname, shop_buy[name].nb, shop_buy[name].price)
return return
elseif fields["quit"] then elseif fields["quit"] then
shop_buy[name] = nil shop_buy[name] = nil
@ -769,7 +774,7 @@ minetest.register_node("minercantile:shop", {
local name = player:get_player_name() local name = player:get_player_name()
if not name or name == "" then return end if not name or name == "" then return end
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
local shop_type = minercantile.shop.shop_type[meta:get_int("shop_type") or 1] local shop_type = minercantile.shop.shop_type[meta:get_int("shop_type")] or "all"
minercantile.shop.set_items_buy_list(name, shop_type) minercantile.shop.set_items_buy_list(name, shop_type)
if minetest.check_player_privs(name, {protection_bypass = true}) or minetest.check_player_privs(name, {server = true}) then if minetest.check_player_privs(name, {protection_bypass = true}) or minetest.check_player_privs(name, {server = true}) then
minetest.show_formspec(name, "minercantile:shop_admin_shop", minercantile.get_formspec_shop_admin_shop(pos, node.name, name)) minetest.show_formspec(name, "minercantile:shop_admin_shop", minercantile.get_formspec_shop_admin_shop(pos, node.name, name))
@ -778,10 +783,10 @@ minetest.register_node("minercantile:shop", {
if (isopen and isopen == 1) then if (isopen and isopen == 1) then
local always_open = meta:get_int("always_open") local always_open = meta:get_int("always_open")
local tod = (minetest.get_timeofday() or 0) * 24000 local tod = (minetest.get_timeofday() or 0) * 24000
if always_open == 1 or (tod > 4500 and tod < 19500) then --FIXME check tod 8h-21h if always_open == 1 or (tod > 8000 and tod < 19000) then --FIXME check tod 8h-19h
minetest.show_formspec(name, "minercantile:shop_welcome", get_formspec_welcome(name)) minetest.show_formspec(name, "minercantile:shop_welcome", get_formspec_welcome(name))
else else
minetest.show_formspec(name, "minercantile:closed", "size[6,3]bgcolor[#2A2A2A;]label[2.6,0;Shop]label[1.2,1;Sorry shop is only open 7h-21h]button_exit[2.3,2.1;1.5,1;close;Close]") minetest.show_formspec(name, "minercantile:closed", "size[6,3]bgcolor[#2A2A2A;]label[2.6,0;Shop]label[1.2,1;Sorry shop is only open 8h-19h]button_exit[2.3,2.1;1.5,1;close;Close]")
end end
else else
minetest.show_formspec(name, "minercantile:closed", "size[6,3]bgcolor[#2A2A2A;]label[2.6,0;Shop]label[1.7,1;Sorry shop is closed]button_exit[2.3,2.1;1.5,1;close;Close]") minetest.show_formspec(name, "minercantile:closed", "size[6,3]bgcolor[#2A2A2A;]label[2.6,0;Shop]label[1.7,1;Sorry shop is closed]button_exit[2.3,2.1;1.5,1;close;Close]")

Binary file not shown.

After

Width:  |  Height:  |  Size: 279 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 236 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 184 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 206 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 240 B

View File

@ -68,7 +68,7 @@ function minercantile.wallet.give_money(name, amount, transaction)
end end
minercantile.wallets[name].money = minercantile.wallet.get_money(name) + amount minercantile.wallets[name].money = minercantile.wallet.get_money(name) + amount
if transaction then if transaction then
local trans = os.date().. ":"..transaction..", new amount:"..minercantile.wallet.get_money(name) local trans = os.date().. ":"..transaction
minercantile.add_transactions(name, trans) minercantile.add_transactions(name, trans)
end end
minercantile.wallet.save_wallet(name) minercantile.wallet.save_wallet(name)
@ -81,7 +81,7 @@ function minercantile.wallet.take_money(name, amount, transaction)
end end
minercantile.wallets[name].money = minercantile.wallet.get_money(name) - amount minercantile.wallets[name].money = minercantile.wallet.get_money(name) - amount
if transaction then if transaction then
local trans = os.date().. ": "..transaction..", new amount:"..minercantile.wallet.get_money(name) local trans = os.date().. ": "..transaction
minercantile.add_transactions(name, trans) minercantile.add_transactions(name, trans)
end end
minercantile.wallet.save_wallet(name) minercantile.wallet.save_wallet(name)
@ -112,8 +112,8 @@ function minercantile.send_money(sender, receiver, amount)
if minercantile.wallet.get_money(sender) < amount then if minercantile.wallet.get_money(sender) < amount then
return false return false
end end
minercantile.wallet.take_money(sender, amount, "Send "..amount.." Minecoins to "..receiver) minercantile.wallet.take_money(sender, amount, "Send "..amount.."$ to "..receiver)
minercantile.wallet.give_money(receiver, amount, "Received "..amount.." Minecoins from "..sender) minercantile.wallet.give_money(receiver, amount, "Received "..amount.."$ from "..sender)
return true return true
end end
@ -123,18 +123,17 @@ function minercantile.get_formspec_wallet(name)
minercantile.wallet.load_wallet(name) minercantile.wallet.load_wallet(name)
end end
local formspec = {} local formspec = {}
table.insert(formspec,"size[10,9]label[4.4,0;My Wallet]") table.insert(formspec,"size[10,9]bgcolor[#2A2A2A;]label[4.4,0;My Wallet]")
table.insert(formspec,"image[1,2;1,1;minercantile_money.png]") --FIXME add image table.insert(formspec,"label[0.5,1;Sold: ".. tostring(minercantile.wallet.get_money(name)) .."$]")
table.insert(formspec,"label[2,2.2;total:".. tostring(minercantile.wallet.get_money(name)) .."]") table.insert(formspec,"label[4,2.3;10 last transactions]")
table.insert(formspec,"label[4,3.3;10 last transactions]")
local transactions = minercantile.wallet.get_transactions(name) local transactions = minercantile.wallet.get_transactions(name)
if #transactions < 1 then if #transactions < 1 then
table.insert(formspec,"label[3.5,5;There are no transactions]") table.insert(formspec,"label[3.5,4;There are no transactions]")
else else
local y = 4 local y = 3
for _,transac in pairs(transactions) do for _,transac in pairs(transactions) do
table.insert(formspec,"label[0,"..y..";".. transac .."]") table.insert(formspec,"label[1.5,"..y..";".. transac .."]")
y = y+0.4 y = y+0.4
end end
end end
@ -148,12 +147,11 @@ end
function minercantile.get_formspec_wallet_transfert(name) function minercantile.get_formspec_wallet_transfert(name)
local money = minercantile.wallet.get_money(name) local money = minercantile.wallet.get_money(name)
local formspec = {} local formspec = {}
table.insert(formspec,"size[10,9]label[4.4,0;My Wallet]") table.insert(formspec,"size[10,9]bgcolor[#2A2A2A;]label[4.4,0;My Wallet]")
table.insert(formspec,"image[1,2;1,1;minercantile_money.png]") table.insert(formspec,"label[0.5,1;Sold: ".. tostring(money) .."$]")
table.insert(formspec,"label[2,2.2;total:".. tostring(money) .."]")
if money < 5 then if money < 5 then
table.insert(formspec, "label[2,4.5;Sorry you can't send Minecoins, minimum amount is 5]") table.insert(formspec, "label[2,4.5;Sorry you can't send money, minimum amount is 5$]")
else else
if not states[name] then if not states[name] then
states[name] = {} states[name] = {}
@ -178,10 +176,10 @@ function minercantile.get_formspec_wallet_transfert(name)
table.insert(formspec,"button[6,3.4;2,1;refresh;refresh list]") table.insert(formspec,"button[6,3.4;2,1;refresh;refresh list]")
else else
table.insert(formspec, "dropdown[3,3.5;3,1;receiver;"..table.concat(states[name].players_list, ",")..";"..states[name].selected_id.."]") table.insert(formspec, "dropdown[3,3.5;3,1;receiver;"..table.concat(states[name].players_list, ",")..";"..states[name].selected_id.."]")
table.insert(formspec, "label[3.5,6.5;Send "..states[name]["amount"].." to "..(states[name]["receiver"] or "").." ?]") table.insert(formspec, "label[3.5,6.4;Send "..states[name]["amount"].."$ to "..(states[name]["receiver"] or "").." ?]")
table.insert(formspec,"button[4.1,7;1.5,1;send;send]") table.insert(formspec,"button[4.1,7;1.5,1;send;send]")
table.insert(formspec,"button[6,3.4;1.5,1;refresh;refresh list]") table.insert(formspec,"button[6,3.4;1.5,1;refresh;refresh list]")
table.insert(formspec, "label[3.5,4.5;amount to send(minimum 5)]") table.insert(formspec, "label[3.5,4.5;Amount to send (minimum 5$)]")
table.insert(formspec, "button[1.7,5;1,1;amount;-1]") table.insert(formspec, "button[1.7,5;1,1;amount;-1]")
table.insert(formspec, "button[2.7,5;1,1;amount;-10]") table.insert(formspec, "button[2.7,5;1,1;amount;-10]")
table.insert(formspec, "button[3.7,5;1,1;amount;-100]") table.insert(formspec, "button[3.7,5;1,1;amount;-100]")
@ -198,8 +196,8 @@ end
function minercantile.get_formspec_wallet_transfert_send(name) function minercantile.get_formspec_wallet_transfert_send(name)
local formspec = {"size[6,3]label[2,0;Validate sending]"} local formspec = {"size[6,3]bgcolor[#2A2A2A;]label[2,0;Validate sending]"}
table.insert(formspec, "label[1,1.2;Send "..tostring(states[name]["amount"]).." Minecoins to ".. states[name]["receiver"] .."]") table.insert(formspec, "label[2,1.2;Send "..tostring(states[name]["amount"]).."$ to ".. states[name]["receiver"] .."]")
table.insert(formspec, "button_exit[1.1,2.1;1.5,1;close;Abort]") table.insert(formspec, "button_exit[1.1,2.1;1.5,1;close;Abort]")
table.insert(formspec, "button[3.3,2.1;1.5,1;send;Send]") table.insert(formspec, "button[3.3,2.1;1.5,1;send;Send]")
return table.concat(formspec) return table.concat(formspec)
@ -258,9 +256,9 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
elseif formname == "minercantile:transfert_send" then elseif formname == "minercantile:transfert_send" then
if fields["send"] then if fields["send"] then
if minercantile.send_money( name, states[name]["receiver"], states[name]["amount"]) then if minercantile.send_money( name, states[name]["receiver"], states[name]["amount"]) then
minetest.show_formspec(name, "minercantile:ended", "size[5,3]label[1.8,0;Validated]label[1.6,1;Minecoins sent]button_exit[1.8,2.1;1.5,1;close;Close]") minetest.show_formspec(name, "minercantile:ended", "size[5,3]bgcolor[#2A2A2A;]label[1.8,0;Validated]label[1.7,1;Money sent]button_exit[1.8,2.1;1.5,1;close;Close]")
else else
minetest.show_formspec(name, "minercantile:ended", "size[5,3]label[1.6,0;Error]label[1.5,1;Error occured]button_exit[1.8,2.1;1.5,1;close;Close]") minetest.show_formspec(name, "minercantile:ended", "size[5,3]bgcolor[#2A2A2A;]label[1.6,0;Error]label[1.6,1;Error occured]button_exit[1.8,2.1;1.5,1;close;Close]")
end end
elseif fields["quit"] or fields["close"] then elseif fields["quit"] or fields["close"] then
states[name] = nil states[name] = nil
@ -273,7 +271,7 @@ end)
if (minetest.get_modpath("unified_inventory")) then if (minetest.get_modpath("unified_inventory")) then
unified_inventory.register_button("wallet", { unified_inventory.register_button("wallet", {
type = "image", type = "image",
image = "minercantile_money.png", image = "minercantile_gold_coin.png",
tooltip = "My Wallet", tooltip = "My Wallet",
show_with = "interact", show_with = "interact",
action = function(player) action = function(player)