Advertisement
lego11

Ingrosso Roxas LP

Jun 21st, 2021 (edited)
933
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local maxw, maxh = term.getSize()
  2.  
  3. function creditoInsufficiente()
  4.     clearRed()
  5.     print("Credito insufficiente.")
  6.     print("")
  7.     print("Premere un tasto per uscire")
  8.     os.pullEvent("key")
  9.     os.reboot()
  10. end
  11.  
  12. function prodottoEsaurito()
  13.     clearRed()
  14.     print("Prodotto esaurito.")
  15.     print("")
  16.     print("Premere un tasto per uscire")
  17.     os.pullEvent("key")
  18.     os.reboot()
  19. end
  20.  
  21. -- IMPLEMENTAZIONE DEL DRAWFILLEDBOX
  22. local function drawPixelInternal(xPos, yPos)
  23.     term.setCursorPos(xPos, yPos)
  24.     term.write(" ")
  25. end
  26.  
  27. local tColourLookup = {}
  28. for n = 1, 16 do
  29.     tColourLookup[string.byte("0123456789abcdef", n, n)] = 2 ^ (n - 1)
  30. end
  31.  
  32. function drawFilledBox(startX, startY, endX, endY, nColour)
  33.     if type(startX) ~= "number" or type(startX) ~= "number" or type(endX) ~=
  34.         "number" or type(endY) ~= "number" or
  35.         (nColour ~= nil and type(nColour) ~= "number") then
  36.         error("Expected startX, startY, endX, endY, colour", 2)
  37.     end
  38.  
  39.     startX = math.floor(startX)
  40.     startY = math.floor(startY)
  41.     endX = math.floor(endX)
  42.     endY = math.floor(endY)
  43.  
  44.     if nColour then term.setBackgroundColor(nColour) end
  45.     if startX == endX and startY == endY then
  46.         drawPixelInternal(startX, startY)
  47.         return
  48.     end
  49.  
  50.     local minX = math.min(startX, endX)
  51.     if minX == startX then
  52.         minY = startY
  53.         maxX = endX
  54.         maxY = endY
  55.     else
  56.         minY = endY
  57.         maxX = startX
  58.         maxY = startY
  59.     end
  60.  
  61.     for x = minX, maxX do for y = minY, maxY do drawPixelInternal(x, y) end end
  62. end
  63.  
  64. function clear()
  65.     sfondo(colors.black)
  66.     term.clear()
  67.     term.setCursorPos(1, 1)
  68. end
  69.  
  70. function clearRed()
  71.     sfondo(colors.red)
  72.     term.clear()
  73.     term.setCursorPos(1, 1)
  74. end
  75.  
  76. function colore(sfumatura) term.setTextColour(sfumatura) end
  77.  
  78. function sfondo(sfumaturaSfondo) term.setBackgroundColour(sfumaturaSfondo) end
  79.  
  80. function fineColore() term.setTextColour(colours.white) end
  81.  
  82. function fineSfondo() term.setBackgroundColour(colours.black) end
  83.  
  84. function titolo(testo)
  85.     drawFilledBox(1, 1, maxw, 1, colors.yellow)
  86.     term.setCursorPos((maxw - #testo) / 2, 1)
  87.     colore(colors.black)
  88.     term.write(testo)
  89.     sfondo(colors.blue)
  90. end
  91.  
  92. function errore(errore)
  93.     sfondo(colors.red)
  94.     colore(colors.white)
  95.     term.clear()
  96.     term.setCursorPos(1, 1)
  97.     titolo("Errore irreversibile")
  98.     term.setCursorPos(1, 3)
  99.     sfondo(colors.red)
  100.     colore(colors.white)
  101.     print(errore)
  102.     print("\n\n\nAttendere qualche secondo...")
  103.     os.sleep(5)
  104.     os.reboot()
  105. end
  106.  
  107. sfondo(colours.blue)
  108.     term.clear()
  109.     term.setCursorPos(1, 1)
  110.     titolo("Pagamento rapido con Nebraska Pay")
  111.     sfondo(colours.blue)
  112.     colore(colors.white)
  113.     print(
  114.         "\n\nInserire i propri dati. Premere Enter per confermare i dati inseriti. \nSe i dati sono corretti, il campo diventerà verde. Se sono errati, il programma chiederà di reinserirli nuovamente.")
  115.  
  116.     -- nomeutente
  117.     term.setCursorPos(1, 9)
  118.     term.write("Nome utente:")
  119.     term.setCursorPos(15, 9)
  120.     fineColore()
  121.     utenteAccettato = false
  122.     conteggioErrori = 0
  123.     while utenteAccettato == false do
  124.         utente = read()
  125.         checkuser = http.get(
  126.                         "http://172.16.20.220/luanet/servlets/nebraskapay.php?auth=no&richiesta=verifica&utente=" ..
  127.                             utente).readAll()
  128.         tabcheckuser = textutils.unserialize(checkuser)
  129.         if tabcheckuser.stato == "OK" then
  130.             term.setCursorPos(15, 9)
  131.             colore(colours.lime)
  132.             term.write(utente)
  133.             fineColore()
  134.             utenteAccettato = true
  135.         else
  136.             term.setCursorPos(15, 9)
  137.             colore(colours.red)
  138.             term.write("Utente errato!          ")
  139.             sleep(2)
  140.             term.setCursorPos(15, 9)
  141.             fineColore()
  142.             term.write("                       ")
  143.             term.setCursorPos(15, 9)
  144.             conteggioErrori = conteggioErrori + 1
  145.             if conteggioErrori > 2 then
  146.                 term.setCursorPos(15, 9)
  147.                 colore(colours.red)
  148.                 errore("Troppi tentativi di immissione errati    ")
  149.             end
  150.         end
  151.     end
  152.     colore(colours.white)
  153.     term.setCursorPos(1, 11)
  154.     term.write("Password:")
  155.     term.setCursorPos(15, 11)
  156.     conteggioErrori = 0
  157.     passAccettata = false
  158.     while passAccettata == false do
  159.         fineColore()
  160.         password = read("#")
  161.         colore(colours.black)
  162.         checkuser = http.get(
  163.                         "http://172.16.20.220/luanet/servlets/nebraskapay.php?auth=" ..
  164.                             password .. "&richiesta=addebito&valore=0&utente=" ..
  165.                             utente).readAll()
  166.         risposta = textutils.unserialize(checkuser)
  167.         if risposta.stato == "OK" then
  168.             term.setCursorPos(15, 11)
  169.             colore(colours.lime)
  170.             term.write("##############               ")
  171.             fineColore()
  172.             passAccettata = true
  173.         else
  174.             term.setCursorPos(15, 11)
  175.             colore(colours.red)
  176.             term.write("Password errata!            ")
  177.             conteggioErrori = conteggioErrori + 1
  178.             sleep(2)
  179.             term.setCursorPos(15, 11)
  180.             term.write("                               ")
  181.             term.setCursorPos(15, 11)
  182.             if conteggioErrori > 2 then
  183.                 term.setCursorPos(15, 11)
  184.                 colore(colours.red)
  185.                 errore("Troppi tentativi di immissione errati")
  186.             end
  187.         end
  188.     end
  189.  
  190. while true do
  191.     clear()
  192.     titolo("ROXAS MINING COMPANY             ")
  193.     colore(colors.white)
  194.     sfondo(colors.red)
  195.     term.setCursorPos(35, 1)
  196.     term.write(" CHIUDI SESSIONE ")
  197.     fineColore()
  198.     fineSfondo()
  199.     print("")
  200.     print("\nProdotto           Prezzo")
  201.     p = {}
  202.     -- nome, prezzo, id, meta, colore cavo
  203.     p[1] = {"Zirconi", 60, 16311, 0, 1}
  204.     p[2] = {"Uraninite", 864, 146, 10, 2}
  205.  
  206.     ypos = 4
  207.     for k, v in pairs(p) do
  208.         term.setCursorPos(1, ypos)
  209.         term.write(v[1])
  210.         term.setCursorPos(20, ypos)
  211.         term.write(v[2])
  212.         term.setCursorPos(30, ypos)
  213.         if alt == false then
  214.             sfondo(colors.lightBlue)
  215.             alt = true
  216.         else
  217.             sfondo(colors.blue)
  218.             alt = false
  219.         end
  220.         colore(colors.white)
  221.         term.write(" Compra ")
  222.         fineSfondo()
  223.         fineColore()
  224.         ypos = ypos + 1
  225.     end
  226.  
  227.     while true do
  228.  
  229.         local event, par1, x, y = os.pullEvent("mouse_click")
  230.         if event == "mouse_click" and y > 3 and y < 6 then
  231.             prodotto = p[y - 3]
  232.             break
  233.         elseif event == "mouse_click" and y == 1 then
  234.             os.reboot()
  235.         end
  236.         sleep(1)
  237.     end
  238.     clear()
  239.  
  240.     print(prodotto[1])
  241.  
  242.     if colors.test(redstone.getBundledInput("bottom"), prodotto[5]) == true then
  243.         prodottoEsaurito()
  244.     end
  245.     term.clear()
  246.     term.setCursorPos(1, 1)
  247.     titolo("Paga con Nebraska Pay")
  248.     sfondo(colours.black)
  249.     colore(colors.white)
  250.     print("\n\nSaldo disponibile: " .. risposta.saldo .. " IC")
  251.     if tonumber(risposta.saldo) >= tonumber(prodotto[2]) then
  252.         prezzoAccettato = true
  253.     else
  254.         errore("Disponibilità insufficiente!")
  255.     end
  256.     term.setCursorPos(1, 3)
  257.     term.write("Invio di ")
  258.     term.write(prodotto[2])
  259.     term.write(" IC a favore di ")
  260.     term.write("Highland Mining")
  261.     print("\n\nConfermare l'operazione?")
  262.     colore(colors.yellow)
  263.     print("\n\nInvia il denaro           Annulla")
  264.     while true do
  265.         event, key, x, y = os.pullEvent()
  266.         if event == "mouse_click" and x < 16 and y == 8 then
  267.             inviaDenaro = http.get(
  268.                               "http://172.16.20.220/luanet/servlets/nebraskapay.php?auth=" ..
  269.                                   password .. "&utente=" .. utente ..
  270.                                   "&richiesta=trasferimento&valore=" ..
  271.                                   prodotto[2] .. "&beneficiario=HighlandMining&causale=Merce%20ingrosso%20Roxas")
  272.                               .readAll()
  273.             risultatoInvio = textutils.unserialize(inviaDenaro)
  274.             if risultatoInvio.stato == "OK" then
  275.                 break
  276.             else
  277.                 clear()
  278.                 errore("Errore durante il pagamento")
  279.             end
  280.         elseif event == "mouse_click" and x > 18 and y == 8 then
  281.             errore("Pagamento annullato dall'utente.")
  282.         end
  283.     end
  284.     clear()
  285.     titolo("Erogazione in corso")
  286.     fineSfondo()
  287.     fineColore()
  288.     print("\n\nErogazione di un vagone di " .. prodotto[1] .. " in corso...")
  289.     print("\nATTENZIONE: IMPIANTO LOGISTIC LENTO, ATTENDERE")
  290.     sfondo(colors.red)
  291.     colore(colors.white)
  292.     ben = peripheral.wrap("back")
  293.     ben.makeRequest(ben.getItemIdentifierIDFor(prodotto[3], prodotto[4]), 3456)
  294.     sleep(10)
  295. end
  296.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement