SHOW:
|
|
- or go back to the newest paste.
| 1 | os.pullEvent = os.pullEventRaw | |
| 2 | local order = ""; | |
| 3 | local price = 0 | |
| 4 | local passAccettata = false | |
| 5 | local ben = peripheral.wrap("back")
| |
| 6 | ||
| 7 | -- IMPLEMENTAZIONE DEL DRAWFILLEDBOX | |
| 8 | local function drawPixelInternal(xPos, yPos) | |
| 9 | term.setCursorPos(xPos, yPos) | |
| 10 | term.write(" ")
| |
| 11 | end | |
| 12 | ||
| 13 | local tColourLookup = {}
| |
| 14 | for n = 1, 16 do | |
| 15 | tColourLookup[string.byte("0123456789abcdef", n, n)] = 2 ^ (n - 1)
| |
| 16 | end | |
| 17 | ||
| 18 | function drawFilledBox(startX, startY, endX, endY, nColour) | |
| 19 | if type(startX) ~= "number" or type(startX) ~= "number" or type(endX) ~= | |
| 20 | "number" or type(endY) ~= "number" or | |
| 21 | (nColour ~= nil and type(nColour) ~= "number") then | |
| 22 | error("Expected startX, startY, endX, endY, colour", 2)
| |
| 23 | end | |
| 24 | ||
| 25 | startX = math.floor(startX) | |
| 26 | startY = math.floor(startY) | |
| 27 | endX = math.floor(endX) | |
| 28 | endY = math.floor(endY) | |
| 29 | ||
| 30 | if nColour then term.setBackgroundColor(nColour) end | |
| 31 | if startX == endX and startY == endY then | |
| 32 | drawPixelInternal(startX, startY) | |
| 33 | return | |
| 34 | end | |
| 35 | ||
| 36 | local minX = math.min(startX, endX) | |
| 37 | if minX == startX then | |
| 38 | minY = startY | |
| 39 | maxX = endX | |
| 40 | maxY = endY | |
| 41 | else | |
| 42 | minY = endY | |
| 43 | maxX = startX | |
| 44 | maxY = startY | |
| 45 | end | |
| 46 | ||
| 47 | for x = minX, maxX do for y = minY, maxY do drawPixelInternal(x, y) end end | |
| 48 | end | |
| 49 | ||
| 50 | function clear() | |
| 51 | sfondo(colors.black) | |
| 52 | term.clear() | |
| 53 | term.setCursorPos(1, 1) | |
| 54 | end | |
| 55 | ||
| 56 | function clearRed() | |
| 57 | sfondo(colors.red) | |
| 58 | term.clear() | |
| 59 | term.setCursorPos(1, 1) | |
| 60 | end | |
| 61 | ||
| 62 | function colore(sfumatura) term.setTextColour(sfumatura) end | |
| 63 | ||
| 64 | function sfondo(sfumaturaSfondo) term.setBackgroundColour(sfumaturaSfondo) end | |
| 65 | ||
| 66 | function fineColore() term.setTextColour(colours.white) end | |
| 67 | ||
| 68 | function fineSfondo() term.setBackgroundColour(colours.black) end | |
| 69 | function paga(prezzo,id,modid,qty) | |
| 70 | sfondo(colours.blue) | |
| 71 | term.clear() | |
| 72 | term.setCursorPos(1, 1) | |
| 73 | sfondo(colours.blue) | |
| 74 | colore(colors.white) | |
| 75 | print( | |
| 76 | "\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.") | |
| 77 | ||
| 78 | -- nomeutente | |
| 79 | term.setCursorPos(1, 9) | |
| 80 | term.write("Nome utente:")
| |
| 81 | term.setCursorPos(15, 9) | |
| 82 | fineColore() | |
| 83 | utenteAccettato = false | |
| 84 | conteggioErrori = 0 | |
| 85 | while utenteAccettato == false do | |
| 86 | utente = read() | |
| 87 | checkuser = http.get( | |
| 88 | "http://172.16.20.220/luanet/servlets/nebraskapay.php?auth=no&richiesta=verifica&utente=" .. | |
| 89 | utente).readAll() | |
| 90 | tabcheckuser = textutils.unserialize(checkuser) | |
| 91 | if tabcheckuser.stato == "OK" then | |
| 92 | term.setCursorPos(15, 9) | |
| 93 | colore(colours.lime) | |
| 94 | term.write(utente) | |
| 95 | fineColore() | |
| 96 | utenteAccettato = true | |
| 97 | else | |
| 98 | term.setCursorPos(15, 9) | |
| 99 | colore(colours.red) | |
| 100 | term.write("Utente errato! ")
| |
| 101 | sleep(2) | |
| 102 | term.setCursorPos(15, 9) | |
| 103 | fineColore() | |
| 104 | term.write(" ")
| |
| 105 | term.setCursorPos(15, 9) | |
| 106 | conteggioErrori = conteggioErrori + 1 | |
| 107 | if conteggioErrori > 2 then | |
| 108 | term.setCursorPos(15, 9) | |
| 109 | colore(colours.red) | |
| 110 | errore("Troppi tentativi di immissione errati ")
| |
| 111 | end | |
| 112 | end | |
| 113 | end | |
| 114 | colore(colours.white) | |
| 115 | term.setCursorPos(1, 11) | |
| 116 | term.write("Password:")
| |
| 117 | term.setCursorPos(15, 11) | |
| 118 | conteggioErrori = 0 | |
| 119 | while passAccettata == false do | |
| 120 | fineColore() | |
| 121 | password = read("#")
| |
| 122 | colore(colours.black) | |
| 123 | checkuser = http.get( | |
| 124 | "http://172.16.20.220/luanet/servlets/nebraskapay.php?auth=" .. | |
| 125 | password .. "&richiesta=addebito&valore=0&utente=" .. | |
| 126 | utente).readAll() | |
| 127 | risposta = textutils.unserialize(checkuser) | |
| 128 | ||
| 129 | if risposta.stato == "OK" then | |
| 130 | term.setCursorPos(15, 11) | |
| 131 | colore(colours.lime) | |
| 132 | term.write("############## ")
| |
| 133 | fineColore() | |
| 134 | passAccettata = true | |
| 135 | -- rednet.send(6102, order) | |
| 136 | addOrder = http.get("http://192.168.13.103/addOrder.php?order=" .. order .. "&username=" .. utente .. "&password=" .. password .. "&type=pecten").readAll()
| |
| 137 | - | addOrder = http.get("http://192.168.13.103/addOrder.php?order=" .. order .. "&username=" .. utente .. "&password=" .. password .. "&type=pecten")
|
| 137 | + | |
| 138 | ||
| 139 | sleep(0.4) | |
| 140 | sfondo(colours.yellow) | |
| 141 | term.clear() | |
| 142 | term.setCursorPos(1, 1) | |
| 143 | sfondo(colours.yellow) | |
| 144 | colore(colors.black) | |
| 145 | print( | |
| 146 | "\n\Erogazione in corso, attendere, la ringraziamo per l'acquisto!") | |
| 147 | sleep(2) | |
| 148 | local requestOrder = http.get("http://192.168.13.103/requestOrder.php?user=" .. utente .. "-" .. "pecten" .. "&location=3110").readAll()
| |
| 149 | - | --local requestOrder = http.get("http://192.168.13.103/requestOrder.php?user=" .. utente .. "-" .. "pecten" .. "&location=3110").readAll()
|
| 149 | + | |
| 150 | fuelID = ben.getItemIdentifierIDFor(id, modid) | |
| 151 | if(qty == 16 or qty == 32) then | |
| 152 | ben.makeRequest(fuelID, qty) | |
| 153 | elseif(qty == 160) then | |
| 154 | ben.makeRequest(fuelID, 64) | |
| 155 | sleep(17.5) | |
| 156 | ben.makeRequest(fuelID, 64) | |
| 157 | sleep(17.5) | |
| 158 | ben.makeRequest(fuelID, 32) | |
| 159 | elseif(qty == 208) then | |
| 160 | ben.makeRequest(fuelID, 64) | |
| 161 | sleep(17.5) | |
| 162 | ben.makeRequest(fuelID, 64) | |
| 163 | sleep(17.5) | |
| 164 | ben.makeRequest(fuelID, 64) | |
| 165 | sleep(17.5) | |
| 166 | ben.makeRequest(fuelID, 16) | |
| 167 | ||
| 168 | end | |
| 169 | os.reboot() | |
| 170 | ||
| 171 | else | |
| 172 | term.setCursorPos(15, 11) | |
| 173 | colore(colours.red) | |
| 174 | term.write("Password errata o credito insufficiente! ")
| |
| 175 | conteggioErrori = conteggioErrori + 1 | |
| 176 | sleep(2) | |
| 177 | term.setCursorPos(15, 11) | |
| 178 | term.write(" ")
| |
| 179 | term.setCursorPos(15, 11) | |
| 180 | if conteggioErrori > 2 then | |
| 181 | term.setCursorPos(15, 11) | |
| 182 | colore(colours.red) | |
| 183 | errore("Troppi tentativi di immissione errati")
| |
| 184 | end | |
| 185 | end | |
| 186 | end | |
| 187 | end | |
| 188 | ||
| 189 | function acquista(product,modid,price) | |
| 190 | --LEGODEBUG | |
| 191 | print("Prodotto: " .. product)
| |
| 192 | print("Modid " .. modid)
| |
| 193 | print("Prezzo " .. price)
| |
| 194 | term.clear() | |
| 195 | drawFilledBox(1, 1, 51, 19, colors.yellow) | |
| 196 | drawFilledBox(1, 1, 51, 1, colors.orange) | |
| 197 | term.setCursorPos(2, 1) | |
| 198 | colore(colours.white) | |
| 199 | print("PECTEN")
| |
| 200 | drawFilledBox(1, 2, 51, 2, colors.red) | |
| 201 | drawFilledBox(1, 3, 51, 21, colors.yellow) | |
| 202 | ||
| 203 | colore(colors.black) | |
| 204 | drawFilledBox(4, 4, 11, 7, colors.red) | |
| 205 | term.setCursorPos(7, 5) | |
| 206 | print("16")
| |
| 207 | term.setCursorPos(5, 6) | |
| 208 | print("secchi")
| |
| 209 | drawFilledBox(16, 4, 23, 7, colors.red) | |
| 210 | term.setCursorPos(19, 5) | |
| 211 | print("32")
| |
| 212 | term.setCursorPos(17, 6) | |
| 213 | print("secchi")
| |
| 214 | drawFilledBox(40, 4, 47, 7, colors.red) | |
| 215 | term.setCursorPos(41, 5) | |
| 216 | print("Pieno")
| |
| 217 | term.setCursorPos(41, 6) | |
| 218 | print("vagone")
| |
| 219 | drawFilledBox(28, 4, 35, 7, colors.red) | |
| 220 | term.setCursorPos(29, 5) | |
| 221 | print("Pieno")
| |
| 222 | term.setCursorPos(29, 6) | |
| 223 | print("loco")
| |
| 224 | ||
| 225 | term.setCursorPos(20, 9) | |
| 226 | term.setBackgroundColor( colors.yellow ) | |
| 227 | colore(colors.red) | |
| 228 | print("AVVERTENZE:")
| |
| 229 | term.setCursorPos(2, 11) | |
| 230 | colore(colors.black) | |
| 231 | print("Mantenere la loco spenta durante il rifornimento")
| |
| 232 | ||
| 233 | selezione = false | |
| 234 | while(selezione == false) do | |
| 235 | local event, par1, x, y = os.pullEvent("mouse_click")
| |
| 236 | if event == "mouse_click" and x >= 4 and x <= 11 and y >= 4 and y <= 7 then -- 16 | |
| 237 | order = product .. "-" .. modid .. "-16" | |
| 238 | paga(tonumber(price),tonumber(product),tonumber(modid),16) | |
| 239 | ||
| 240 | -- selezione = true | |
| 241 | elseif event == "mouse_click" and x >= 16 and x <= 23 and y >= 4 and y <= 7 then -- 32 | |
| 242 | order = product .. "-" .. modid .. "-32" | |
| 243 | paga(tonumber(price),tonumber(product),tonumber(modid),32) | |
| 244 | ||
| 245 | elseif event == "mouse_click" and x >= 28 and x <= 35 and y >= 4 and y <= 7 then -- pieno loco | |
| 246 | order = product .. "-" .. modid .. "-160" | |
| 247 | paga(tonumber(price),tonumber(product),tonumber(modid),160) | |
| 248 | ||
| 249 | ||
| 250 | elseif event == "mouse_click" and x >= 40 and x <= 47 and y >= 4 and y <= 7 then -- pieno vagone | |
| 251 | order = product .. "-" .. modid .. "-208" | |
| 252 | paga(tonumber(price),tonumber(product),tonumber(modid),208) | |
| 253 | ||
| 254 | ||
| 255 | end | |
| 256 | end | |
| 257 | ||
| 258 | ||
| 259 | end | |
| 260 | ||
| 261 | sfondo(colours.yellow) | |
| 262 | term.clear() | |
| 263 | drawFilledBox(13, 3, 13, 9, colors.red) | |
| 264 | drawFilledBox(14, 3, 15, 3, colors.red) | |
| 265 | drawFilledBox(16, 4, 16, 5, colors.red) | |
| 266 | drawFilledBox(14, 6, 15, 6, colors.red) | |
| 267 | drawFilledBox(18, 5, 18, 9, colors.red) | |
| 268 | drawFilledBox(19, 5, 20, 5, colors.red) | |
| 269 | drawFilledBox(19, 9, 20, 9, colors.red) | |
| 270 | drawFilledBox(19, 7, 19, 7, colors.red) | |
| 271 | drawFilledBox(22, 6, 22, 8, colors.red) | |
| 272 | drawFilledBox(23, 5, 24, 5, colors.red) | |
| 273 | drawFilledBox(23, 9, 24, 9, colors.red) | |
| 274 | drawFilledBox(26, 5, 28, 5, colors.red) | |
| 275 | drawFilledBox(27, 6, 27, 9, colors.red) | |
| 276 | drawFilledBox(30, 5, 30, 9, colors.red) | |
| 277 | drawFilledBox(31, 5, 32, 5, colors.red) | |
| 278 | drawFilledBox(31, 9, 32, 9, colors.red) | |
| 279 | drawFilledBox(31, 7, 31, 7, colors.red) | |
| 280 | drawFilledBox(34, 5, 34, 9, colors.red) | |
| 281 | drawFilledBox(37, 5, 37, 9, colors.red) | |
| 282 | drawFilledBox(35, 6, 35, 6, colors.red) | |
| 283 | drawFilledBox(36, 7, 36, 7, colors.red) | |
| 284 | sfondo(colours.yellow) | |
| 285 | colore(colours.black) | |
| 286 | term.setCursorPos(8, 14) | |
| 287 | print("Premi un tasto qualsiasi per iniziare...")
| |
| 288 | local event, key = os.pullEvent("key")
| |
| 289 | ||
| 290 | clear() | |
| 291 | drawFilledBox(1, 1, 51, 19, colors.yellow) | |
| 292 | drawFilledBox(1, 1, 51, 1, colors.orange) | |
| 293 | term.setCursorPos(2, 1) | |
| 294 | colore(colours.white) | |
| 295 | print("PECTEN")
| |
| 296 | drawFilledBox(1, 2, 51, 2, colors.red) | |
| 297 | local index = -1 | |
| 298 | term.setCursorPos(44, 1) | |
| 299 | colore(colors.black) | |
| 300 | sfondo(colors.red) | |
| 301 | - | local productsRaw = http.get("http://172.16.20.220/luanet/servlets/test.txt").readAll()
|
| 301 | + | |
| 302 | ||
| 303 | ||
| 304 | local productsRaw = http.get("http://192.168.13.103/api.php").readAll()
| |
| 305 | products = textutils.unserialize(productsRaw) | |
| 306 | ||
| 307 | for k, v in pairs(products) do | |
| 308 | if(index == tonumber(v.page)) then | |
| 309 | term.setCursorPos(3, tonumber(v.PagePosition)) | |
| 310 | term.setBackgroundColor( colors.yellow ) | |
| 311 | colore(colors.black) | |
| 312 | if type(v.prezzo) == "string" then | |
| 313 | term.write(v.nome) | |
| 314 | term.setCursorPos(30, tonumber(v.PagePosition)) | |
| 315 | term.write(tostring(v.prezzo) .. " IC") | |
| 316 | ||
| 317 | else | |
| 318 | term.write(v.nome) | |
| 319 | end | |
| 320 | term.setCursorPos(3, tonumber(v.PagePosition)) | |
| 321 | if not (v.categoria == "lista") then | |
| 322 | colore(colors.black) | |
| 323 | term.setBackgroundColor( colors.red ) | |
| 324 | term.setCursorPos(39, tonumber(v.PagePosition)) | |
| 325 | term.write("seleziona")
| |
| 326 | term.setBackgroundColor( colors.yellow ) | |
| 327 | end | |
| 328 | end | |
| 329 | end | |
| 330 | click = false | |
| 331 | while(click == false) do | |
| 332 | local event, par1, x, y = os.pullEvent("mouse_click")
| |
| 333 | ||
| 334 | for k, v in pairs(products) do | |
| 335 | if (v.PagePosition ~= nil) then | |
| 336 | if event == "mouse_click" and x >= 39 and x <= 49 and y >= tonumber(v.PagePosition) and y <= tonumber(v.PagePosition) then -- seleziona | |
| 337 | if (tonumber(v.page) == index) then | |
| 338 | if not (v.categoria == "lista") then | |
| 339 | term.setCursorPos(1, 1) | |
| 340 | acquista(v.id,v.modId,tonumber(v.prezzo)) | |
| 341 | click = true | |
| 342 | end | |
| 343 | end | |
| 344 | elseif event == "mouse_click" and x >= 44 and x <= 50 and y >= 1 and y <= 1 then -- ANNULLA | |
| 345 | os.reboot() | |
| 346 | end | |
| 347 | end | |
| 348 | end | |
| 349 | end | |
| 350 |