From 14d9a9cdc023c1abea03fae80ad537f86634b723 Mon Sep 17 00:00:00 2001 From: jingkaimori Date: Wed, 10 Nov 2021 17:29:56 +0800 Subject: enhanced offer info --- init.lua | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/init.lua b/init.lua index 16f85d6..f97e7bd 100644 --- a/init.lua +++ b/init.lua @@ -90,12 +90,28 @@ smartshop.get_offer=function(pos) local inv=meta:get_inventory() local offer={} for i=1,4,1 do + local pay_stack = inv:get_stack("pay" .. i,1); + local give_stock = 0; offer[i]={ - give=inv:get_stack("give" .. i,1):get_name(), - give_count=inv:get_stack("give" .. i,1):get_count(), - pay=inv:get_stack("pay" .. i,1):get_name(), - pay_count=inv:get_stack("pay" .. i,1):get_count(), + give=inv:get_stack("give" .. i,1):get_name(), + give_count=inv:get_stack("give" .. i,1):get_count(), + pay=pay_stack:get_name(), + pay_count=pay_stack:get_count(), + stock = 0, -- times customer can purchase before sold out + pay_price = 0, -- average minegeld price of sold item, nonzero for minegeld-taking selling shop } + local mg_price = smartshop.minegeldtonumber(pay_stack) + if mg_price ~= nil then + offer[i].pay_price = mg_price/offer[i].give_count + end + for ii=1,32,1 do + local name=inv:get_stack("main",ii):get_name() + local count=inv:get_stack("main",ii):get_count() + if name==offer[i].give then + give_stock = give_stock + count + end + end + offer[i].stock = math.floor(give_stock/offer[i].give_count) end return offer end -- cgit v1.2.3