Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- os.pullEvent = os.pullEventRaw
- local order = "";
- local price = 0
- local passAccettata = false
- local ben = peripheral.wrap("back")
- -- IMPLEMENTAZIONE DEL DRAWFILLEDBOX
- local function drawPixelInternal(xPos, yPos)
- term.setCursorPos(xPos, yPos)
- term.write(" ")
- end
- local tColourLookup = {}
- for n = 1, 16 do
- tColourLookup[string.byte("0123456789abcdef", n, n)] = 2 ^ (n - 1)
- end
- function drawFilledBox(startX, startY, endX, endY, nColour)
- if type(startX) ~= "number" or type(startX) ~= "number" or type(endX) ~=
- "number" or type(endY) ~= "number" or
- (nColour ~= nil and type(nColour) ~= "number") then
- error("Expected startX, startY, endX, endY, colour", 2)
- end
- startX = math.floor(startX)
- startY = math.floor(startY)
- endX = math.floor(endX)
- endY = math.floor(endY)
- if nColour then term.setBackgroundColor(nColour) end
- if startX == endX and startY == endY then
- drawPixelInternal(startX, startY)
- return
- end
- local minX = math.min(startX, endX)
- if minX == startX then
- minY = startY
- maxX = endX
- maxY = endY
- else
- minY = endY
- maxX = startX
- maxY = startY
- end
- for x = minX, maxX do for y = minY, maxY do drawPixelInternal(x, y) end end
- end
- function clear()
- sfondo(colors.black)
- term.clear()
- term.setCursorPos(1, 1)
- end
- function clearRed()
- sfondo(colors.red)
- term.clear()
- term.setCursorPos(1, 1)
- end
- function colore(sfumatura) term.setTextColour(sfumatura) end
- function sfondo(sfumaturaSfondo) term.setBackgroundColour(sfumaturaSfondo) end
- function fineColore() term.setTextColour(colours.white) end
- function fineSfondo() term.setBackgroundColour(colours.black) end
- function paga(prezzo,id,modid,qty)
- sfondo(colours.blue)
- term.clear()
- term.setCursorPos(1, 1)
- sfondo(colours.blue)
- colore(colors.white)
- print(
- "\n\nInserire i propri dati. Premere Enter per confermare i dati inseriti. \nSe i dati sono corretti, il campo diventeråA5A0 verde. Se sono errati, il programma chiederåA5A0 di reinserirli nuovamente.")
- -- nomeutente
- term.setCursorPos(1, 9)
- term.write("Nome utente:")
- term.setCursorPos(15, 9)
- fineColore()
- utenteAccettato = false
- conteggioErrori = 0
- while utenteAccettato == false do
- utente = read()
- checkuser = http.get(
- "http://172.16.20.220/luanet/servlets/nebraskapay.php?auth=no&richiesta=verifica&utente=" ..
- utente).readAll()
- tabcheckuser = textutils.unserialize(checkuser)
- if tabcheckuser.stato == "OK" then
- term.setCursorPos(15, 9)
- colore(colours.lime)
- term.write(utente)
- fineColore()
- utenteAccettato = true
- else
- term.setCursorPos(15, 9)
- colore(colours.red)
- term.write("Utente errato! ")
- sleep(2)
- term.setCursorPos(15, 9)
- fineColore()
- term.write(" ")
- term.setCursorPos(15, 9)
- conteggioErrori = conteggioErrori + 1
- if conteggioErrori > 2 then
- term.setCursorPos(15, 9)
- colore(colours.red)
- errore("Troppi tentativi di immissione errati ")
- end
- end
- end
- colore(colours.white)
- term.setCursorPos(1, 11)
- term.write("Password:")
- term.setCursorPos(15, 11)
- conteggioErrori = 0
- while passAccettata == false do
- fineColore()
- password = read("#")
- colore(colours.black)
- checkuser = http.get(
- "http://172.16.20.220/luanet/servlets/nebraskapay.php?auth=" ..
- password .. "&richiesta=addebito&valore=0&utente=" ..
- utente).readAll()
- risposta = textutils.unserialize(checkuser)
- if risposta.stato == "OK" then
- term.setCursorPos(15, 11)
- colore(colours.lime)
- term.write("############## ")
- fineColore()
- passAccettata = true
- -- rednet.send(6102, order)
- addOrder = http.get("http://192.168.13.103/addOrder.php?order=" .. order .. "&username=" .. utente .. "&password=" .. password .. "&type=pecten")
- sleep(0.4)
- sfondo(colours.yellow)
- term.clear()
- term.setCursorPos(1, 1)
- sfondo(colours.yellow)
- colore(colors.black)
- print(
- "\n\Erogazione in corso, attendere, la ringraziamo per l'acquisto!")
- sleep(2)
- --local requestOrder = http.get("http://192.168.13.103/requestOrder.php?user=" .. utente .. "-" .. "pecten" .. "&location=3110").readAll()
- sleep(10)
- fuelID = ben.getItemIdentifierIDFor(id, modid)
- if(qty == 16 or qty == 32) then
- ben.makeRequest(fuelID, qty)
- elseif(qty == 160) then
- ben.makeRequest(fuelID, 64)
- sleep(17.5)
- ben.makeRequest(fuelID, 64)
- sleep(17.5)
- ben.makeRequest(fuelID, 32)
- elseif(qty == 208) then
- ben.makeRequest(fuelID, 64)
- sleep(17.5)
- ben.makeRequest(fuelID, 64)
- sleep(17.5)
- ben.makeRequest(fuelID, 64)
- sleep(17.5)
- ben.makeRequest(fuelID, 16)
- end
- os.reboot()
- else
- term.setCursorPos(15, 11)
- colore(colours.red)
- term.write("Password errata o credito insufficiente! ")
- conteggioErrori = conteggioErrori + 1
- sleep(2)
- term.setCursorPos(15, 11)
- term.write(" ")
- term.setCursorPos(15, 11)
- if conteggioErrori > 2 then
- term.setCursorPos(15, 11)
- colore(colours.red)
- errore("Troppi tentativi di immissione errati")
- end
- end
- end
- end
- function acquista(product,modid,price)
- term.clear()
- drawFilledBox(1, 1, 51, 19, colors.yellow)
- drawFilledBox(1, 1, 51, 1, colors.orange)
- term.setCursorPos(2, 1)
- colore(colours.white)
- print("PECTEN")
- drawFilledBox(1, 2, 51, 2, colors.red)
- drawFilledBox(1, 3, 51, 21, colors.yellow)
- colore(colors.black)
- drawFilledBox(4, 4, 11, 7, colors.red)
- term.setCursorPos(7, 5)
- print("16")
- term.setCursorPos(5, 6)
- print("secchi")
- drawFilledBox(16, 4, 23, 7, colors.red)
- term.setCursorPos(19, 5)
- print("32")
- term.setCursorPos(17, 6)
- print("secchi")
- drawFilledBox(40, 4, 47, 7, colors.red)
- term.setCursorPos(41, 5)
- print("Pieno")
- term.setCursorPos(41, 6)
- print("vagone")
- drawFilledBox(28, 4, 35, 7, colors.red)
- term.setCursorPos(29, 5)
- print("Pieno")
- term.setCursorPos(29, 6)
- print("loco")
- term.setCursorPos(20, 9)
- term.setBackgroundColor( colors.yellow )
- colore(colors.red)
- print("AVVERTENZE:")
- term.setCursorPos(2, 11)
- colore(colors.black)
- print("Mantenere la loco spenta durante il rifornimento")
- selezione = false
- while(selezione == false) do
- local event, par1, x, y = os.pullEvent("mouse_click")
- if event == "mouse_click" and x >= 4 and x <= 11 and y >= 4 and y <= 7 then -- 16
- order = product .. "-" .. modid .. "-16"
- paga(tonumber(price),tonumber(product),tonumber(modid),16)
- -- selezione = true
- elseif event == "mouse_click" and x >= 16 and x <= 23 and y >= 4 and y <= 7 then -- 32
- order = product .. "-" .. modid .. "-32"
- paga(tonumber(price),tonumber(product),tonumber(modid),32)
- elseif event == "mouse_click" and x >= 28 and x <= 35 and y >= 4 and y <= 7 then -- pieno loco
- order = product .. "-" .. modid .. "-160"
- paga(tonumber(price),tonumber(product),tonumber(modid),160)
- elseif event == "mouse_click" and x >= 40 and x <= 47 and y >= 4 and y <= 7 then -- pieno vagone
- order = product .. "-" .. modid .. "-208"
- paga(tonumber(price),tonumber(product),tonumber(modid),208)
- end
- end
- end
- sfondo(colours.yellow)
- term.clear()
- drawFilledBox(13, 3, 13, 9, colors.red)
- drawFilledBox(14, 3, 15, 3, colors.red)
- drawFilledBox(16, 4, 16, 5, colors.red)
- drawFilledBox(14, 6, 15, 6, colors.red)
- drawFilledBox(18, 5, 18, 9, colors.red)
- drawFilledBox(19, 5, 20, 5, colors.red)
- drawFilledBox(19, 9, 20, 9, colors.red)
- drawFilledBox(19, 7, 19, 7, colors.red)
- drawFilledBox(22, 6, 22, 8, colors.red)
- drawFilledBox(23, 5, 24, 5, colors.red)
- drawFilledBox(23, 9, 24, 9, colors.red)
- drawFilledBox(26, 5, 28, 5, colors.red)
- drawFilledBox(27, 6, 27, 9, colors.red)
- drawFilledBox(30, 5, 30, 9, colors.red)
- drawFilledBox(31, 5, 32, 5, colors.red)
- drawFilledBox(31, 9, 32, 9, colors.red)
- drawFilledBox(31, 7, 31, 7, colors.red)
- drawFilledBox(34, 5, 34, 9, colors.red)
- drawFilledBox(37, 5, 37, 9, colors.red)
- drawFilledBox(35, 6, 35, 6, colors.red)
- drawFilledBox(36, 7, 36, 7, colors.red)
- sfondo(colours.yellow)
- colore(colours.black)
- term.setCursorPos(8, 14)
- print("Premi un tasto qualsiasi per iniziare...")
- local event, key = os.pullEvent("key")
- clear()
- drawFilledBox(1, 1, 51, 19, colors.yellow)
- drawFilledBox(1, 1, 51, 1, colors.orange)
- term.setCursorPos(2, 1)
- colore(colours.white)
- print("PECTEN")
- drawFilledBox(1, 2, 51, 2, colors.red)
- local index = -1
- term.setCursorPos(44, 1)
- colore(colors.black)
- sfondo(colors.red)
- term.write("Annulla")
- local productsRaw = http.get("http://172.16.20.220/luanet/servlets/test.txt").readAll()
- products = textutils.unserialize(productsRaw)
- for k, v in pairs(products) do
- if(index == tonumber(v.page)) then
- term.setCursorPos(3, tonumber(v.PagePosition))
- term.setBackgroundColor( colors.yellow )
- colore(colors.black)
- if type(v.prezzo) == "string" then
- term.write(v.nome)
- term.setCursorPos(30, tonumber(v.PagePosition))
- term.write(tostring(v.prezzo) .. " IC")
- else
- term.write(v.nome)
- end
- term.setCursorPos(3, tonumber(v.PagePosition))
- if not (v.categoria == "lista") then
- colore(colors.black)
- term.setBackgroundColor( colors.red )
- term.setCursorPos(39, tonumber(v.PagePosition))
- term.write("seleziona")
- term.setBackgroundColor( colors.yellow )
- end
- end
- end
- click = false
- while(click == false) do
- local event, par1, x, y = os.pullEvent("mouse_click")
- for k, v in pairs(products) do
- if (v.PagePosition ~= nil) then
- if event == "mouse_click" and x >= 39 and x <= 49 and y >= tonumber(v.PagePosition) and y <= tonumber(v.PagePosition) then -- seleziona
- if (tonumber(v.page) == index) then
- if not (v.categoria == "lista") then
- term.setCursorPos(1, 1)
- acquista(v.id,v.modId,tonumber(v.prezzo))
- click = true
- end
- end
- elseif event == "mouse_click" and x >= 44 and x <= 50 and y >= 1 and y <= 1 then -- ANNULLA
- os.reboot()
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment