View difference between Paste ID: yEyV3cLJ and aCr16vcw
SHOW: | | - or go back to the newest paste.
1
local maxw, maxh = term.getSize()
2
3
4
function creditoInsufficiente()
5
    clearRed()
6
    print("Credito insufficiente.")
7
    print("")
8
    print("Premere un tasto per uscire")
9
    os.pullEvent("key")
10
    os.reboot()
11
end
12
13
function prodottoEsaurito()
14
    clearRed()
15
    print("Prodotto esaurito.")
16
    print("")
17
    print("Premere un tasto per uscire")
18
    os.pullEvent("key")
19
    os.reboot()
20
end
21
22
-- IMPLEMENTAZIONE DEL DRAWFILLEDBOX
23
local function drawPixelInternal(xPos, yPos)
24
    term.setCursorPos(xPos, yPos)
25
    term.write(" ")
26
end
27
28
local tColourLookup = {}
29
for n = 1, 16 do
30
    tColourLookup[string.byte("0123456789abcdef", n, n)] = 2 ^ (n - 1)
31
end
32
33
function drawFilledBox(startX, startY, endX, endY, nColour)
34
    if type(startX) ~= "number" or type(startX) ~= "number" or type(endX) ~=
35
        "number" or type(endY) ~= "number" or
36
        (nColour ~= nil and type(nColour) ~= "number") then
37
        error("Expected startX, startY, endX, endY, colour", 2)
38
    end
39
40
    startX = math.floor(startX)
41
    startY = math.floor(startY)
42
    endX = math.floor(endX)
43
    endY = math.floor(endY)
44
45
    if nColour then term.setBackgroundColor(nColour) end
46
    if startX == endX and startY == endY then
47
        drawPixelInternal(startX, startY)
48
        return
49
    end
50
51
    local minX = math.min(startX, endX)
52
    if minX == startX then
53
        minY = startY
54
        maxX = endX
55
        maxY = endY
56
    else
57
        minY = endY
58
        maxX = startX
59
        maxY = startY
60
    end
61
62
    for x = minX, maxX do for y = minY, maxY do drawPixelInternal(x, y) end end
63
end
64
65
function clear()
66
    sfondo(colors.black)
67
    term.clear()
68
    term.setCursorPos(1, 1)
69
end
70
71
function clearRed()
72
    sfondo(colors.red)
73
    term.clear()
74
    term.setCursorPos(1, 1)
75
end
76
77
function colore(sfumatura) term.setTextColour(sfumatura) end
78
79
function sfondo(sfumaturaSfondo) term.setBackgroundColour(sfumaturaSfondo) end
80
81
function fineColore() term.setTextColour(colours.white) end
82
83
function fineSfondo() term.setBackgroundColour(colours.black) end
84
85
function titolo(testo)
86
    drawFilledBox(1, 1, maxw, 1, colors.yellow)
87
    term.setCursorPos((maxw - #testo) / 2, 1)
88
    colore(colors.black)
89
    term.write(testo)
90
    sfondo(colors.blue)
91
end
92
93
function errore(errore)
94
    sfondo(colors.red)
95
    colore(colors.white)
96
    term.clear()
97
    term.setCursorPos(1, 1)
98
    titolo("Errore irreversibile")
99
    term.setCursorPos(1, 3)
100
    sfondo(colors.red)
101
    colore(colors.white)
102
    print(errore)
103
    print("\n\n\nAttendere qualche secondo...")
104
    os.sleep(5)
105
    os.reboot()
106
end
107
108
sfondo(colours.blue)
109
    term.clear()
110
    term.setCursorPos(1, 1)
111
    titolo("Pagamento rapido con Nebraska Pay")
112
    sfondo(colours.blue)
113
    colore(colors.white)
114
    print(
115
        "\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.")
116
117
    -- nomeutente
118
    term.setCursorPos(1, 9)
119
    term.write("Nome utente:")
120
    term.setCursorPos(15, 9)
121
    fineColore()
122
    utenteAccettato = false
123
    conteggioErrori = 0
124
    while utenteAccettato == false do
125
        utente = read()
126
        checkuser = http.get(
127
                        "http://172.16.20.220/luanet/servlets/nebraskapay.php?auth=no&richiesta=verifica&utente=" ..
128
                            utente).readAll()
129
        tabcheckuser = textutils.unserialize(checkuser)
130
        if tabcheckuser.stato == "OK" then
131
            term.setCursorPos(15, 9)
132
            colore(colours.lime)
133
            term.write(utente)
134
            fineColore()
135
            utenteAccettato = true
136
        else
137
            term.setCursorPos(15, 9)
138
            colore(colours.red)
139
            term.write("Utente errato!          ")
140
            sleep(2)
141
            term.setCursorPos(15, 9)
142
            fineColore()
143
            term.write("                       ")
144
            term.setCursorPos(15, 9)
145
            conteggioErrori = conteggioErrori + 1
146
            if conteggioErrori > 2 then
147
                term.setCursorPos(15, 9)
148
                colore(colours.red)
149
                errore("Troppi tentativi di immissione errati    ")
150
            end
151
        end
152
    end
153
    colore(colours.white)
154
    term.setCursorPos(1, 11)
155
    term.write("Password:")
156
    term.setCursorPos(15, 11)
157
    conteggioErrori = 0
158
    passAccettata = false
159
    while passAccettata == false do
160
        fineColore()
161
        password = read("#")
162
        colore(colours.black)
163
        checkuser = http.get(
164
                        "http://172.16.20.220/luanet/servlets/nebraskapay.php?auth=" ..
165
                            password .. "&richiesta=addebito&valore=0&utente=" ..
166
                            utente).readAll()
167
        risposta = textutils.unserialize(checkuser)
168
        if risposta.stato == "OK" then
169
            term.setCursorPos(15, 11)
170
            colore(colours.lime)
171
            term.write("##############               ")
172
            fineColore()
173
            passAccettata = true
174
        else
175
            term.setCursorPos(15, 11)
176
            colore(colours.red)
177
            term.write("Password errata!            ")
178
            conteggioErrori = conteggioErrori + 1
179
            sleep(2)
180
            term.setCursorPos(15, 11)
181
            term.write("                               ")
182
            term.setCursorPos(15, 11)
183
            if conteggioErrori > 2 then
184
                term.setCursorPos(15, 11)
185
                colore(colours.red)
186
                errore("Troppi tentativi di immissione errati")
187
            end
188
        end
189
    end
190
191
while true do
192
    clear()
193
    titolo("FoxInvest Holding             ")
194
    colore(colors.white)
195
    sfondo(colors.red)
196
    term.setCursorPos(35, 1)
197
    term.write(" CHIUDI SESSIONE ")
198
    fineColore()
199
    fineSfondo()
200
    print("")
201
    print("\nProdotto           Prezzo")
202
    p = {}
203
    -- nome, prezzo, id, meta, colore cavo
204-
    p[1] = {"Scrap", 40, 337, 0, 1}
204+
    p[1] = {"64 IC", 40, 337, 0, 1}
205
    p[2] = {"128 IC", 40, 337, 0, 1}
206
207
    ypos = 4
208
    for k, v in pairs(p) do
209
        term.setCursorPos(1, ypos)
210
        term.write(v[1])
211
        term.setCursorPos(20, ypos)
212
        term.write(v[2])
213
        term.setCursorPos(30, ypos)
214
        if alt == false then
215
            sfondo(colors.lightBlue)
216
            alt = true
217
        else
218
            sfondo(colors.blue)
219
            alt = false
220
        end
221
        colore(colors.white)
222
        term.write(" Compra ")
223
        fineSfondo()
224
        fineColore()
225
        ypos = ypos + 1
226
    end
227
228
    while true do
229
230
        local event, par1, x, y = os.pullEvent("mouse_click")
231
        if event == "mouse_click" and y > 3 and y < 5 then
232
            prodotto = p[y - 3]
233
            break
234
        elseif event == "mouse_click" and y == 1 then
235
            os.reboot()
236
        end
237
        sleep(1)
238
    end
239
    clear()
240
241
    print(prodotto[1])
242
243
    if colors.test(redstone.getBundledInput("bottom"), prodotto[5]) == true then
244
        prodottoEsaurito()
245
    end
246
    term.clear()
247
    term.setCursorPos(1, 1)
248
    titolo("Paga con Nebraska Pay")
249
    sfondo(colours.black)
250
    colore(colors.white)
251
    print("\n\nSaldo disponibile: " .. risposta.saldo .. " IC")
252
    if tonumber(risposta.saldo) >= tonumber(prodotto[2]) then
253
        prezzoAccettato = true
254
    else
255
        errore("Disponibilità insufficiente!")
256
    end
257
    term.setCursorPos(1, 3)
258
    term.write("Invio di ")
259
    term.write(prodotto[2])
260
    term.write(" IC a favore di ")
261
    term.write("FoxInvest Holding")
262
    print("\n\nConfermare l'operazione?")
263
    colore(colors.yellow)
264
    print("\n\nInvia il denaro           Annulla")
265
    while true do
266
        event, key, x, y = os.pullEvent()
267
        if event == "mouse_click" and x < 16 and y == 8 then
268
            inviaDenaro = http.get(
269
                              "http://172.16.20.220/luanet/servlets/nebraskapay.php?auth=" ..
270
                                  password .. "&utente=" .. utente ..
271
                                  "&richiesta=trasferimento&valore=" ..
272
                                  prodotto[2] .. "&beneficiario=FoxWorn3365")
273
                              .readAll()
274
            risultatoInvio = textutils.unserialize(inviaDenaro)
275
            if risultatoInvio.stato == "OK" then
276
                break
277
            else
278
                clear()
279
                errore("Errore durante il pagamento")
280
            end
281
        elseif event == "mouse_click" and x > 18 and y == 8 then
282
            errore("Pagamento annullato dall'utente.")
283
        end
284
    end
285
    clear()
286
    titolo("Erogazione in corso")
287
    fineSfondo()
288
    fineColore()
289
    print("\n\nErogazione di un vagone di " .. prodotto[1] .. " in corso...")
290
    print("\nATTENZIONE: IMPIANTO LOGISTIC LENTO, ATTENDERE")
291
    sfondo(colors.red)
292
    colore(colors.white)
293
    ben = peripheral.wrap("back")
294
    rs.setOutput("back", true)
295
    sleep(1)
296
    rs.setOutput("back", false)
297
    sleep(10)
298
end
299