summaryrefslogtreecommitdiff
path: root/shop2/main.lua
diff options
context:
space:
mode:
Diffstat (limited to 'shop2/main.lua')
-rw-r--r--shop2/main.lua39
1 files changed, 10 insertions, 29 deletions
diff --git a/shop2/main.lua b/shop2/main.lua
index c110f83..322d76c 100644
--- a/shop2/main.lua
+++ b/shop2/main.lua
@@ -1,5 +1,9 @@
+package.path = "/?;/?.lua;"..package.path
+
local key=assert(settings.get"krist.pkey","please set private key")
-local pp = require"cc.pretty".pretty_print
+
+local stock=require"shop2.stock"
+
-- ac.kst
local OURNAME = "ac"
@@ -10,7 +14,6 @@ end
i("dmn","minecraft:diamond","Diamond",5)
i("blz","minecraft:blaze_rod","Blaze Rod",10)
i("ely","minecraft:elytra","Elytra",200)
-i=nil
local sres =textutils.unserializeJSON( http.post("https://krist.dev/ws/start","privatekey="..key).readAll())
@@ -40,25 +43,6 @@ local function parsemeta(m)
end
return out
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(stock_amt(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
local function proctrans(tr)
if tr.to ~= our_addr then return end
@@ -82,8 +66,8 @@ local function proctrans(tr)
tell("i can only give you a whole number of items. make sure the amount you gave me is a multiple of "..idesc.price)
refund()
else
- local si = take_stock()
- local in_stock = stock_amt(si,idesc)
+ local si = stock.take_stock()
+ local in_stock = stock.amt_of(si,idesc)
if in_stock == 0 then
tell("we are out of stock! please yell at ubq323 about this")
refund()
@@ -93,7 +77,7 @@ local function proctrans(tr)
tell("i don't have that many items in stock, sorry")
refund()
else
- give(si,idesc,to_give)
+ stock.give(si,idesc,to_give)
tell("thank you!!! :3")
end
end
@@ -103,9 +87,9 @@ end
local function run_shop()
print("RUNSHOP")
while true do
- msgtxt = assert(ws.receive(),"ws error")
+ local msgtxt = assert(ws.receive(),"ws error")
print(msgtxt)
- msg = textutils.unserializeJSON(msgtxt)
+ local msg = textutils.unserializeJSON(msgtxt)
if msg.type == "response" and msg.responding_to_type == "me" then
our_addr = msg.address.address
end
@@ -116,9 +100,6 @@ local function run_shop()
end
end
-local function run_sidedisp()
-end
-
print(pcall(parallel.waitForAny,run_shop))
-- print("hi")
-- peripheral.call("top","clear")