SHOW:
|
|
- or go back to the newest paste.
| 1 | costante = 0.4 | |
| 2 | local maxw, maxh = term.getSize() | |
| 3 | m = peripheral.wrap("top")
| |
| 4 | - | m.write(" KENI")
|
| 4 | + | m.write(" IPDB")
|
| 5 | m.setCursorPos(1,3) | |
| 6 | m.write("Diesel:")
| |
| 7 | m.setCursorPos(1,4) | |
| 8 | m.write(costante) | |
| 9 | m.setCursorPos(1,5) | |
| 10 | m.write("IC/s.")
| |
| 11 | ||
| 12 | ||
| 13 | function creditoInsufficiente() | |
| 14 | clearRed() | |
| 15 | print("Credito insufficiente.")
| |
| 16 | print("")
| |
| 17 | print("Premere un tasto per uscire")
| |
| 18 | os.pullEvent("key")
| |
| 19 | os.reboot() | |
| 20 | end | |
| 21 | ||
| 22 | function gasolioNonDisponibile() | |
| 23 | clearRed() | |
| 24 | print("Gasolio esaurito.")
| |
| 25 | print("")
| |
| 26 | print("Premere un tasto per uscire")
| |
| 27 | os.pullEvent("key")
| |
| 28 | os.reboot() | |
| 29 | end | |
| 30 | ||
| 31 | -- IMPLEMENTAZIONE DEL DRAWFILLEDBOX | |
| 32 | local function drawPixelInternal(xPos, yPos) | |
| 33 | term.setCursorPos(xPos, yPos) | |
| 34 | term.write(" ")
| |
| 35 | end | |
| 36 | ||
| 37 | local tColourLookup = {}
| |
| 38 | for n = 1, 16 do | |
| 39 | tColourLookup[string.byte("0123456789abcdef", n, n)] = 2 ^ (n - 1)
| |
| 40 | end | |
| 41 | ||
| 42 | function drawFilledBox(startX, startY, endX, endY, nColour) | |
| 43 | if type(startX) ~= "number" or type(startX) ~= "number" or type(endX) ~= | |
| 44 | "number" or type(endY) ~= "number" or | |
| 45 | (nColour ~= nil and type(nColour) ~= "number") then | |
| 46 | error("Expected startX, startY, endX, endY, colour", 2)
| |
| 47 | end | |
| 48 | ||
| 49 | startX = math.floor(startX) | |
| 50 | startY = math.floor(startY) | |
| 51 | endX = math.floor(endX) | |
| 52 | endY = math.floor(endY) | |
| 53 | ||
| 54 | if nColour then term.setBackgroundColor(nColour) end | |
| 55 | if startX == endX and startY == endY then | |
| 56 | drawPixelInternal(startX, startY) | |
| 57 | return | |
| 58 | end | |
| 59 | ||
| 60 | local minX = math.min(startX, endX) | |
| 61 | if minX == startX then | |
| 62 | minY = startY | |
| 63 | maxX = endX | |
| 64 | maxY = endY | |
| 65 | else | |
| 66 | minY = endY | |
| 67 | maxX = startX | |
| 68 | maxY = startY | |
| 69 | end | |
| 70 | ||
| 71 | for x = minX, maxX do for y = minY, maxY do drawPixelInternal(x, y) end end | |
| 72 | end | |
| 73 | ||
| 74 | function clear() | |
| 75 | sfondo(colors.blue) | |
| 76 | term.clear() | |
| 77 | term.setCursorPos(1, 1) | |
| 78 | end | |
| 79 | ||
| 80 | function clearRed() | |
| 81 | sfondo(colors.red) | |
| 82 | term.clear() | |
| 83 | term.setCursorPos(1, 1) | |
| 84 | end | |
| 85 | ||
| 86 | function colore(sfumatura) term.setTextColour(sfumatura) end | |
| 87 | ||
| 88 | function sfondo(sfumaturaSfondo) term.setBackgroundColour(sfumaturaSfondo) end | |
| 89 | ||
| 90 | function fineColore() term.setTextColour(colours.white) end | |
| 91 | ||
| 92 | function fineSfondo() term.setBackgroundColour(colours.black) end | |
| 93 | ||
| 94 | function titolo(testo) | |
| 95 | drawFilledBox(1, 1, maxw, 1, colors.yellow) | |
| 96 | term.setCursorPos((maxw - #testo) / 2, 1) | |
| 97 | colore(colors.black) | |
| 98 | term.write(testo) | |
| 99 | sfondo(colors.blue) | |
| 100 | end | |
| 101 | ||
| 102 | function errore(errore) | |
| 103 | sfondo(colors.red) | |
| 104 | colore(colors.white) | |
| 105 | term.clear() | |
| 106 | term.setCursorPos(1, 1) | |
| 107 | titolo("Errore irreversibile")
| |
| 108 | term.setCursorPos(1, 3) | |
| 109 | sfondo(colors.red) | |
| 110 | colore(colors.white) | |
| 111 | print(errore) | |
| 112 | print("\n\n\nAttendere qualche secondo...")
| |
| 113 | os.sleep(5) | |
| 114 | os.reboot() | |
| 115 | end | |
| 116 | ||
| 117 | clear() | |
| 118 | ||
| 119 | - | titolo("DISTRIBUTORE DI BluDiesel® Premium KENI®")
|
| 119 | + | titolo("DISTRIBUTORE DI GASOLIO Premium IPDB")
|
| 120 | -- startx, starty, endx, endy | |
| 121 | drawFilledBox(3, 4, 15, 6, colors.yellow) | |
| 122 | drawFilledBox(3, 8, 15, 10, colors.yellow) | |
| 123 | drawFilledBox(3, 12, 15, 14, colors.yellow) | |
| 124 | drawFilledBox(3, 16, 15, 18, colors.yellow) | |
| 125 | term.setCursorPos(4, 5) | |
| 126 | colore(colors.black) | |
| 127 | sfondo(colors.yellow) | |
| 128 | term.write("16 secchi")
| |
| 129 | ||
| 130 | term.setCursorPos(4, 9) | |
| 131 | colore(colors.black) | |
| 132 | sfondo(colors.yellow) | |
| 133 | term.write("32 secchi")
| |
| 134 | ||
| 135 | term.setCursorPos(4, 13) | |
| 136 | colore(colors.black) | |
| 137 | sfondo(colors.yellow) | |
| 138 | - | term.write("Pieno Loco")
|
| 138 | + | term.write("64 secchi")
|
| 139 | ||
| 140 | term.setCursorPos(4, 17) | |
| 141 | colore(colors.black) | |
| 142 | sfondo(colors.yellow) | |
| 143 | - | term.write("Pieno Vagone")
|
| 143 | + | term.write("Pieno (160)")
|
| 144 | ||
| 145 | while true do | |
| 146 | drawFilledBox(18, 5, 50, 17, colors.yellow) | |
| 147 | term.setCursorPos(19, 6) | |
| 148 | colore(colors.black) | |
| 149 | sfondo(colors.yellow) | |
| 150 | term.write("ISTRUZIONI - LEGGERE:")
| |
| 151 | term.setCursorPos(19, 8) | |
| 152 | term.write("1. Posizionare il vagone/loco")
| |
| 153 | term.setCursorPos(19, 9) | |
| 154 | term.write(" sotto l'erogatore appropriato")
| |
| 155 | term.setCursorPos(19, 10) | |
| 156 | - | term.write("2. Controllare che il vagone")
|
| 156 | + | term.write("2. Controllare che la spia")
|
| 157 | term.setCursorPos(19, 11) | |
| 158 | - | term.write(" o loco siano vuoti.")
|
| 158 | + | term.write(" «presenza vagone» sia accesa")
|
| 159 | term.setCursorPos(19, 12) | |
| 160 | term.write("3. Selezionare su questo PC")
| |
| 161 | term.setCursorPos(19, 13) | |
| 162 | - | term.write(" la quantità desiderata")
|
| 162 | + | term.write(" la quantitåA0 desiderata")
|
| 163 | term.setCursorPos(19, 14) | |
| 164 | term.write("4. Attendere l'erogazione")
| |
| 165 | term.setCursorPos(19, 15) | |
| 166 | term.write("5. Non appena l'operazione sarà")
| |
| 167 | term.setCursorPos(19, 16) | |
| 168 | term.write(" terminata liberare l'area")
| |
| 169 | ||
| 170 | local event, par1, x, y = os.pullEvent("mouse_click")
| |
| 171 | if event == "mouse_click" and x >= 3 and x <= 15 and y >= 4 and y <= 6 then | |
| 172 | qta = 16 | |
| 173 | materiale = "16 secchi" | |
| 174 | prezzo = qta * costante | |
| 175 | break | |
| 176 | elseif event == "mouse_click" and x >= 3 and x <= 15 and y >= 8 and y <= 10 then | |
| 177 | qta = 32 | |
| 178 | materiale = "32 secchi" | |
| 179 | prezzo = qta * costante | |
| 180 | break | |
| 181 | elseif event == "mouse_click" and x >= 3 and x <= 15 and y >= 12 and y <= 14 then | |
| 182 | qta = 64 | |
| 183 | - | materiale = "Pieno Loco" |
| 183 | + | materiale = "64 secchi" |
| 184 | prezzo = qta * costante | |
| 185 | break | |
| 186 | elseif event == "mouse_click" and x >= 3 and x <= 15 and y >= 16 and y <= 18 then | |
| 187 | - | qta = 208 |
| 187 | + | |
| 188 | prezzo = qta * costante | |
| 189 | - | materiale = "Pieno Vagone" |
| 189 | + | materiale = "Pieno (160)" |
| 190 | break | |
| 191 | end | |
| 192 | sleep(1) | |
| 193 | end | |
| 194 | clear() | |
| 195 | ||
| 196 | if redstone.getInput("back") == true then
| |
| 197 | errore("Gasolio esaurito")
| |
| 198 | end | |
| 199 | sfondo(colours.blue) | |
| 200 | term.clear() | |
| 201 | term.setCursorPos(1, 1) | |
| 202 | titolo("Paga con Nebraska Pay")
| |
| 203 | sfondo(colours.blue) | |
| 204 | colore(colors.white) | |
| 205 | print( | |
| 206 | "\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.") | |
| 207 | ||
| 208 | -- nomeutente | |
| 209 | term.setCursorPos(1, 9) | |
| 210 | term.write("Nome utente:")
| |
| 211 | term.setCursorPos(15, 9) | |
| 212 | fineColore() | |
| 213 | utenteAccettato = false | |
| 214 | conteggioErrori = 0 | |
| 215 | while utenteAccettato == false do | |
| 216 | utente = read() | |
| 217 | checkuser = http.get( | |
| 218 | "http://172.16.20.220/luanet/servlets/nebraskapay.php?auth=no&richiesta=verifica&utente=" .. | |
| 219 | utente).readAll() | |
| 220 | tabcheckuser = textutils.unserialize(checkuser) | |
| 221 | if tabcheckuser.stato == "OK" then | |
| 222 | term.setCursorPos(15, 9) | |
| 223 | colore(colours.lime) | |
| 224 | term.write(utente) | |
| 225 | fineColore() | |
| 226 | utenteAccettato = true | |
| 227 | else | |
| 228 | term.setCursorPos(15, 9) | |
| 229 | colore(colours.red) | |
| 230 | term.write("Utente errato! ")
| |
| 231 | sleep(2) | |
| 232 | term.setCursorPos(15, 9) | |
| 233 | fineColore() | |
| 234 | term.write(" ")
| |
| 235 | term.setCursorPos(15, 9) | |
| 236 | conteggioErrori = conteggioErrori + 1 | |
| 237 | if conteggioErrori > 2 then | |
| 238 | term.setCursorPos(15, 9) | |
| 239 | colore(colours.red) | |
| 240 | errore("Troppi tentativi di immissione errati ")
| |
| 241 | end | |
| 242 | end | |
| 243 | end | |
| 244 | colore(colours.white) | |
| 245 | term.setCursorPos(1, 11) | |
| 246 | term.write("Password:")
| |
| 247 | term.setCursorPos(15, 11) | |
| 248 | conteggioErrori = 0 | |
| 249 | passAccettata = false | |
| 250 | while passAccettata == false do | |
| 251 | fineColore() | |
| 252 | password = read("#")
| |
| 253 | colore(colours.black) | |
| 254 | checkuser = http.get( | |
| 255 | "http://172.16.20.220/luanet/servlets/nebraskapay.php?auth=" .. | |
| 256 | password .. "&richiesta=addebito&valore=0&utente=" .. | |
| 257 | utente).readAll() | |
| 258 | risposta = textutils.unserialize(checkuser) | |
| 259 | if risposta.stato == "OK" then | |
| 260 | term.setCursorPos(15, 11) | |
| 261 | colore(colours.lime) | |
| 262 | term.write("############## ")
| |
| 263 | fineColore() | |
| 264 | passAccettata = true | |
| 265 | else | |
| 266 | term.setCursorPos(15, 11) | |
| 267 | colore(colours.red) | |
| 268 | term.write("Password errata! ")
| |
| 269 | conteggioErrori = conteggioErrori + 1 | |
| 270 | sleep(2) | |
| 271 | term.setCursorPos(15, 11) | |
| 272 | term.write(" ")
| |
| 273 | term.setCursorPos(15, 11) | |
| 274 | if conteggioErrori > 2 then | |
| 275 | term.setCursorPos(15, 11) | |
| 276 | colore(colours.red) | |
| 277 | errore("Troppi tentativi di immissione errati")
| |
| 278 | end | |
| 279 | end | |
| 280 | end | |
| 281 | ||
| 282 | -- Mostra saldo | |
| 283 | term.clear() | |
| 284 | ||
| 285 | term.clear() | |
| 286 | term.setCursorPos(1, 1) | |
| 287 | titolo("Paga con Nebraska Pay")
| |
| 288 | sfondo(colours.blue) | |
| 289 | colore(colors.white) | |
| 290 | print("\n\nSaldo disponibile: " .. risposta.saldo .. " IC")
| |
| 291 | if tonumber(risposta.saldo) >= tonumber(prezzo) then | |
| 292 | prezzoAccettato = true | |
| 293 | else | |
| 294 | - | errore("Disponibilità insufficiente!")
|
| 294 | + | errore("DisponibilitåA0 insufficiente!")
|
| 295 | end | |
| 296 | term.setCursorPos(1, 3) | |
| 297 | term.write("Invio di ")
| |
| 298 | term.write(prezzo) | |
| 299 | term.write(" IC a favore di ")
| |
| 300 | - | term.write("KENI")
|
| 300 | + | term.write("IPDB")
|
| 301 | print("\n\nConfermare l'operazione?")
| |
| 302 | colore(colors.yellow) | |
| 303 | print("\n\nInvia il denaro Annulla")
| |
| 304 | while true do | |
| 305 | event, key, x, y = os.pullEvent() | |
| 306 | if event == "mouse_click" and x < 16 and y == 8 then | |
| 307 | inviaDenaro = http.get( | |
| 308 | "http://172.16.20.220/luanet/servlets/nebraskapay.php?auth=" .. | |
| 309 | password .. "&utente=" .. utente .. | |
| 310 | "&richiesta=trasferimento&valore=" .. prezzo .. | |
| 311 | - | "&beneficiario=KENI").readAll() |
| 311 | + | "&beneficiario=IPDB").readAll() |
| 312 | risultatoInvio = textutils.unserialize(inviaDenaro) | |
| 313 | if risultatoInvio.stato == "OK" then | |
| 314 | colore(colors.white) | |
| 315 | break | |
| 316 | else | |
| 317 | clear() | |
| 318 | errore("Errore durante il pagamento")
| |
| 319 | end | |
| 320 | elseif event == "mouse_click" and x > 18 and y == 8 then | |
| 321 | errore("Pagamento annullato dall'utente.")
| |
| 322 | end | |
| 323 | end | |
| 324 | clear() | |
| 325 | titolo("Erogazione in corso")
| |
| 326 | ||
| 327 | print("\n\nErogazione di " .. materiale .. " di gasolio in corso...")
| |
| 328 | ben = peripheral.wrap("back")
| |
| 329 | ben.makeRequest(ben.getItemIdentifierIDFor(21258, 18), qta) | |
| 330 | sleep(10) | |
| 331 | - | term.setTextColor(colors.black) |
| 331 | + | |
| 332 | - | term.setBackgroundColor(colors.black) |
| 332 | + |