Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --cab
- local term=require('term')
- local event=require('event')
- local shell=require('shell')
- local com = require("component")
- local card=com.card_reader
- local fs=require('filesystem')
- local tun=com.tunnel
- local serialization=require('serialization')
- local function saveTbl(tbl, fl) file = io.open(fl, 'w') file:write(serialization.serialize(tbl)) file:close() end
- local function loadTbl(fl) file = io.open(fl, 'r') if not file then file = io.open(fl, 'w') file:write('{}') return {} else return serialization.unserialize(file:read('*a')) end file:close() end
- local gpu=com.gpu
- local m=com.modem
- local loc1
- local owner='vah'
- page=1
- local nextcab='82b0b45e-d89e-a686-off15c9aee7a' --2 кабинка
- local addressRobot='e51089c7-42c7-465b-9791-ccd8758480ea'
- m.open(1)
- local x1,y1,w1,h1=38,20,4,1 local x2,y2,w2,h2=46,20,4,1 local x3,y3,w3,h3=45,3,5,3 local x4,y4,w4,h4=51,3,4,3
- local x5,y5,w5,h5=67,3,4,3 local x6,y6,w6,h6=72,3,5,3 local x7,y7,w7,h7=45,7,32,3 local x8,y8,w8,h8=45,11,32,3
- local x9,y9,w9,h9=45,15,32,3
- strlk='|< |' strlk1='| >|'
- items1={} price1={}
- local thread=require('thread')
- thread.init()
- gpu.setResolution(87,20)
- A,B=gpu.getResolution()
- col={blue=0x0000FF,blue1=0x0000AF,grey=0x898989,grey1=0xACACAC}
- bp={'╬═══════════[Ticket]═══════════╬','╬══════════════════════════════╬','║'}
- function getxy() _,_,ps1,ps2,_=event.pull('touch') return ps1,ps2 end
- function au() card.auth() _,_,_,_,nick=event.pull('card_event') return nick end
- function cpay(sko) card.pay(owner,sko) _,_,_,tf,pri=event.pull('card_event') return tf,pri end
- function top()
- gpu.setBackground(col.grey) term.clear()
- gpu.setBackground(col.grey1) gpu.fill(51,2,15,28,' ')
- gpu.setBackground(col.blue1) gpu.fill(1,1,A,1,' ')
- term.setCursor(5,1) io.write('Предмет:')
- gpu.setBackground(col.blue) term.setCursor(51,1) io.write(' В наличии: ') gpu.setBackground(col.blue1)
- term.setCursor(A-12,1) io.write('Цена за шт:')
- gpu.setBackground(0x6495ED) gpu.fill(1,20,87,1,' ') gpu.setBackground(0xFFA500) gpu.set(x1,y1,strlk) gpu.set(x2,y2,strlk1) gpu.setBackground(col.grey)
- end
- function adch()
- while true do
- c=nil price=nil amount=nil b=nil
- key,_,address,port,_,message = event.pull('modem_message')
- c=string.sub(message,1,3) price=string.sub(message,4,9) amount=string.sub(message,10,13) b=string.sub(message,14)
- amount=tonumber(amount) price=tonumber(price)
- if c=='add' then
- for i=1,#items1 do if items1[i]==b then per=1 per2=i break else per=0 end end
- if per==0 then items1[#items1+1]=b saveTbl(items1,'items.txt') f1=io.open(b..'.txt','w') f1:write('{'..amount..','..price..'}') f1:close()
- elseif per==1 then f2=loadTbl(items1[per2]..'.txt') f2[1]=amount saveTbl(f2,items1[per2]..'.txt') end
- elseif c=='del' then
- for i=1,#items do if items[i]==b then per=1 per2=i break else per=0 end end
- if per==1 then
- shell.execute('del '..items[per2]..'.txt')
- items1={}
- for sp=1,#items do if items[sp]~=b then items1[#items1+1]=items[sp] end end
- items=loadTbl('items.txt') saveTbl(items1,'items.txt') end
- end end end
- function tb(co,str)
- gpu.setBackground(0x898989) term.clear()
- gpu.setBackground(co) gpu.fill(23,7,36,5,' ') term.setCursor(25,9) io.write(str)
- term.setCursor(23,7) io.write('╬══════════════════════════════════╬') for i=8,11 do term.setCursor(23,i) io.write(bp[3]) end
- term.setCursor(23,12) io.write('╬══════════════════════════════════╬') for i=8,11 do term.setCursor(58,i) io.write(bp[3]) end
- end
- function wrt()
- gpu.setBackground(col.grey) term.clear()
- gpu.setBackground(col.blue1) gpu.fill(1,1,A,1,' ')
- gpu.set(39,1,'[Покупка]') gpu.setBackground(col.grey)
- gpu.setBackground(col.grey1) gpu.fill(3,3,30,16,' ')
- term.setCursor(2,3) io.write(bp[1]) term.setCursor(2,18) io.write(bp[2])
- for i=4,17 do term.setCursor(2,i) io.write(bp[3]) end
- for i=4,17 do term.setCursor(33,i) io.write(bp[3]) end
- gpu.setBackground(0xFFA500)
- gpu.fill(x3,y3,w3,h3,' ') term.setCursor(x3+1,y3+1) io.write('+10') gpu.fill(x4,y4,w4,h4,' ') term.setCursor(x4+1,y4+1) io.write('+1')
- gpu.fill(x5,y5,w5,h5,' ') term.setCursor(x5+1,y5+1) io.write('-1') gpu.fill(x6,y6,w6,h6,' ') term.setCursor(x6+1,y6+1) io.write('-10')
- gpu.setBackground(0x00AA00) gpu.fill(x7,y7,w7,h7,' ') term.setCursor(x7+13,y7+1) io.write('Купить')
- gpu.setBackground(0x6495ED) gpu.fill(x8,y8,w8,h8,' ') term.setCursor(x8+6,y8+1) io.write('Использовать скидку')
- gpu.setBackground(0xD00000) gpu.fill(x9,y9,w9,h9,' ') term.setCursor(x9+13,y9+1) io.write('Выход')
- end
- function buy(pos,it)
- skdk=0
- et=true
- items=loadTbl('items.txt') tps=pos*it-1
- if items1[tps] ~=nil then
- tps1=loadTbl(items1[tps]..'.txt')
- locc=tps1[1] locc1=tps1[2]
- m.send(nextcab,1,'add'..'000000'..'0000'..items1[tps])
- if locc ~=0 then
- mlt=math.floor(999998/locc1)
- lct=1
- wrt()
- while et do
- mtp=lct*tps1[2]
- sys=math.floor(mtp-mtp*skdk)
- ss=mtp-sys
- if skdk==0 then mlt1=math.floor(999998/locc1) else
- ml=locc1*skdk mlt1=math.floor(999998/(locc1-ml)) end
- gpu.setBackground(col.grey1) gpu.fill(4,4,29,14,' ')
- term.setCursor(5,4) io.write('Предмет:') term.setCursor(5,5) io.write(items[tps])
- term.setCursor(5,6) io.write('Цена за штуку: ',tps1[2])
- term.setCursor(5,7) io.write('Предметов на складе: ',tps1[1])
- term.setCursor(5,8) io.write('Предметов в чеке: ',lct)
- term.setCursor(5,11) io.write('Итого: ',mtp)
- term.setCursor(5,12) io.write('Скидка: ',skdk*100,'%')
- term.setCursor(5,13) io.write('С учетом скидки: ',sys)
- term.setCursor(5,14) io.write('Сэкономленно средств: ',ss)
- term.setCursor(5,16) io.write('К оплате: ',sys)
- gpu.setBackground(0) gpu.fill(57,3,8,3,' ') term.setCursor(59,4) io.write(lct)
- gpu.setBackground(col.grey)
- sis,sis2=getxy()
- if sis > x3-1 and sis < x3+w3+1 and sis2 > y3-1 and sis2 < h3+y3 then
- if locc>1 then lct=lct+10 end if lct>locc then lct=locc end if lct>mlt1 then lct=mlt1 end
- elseif sis > x4-1 and sis < x4+w4+1 and sis2 > y4-1 and sis2 < h4+y4 then
- if locc>1 then lct=lct+1 end if lct>locc then lct=locc end if lct>mlt1 then lct=mlt1 end
- elseif sis > x5-1 and sis < x5+w5+1 and sis2 > y5-1 and sis2 < h5+y5 then
- if locc>1 then lct=lct-1 end if lct<1 then lct=1 end
- elseif sis > x6-1 and sis < x6+w6+1 and sis2 > y6-1 and sis2 < h6+y6 then
- if locc>1 then lct=lct-10 end if lct<1 then lct=1 end
- elseif sis > x7-1 and sis < x7+w7+1 and sis2 > y7-1 and sis2 < h7+y7 then
- tb(0x6495ED,'Приложите карту к картоприёмнику!')
- nickname=au()
- tb(0xFFA500,'Приложите карту для оплаты чека !')
- usp,prich=cpay(sys)
- if usp==true and prich=='ok' then
- if fs.exists(nickname..'.sale')==false then fi=io.open(nickname..'.sale','w') fi:write('{'..sys..'}') fi:close()
- tb(0x00AA00,' Спасибо за покупку! ')
- tps1[1]=locc1-lct saveTbl(tps1,items1[tps]..'.txt')
- if tps1[1]<9 then tps1[1]='000'..tps1[1] elseif tps1[1]<99 and tps1[1] > 9 then loc1='00'..tps1[1] elseif tps1[1]<999 and tps1[1]>99 then loc1='0'..tps1[1] elseif tps1[1]<9999 and tps1[1]>999 then loc1=tps1[1] end
- m.send(nextcab,1,'add'..'000000'..loc1..items1[tps])
- if lct<9 then lct1=tostring('000'..lct) elseif lct<99 and lct > 9 then lct1=tostring('00'..lct) elseif lct<999 and lct>99 then lct1=tostring('0'..lct) elseif lct<9999 and lct>999 then lct1=tostring(lct) end
- tun.send(lct1..items1[tps]) os.sleep(2) et=false
- elseif fs.exists(nickname..'.sale')==true then sal=loadTbl(nickname..'.sale') sal[1]=sal[1]+sys saveTbl(sal,nickname..'.sale') tb(0x00AA00,' Спасибо за покупку! ')
- tps1[1]=locc-lct saveTbl(tps1,items1[tps]..'.txt')
- if tps1[1]<9 then tps1[1]='000'..tps1[1] elseif tps1[1]<99 and tps1[1] > 9 then loc1='00'..tps1[1] elseif tps1[1]<999 and tps1[1]>99 then loc1='0'..tps1[1] elseif tps1[1]<9999 and tps1[1]>999 then loc1=tps1[1] end
- m.send(nextcab,1,'add'..'000000'..loc1..items1[tps])
- if lct<9 then lct1=tostring('000'..lct) elseif lct<99 and lct > 9 then lct1=tostring('00'..lct) elseif lct<999 and lct>99 then lct1=tostring('0'..lct) elseif lct<9999 and lct>999 then lct1=tostring(lct) end
- tun.send(lct1..items1[tps]) os.sleep(2) et=false end
- elseif usp==false and prich=='rejected' then
- tb(0xD00000,' Платеж отменен пользователем! ') os.sleep(2) et=false
- end
- term.clear() wr(page)
- elseif sis > x8-1 and sis < x8+w8+1 and sis2 > y8-1 and sis2 < h8+y8 then
- tb(0x6495ED,'Приложите карту к картоприёмнику!') nickname=au()
- if fs.exists(nickname..'.sale')==false then fi=io.open(nickname..'.sale','w') fi:write('{0}') fi:close() skdk=0.05
- elseif fs.exists(nickname..'.sale')==true then sal=loadTbl(nickname..'.sale') skdk=sal[1]/10000000 if skdk>0.20 then skdk=0.20 end saveTbl(sal,nickname..'.sale') end wrt()
- elseif sis > x9-1 and sis < x9+w9+1 and sis2 > y9-1 and sis2 < h9+y9 then et=false term.clear() wr(page) end end
- end end end
- function wr(k)
- top()
- op=k*18-18
- op1=k*18
- for i=op,op1 do
- os.sleep(0.0001)
- if items1[i]~=nil then
- mas=loadTbl(items1[i]..'.txt')
- gpu.setBackground(col.grey) term.setCursor(2,i+1) io.write(items1[i]) term.setCursor(57,i+1) gpu.setBackground(col.grey1) io.write(mas[1]) term.setCursor(A-8,i+1) gpu.setBackground(col.grey) io.write(mas[2])
- end end end
- function osn()
- while true do
- key,_,address,port,_,message = event.pull('touch')
- if address > x1-1 and address < x1+w1+1 and port > y1-1 and port < h1+y1 then
- if page>1 and page~=0 then page=page-1 end if page<1 then page=1 end
- wr(page)
- elseif address > x2-1 and address < x2+w2+1 and port > y2-1 and port < h2+y2 then
- ypa=math.floor(#items1/18) ypa2=#items/18 if ypa2>ypa then ypa3=math.floor(ypa+1) else ypa3=ypa end
- if page<ypa3 then page=page+1 end if page>ypa3 then page=ypa3 end
- wr(page)
- elseif port>1 and port<20 then
- buy(page,port)
- end end end
- items=loadTbl('items.txt') for i=1,#items do items1[i]=items[i] end
- wr(page)
- thread.create(osn)
- thread.create(adch)
- thread.waitForAll()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement