View difference between Paste ID: Q61MwDZ8 and 8guBJxhh
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 QUARRIES             ")
193
    colore(colors.white)
194
    sfondo(colors.red)
195
    term.setCursorPos(35, 1)
196
    term.write(" CHIUDI SESSIONE ")
197
    fineColore()
198
    fineSfondo()
199
    print("")
200
    print("\nProdotto           Prezzo")
201
    p = {}
202
    -- nome, prezzo, id, meta, colore cavo
203-
    p[1] = {"Barite (Glowstone)", 648, 348, 0, 1}
203+
    p[1] = {"Sabbia", 12, 12, 0, 1}
204-
    p[2] = {"Antracite densa", 378, 149, 0, 2}
204+
    p[2] = {"Terra", 6, 3, 0, 2}
205-
    p[3] = {"Ferro denso", 2990, 149, 1, 4}
205+
    p[3] = {"Ghiaia", 14, 13, 0, 4}
206
    p[4] = {"Carbone", 50, 263, 0, 4}
207
208
    ypos = 4
209
    for k, v in pairs(p) do
210
        term.setCursorPos(1, ypos)
211
        term.write(v[1])
212
        term.setCursorPos(20, ypos)
213
        term.write(v[2])
214
        term.setCursorPos(30, ypos)
215
        if alt == false then
216
            sfondo(colors.lightBlue)
217
            alt = true
218
        else
219
            sfondo(colors.blue)
220
            alt = false
221
        end
222
        colore(colors.white)
223
        term.write(" Compra ")
224
        fineSfondo()
225
        fineColore()
226
        ypos = ypos + 1
227
    end
228
229
    while true do
230
231-
        if event == "mouse_click" and y > 3 and y < 7 then
231+
232
        if event == "mouse_click" and y > 3 and y < 8 then
233
            prodotto = p[y - 3]
234
            break
235
        elseif event == "mouse_click" and y == 1 then
236
            os.reboot()
237
        end
238
        sleep(1)
239
    end
240
    clear()
241
242
    print(prodotto[1])
243
244
    if colors.test(redstone.getBundledInput("bottom"), prodotto[5]) == true then
245
        prodottoEsaurito()
246
    end
247
    term.clear()
248
    term.setCursorPos(1, 1)
249
    titolo("Paga con Nebraska Pay")
250
    sfondo(colours.black)
251
    colore(colors.white)
252
    print("\n\nSaldo disponibile: " .. risposta.saldo .. " IC")
253
    if tonumber(risposta.saldo) >= tonumber(prodotto[2]) then
254
        prezzoAccettato = true
255
    else
256
        errore("Disponibilità insufficiente!")
257
    end
258
    term.setCursorPos(1, 3)
259
    term.write("Invio di ")
260
    term.write(prodotto[2])
261
    term.write(" IC a favore di ")
262
    term.write("Highland Mining")
263
    print("\n\nConfermare l'operazione?")
264
    colore(colors.yellow)
265
    print("\n\nInvia il denaro           Annulla")
266
    while true do
267
        event, key, x, y = os.pullEvent()
268
        if event == "mouse_click" and x < 16 and y == 8 then
269
            inviaDenaro = http.get(
270
                              "http://172.16.20.220/luanet/servlets/nebraskapay.php?auth=" ..
271
                                  password .. "&utente=" .. utente ..
272-
                                  prodotto[2] .. "&beneficiario=HighlandMining&causale=Merce%20ingrosso%20Kargat")
272+
273
                                  prodotto[2] .. "&beneficiario=HighlandMining&causale=Merce%20ingrosso%20Sandaoling")
274
                              .readAll()
275
            risultatoInvio = textutils.unserialize(inviaDenaro)
276
            if risultatoInvio.stato == "OK" then
277
                break
278
            else
279
                clear()
280
                errore("Errore durante il pagamento")
281
            end
282
        elseif event == "mouse_click" and x > 18 and y == 8 then
283
            errore("Pagamento annullato dall'utente.")
284
        end
285
    end
286
    clear()
287
    titolo("Erogazione in corso")
288
    fineSfondo()
289
    fineColore()
290
    print("\n\nErogazione di un vagone di " .. prodotto[1] .. " in corso...")
291
    print("\nATTENZIONE: IMPIANTO LOGISTIC LENTO, ATTENDERE")
292
    sfondo(colors.red)
293
    colore(colors.white)
294
    ben = peripheral.wrap("back")
295
    ben.makeRequest(ben.getItemIdentifierIDFor(prodotto[3], prodotto[4]), 3456)
296
    sleep(10)
297
end
298