View difference between Paste ID: QpQvjRfr and Rmc4U7h5
SHOW: | | - or go back to the newest paste.
1
local maxw, maxh = term.getSize()
2
3
function cartaNonValida()
4
    clearRed()
5
    print("Carta non valida o corrotta.")
6
    print("")
7
    print("Premere un tasto per uscire")
8
    os.pullEvent("key")
9
    os.reboot()
10
end
11
12
function cartaVuota()
13
    clearRed()
14
    print("Carta smagnetizzata o vuota.")
15
    print("")
16
    print("Premere un tasto per uscire")
17
    os.pullEvent("key")
18
    os.reboot()
19
end
20
21
function creditoInsufficiente()
22
    clearRed()
23
    print("Credito insufficiente.")
24
    print("")
25
    print("Premere un tasto per uscire")
26
    os.pullEvent("key")
27
    os.reboot()
28
end
29
30
function materialeNonDisponibile()
31
    clearRed()
32
    print("Materiale esaurito.")
33
    print("")
34
    print("Premere un tasto per uscire")
35
    os.pullEvent("key")
36
    os.reboot()
37
end
38
39
-- IMPLEMENTAZIONE DEL DRAWFILLEDBOX
40
local function drawPixelInternal(xPos, yPos)
41
    term.setCursorPos(xPos, yPos)
42
    term.write(" ")
43
end
44
45
local tColourLookup = {}
46
for n = 1, 16 do
47
    tColourLookup[string.byte("0123456789abcdef", n, n)] = 2 ^ (n - 1)
48
end
49
50
function drawFilledBox(startX, startY, endX, endY, nColour)
51
    if type(startX) ~= "number" or type(startX) ~= "number" or type(endX) ~=
52
        "number" or type(endY) ~= "number" or
53
        (nColour ~= nil and type(nColour) ~= "number") then
54
        error("Expected startX, startY, endX, endY, colour", 2)
55
    end
56
57
    startX = math.floor(startX)
58
    startY = math.floor(startY)
59
    endX = math.floor(endX)
60
    endY = math.floor(endY)
61
62
    if nColour then term.setBackgroundColor(nColour) end
63
    if startX == endX and startY == endY then
64
        drawPixelInternal(startX, startY)
65
        return
66
    end
67
68
    local minX = math.min(startX, endX)
69
    if minX == startX then
70
        minY = startY
71
        maxX = endX
72
        maxY = endY
73
    else
74
        minY = endY
75
        maxX = startX
76
        maxY = startY
77
    end
78
79
    for x = minX, maxX do for y = minY, maxY do drawPixelInternal(x, y) end end
80
end
81
82
function clear()
83
    sfondo(colors.lightBlue)
84
    term.clear()
85
    term.setCursorPos(1, 1)
86
end
87
88
function clearRed()
89
    sfondo(colors.red)
90
    term.clear()
91
    term.setCursorPos(1, 1)
92
end
93
94
95
function colore(sfumatura) term.setTextColour(sfumatura) end
96
97
function sfondo(sfumaturaSfondo) term.setBackgroundColour(sfumaturaSfondo) end
98
99
function titolo(testo)
100
    drawFilledBox(1, 1, maxw, 1, colors.yellow)
101
    term.setCursorPos((maxw - #testo) / 2, 1)
102
    colore(colors.black)
103
    term.write(testo)
104
    sfondo(colors.lightBlue)
105
end
106
107
clear()
108
109-
titolo("MINIERA DI BLAR ATHALL - MATERIALI ALL'INGROSSO")
109+
titolo("MINIERA DI KLOW - MATERIALI ALL'INGROSSO")
110
-- startx, starty, endx, endy
111
drawFilledBox(3, 5, 15, 7, colors.yellow)
112
drawFilledBox(3, 10, 15, 12, colors.lightGray)
113
114
term.setCursorPos(4, 6)
115
colore(colors.black)
116-
sfondo(colors.yellow)
116+
sfondo(colors.cyan)
117-
term.write("Oro")
117+
term.write("Diamante")
118
119
term.setCursorPos(4, 11)
120
colore(colors.white)
121-
sfondo(colors.lightGray)
121+
sfondo(colors.black
122-
term.write("Quarzite")
122+
term.write("Antracite")
123
124
while true do
125
    drawFilledBox(18, 5, 50, 17, colors.yellow)
126
    term.setCursorPos(19, 6)
127
    colore(colors.black)
128
    sfondo(colors.yellow)
129
    term.write("ISTRUZIONI - LEGGERE:")
130
    term.setCursorPos(19, 8)
131
    term.write("1. Posizionare il vagone sotto")
132
    term.setCursorPos(19, 9)
133
    term.write("   l'erogatore appropriato")
134
    term.setCursorPos(19, 10)
135
    term.write("2. Controllare che la spia")
136
    term.setCursorPos(19, 11)
137
    term.write("   «presenza vagone» sia accesa")
138
    term.setCursorPos(19, 12)
139
    term.write("3. Selezionare su questo PC")
140
    term.setCursorPos(19, 13)
141
    term.write("   il prodotto desiderato")
142
    term.setCursorPos(19, 14)
143
    term.write("4. Attendere l'erogazione")
144
    term.setCursorPos(19, 15)
145
    term.write("5. Non appena l'operazione sarà")
146
    term.setCursorPos(19, 16)
147
    term.write("   terminata liberare l'area")
148
149
    local event, par1, x, y = os.pullEvent("mouse_click")
150
    if event == "mouse_click" and x >= 3 and x <= 15 and y >= 5 and y <= 7 then
151
        cavo1 = colors.white
152
        cavo2 = colors.lightBlue
153
        cavo3 = colors.pink
154-
        prezzo = 10240
154+
        prezzo = 15400
155-
        materiale = "Oro"
155+
        materiale = "Diamante"
156
        break
157
    elseif event == "mouse_click" and x >= 3 and x <= 15 and y >= 10 and y <= 12 then
158
        cavo1 = colors.orange
159
        cavo2 = colors.yellow
160
        cavo3 = colors.gray
161-
        prezzo = 108
161+
        prezzo = 63
162-
        materiale = "Quarzite"
162+
        materiale = "Antracite"
163
        break
164
    end
165
    sleep(1)
166
end
167
clear()
168
169
if colors.test(redstone.getBundledInput("back"), cavo3) == true then
170
    materialeNonDisponibile()
171
end
172
173
while true do
174
    titolo("Vendita di un vagone di " .. materiale)
175
176
    term.setCursorPos(3, 5)
177
    print("Si sta per acquistare un vagone di " .. materiale)
178
    print("\n  Il prezzo è di " .. prezzo .. " IC")
179
    colore(colors.white)
180
    print("\n\n  Inserire la carta per procedere\n  con l'acquisto")
181
182
    drawFilledBox(15, 14, 36, 16, colors.red)
183
    term.setCursorPos(22, 15)
184
    colore(colors.white)
185
    term.write("Annulla")
186
187
    m = peripheral.wrap("bottom") -- magcard
188
    m.setInsertCardLight(true)
189
190
    event, par1, x, y = os.pullEvent()
191
    if event == "mouse_click" and x >= 15 and x <= 36 and y >= 14 and y <= 16 then
192
        m.setInsertCardLight(false)
193
        os.reboot()
194
    elseif event == "mag_swipe" then
195
        m.setInsertCardLight(false)
196
        break
197
    end
198
end
199
200
if par1 == nil then cartaVuota() end
201
202
tab = textutils.unserialize(par1)
203
204
if type(tab) ~= "table" then cartaNonValida() end
205
206
if tab.t ~= "cc" then cartaNonValida() end
207
208
if tab.e ~= "BN" then cartaNonValida() end
209
210
credito = tonumber(tab.v)
211
212
if prezzo > credito then
213
    creditoInsufficiente()
214
end
215
216
clear()
217
titolo("Conferma pagamento")
218
219
print("\n\nInserire nuovamente la carta per confermare il pagamento")
220
 
221
tabr = {}
222
223
tabr.t = tab.t
224
tabr.e = tab.e
225
tabr.p = tab.p
226
tabr.v = tostring(credito - prezzo)
227
228
ncr = textutils.serialize(tabr)
229
m.setInsertCardLight(true)
230
m.beginWrite(ncr,"BN Credit")
231
os.pullEvent("mag_write_done")
232
m.setInsertCardLight(false)
233
234
clear()
235
titolo("Erogazione in corso")
236
237
print("\n\nErogazione " .. materiale .. " in corso...")
238
239
redstone.setBundledOutput("back", cavo1)
240
sleep(1)
241
redstone.setBundledOutput("back", 0)
242
243
erogazione = false
244
245
while erogazione == false do
246
    erogazione = colors.test(redstone.getBundledInput("back"), cavo2)
247
    sleep(1)
248
end
249
os.reboot()