calc prices for items
parent
1b38168117
commit
9b56c0ac56
25
api.lua
25
api.lua
|
@ -4,6 +4,25 @@ function kiosk.demangle_for_formspec(str)
|
|||
return string.gsub(str, "_([0-9]+)_", function (v) return string.char(v) end)
|
||||
end
|
||||
|
||||
kiosk.add_inv=function(name,def)
|
||||
if name == nil then return end
|
||||
def.name = name
|
||||
if def.buy == nil then
|
||||
def.buy=1
|
||||
end
|
||||
if def.sell == nil then
|
||||
def.sell = 1
|
||||
end
|
||||
if def.sell > def.buy then
|
||||
def.sell = kiosk.sell_factor * def.buy
|
||||
end
|
||||
if def.stock==nil then def.stock=0 end
|
||||
|
||||
if kiosk.inventar[name] ~= nil then kiosk.inventar[name] = nil end
|
||||
|
||||
kiosk.inventar[name] = def
|
||||
|
||||
end
|
||||
|
||||
kiosk.add_inventar=function(name,buy_value,sell_value,stock,fixed)
|
||||
if name == nil then
|
||||
|
@ -28,7 +47,7 @@ kiosk.add_inventar=function(name,buy_value,sell_value,stock,fixed)
|
|||
if kiosk.inventar[name] == nil then
|
||||
local kinv = {name = name,
|
||||
sell = sell_value,
|
||||
buy = sell_value,
|
||||
buy = buy_value,
|
||||
stock=stock,
|
||||
}
|
||||
if fixed ~= nil then kinv.fixed=fixed end
|
||||
|
@ -43,6 +62,10 @@ kiosk.add_inventar=function(name,buy_value,sell_value,stock,fixed)
|
|||
end
|
||||
end
|
||||
|
||||
kiosk.is_inventar=function(name)
|
||||
return kiosk.inventar[name] ~= nil
|
||||
end
|
||||
|
||||
kiosk.get_value=function(name,value)
|
||||
if name == nil then return end
|
||||
if kiosk.inventar[name] == nil then
|
||||
|
|
91
config.lua
91
config.lua
|
@ -15,20 +15,91 @@ for i,mg in ipairs({"currency:minegeld","currency:minegeld_5","currency:minegeld
|
|||
end
|
||||
end
|
||||
|
||||
kiosk.map_nodes={}
|
||||
kiosk.craftitems={}
|
||||
kiosk.map_stat={}
|
||||
for i,k in pairs(minetest.registered_nodes) do
|
||||
if k.drop then
|
||||
table.insert(kiosk.map_nodes,i)
|
||||
kiosk.map_stat[i]=0
|
||||
local has_value = basic_functions.has_value
|
||||
local price_cols={
|
||||
col_num={"buy_value","sell_value"},}
|
||||
local price_def = basic_functions.import_csv(kiosk.path.."/initial_prices.txt",price_cols)
|
||||
local int_pri={}
|
||||
for i,v in pairs(price_def) do
|
||||
v.groups=nil
|
||||
kiosk.add_inv(i,v)
|
||||
local reci=minetest.get_all_craft_recipes(i)
|
||||
-- print(dump2(reci))
|
||||
if reci ~= nil then
|
||||
for j,w in pairs(reci) do
|
||||
local count = w.output:split(" ")[2]
|
||||
if count == nil then count = 1 end
|
||||
if #w.items==1 then
|
||||
local nit=w.items[1]
|
||||
if int_pri[nit] == nil then
|
||||
int_pri[nit]={v.buy*count/0.9}
|
||||
else
|
||||
table.insert(int_pri[nit],v.buy*count/0.9)
|
||||
end
|
||||
else
|
||||
local in_it={}
|
||||
local vb=v.buy*count/(0.9*#w.items)
|
||||
for n=1,#w.items do
|
||||
if in_it[w.items[n]]==nil then
|
||||
in_it[w.items[n]]=1
|
||||
else
|
||||
in_it[w.items[n]]=1+in_it[w.items[n]]
|
||||
end
|
||||
end
|
||||
for n,c in pairs(in_it) do
|
||||
if int_pri[n] == nil then
|
||||
int_pri[n]={vb*c}
|
||||
else
|
||||
table.insert(int_pri[n],vb*c)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
if #minetest.get_craft_recipe(i) > 0 then
|
||||
table.insert(kiosk.craftitems,i)
|
||||
local reci=minetest.get_craft_result({method="cooking",items={i}})
|
||||
if reci.time > 0 then
|
||||
local output=reci.item:get_name()
|
||||
local count = output:split(" ")[2]
|
||||
if count == nil then count = 1 end
|
||||
if int_pri[output] == nil then
|
||||
int_pri[output]={v.buy+reci.time/20}
|
||||
else
|
||||
table.insert(int_pri[output],v.buy+reci.time/20)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local new_inv={}
|
||||
for i,v in pairs(minetest.registered_nodes) do
|
||||
local node_price=0
|
||||
if v.groups then
|
||||
for j,w in pairs({[10]="cracky",[8]="choppy",[5]="snappy",[3]="crumbly",[1]="fleshy"}) do
|
||||
if v.groups[w]~=nil then node_price=j*v.groups[w] end
|
||||
end
|
||||
end
|
||||
-- print(dump2(v))
|
||||
if v.drop ~= nil and node_price > 0 then
|
||||
if type(v.drop)=="string" then
|
||||
if not kiosk.is_inventar(v.drop) then
|
||||
print(dump2(v.drop))
|
||||
if new_inv[v.drop]==nil then
|
||||
new_inv[v.drop]={node_price/10}
|
||||
else
|
||||
table.insert(new_inv[v.drop],node_price/10)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
for i,v in pairs(new_inv) do
|
||||
print(i,#v)
|
||||
end
|
||||
--print(dump2(new_inv))
|
||||
--print(dump2(int_pri))
|
||||
--print(dump2(kiosk.inventar))
|
||||
|
||||
|
||||
print(dump2(minetest.registered_items["default:coal_lump"]))
|
||||
-- initialise map_extend with values, which are corrected in first run
|
||||
kiosk.map_extend={emin={x=31000,y=31000,z=31000},emax={x=(-31000),y=(-31000),z=(-31000)},volume=0}
|
||||
|
||||
print(#kiosk.map_nodes)
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
name,buy,sell
|
||||
default:cobble,0.1,0.095
|
||||
default:gravel,0.09,0.085
|
||||
default:clay_lump,0.09,0.085
|
||||
default:gold_lump,15,14
|
||||
default:diamond,20,19.5
|
||||
default:desert_cobble,0.1,0.095
|
||||
default:sand,0.05,0.045
|
||||
default:silver_sand,0.05,0.045
|
||||
default:ice,0.05,0.045
|
||||
default:desert_sand,0.05,0.045
|
||||
default:iron_lump,0.5,0.45
|
1
mod.conf
1
mod.conf
|
@ -3,5 +3,6 @@ title = kiosk
|
|||
author = ademant
|
||||
description = Global trading via unified_inventories
|
||||
depends = default,basic_functions,unified_inventory,xpfw
|
||||
optional_depends = technic
|
||||
license = MIT
|
||||
version = 1.0.0
|
||||
|
|
31
register.lua
31
register.lua
|
@ -208,36 +208,5 @@ minetest.register_on_generated(function(minp,maxp,seed)
|
|||
kiosk.map_extend.volume=kiosk.map_extend.volume+gen_vol
|
||||
print(dump2(kiosk.map_extend))
|
||||
|
||||
print("ping")
|
||||
local starttime=os.clock()
|
||||
local found=0
|
||||
local map_stat=kiosk.map_stat
|
||||
local forcount=0
|
||||
--[[ for i in pairs(kiosk.map_nodes) do
|
||||
local lnode=#minetest.find_nodes_in_area(minp,maxp,i)
|
||||
forcount=forcount+1
|
||||
if lnode>0 then
|
||||
map_stat[i]=map_stat[i]+lnode
|
||||
found=found+lnode
|
||||
print(v,i,lnode,found)
|
||||
if found>= gen_vol then print("pong",forcount) break end
|
||||
end
|
||||
end]]
|
||||
print((os.clock()-starttime),forcount)
|
||||
table.sort(kiosk.map_nodes,mn_compare)
|
||||
-- print(dump2(kiosk.map_stat))
|
||||
|
||||
end)
|
||||
|
||||
minetest.register_abm({
|
||||
-- change wetness of soil by time
|
||||
label = "count",
|
||||
nodenames = {"group:cracky"},
|
||||
interval = 15,
|
||||
chance = 1,
|
||||
action = function(pos, node)
|
||||
local name=node.name
|
||||
if kiosk.map_stat[name] == nil then kiosk.map_stat[name] = 0 end
|
||||
kiosk.map_stat[name]=kiosk.map_stat[name]+1
|
||||
end
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue