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