View difference between Paste ID: aCr16vcw and cpJExnjX
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-
    titolo("HIGHLAND MINING")
192+
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-
    p[1] = {"Salnitro", 1500, 458, 1, 1}
203+
204
    p[1] = {"Scrap", 40, 337, 0, 1}
205
206
    ypos = 4
207
    for k, v in pairs(p) do
208
        term.setCursorPos(1, ypos)
209
        term.write(v[1])
210
        term.setCursorPos(20, ypos)
211
        term.write(v[2])
212
        term.setCursorPos(30, ypos)
213
        if alt == false then
214
            sfondo(colors.lightBlue)
215
            alt = true
216
        else
217
            sfondo(colors.blue)
218
            alt = false
219
        end
220
        colore(colors.white)
221
        term.write(" Compra ")
222
        fineSfondo()
223
        fineColore()
224
        ypos = ypos + 1
225
    end
226
227
    while true do
228
229
        local event, par1, x, y = os.pullEvent("mouse_click")
230
        if event == "mouse_click" and y > 3 and y < 5 then
231
            prodotto = p[y - 3]
232
            break
233
        elseif event == "mouse_click" and y == 1 then
234
            os.reboot()
235
        end
236
        sleep(1)
237
    end
238
    clear()
239
240
    print(prodotto[1])
241
242
    if colors.test(redstone.getBundledInput("bottom"), prodotto[5]) == true then
243
        prodottoEsaurito()
244
    end
245
    term.clear()
246
    term.setCursorPos(1, 1)
247
    titolo("Paga con Nebraska Pay")
248
    sfondo(colours.black)
249
    colore(colors.white)
250
    print("\n\nSaldo disponibile: " .. risposta.saldo .. " IC")
251
    if tonumber(risposta.saldo) >= tonumber(prodotto[2]) then
252
        prezzoAccettato = true
253
    else
254
        errore("Disponibilità insufficiente!")
255
    end
256
    term.setCursorPos(1, 3)
257
    term.write("Invio di ")
258
    term.write(prodotto[2])
259-
    term.write("Highland Mining")
259+
260
    term.write("FoxInvest Holding")
261
    print("\n\nConfermare l'operazione?")
262
    colore(colors.yellow)
263
    print("\n\nInvia il denaro           Annulla")
264
    while true do
265
        event, key, x, y = os.pullEvent()
266
        if event == "mouse_click" and x < 16 and y == 8 then
267
            inviaDenaro = http.get(
268
                              "http://172.16.20.220/luanet/servlets/nebraskapay.php?auth=" ..
269
                                  password .. "&utente=" .. utente ..
270-
                                  prodotto[2] .. "&beneficiario=HighlandMining&causale=Merce%20ingrosso%20Fornost")
270+
271
                                  prodotto[2] .. "&beneficiario=FoxWorn3365")
272
                              .readAll()
273
            risultatoInvio = textutils.unserialize(inviaDenaro)
274
            if risultatoInvio.stato == "OK" then
275
                break
276
            else
277
                clear()
278
                errore("Errore durante il pagamento")
279
            end
280
        elseif event == "mouse_click" and x > 18 and y == 8 then
281
            errore("Pagamento annullato dall'utente.")
282
        end
283
    end
284
    clear()
285
    titolo("Erogazione in corso")
286
    fineSfondo()
287
    fineColore()
288
    print("\n\nErogazione di un vagone di " .. prodotto[1] .. " in corso...")
289
    print("\nATTENZIONE: IMPIANTO LOGISTIC LENTO, ATTENDERE")
290
    sfondo(colors.red)
291
    colore(colors.white)
292-
    ben.makeRequest(ben.getItemIdentifierIDFor(prodotto[3], prodotto[4]), 3456)
292+
293
    rs.setOutput("back", true)
294
    sleep(1)
295
    rs.setOutput("back", false)
296
    sleep(10)
297
end
298