lego11

ConcessioniPetrolifere

Sep 30th, 2020 (edited)
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 12.19 KB | None | 0 0
  1. local maxw, maxh = term.getSize()
  2.  
  3. -- IMPLEMENTAZIONE DEL DRAWFILLEDBOX
  4. local function drawPixelInternal(xPos, yPos)
  5.     term.setCursorPos(xPos, yPos)
  6.     term.write(" ")
  7. end
  8.  
  9. local tColourLookup = {}
  10. for n = 1, 16 do
  11.     tColourLookup[string.byte("0123456789abcdef", n, n)] = 2 ^ (n - 1)
  12. end
  13.  
  14. function drawFilledBox(startX, startY, endX, endY, nColour)
  15.     if type(startX) ~= "number" or type(startX) ~= "number" or type(endX) ~=
  16.         "number" or type(endY) ~= "number" or
  17.         (nColour ~= nil and type(nColour) ~= "number") then
  18.         error("Expected startX, startY, endX, endY, colour", 2)
  19.     end
  20.  
  21.     startX = math.floor(startX)
  22.     startY = math.floor(startY)
  23.     endX = math.floor(endX)
  24.     endY = math.floor(endY)
  25.  
  26.     if nColour then term.setBackgroundColor(nColour) end
  27.     if startX == endX and startY == endY then
  28.         drawPixelInternal(startX, startY)
  29.         return
  30.     end
  31.  
  32.     local minX = math.min(startX, endX)
  33.     if minX == startX then
  34.         minY = startY
  35.         maxX = endX
  36.         maxY = endY
  37.     else
  38.         minY = endY
  39.         maxX = startX
  40.         maxY = startY
  41.     end
  42.  
  43.     for x = minX, maxX do for y = minY, maxY do drawPixelInternal(x, y) end end
  44. end
  45.  
  46. function colore(nome) term.setTextColor(nome) end
  47.  
  48. function sfondo(nome) term.setBackgroundColor(nome) end
  49.  
  50. function fineColore() term.setTextColour(colours.white) end
  51.  
  52. function fineSfondo() term.setBackgroundColour(colours.black) end
  53.  
  54. function titolo(testo)
  55.     drawFilledBox(1, 1, maxw, 1, colors.yellow)
  56.     term.setCursorPos((maxw - #testo) / 2, 1)
  57.     colore(colors.black)
  58.     term.write(testo)
  59.     sfondo(colors.blue)
  60. end
  61.  
  62. function clear()
  63.     sfondo(colors.blue)
  64.     term.clear()
  65.     term.setCursorPos(1, 1)
  66. end
  67.  
  68. function errore(errore)
  69.     sfondo(colors.red)
  70.     colore(colors.white)
  71.     term.clear()
  72.     term.setCursorPos(1, 1)
  73.     titolo("Errore irreversibile")
  74.     term.setCursorPos(1, 3)
  75.     sfondo(colors.red)
  76.     colore(colors.white)
  77.     print(errore)
  78.     print("\n\n\nAttendere qualche secondo...")
  79.     os.sleep(5)
  80.     os.reboot()
  81. end
  82.  
  83. mappa = paintutils.loadImage("sfondo")
  84. sfondo(colors.white)
  85. term.clear()
  86. term.setCursorPos(1, 1)
  87. colore(colors.white)
  88. paintutils.drawImage(mappa, 1, 2)
  89. colore(colors.black)
  90. sfondo(colors.white)
  91. term.setCursorPos(14, 1)
  92. term.write("Registrazione concessione petrolifera")
  93. colore(colors.white)
  94. sfondo(colors.lime)
  95. term.setCursorPos(31, 10)
  96. term.write("Registra una")
  97. term.setCursorPos(31, 11)
  98. term.write("concessione")
  99. term.setCursorPos(31, 12)
  100. term.write("petrolifera")
  101. while true do
  102.     local event, par1, par2, par3 = os.pullEvent("mouse_click")
  103.     if par2 >= 31 and par2 <= 42 and par3 >= 10 and par3 <= 12 then
  104.         sfondo(colours.blue)
  105.         term.clear()
  106.         term.setCursorPos(1, 1)
  107.         titolo("Ministero delle Georisorse")
  108.         sfondo(colours.blue)
  109.         colore(colors.white)
  110.         print(
  111.             "\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.")
  112.  
  113.         -- nomeutente
  114.         term.setCursorPos(1, 9)
  115.         term.write("Nome utente nPay:")
  116.         term.setCursorPos(21, 9)
  117.         fineColore()
  118.         utenteAccettato = false
  119.         conteggioErrori = 0
  120.         while utenteAccettato == false do
  121.             utente = read()
  122.             checkuser = http.get(
  123.                             "http://172.16.20.220/luanet/servlets/nebraskapay.php?auth=no&richiesta=verifica&utente=" ..
  124.                                 utente).readAll()
  125.             tabcheckuser = textutils.unserialize(checkuser)
  126.             if tabcheckuser.stato == "OK" then
  127.                 term.setCursorPos(21, 9)
  128.                 colore(colours.lime)
  129.                 term.write(utente)
  130.                 fineColore()
  131.                 utenteAccettato = true
  132.             else
  133.                 term.setCursorPos(21, 9)
  134.                 colore(colours.red)
  135.                 term.write("Utente errato!          ")
  136.                 sleep(2)
  137.                 term.setCursorPos(21, 9)
  138.                 fineColore()
  139.                 term.write("                       ")
  140.                 term.setCursorPos(21, 9)
  141.                 conteggioErrori = conteggioErrori + 1
  142.                 if conteggioErrori > 2 then
  143.                     term.setCursorPos(21, 9)
  144.                     colore(colours.red)
  145.                     errore("Troppi tentativi di immissione errati    ")
  146.                 end
  147.             end
  148.         end
  149.  
  150.         colore(colours.white)
  151.         term.setCursorPos(1, 11)
  152.         term.write("Password nPay:")
  153.         term.setCursorPos(21, 11)
  154.  
  155.         conteggioErrori = 0
  156.         passAccettata = false
  157.         while passAccettata == false do
  158.             fineColore()
  159.             password = read("#")
  160.             colore(colours.black)
  161.             checkuser = http.get(
  162.                             "http://172.16.20.220/luanet/servlets/nebraskapay.php?auth=" ..
  163.                                 password ..
  164.                                 "&richiesta=addebito&valore=0&utente=" .. utente)
  165.                             .readAll()
  166.             risposta = textutils.unserialize(checkuser)
  167.             if risposta.stato == "OK" then
  168.                 term.setCursorPos(21, 11)
  169.                 colore(colours.lime)
  170.                 term.write("##############               ")
  171.                 fineColore()
  172.                 passAccettata = true
  173.             else
  174.                 term.setCursorPos(21, 11)
  175.                 colore(colours.red)
  176.                 term.write("Password errata!            ")
  177.                 conteggioErrori = conteggioErrori + 1
  178.                 sleep(2)
  179.                 term.setCursorPos(21, 11)
  180.                 term.write("                               ")
  181.                 term.setCursorPos(21, 11)
  182.                 if conteggioErrori > 2 then
  183.                     term.setCursorPos(21, 11)
  184.                     colore(colours.red)
  185.                     errore("Troppi tentativi di immissione errati")
  186.                 end
  187.             end
  188.         end
  189.  
  190.         colore(colours.white)
  191.         term.setCursorPos(1, 13)
  192.         term.write("Coordinata X:")
  193.         term.setCursorPos(21, 13)
  194.  
  195.         xAccettato = false
  196.         while xAccettato == false do
  197.             x = read()
  198.  
  199.             if tonumber(x) == "" or tonumber(x) == nil then
  200.                 term.setCursorPos(21, 13)
  201.                 colore(colours.red)
  202.                 term.write("Coord. X errata!          ")
  203.                 sleep(2)
  204.                 term.setCursorPos(21, 13)
  205.                 fineColore()
  206.                 term.write("                       ")
  207.                 term.setCursorPos(21, 13)
  208.                 conteggioErrori = conteggioErrori + 1
  209.                 if conteggioErrori > 2 then
  210.                     term.setCursorPos(21, 13)
  211.                     colore(colours.red)
  212.                     errore("Troppi tentativi di immissione errati    ")
  213.                 end
  214.             else
  215.                 term.setCursorPos(21, 13)
  216.                 colore(colours.lime)
  217.                 term.write(x)
  218.                 fineColore()
  219.                 xAccettato = true
  220.             end
  221.         end
  222.  
  223.         colore(colours.white)
  224.         term.setCursorPos(1, 15)
  225.         term.write("Coordinata Y:")
  226.         term.setCursorPos(21, 15)
  227.  
  228.         yAccettato = false
  229.         while yAccettato == false do
  230.             y = read()
  231.  
  232.             if tonumber(y) == "" or tonumber(y) == nil then
  233.                 term.setCursorPos(21, 15)
  234.                 colore(colours.red)
  235.                 term.write("Coord. Y errata!          ")
  236.                 sleep(2)
  237.                 term.setCursorPos(21, 15)
  238.                 fineColore()
  239.                 term.write("                       ")
  240.                 term.setCursorPos(21, 15)
  241.                 conteggioErrori = conteggioErrori + 1
  242.                 if conteggioErrori > 2 then
  243.                     term.setCursorPos(21, 15)
  244.                     colore(colours.red)
  245.                     errore("Troppi tentativi di immissione errati    ")
  246.                 end
  247.             else
  248.                 term.setCursorPos(21, 15)
  249.                 colore(colours.lime)
  250.                 term.write(y)
  251.                 fineColore()
  252.                 yAccettato = true
  253.             end
  254.         end
  255.  
  256.         colore(colours.white)
  257.         term.setCursorPos(1, 17)
  258.         term.write("Coordinata Z:")
  259.         term.setCursorPos(21, 17)
  260.  
  261.         zAccettato = false
  262.         while zAccettato == false do
  263.             z = read()
  264.  
  265.             if tonumber(z) == "" or tonumber(z) == nil then
  266.                 term.setCursorPos(21, 17)
  267.                 colore(colours.red)
  268.                 term.write("Coord. Z errata!          ")
  269.                 sleep(2)
  270.                 term.setCursorPos(21, 17)
  271.                 fineColore()
  272.                 term.write("                       ")
  273.                 term.setCursorPos(21, 17)
  274.                 conteggioErrori = conteggioErrori + 1
  275.                 if conteggioErrori > 2 then
  276.                     term.setCursorPos(21, 17)
  277.                     colore(colours.red)
  278.                     errore("Troppi tentativi di immissione errati    ")
  279.                 end
  280.             else
  281.                 term.setCursorPos(21, 17)
  282.                 colore(colours.lime)
  283.                 term.write(z)
  284.                 fineColore()
  285.                 zAccettato = true
  286.             end
  287.         end
  288.  
  289.         -- Mostra saldo
  290.         term.clear()
  291.  
  292.         term.clear()
  293.         term.setCursorPos(1, 1)
  294.         titolo("Paga con Nebraska Pay")
  295.         sfondo(colours.blue)
  296.         colore(colors.white)
  297.         print("\n\nSaldo disponibile: " .. risposta.saldo .. " IC")
  298.         importo = 200
  299.         if tonumber(risposta.saldo) >= tonumber(importo) then
  300.             importoAccettato = true
  301.         else
  302.             errore("Disponibilità insufficiente!")
  303.         end
  304.         term.setCursorPos(1, 3)
  305.         term.write("Invio di ")
  306.         term.write(importo)
  307.         term.write(" IC a favore di ")
  308.         term.write("Min. Georisorse")
  309.         print("\n\nConfermare l'operazione?")
  310.         colore(colors.yellow)
  311.         print("\n\nInvia il denaro           Annulla")
  312.         while true do
  313.             event, key, x, y = os.pullEvent()
  314.             if event == "mouse_click" and x < 16 and y == 8 then
  315.                 inviaDenaro = http.get(
  316.                                   "http://172.16.20.220/luanet/servlets/nebraskapay.php?auth=" ..
  317.                                       password .. "&utente=" .. utente ..
  318.                                       "&richiesta=trasferimento&valore=" ..
  319.                                       importo .. "&beneficiario=ComuneNR")
  320.                                   .readAll()
  321.                 risultatoInvio = textutils.unserialize(inviaDenaro)
  322.                 if risultatoInvio.stato == "OK" then
  323.                     colore(colors.white)
  324.                     break
  325.                 else
  326.                     clear()
  327.                     errore("Errore durante il pagamento")
  328.                 end
  329.             elseif event == "mouse_click" and x > 18 and y == 8 then
  330.                 errore("Pagamento annullato dall'utente.")
  331.             end
  332.         end
  333.  
  334.         conferma = textutils.unserialize(
  335.                        http.get(
  336.                            "http://172.16.20.220/luanet/servlets/conc_petrolifera/?nome=" ..
  337.                                utente .. "&x=" .. x .. "&y=" .. y .. "&z=" .. z)
  338.                            .readAll())
  339.  
  340.         if conferma.stato == "OK" then
  341.             clear()
  342.             titolo("Ministero delle Georisorse")
  343.             term.setCursorPos(1, 3)
  344.             colore(colors.white)
  345.             print("Grazie per l'acquisto!\n\n")
  346.             print("Questo è il codice della concessione: " ..
  347.                       conferma.dettaglio)
  348.             print(
  349.                 "\nIL CODICE VA SCRITTO SU UN CARTELLO VICINO ALLA CONCESSIONE!")
  350.             print(
  351.                 "\nIn caso di ispezione se non è presente il numero, si incorrerà in una sanzione amministrativa sino a 4000 IC.")
  352.             os.sleep(10)
  353.             os.reboot()
  354.         else
  355.             errore(conferma.errore)
  356.         end
  357.     end
  358.     sleep(0.1)
  359. end
  360.  
Add Comment
Please, Sign In to add comment