Advertisement
Guest User

Untitled

a guest
Jun 18th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.77 KB | None | 0 0
  1. local component = require("component")
  2. local event = require("event")
  3. local term = require("term")
  4. local fs = require("filesystem")
  5. local sides = require("sides")
  6. local colors = require("colors")
  7.  
  8. local modem = component.modem
  9. local computer = component.computer
  10. local card_reader = component.os_magreader
  11. local redstone = component.redstone
  12.  
  13. local bundle = sides.right
  14. local cab100 = colors.orange
  15. local cab500 = colors.red
  16. local cab2000 = colors.yellow
  17. local cab10000 = colors.green
  18.  
  19. vyber = true
  20.  
  21. modem.open(443)
  22.  
  23. function center(str, line)
  24. c = 1 + math.floor((80 - 0) / 2) - math.floor(#str / 2)
  25. term.setCursor(c, line)
  26. term.write(str)
  27. end
  28.  
  29.  
  30. function toHeader(balance, name)
  31. term.setCursor(1, 0)
  32. term.write(balance)
  33. p = 80 - (math.floor(#balance) + math.floor(#name))
  34.  
  35. for i = p,0,-1 do
  36. term.write(" ")
  37. end
  38.  
  39. term.write(name)
  40. end
  41.  
  42.  
  43. function split(inputstr, sep)
  44. if sep == nil then
  45. sep = "%s"
  46. end
  47. local t={} ; i=1
  48. for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
  49. t[i] = str
  50. i = i + 1
  51. end
  52. return t
  53. end
  54.  
  55.  
  56. function loadC(price)
  57. a = io.open("/home/bankovky/"..price, "r")
  58. b = a:read("*all")
  59. a:close()
  60. return tonumber(b)
  61. end
  62.  
  63. function writeC(val, price)
  64. a = io.open("/home/bankovky/"..price, "w")
  65. a:write(val)
  66. a:close()
  67. end
  68.  
  69. while true do
  70. c100 = loadC(100)
  71. c500 = loadC(500)
  72. c2000 = loadC(2000)
  73. c10000 = loadC(10000)
  74.  
  75. v100 = 0
  76. v500 = 0
  77. v2000 = 0
  78. v10000 = 0
  79.  
  80. celkem_skladem = c100*100 + c500*500 + c2000*2000 + c10000*10000
  81.  
  82. if c100 == 0 and c500 == 0 and c2000 == 0 and c10000 == 0 then
  83. vyber = false
  84. else
  85. vyber = true
  86. end
  87.  
  88. term.clear()
  89. center("ATM Komerční banka", 7)
  90. center("Přiložte kartu", 8)
  91.  
  92. ev, _, user, ucet, uuid = event.pull("magData")
  93. computer.beep(500, 0.5)
  94.  
  95. term.clear()
  96. center("ATM Komerční banka", 7)
  97. center("Zadejte pin: ", 8)
  98. pin = term.read();
  99.  
  100. term.clear()
  101. center("ATM Komerční banka", 7)
  102. center("Probíhá autorizace...", 8)
  103.  
  104. modem.broadcast(443, "LOGIN#" .. ucet .. "#" .. pin)
  105. local _, _, from, port, _, msg = event.pull("modem_message")
  106.  
  107. if msg == "UNKNOW_ACCOUNT" then
  108.  
  109. else
  110. if msg == "BAD_PIN" then
  111.  
  112. else
  113. logged = true
  114. while logged == true do
  115. cut = split(msg, "#")
  116. term.clear()
  117. toHeader("Zůstatek: " .. cut[1] .. "$", "Majitel: " .. cut[2] )
  118. center("ATM Komerční banka", 7)
  119. center("Výběr 1", 9)
  120. center("Odhlásit 0", 10)
  121. term.setCursor(39,11)
  122. volba = tonumber(term.read())
  123.  
  124. if volba == 0 then
  125. logged = false
  126. elseif volba == 1 then
  127. term.clear()
  128. toHeader("Zůstatek: " .. cut[1] .. "$", "Majitel: " .. cut[2] )
  129. center("ATM Komerční banka", 7)
  130. center("Zadejte částku:", 9)
  131. term.setCursor(39,10)
  132. castka = tonumber(term.read())
  133.  
  134. zbyva_vydat = castka
  135. if (tonumber(cut[1]) - castka) >= 0 then
  136. if celkem_skladem >= castka then
  137. term.clear()
  138. toHeader("Zůstatek: " .. cut[1] .. "$", "Majitel: " .. cut[2] )
  139. center("ATM Komerční banka", 7)
  140. center("Zpracovávání...", 9)
  141. center("Prosím počkejte!", 10)
  142. bankovky = 0
  143. while zbyva_vydat ~= 0 do
  144. if zbyva_vydat >= 10000 then
  145. numero = zbyva_vydat / 10000
  146. v10000 = math.floor(numero)
  147. if v10000 > c10000 then
  148. v10000 = c10000
  149. end
  150. zbyva_vydat = zbyva_vydat - (v10000 * 10000)
  151. bankovky = bankovky + v10000
  152. elseif zbyva_vydat >= 2000 then
  153. numero = zbyva_vydat / 2000
  154. v2000 = math.floor(numero)
  155. if v2000 > c2000 then
  156. v2000 = c2000
  157. end
  158. zbyva_vydat = zbyva_vydat - (v2000 * 2000)
  159. bankovky = bankovky + v2000
  160. elseif zbyva_vydat >= 500 then
  161. numero = zbyva_vydat / 500
  162. v500 = math.floor(numero)
  163. if v500 > c500 then
  164. v500 = c500
  165. end
  166. zbyva_vydat = zbyva_vydat - (v500 * 500)
  167. bankovky = bankovky + v500
  168. elseif zbyva_vydat >= 100 then
  169. numero = zbyva_vydat / 100
  170. v100 = math.floor(numero)
  171. if v100 > c100 then
  172. v100 = c100
  173. end
  174. zbyva_vydat = zbyva_vydat - (v100 * 100)
  175. bankovky = bankovky + v100
  176. else
  177. ignore = zbyva_vydat
  178. zbyva_vydat = 0
  179. end
  180. end--while
  181.  
  182. term.clear()
  183. toHeader("Zůstatek: " .. cut[1] .. "$", "Majitel: " .. cut[2] )
  184. center("ATM Komerční banka", 7)
  185. center("Zpracovávání...", 9)
  186. center("Už jen dotaz na server!", 10)
  187.  
  188. if ignore == nil then
  189. ignore = 0
  190. end
  191.  
  192. celk = (castka - ignore) * -1
  193. modem.broadcast(443, "ATM#" .. ucet .. "#" .. celk)
  194. local _, _, from, port, _, msg = event.pull("modem_message")
  195.  
  196. term.clear()
  197. toHeader("Zůstatek: " .. cut[1] .. "$", "Majitel: " .. cut[2] )
  198. center("ATM Komerční banka", 7)
  199. center("Zpracovávání...", 9)
  200. center("K výdeji: "..v10000.."x 10000, "..v2000.."x 2000, "..v500.."x 500,"..v100.."x 100.", 10)
  201. os.sleep(3)
  202.  
  203. while bankovky ~= 0 do
  204. if v10000 ~= nil and v10000 ~= 0 then
  205. while v10000 ~= 0 do
  206. -- Výdej 10 000
  207. redstone.setBundledOutput(bundle, cab10000, 1000)
  208. os.sleep(0.5)
  209. redstone.setBundledOutput(bundle, cab10000, 0)
  210. v10000 = v10000 - 1
  211. c10000 = c10000 - 1
  212. bankovky = bankovky - 1
  213. end
  214. elseif v2000 ~= nil and v2000 ~= 0 then
  215. while v2000 ~= 0 do
  216. -- Výdej 2 000
  217. redstone.setBundledOutput(bundle, cab2000, 1000)
  218. os.sleep(0.5)
  219. redstone.setBundledOutput(bundle, cab2000, 0)
  220. v2000 = v2000 - 1
  221. c2000 = c2000 - 1
  222. bankovky = bankovky - 1
  223. end
  224. elseif v500 ~= nil and v500 ~= 0 then
  225. while v500 ~= 0 do
  226. -- Výdej 500
  227. redstone.setBundledOutput(bundle, cab500, 1000)
  228. os.sleep(0.5)
  229. redstone.setBundledOutput(bundle, cab500, 0)
  230. v500 = v500 - 1
  231. c500 = c500 - 1
  232. bankovky = bankovky - 1
  233. end
  234. elseif v100 ~= nil and v100 ~= 0 then
  235. while v100 ~= 0 do
  236. -- Výdej 100
  237. redstone.setBundledOutput(bundle, cab100, 1000)
  238. os.sleep(0.5)
  239. redstone.setBundledOutput(bundle, cab100, 0)
  240. v100 = v100 - 1
  241. c100 = c100 - 1
  242. bankovky = bankovky - 1
  243. end
  244. end
  245. end
  246.  
  247. writeC(c10000, "10000")
  248. writeC(c2000, "2000")
  249. writeC(c500, "500")
  250. writeC(c100, "100")
  251.  
  252. term.clear()
  253. toHeader("Zůstatek: " .. cut[1] .. "$", "Majitel: " .. cut[2] )
  254. center("ATM Komerční banka", 7)
  255. center("Bankovky byly vyslány, prosím počkejte", 9)
  256. center("než dorazí všechny.", 10)
  257.  
  258. os.sleep(5)
  259.  
  260. else
  261. term.clear()
  262. toHeader("Zůstatek: " .. cut[1] .. "$", "Majitel: " .. cut[2] )
  263. center("ATM Komerční banka", 7)
  264. center("Je nám líto, ale bankomat nemá dostatek financí.", 9)
  265. os.sleep(5)
  266. end--dostatekban
  267. else
  268. term.clear()
  269. toHeader("Zůstatek: " .. cut[1] .. "$", "Majitel: " .. cut[2] )
  270. center("ATM Komerční banka", 7)
  271. center("Je nám líto, ale nemáte dostatek financí na účtu.", 9)
  272. os.sleep(5)
  273. end--dostatekfin
  274. end--volba
  275. end--logged
  276. end --bad pin
  277. end --unknown acc
  278. end --while
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement