View difference between Paste ID: CDyqxXeZ and eZ0K6Kdq
SHOW: | | - or go back to the newest paste.
1-
costante = 1
1+
2
3-
m = peripheral.wrap("top")
3+
4-
m.write(" Latte")
4+
5-
m.setCursorPos(1,3)
5+
6-
m.write("Dalmeny:")
6+
7-
m.setCursorPos(1,4)
7+
8-
m.write(costante)
8+
9-
m.setCursorPos(1,5)
9+
10-
m.write("IC/s.")
10+
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-
function gasolioNonDisponibile()
22+
23
    term.setCursorPos(xPos, yPos)
24-
    print("Gasolio esaurito.")
24+
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-
    sfondo(colors.white)
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-
 
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-
clear()
117+
118
    term.write("Nome utente:")
119-
titolo("DISTRIBUTORE DI LATTE DALMENY®")
119+
120-
-- startx, starty, endx, endy
120+
121-
drawFilledBox(3, 4, 15, 6, colors.yellow)
121+
122-
drawFilledBox(3, 8, 15, 10, colors.yellow)
122+
123-
drawFilledBox(3, 12, 15, 14, colors.yellow)
123+
124-
drawFilledBox(3, 16, 15, 18, colors.yellow)
124+
125-
term.setCursorPos(4, 5)
125+
126-
colore(colors.black)
126+
127-
sfondo(colors.yellow)
127+
128-
term.write("16 secchi")
128+
129
        if tabcheckuser.stato == "OK" then
130-
term.setCursorPos(4, 9)
130+
131-
colore(colors.black)
131+
132-
sfondo(colors.yellow)
132+
133-
term.write("32 secchi")
133+
134
            utenteAccettato = true
135-
term.setCursorPos(4, 13)
135+
136-
colore(colors.black)
136+
137-
sfondo(colors.yellow)
137+
138-
term.write("64 secchi")
138+
139
            sleep(2)
140-
term.setCursorPos(4, 17)
140+
141-
colore(colors.black)
141+
142-
sfondo(colors.yellow)
142+
143-
term.write("Pieno Vagone")
143+
144
            conteggioErrori = conteggioErrori + 1
145
            if conteggioErrori > 2 then
146-
    drawFilledBox(18, 5, 50, 17, colors.yellow)
146+
147-
    term.setCursorPos(19, 6)
147+
148
                errore("Troppi tentativi di immissione errati    ")
149-
    sfondo(colors.yellow)
149+
150-
    term.write("ISTRUZIONI - LEGGERE:")
150+
151-
    term.setCursorPos(19, 8)
151+
152-
    term.write("1. Posizionare il vagone/loco")
152+
153-
    term.setCursorPos(19, 9)
153+
154-
    term.write("   sotto l'erogatore appropriato")
154+
155-
    term.setCursorPos(19, 10)
155+
156-
    term.write("2. Controllare che il vagone")
156+
157-
    term.setCursorPos(19, 11)
157+
158-
    term.write("   o loco siano vuoti.")
158+
159-
    term.setCursorPos(19, 12)
159+
160-
    term.write("3. Selezionare su questo PC")
160+
161-
    term.setCursorPos(19, 13)
161+
162-
    term.write("   la quantità desiderata")
162+
163-
    term.setCursorPos(19, 14)
163+
164-
    term.write("4. Attendere l'erogazione")
164+
165-
    term.setCursorPos(19, 15)
165+
166-
    term.write("5. Non appena l'operazione sarà")
166+
167-
    term.setCursorPos(19, 16)
167+
168-
    term.write("   terminata liberare l'area")
168+
169
            colore(colours.lime)
170-
    local event, par1, x, y = os.pullEvent("mouse_click")
170+
171-
    if event == "mouse_click" and x >= 3 and x <= 15 and y >= 4 and y <= 6 then
171+
172-
        qta = 16
172+
173-
        materiale = "16 secchi"
173+
174-
        prezzo = qta * costante
174+
175-
        break
175+
176-
    elseif event == "mouse_click" and x >= 3 and x <= 15 and y >= 8 and y <= 10 then
176+
177-
        qta = 32
177+
178-
        materiale = "32 secchi"
178+
179-
        prezzo = qta * costante
179+
180-
        break
180+
181-
    elseif event == "mouse_click" and x >= 3 and x <= 15 and y >= 12 and y <= 14 then
181+
182-
        qta = 64
182+
183-
        materiale = "64 secchi"
183+
184-
        prezzo = qta * costante
184+
185-
        break
185+
186-
    elseif event == "mouse_click" and x >= 3 and x <= 15 and y >= 16 and y <= 18 then
186+
187-
        qta = 208
187+
188-
        prezzo = qta * costante
188+
189-
        materiale = "Pieno Vagone"
189+
190-
        break
190+
191
    clear()
192-
    sleep(1)
192+
    titolo("HIGHLAND LUMBER             ")
193
    colore(colors.white)
194-
clear()
194+
195
    term.setCursorPos(35, 1)
196-
if redstone.getInput("back") == true then
196+
    term.write(" CHIUDI SESSIONE ")
197-
    errore("Latte esaurito")
197+
198
    fineSfondo()
199
    print("")
200
    print("\nProdotto           Prezzo")
201
    p = {}
202
    -- nome, prezzo, id, meta, colore cavo
203
    p[1] = {"Oak", 54, 17, 0, 1}
204
    p[2] = {"Spruce", 54, 17, 1, 2}
205
    p[3] = {"Birch", 54, 17, 2, 4}
206
    p[4] = {"Larch", 162, 1388, 0, 8}
207-
 
207+
    p[5] = {"Teak", 162, 1388, 1, 16}
208
    p[6] = {"Acacia", 162, 1388, 2, 32}
209
    p[7] = {"Walnut", 162, 1391, 1, 64}
210
    p[8] = {"Chestnut", 162, 1389, 0, 128}
211
    p[9] = {"Wenge", 162, 1389, 1, 256}
212
    p[10] = {"Baobab", 162, 1389, 2, 512}
213
    p[11] = {"Sequoia", 162, 1389, 3, 1024}
214
    p[12] = {"Kapok", 162, 1390, 0, 2048}
215
    p[13] = {"Ebony", 162, 1390, 1, 4096}
216
    p[14] = {"Mahogany", 162, 1390, 2, 8192}
217
    p[15] = {"Balsa", 162, 1390, 3, 16384}
218
    p[16] = {"Willow", 162, 1391, 0, 32768}
219
220
    ypos = 4
221
    for k, v in pairs(p) do
222
        term.setCursorPos(1, ypos)
223
        term.write(v[1])
224
        term.setCursorPos(20, ypos)
225
        term.write(v[2])
226
        term.setCursorPos(30, ypos)
227
        if alt == false then
228
            sfondo(colors.lightBlue)
229
            alt = true
230
        else
231
            sfondo(colors.blue)
232
            alt = false
233
        end
234
        colore(colors.white)
235
        term.write(" Compra ")
236
        fineSfondo()
237
        fineColore()
238
        ypos = ypos + 1
239
    end
240
241
    while true do
242
243
        local event, par1, x, y = os.pullEvent("mouse_click")
244
        if event == "mouse_click" and y > 3 then
245
            prodotto = p[y - 3]
246
            break
247
        elseif event == "mouse_click" and y == 1 then
248
            os.reboot()
249
        end
250
        sleep(1)
251
    end
252
    clear()
253
254
    print(prodotto[1])
255
256
    if colors.test(redstone.getBundledInput("bottom"), prodotto[5]) == true then
257
        prodottoEsaurito()
258
    end
259
    term.clear()
260
    term.setCursorPos(1, 1)
261
    titolo("Paga con Nebraska Pay")
262
    sfondo(colours.blue)
263
    colore(colors.white)
264
    print("\n\nSaldo disponibile: " .. risposta.saldo .. " IC")
265
    if tonumber(risposta.saldo) >= tonumber(prodotto[2]) then
266
        prezzoAccettato = true
267
    else
268
        errore("Disponibilità insufficiente!")
269
    end
270
    term.setCursorPos(1, 3)
271
    term.write("Invio di ")
272
    term.write(prodotto[2])
273
    term.write(" IC a favore di ")
274
    term.write("Highland Mining")
275
    print("\n\nConfermare l'operazione?")
276
    colore(colors.yellow)
277
    print("\n\nInvia il denaro           Annulla")
278
    while true do
279
        event, key, x, y = os.pullEvent()
280
        if event == "mouse_click" and x < 16 and y == 8 then
281-
 
281+
282-
    -- Mostra saldo
282+
283
                                  password .. "&utente=" .. utente ..
284-
 
284+
                                  "&richiesta=trasferimento&valore=" ..
285
                                  prodotto[2] .. "&beneficiario=HighlandMining&causale=Merce%20ingrosso%20Crianlarich")
286
                              .readAll()
287
            risultatoInvio = textutils.unserialize(inviaDenaro)
288
            if risultatoInvio.stato == "OK" then
289
                break
290
            else
291-
    if tonumber(risposta.saldo) >= tonumber(prezzo) then
291+
292
                errore("Errore durante il pagamento")
293
            end
294
        elseif event == "mouse_click" and x > 18 and y == 8 then
295
            errore("Pagamento annullato dall'utente.")
296
        end
297
    end
298-
    term.write(prezzo)
298+
    clear()
299
    titolo("Erogazione in corso")
300-
    term.write("LatteDalmeny")
300+
    fineSfondo()
301
    fineColore()
302
    print("\n\nErogazione di un vagone di " .. prodotto[1] .. " in corso...")
303
    print("\nATTENZIONE: IMPIANTO LOGISTIC LENTO, ATTENDERE")
304
    sfondo(colors.red)
305
    colore(colors.white)
306
    ben = peripheral.wrap("back")
307
    ben.makeRequest(ben.getItemIdentifierIDFor(prodotto[3], prodotto[4]), 3456)
308
    sleep(10)
309
end
310-
                                  "&richiesta=trasferimento&valore=" .. prezzo ..
310+