summaryrefslogtreecommitdiff
path: root/shop2/stock.lua
diff options
context:
space:
mode:
authorubq323 <ubq323@ubq323.website>2023-01-07 05:15:11 +0000
committerubq323 <ubq323@ubq323.website>2023-01-07 05:15:11 +0000
commitc3d1cdb9d7ccc5cd7502a7bccc4207a17a27c525 (patch)
tree813d7bb6d9a968adea203ff914449838d3581140 /shop2/stock.lua
parentd295f4756237d981259e37a2d924f064e7f1fde5 (diff)
shop2
Diffstat (limited to 'shop2/stock.lua')
-rw-r--r--shop2/stock.lua24
1 files changed, 23 insertions, 1 deletions
diff --git a/shop2/stock.lua b/shop2/stock.lua
index ce76bf0..71a6844 100644
--- a/shop2/stock.lua
+++ b/shop2/stock.lua
@@ -27,7 +27,7 @@ local function item_desc_matches(idesc,itemdetail)
return idesc.itname == itemdetail.name
end
-local function stock_amt(stockinfo,idesc)
+local function amt_of(stockinfo,idesc)
local total = 0
for ix,itm in pairs(stockinfo) do
if item_desc_matches(idesc,itm) then
@@ -37,3 +37,25 @@ local function stock_amt(stockinfo,idesc)
return total
end
+local function give(stockinfo,idesc,amt)
+ amt = amt or 1
+ -- assumes that we have at least amt in stock already
+ -- actually no, might as well double check this anyway
+ assert(amt_of(stockinfo,idesc) >= amt)
+ assert(amt>0)
+ -- make sure current turtle inv slot is empty
+ assert(turtle.getItemCount() == 0)
+
+ for slotidx,idtl in pairs(stockinfo) do
+ if item_desc_matches(idesc,idtl) then
+ local a = math.min(amt,idtl.count)
+ chest.pushItems(localname, slotidx, a, 1)
+ turtle.drop(a)
+ amt = amt - a
+ if amt <= 0 then break end
+ end
+ end
+end
+
+
+return {take_stock=take_stock,amt_of=amt_of,give=give}