lego11

Vendita petrolio Pecten

Apr 21st, 2022 (edited)
569
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --Pompa petrolio al rovescio
  2.  
  3. -- Configurazione
  4. local price = 0.3
  5. local meter = peripheral.wrap("bottom")
  6. local meterDisplay = "left"
  7.  
  8. local maxw, maxh = term.getSize()
  9.  
  10. -- Reset variabili
  11. local oil = 0
  12. local contanti = 0
  13.  
  14. -- Accensione display di destra
  15. rs.setOutput("right", true)
  16. -- Blocca contatore
  17. rs.setOutput("bottom", true)
  18.  
  19.  
  20.  
  21. function clear()
  22.     term.clear()
  23.     term.setCursorPos(1, 1)
  24. end
  25.  
  26. function clearRed()
  27.     sfondo(colors.red)
  28.     term.clear()
  29.     term.setCursorPos(1, 1)
  30. end
  31.  
  32. function colore(sfumatura) term.setTextColour(sfumatura) end
  33.  
  34. function sfondo(sfumaturaSfondo) term.setBackgroundColour(sfumaturaSfondo) end
  35.  
  36. function fineColore() term.setTextColour(colours.white) end
  37.  
  38. function fineSfondo() term.setBackgroundColour(colours.black) end
  39.  
  40.  
  41. -- IMPLEMENTAZIONE DEL DRAWFILLEDBOX
  42. local function drawPixelInternal(xPos, yPos)
  43.     term.setCursorPos(xPos, yPos)
  44.     term.write(" ")
  45. end
  46.  
  47. local tColourLookup = {}
  48. for n = 1, 16 do
  49.     tColourLookup[string.byte("0123456789abcdef", n, n)] = 2 ^ (n - 1)
  50. end
  51.  
  52. function drawFilledBox(startX, startY, endX, endY, nColour)
  53.     if type(startX) ~= "number" or type(startX) ~= "number" or type(endX) ~=
  54.         "number" or type(endY) ~= "number" or
  55.         (nColour ~= nil and type(nColour) ~= "number") then
  56.         error("Expected startX, startY, endX, endY, colour", 2)
  57.     end
  58.  
  59.     startX = math.floor(startX)
  60.     startY = math.floor(startY)
  61.     endX = math.floor(endX)
  62.     endY = math.floor(endY)
  63.  
  64.     if nColour then term.setBackgroundColor(nColour) end
  65.     if startX == endX and startY == endY then
  66.         drawPixelInternal(startX, startY)
  67.         return
  68.     end
  69.  
  70.     local minX = math.min(startX, endX)
  71.     if minX == startX then
  72.         minY = startY
  73.         maxX = endX
  74.         maxY = endY
  75.     else
  76.         minY = endY
  77.         maxX = startX
  78.         maxY = startY
  79.     end
  80.  
  81.     for x = minX, maxX do for y = minY, maxY do drawPixelInternal(x, y) end end
  82. end
  83.  
  84.  
  85. function titolo(testo)
  86.     drawFilledBox(1, 1, maxw, 1, colors.yellow)
  87.     term.setCursorPos((maxw - #testo) / 2, 1)
  88.     colore(colors.black)
  89.     term.write(testo)
  90.     term.setBackgroundColor(colors.black)
  91.     colore(colors.white)
  92. end
  93.  
  94. function errore(errore)
  95.     sfondo(colors.red)
  96.     colore(colors.white)
  97.     term.clear()
  98.     term.setCursorPos(1, 1)
  99.     titolo("Errore irreversibile")
  100.     term.setCursorPos(1, 3)
  101.     sfondo(colors.red)
  102.     colore(colors.white)
  103.     print(errore)
  104.     print("\n\n\nAttendere qualche secondo...")
  105.     os.sleep(5)
  106.     os.reboot()
  107. end
  108.  
  109. oil = meter.getAmount()
  110. if oil > 0 then
  111.     -- Sblocca il contatore, così si svuota, attendi e riblocca
  112.     rs.setOutput("bottom", true)
  113.     meter.reset()
  114.     errore("Pompa temporaneamente non disponibile.\n\nLavaggio circuiti in corso...")
  115.     sleep(10)
  116.     rs.setOutput("bottom", false)
  117.     os.reboot()
  118. end
  119.  
  120. clear()
  121. titolo("NuovoPignone DigitalPump")
  122. print("\n\nPECTEN S.p.A.")
  123. print("")
  124. print("Premere un tasto per iniziare l'operazione")
  125. print("")
  126. colore(colors.orange)
  127. print("ATTENZIONE, AVVERTENZA MOLTO IMPORTANTE")
  128. print("NON RIAVVIARE MAI IL COMPUTER DURANTE IL POMPAGGIO")
  129. print("In caso contrario, il petrolio pompato verrà perduto!")
  130. os.pullEvent("key")
  131.  
  132.     sfondo(colours.blue)
  133.     term.clear()
  134.     term.setCursorPos(1, 1)
  135.     titolo("Accredita su Nebraska Pay")
  136.     sfondo(colours.blue)
  137.     colore(colors.white)
  138.     print(
  139.         "\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.")
  140.  
  141.     -- nomeutente
  142.     term.setCursorPos(1, 9)
  143.     term.write("Nome utente:")
  144.     term.setCursorPos(15, 9)
  145.     fineColore()
  146.     utenteAccettato = false
  147.     conteggioErrori = 0
  148.     while utenteAccettato == false do
  149.         utente = read()
  150.         utente = string.gsub(utente, "%s", "")
  151.         checkuser = http.get(
  152.                         "http://172.16.20.220/luanet/servlets/nebraskapay.php?auth=no&richiesta=verifica&utente=" ..
  153.                             utente).readAll()
  154.         tabcheckuser = textutils.unserialize(checkuser)
  155.         if tabcheckuser.stato == "OK" then
  156.             term.setCursorPos(15, 9)
  157.             colore(colours.lime)
  158.             term.write(utente)
  159.             fineColore()
  160.             utenteAccettato = true
  161.         else
  162.             term.setCursorPos(15, 9)
  163.             colore(colours.red)
  164.             term.write("Utente errato!          ")
  165.             sleep(2)
  166.             term.setCursorPos(15, 9)
  167.             fineColore()
  168.             term.write("                       ")
  169.             term.setCursorPos(15, 9)
  170.             conteggioErrori = conteggioErrori + 1
  171.             if conteggioErrori > 2 then
  172.                 term.setCursorPos(15, 9)
  173.                 colore(colours.red)
  174.                 errore("Troppi tentativi di immissione errati    ")
  175.             end
  176.         end
  177.     end
  178.     colore(colours.white)
  179.     term.setCursorPos(1, 11)
  180.     term.write("Password:")
  181.     term.setCursorPos(15, 11)
  182.     conteggioErrori = 0
  183.     passAccettata = false
  184.     while passAccettata == false do
  185.         fineColore()
  186.         password = read("#")
  187.         colore(colours.black)
  188.         checkuser = http.get(
  189.                         "http://172.16.20.220/luanet/servlets/nebraskapay.php?auth=" ..
  190.                             password .. "&richiesta=addebito&valore=0&utente=" ..
  191.                             utente).readAll()
  192.         risposta = textutils.unserialize(checkuser)
  193.         if risposta.stato == "OK" then
  194.             term.setCursorPos(15, 11)
  195.             colore(colours.lime)
  196.             term.write("##############               ")
  197.             fineColore()
  198.             passAccettata = true
  199.         else
  200.             term.setCursorPos(15, 11)
  201.             colore(colours.red)
  202.             term.write("Password errata!            ")
  203.             conteggioErrori = conteggioErrori + 1
  204.             sleep(2)
  205.             term.setCursorPos(15, 11)
  206.             term.write("                               ")
  207.             term.setCursorPos(15, 11)
  208.             if conteggioErrori > 2 then
  209.                 term.setCursorPos(15, 11)
  210.                 colore(colours.red)
  211.                 errore("Troppi tentativi di immissione errati")
  212.             end
  213.         end
  214.     end
  215. metodoPagamento = "NPAY"
  216. credito = tonumber(risposta.saldo)
  217. sfondo(colors.black)
  218. clear()
  219. titolo("NuovoPignone DigitalPump")
  220. while true do
  221. print("\n\n")
  222. print("Il conto ha un saldo di "..credito.." IC.")
  223. print("")
  224. print("Per favore scegliere un'opzione utilizzando i tasti numerici e confermare con ENTER:")
  225. print("")
  226. colore(colors.lime)
  227. print("[1] Scaricare il petrolio")
  228. colore(colors.red)
  229. print("[2] Annullare il pompaggio")
  230. colore(colors.white)
  231. num=tonumber(read())
  232. if num == 1 then
  233. clear()
  234. titolo("NuovoPignone DigitalPump")
  235. sfondo(colors.black)
  236. print("\n\n")
  237. print("Posizionare i vagoni sul dispositivo di pompaggio")
  238. print("")
  239. print("AVVERTENZA IMPORTANTE:")
  240. print("Accetta SOLO petrolio.")
  241. print("")
  242. print("NON RIAVVIARE IL COMPUTER O SI PERDERA' IL VERSAMENTO")
  243. print("")
  244. print("Quando si è pronti per continuare, premere un tasto qualsiasi.")
  245. os.pullEvent("key")
  246.  
  247. --Ricalibra e sblocca il contatore. Accendi display di sinistra
  248. meter.reset()
  249. rs.setOutput(meterDisplay, true)
  250. rs.setOutput("bottom", false)
  251.  
  252. clear()
  253. while true do
  254.     clear()
  255.     titolo("NuovoPignone DigitalPump")
  256.     sfondo(colors.black)
  257.     print("\n\n")
  258.     print("Pompaggio in corso.\n\nPremere il tasto S per terminare.")
  259.     local event, key = os.pullEvent("key")
  260.     if event == "key" and key == 31 then
  261.         break
  262.     end
  263.     sleep(0.1)
  264. end
  265.  
  266. -- Conta il piscio e ricalibra
  267. clear()
  268. titolo("NuovoPignone DigitalPump")
  269. sfondo(colors.black)
  270. print("\n\n")
  271. print("Calibrazione in corso, attendere")
  272. while true do
  273.     oil = meter.getAmount()
  274.     term.setCursorPos(3, 3)
  275.     term.write("*--")
  276.     sleep(1)
  277.     term.setCursorPos(3, 3)
  278.     term.write("-*-")
  279.     sleep(1)
  280.     if oil == meter.getAmount() then
  281.         break
  282.     end
  283.     term.setCursorPos(3, 3)
  284.     term.write("--*")
  285. end
  286.  
  287. --Blocca contatore
  288. rs.setOutput("bottom", true)
  289.  
  290. clear()
  291. -- millibucket -> bucket
  292. oil = oil / 1000
  293.  
  294. contanti = oil * price
  295. titolo ("Vendita completata!")
  296. print("\n\n")
  297. print("Totale pompato:  "..oil.." secchi")
  298. print("Prezzo unitario: "..price.." IC/secchio")
  299. print("Pagato:          "..contanti.." IC")
  300. print("")
  301. sleep(1)
  302.             inviaDenaro = http.get(
  303.                               "http://172.16.20.220/luanet/servlets/pecten/npayproxy.php?beneficiario=" .. utente ..
  304.                                   "&valore=" .. contanti).readAll()
  305.             risultatoInvio = textutils.unserialize(inviaDenaro)
  306.             if risultatoInvio.stato == "OK" then
  307.                 colore(colors.white)
  308.                 alert = http.get("http://172.16.20.220/luanet/servlets/pecten/email_service.php?auth=BEAFFBAC111&npay="  .. utente .. "&qty=" .. contanti .. "&success=true").readAll()
  309.             else
  310.                 clear()
  311.             alert = http.get("http://172.16.20.220/luanet/servlets/pecten/email_service.php?auth=BEAFFBAC111&npay="  .. utente .. "&qty=" .. contanti .. "&success=false").readAll()
  312.                 errore("Errore durante il pagamento.\n\nPer favore contattare un responsabile Pecten.\n\nQuesto evento è stato segnalato al Supporto Tecnico Pecten.")
  313.                 sleep(10)
  314.                 os.reboot()
  315.             end
  316. sleep(1)
  317. print("Denaro versato.")
  318. print("")
  319. print("")
  320. print("Grazie!")
  321. sleep(1)
  322.  
  323. --Spegni display di sinistra e ricalibra
  324. meter.reset()
  325. rs.setOutput(meterDisplay, false)
  326. term.setTextColor(colors.black)
  327. clear()
  328. shell.run("pastebin get fc3G1D61 startup2")
  329.     if fs.exists("startup2") then
  330.         shell.run("rm startup")
  331.         shell.run("mv startup2 startup")
  332.     end
  333. os.reboot()
  334. elseif num == 2 then clear() break end
  335. end
  336. clear()
  337. print("Attendere")
  338. term.setTextColor(colors.black)
  339. shell.run("pastebin get fc3G1D61 startup2")
  340.     if fs.exists("startup2") then
  341.         shell.run("rm startup")
  342.         shell.run("mv startup2 startup")
  343.     end
  344. os.reboot()
Add Comment
Please, Sign In to add comment