View difference between Paste ID: ZABbihie and CDyqxXeZ
SHOW: | | - or go back to the newest paste.
1
local maxw, maxh = term.getSize()
2
3
function creditoInsufficiente()
4
    clearRed()
5
    print("Credito insufficiente.")
6
    print("")
7
    print("Premere un tasto per uscire")
8
    os.pullEvent("key")
9
    os.reboot()
10
end
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
local function drawPixelInternal(xPos, yPos)
23
    term.setCursorPos(xPos, yPos)
24
    term.write(" ")
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
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
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
    term.setCursorPos(1, 9)
118
    term.write("Nome utente:")
119
    term.setCursorPos(15, 9)
120
    fineColore()
121
    utenteAccettato = false
122
    conteggioErrori = 0
123
    while utenteAccettato == false do
124
        utente = read()
125
        checkuser = http.get(
126
                        "http://172.16.20.220/luanet/servlets/nebraskapay.php?auth=no&richiesta=verifica&utente=" ..
127
                            utente).readAll()
128
        tabcheckuser = textutils.unserialize(checkuser)
129
        if tabcheckuser.stato == "OK" then
130
            term.setCursorPos(15, 9)
131
            colore(colours.lime)
132
            term.write(utente)
133
            fineColore()
134
            utenteAccettato = true
135
        else
136
            term.setCursorPos(15, 9)
137
            colore(colours.red)
138
            term.write("Utente errato!          ")
139
            sleep(2)
140
            term.setCursorPos(15, 9)
141
            fineColore()
142
            term.write("                       ")
143
            term.setCursorPos(15, 9)
144
            conteggioErrori = conteggioErrori + 1
145
            if conteggioErrori > 2 then
146
                term.setCursorPos(15, 9)
147
                colore(colours.red)
148
                errore("Troppi tentativi di immissione errati    ")
149
            end
150
        end
151
    end
152
    colore(colours.white)
153
    term.setCursorPos(1, 11)
154
    term.write("Password:")
155
    term.setCursorPos(15, 11)
156
    conteggioErrori = 0
157
    passAccettata = false
158
    while passAccettata == false do
159
        fineColore()
160
        password = read("#")
161
        colore(colours.black)
162
        checkuser = http.get(
163
                        "http://172.16.20.220/luanet/servlets/nebraskapay.php?auth=" ..
164
                            password .. "&richiesta=addebito&valore=0&utente=" ..
165
                            utente).readAll()
166
        risposta = textutils.unserialize(checkuser)
167
        if risposta.stato == "OK" then
168
            term.setCursorPos(15, 11)
169
            colore(colours.lime)
170
            term.write("##############               ")
171
            fineColore()
172
            passAccettata = true
173
        else
174
            term.setCursorPos(15, 11)
175
            colore(colours.red)
176
            term.write("Password errata!            ")
177
            conteggioErrori = conteggioErrori + 1
178
            sleep(2)
179
            term.setCursorPos(15, 11)
180
            term.write("                               ")
181
            term.setCursorPos(15, 11)
182
            if conteggioErrori > 2 then
183
                term.setCursorPos(15, 11)
184
                colore(colours.red)
185
                errore("Troppi tentativi di immissione errati")
186
            end
187
        end
188
    end
189
190
while true do
191
    clear()
192
    titolo("HIGHLAND LUMBER             ")
193
    colore(colors.white)
194
    sfondo(colors.red)
195
    term.setCursorPos(35, 1)
196
    term.write(" CHIUDI SESSIONE ")
197
    fineColore()
198
    fineSfondo()
199
    print("\nProdotto           Prezzo")
200
    p = {}
201
    -- nome, prezzo, id, meta, colore cavo
202
    p[1] = {"Nero", 144, 351, 0, 1}
203-
    p[1] = {"Oak", 54, 17, 0, 1}
203+
    p[2] = {"Rosso", 144, 351, 1, 2}
204-
    p[2] = {"Spruce", 54, 17, 1, 2}
204+
    p[3] = {"Verde scuro", 144, 351, 2, 4}
205-
    p[3] = {"Birch", 54, 17, 2, 4}
205+
    p[4] = {"Marrone", 144, 351, 3, 8}
206-
    p[4] = {"Larch", 162, 1388, 0, 8}
206+
    p[5] = {"Blu", 144, 351, 4, 16}
207-
    p[5] = {"Teak", 162, 1388, 1, 16}
207+
    p[6] = {"Viola", 144, 351, 5, 32}
208-
    p[6] = {"Acacia", 162, 1388, 2, 32}
208+
    p[7] = {"Ciano", 144, 351, 6, 64}
209-
    p[7] = {"Walnut", 162, 1391, 1, 64}
209+
    p[8] = {"Grigio chiaro", 144, 351, 7, 128}
210-
    p[8] = {"Chestnut", 162, 1389, 0, 128}
210+
    p[9] = {"Grigio scuro", 144, 351, 8, 256}
211-
    p[9] = {"Wenge", 162, 1389, 1, 256}
211+
    p[10] = {"Rosa", 144, 351, 9, 512}
212-
    p[10] = {"Baobab", 162, 1389, 2, 512}
212+
    p[11] = {"Verde chiaro", 144, 351, 10, 1024}
213-
    p[11] = {"Sequoia", 162, 1389, 3, 1024}
213+
    p[12] = {"Giallo", 144, 351, 11, 2048}
214-
    p[12] = {"Kapok", 162, 1390, 0, 2048}
214+
    p[13] = {"Azzurro", 144, 351, 12, 4096}
215-
    p[13] = {"Ebony", 162, 1390, 1, 4096}
215+
    p[14] = {"Magenta", 144, 351, 13, 8192}
216-
    p[14] = {"Mahogany", 162, 1390, 2, 8192}
216+
    p[15] = {"Arancione", 144, 351, 14, 16384}
217-
    p[15] = {"Balsa", 162, 1390, 3, 16384}
217+
    p[16] = {"Bianco", 144, 351, 15, 32768}
218-
    p[16] = {"Willow", 162, 1391, 0, 32768}
218+
	p[17] = {"Schiavo", 50000, 352, 0, 32768}
219
220-
    ypos = 4
220+
    ypos = 3
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
244+
        if event == "mouse_click" and y > 2 then
245-
            prodotto = p[y - 3]
245+
            prodotto = p[y - 2]
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
            inviaDenaro = http.get(
282
                              "http://172.16.20.220/luanet/servlets/nebraskapay.php?auth=" ..
283
                                  password .. "&utente=" .. utente ..
284
                                  "&richiesta=trasferimento&valore=" ..
285-
                                  prodotto[2] .. "&beneficiario=HighlandMining&causale=Merce%20ingrosso%20Crianlarich")
285+
                                  prodotto[2] .. "&beneficiario=HighlandMining&causale=Merce%20ingrosso%20Endovier")
286
                              .readAll()
287
            risultatoInvio = textutils.unserialize(inviaDenaro)
288
            if risultatoInvio.stato == "OK" then
289
                break
290
            else
291
                clear()
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
    clear()
299
    titolo("Erogazione in corso")
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