CultistaDeCrocs

escavar.lua

Mar 19th, 2024
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.24 KB | None | 0 0
  1. estadosQuarry =
  2. {
  3. [0] = "Cavando",
  4. [1] = "Falta de combustível provável",
  5. [2] = "Bedrock provável",
  6. [3] = "Subindo",
  7. }
  8.  
  9. inverteDirecao = false
  10. tamanhoLado = 5
  11. maxDropar = 20
  12. counterDropar = 0
  13. passosLinha = 0
  14. passosCamada = 1
  15. passosCubo = 1
  16. passosGeral = 0
  17. camada = 1
  18. escolhaModo = 1
  19. areaCubo = 1
  20. estadoQuarry = 0
  21. alturaLinha = 0
  22. comprimentoTunel = 0
  23. cuboAtual = 0
  24.  
  25. local atari = require("bibliotecas.atari")
  26.  
  27. function informacaoCubo()
  28. printSync("Camada: "..camada)
  29. printSync("Passos até dropar: "..maxDropar-counterDropar)
  30. printSync("Passos andados: "..passosGeral.."/"..(areaCubo)-1)
  31. printSync("Passos andados (camada): "..passosCamada.."/"..(tamanhoLado^2)-1)
  32. printSync("Passos andados (linha): "..passosLinha.."/"..tamanhoLado-1)
  33. printBool("Direção invertida", inverteDirecao)
  34. end
  35.  
  36. function informacaoQuarry()
  37. printSync("Passos até dropar: "..maxDropar-counterDropar)
  38. printSync("Passos andados: "..passosGeral.."/?")
  39. writeSync("Status: ")
  40. printCor(estadosQuarry[estadoQuarry], colors.blue)
  41. end
  42.  
  43. function informacaoTunelHorizontal()
  44. printSync("Camada: "..camada)
  45. printSync("Passos até dropar: "..maxDropar-counterDropar)
  46. printSync("Passos andados (cubo): "..passosCubo.."/"..(tamanhoLado^3)-1)
  47. printSync("Passos andados (camada): "..passosCamada.."/"..(tamanhoLado^2)-1)
  48. printSync("Passos andados (linha): "..passosLinha.."/"..tamanhoLado-1)
  49. printSync("Cubos cavados: "..cuboAtual.."/"..comprimentoTunel)
  50. printBool("Direção invertida", inverteDirecao)
  51. end
  52.  
  53. function imprimirInformacao()
  54. funcoesInformacao =
  55. {
  56. [1] = informacaoCubo,
  57. [2] = informacaoCubo,
  58. [3] = informacaoTunelHorizontal,
  59. [4] = informacaoQuarry,
  60. }
  61.  
  62. funcoesInformacao[escolhaModo]()
  63. imprimirCombustivel()
  64. end
  65.  
  66. function cavar()
  67. if(turtle.dig()) then
  68. counterDropar = counterDropar + 1
  69. end
  70. end
  71.  
  72. function cavarBaixo()
  73. if(turtle.digDown()) then
  74. counterDropar = counterDropar + 1
  75. return true
  76. end
  77. end
  78.  
  79. function cavarCima()
  80. if(turtle.digUp()) then
  81. counterDropar = counterDropar + 1
  82. end
  83. end
  84.  
  85. function aumentaPassos()
  86. passosLinha = passosLinha+1
  87. passosCamada = passosCamada+1
  88. passosCubo = passosCubo+1
  89. passosGeral = passosGeral+1
  90. end
  91.  
  92. function andar()
  93. atualizarMonitor(imprimirInformacao)
  94. cavar()
  95.  
  96. if(not(turtle.forward())) then -- Proteção contra gravel
  97. andar()
  98. else
  99. aumentaPassos()
  100. end
  101. end
  102.  
  103. function andarCima()
  104. atualizarMonitor(imprimirInformacao)
  105. cavarCima()
  106.  
  107. if(not(turtle.up())) then -- Proteção contra gravel
  108. andarCima()
  109. else
  110. aumentaPassos()
  111. end
  112. end
  113.  
  114. function cavaLinha()
  115. for i=1, tamanhoLado-1 do
  116. andar()
  117.  
  118. if (counterDropar >= maxDropar) then
  119. jogaLixoFora()
  120. end
  121. end
  122.  
  123. passosLinha = 0
  124. end
  125.  
  126. function cavaCamada()
  127. for i=1, tamanhoLado do
  128. cavaLinha()
  129.  
  130. if (i ~= tamanhoLado) then
  131. if (inverteDirecao) then
  132. turtle.turnLeft()
  133. andar()
  134. turtle.turnLeft()
  135. inverteDirecao = false
  136. else
  137. turtle.turnRight()
  138. andar()
  139. turtle.turnRight()
  140. inverteDirecao = true
  141. end
  142. end
  143. end
  144.  
  145. turtle.turnRight()
  146. turtle.turnRight()
  147. end
  148.  
  149. function posicionaProximoCubo()
  150. if (tamanhoLado%2 == 1) then
  151. turtle.turnRight()
  152. end
  153.  
  154. for i=1, tamanhoLado-1 do
  155. andar()
  156. andarCima()
  157. end
  158.  
  159. if (tamanhoLado%2 == 1) then
  160. turtle.turnRight()
  161. end
  162.  
  163. andar()
  164.  
  165. passosLinha = 0
  166. passosCamada = 1
  167. camada = 1
  168. end
  169.  
  170. function cavaCubo ()
  171. for i=1, tamanhoLado do
  172. cavaCamada()
  173.  
  174. if(i ~= tamanhoLado) then
  175. turtle.digDown()
  176. turtle.down()
  177. aumentaPassos()
  178. atualizarMonitor(imprimirInformacao)
  179.  
  180. passosLinha = 0
  181. passosCamada = 1
  182. end
  183.  
  184. camada = camada+1
  185. end
  186. end
  187.  
  188. function cavaTunelVertical ()
  189. for i=1, alturaTunel do
  190. cavaCamada()
  191.  
  192. if(i ~= tamanhoLado) then
  193. turtle.digDown()
  194. turtle.down()
  195. aumentaPassos()
  196. atualizarMonitor(imprimirInformacao)
  197.  
  198. passosLinha = 0
  199. passosCamada = 1
  200. end
  201.  
  202. camada = camada+1
  203. end
  204. end
  205.  
  206. function cavaTunelHorizontal ()
  207. for i=1, comprimentoTunel do
  208. cavaCubo()
  209. posicionaProximoCubo()
  210. cuboAtual = cuboAtual+1
  211. passosCubo = 0
  212. end
  213. end
  214.  
  215. function cavaTunelCustomizado ()
  216. for i=1, comprimentoTunel do
  217. cavaTunelVertical()
  218. posicionaProximoCubo()
  219. cuboAtual = cuboAtual+1
  220. passosCubo = 0
  221. end
  222. end
  223.  
  224. function cavaQuarry ()
  225. for i=1, tamanhoLado do
  226. for i=1, tamanhoLado do
  227. coluna()
  228. turtle.turnRight()
  229. andar()
  230. turtle.turnLeft()
  231. end
  232.  
  233. andar()
  234. turtle.turnLeft()
  235.  
  236. for i=1, tamanhoLado do
  237. andar()
  238.  
  239. end
  240.  
  241. turtle.turnRight()
  242. end
  243. end
  244.  
  245. function cavarBaixo()
  246. if(turtle.digDown()) then
  247. counterDropar = counterDropar + 1
  248. return true
  249. else
  250. return false
  251. end
  252. end
  253.  
  254. function cavaColuna()
  255. atualizarMonitor(imprimirInformacao)
  256. if (counterDropar >= maxDropar) then
  257. jogaLixoFora()
  258. end
  259.  
  260. if estadoQuarry ~= 3 then
  261. estadoQuarry = 0
  262. end
  263.  
  264. if cavarBaixo() == false then
  265. estadoQuarry = 1
  266. end
  267.  
  268. if turtle.down() == false then
  269. if estadoQuarry == 0 then
  270. estadoQuarry = 1
  271. atualizarMonitor(imprimirInformacao)
  272. turtle.select(1)
  273. turtle.refuel(1)
  274. else
  275. estadoQuarry = 2
  276. end
  277. else
  278. alturaLinha = alturaLinha + 1
  279. passosGeral = passosGeral + 1
  280. end
  281.  
  282. if estadoQuarry == 2 then
  283. for i=1, alturaLinha do
  284. atualizarMonitor(imprimirInformacao)
  285. if turtle.up() == false then
  286. turtle.digUp()
  287. turtle.select(1)
  288. turtle.refuel(1)
  289. else
  290. passosGeral = passosGeral + 1
  291. end
  292. end
  293. estadoQuarry = 3
  294. atualizarMonitor(imprimirInformacao)
  295. end
  296. end
  297.  
  298. function coluna()
  299. while estadoQuarry ~= 3 do
  300. cavaColuna()
  301. end
  302. estadoQuarry = 0
  303. alturaLinha = 0
  304. end
  305.  
  306. function perguntaCubo()
  307. printCor("Qual é o tamanho do lado do cubo?", colors.orange)
  308. tamanhoLado = lerNumero()
  309.  
  310. areaCubo = tamanhoLado^3
  311.  
  312. informacaoCombustivelNecessario((areaCubo) - 1)
  313. end
  314.  
  315. function perguntaTunelVertical()
  316. printCor("Qual é o tamanho do lado do túnel?", colors.orange)
  317. tamanhoLado = lerNumero()
  318.  
  319. printCor("Qual é a altura do túnel?", colors.orange)
  320. alturaTunel = lerNumero()
  321.  
  322. areaCubo = (tamanhoLado^2)*alturaTunel
  323.  
  324. informacaoCombustivelNecessario((areaCubo) - 1)
  325. end
  326.  
  327. function perguntaTunelHorizontal()
  328. printCor("Qual é o tamanho do lado do cubo?", colors.orange)
  329. tamanhoLado = lerNumero()
  330.  
  331. printCor("Quantos cubos de comprimento o túnel deve ter?", colors.orange)
  332. comprimentoTunel = lerNumero()
  333. end
  334.  
  335. function perguntaQuarry ()
  336. printCor("Qual é o tamanho do lado do quarry?", colors.orange)
  337. tamanhoLado = lerNumero()
  338. end
  339.  
  340. function perguntaValores()
  341. funcoesPergunta =
  342. {
  343. [1] = perguntaCubo,
  344. [2] = perguntaTunelVertical,
  345. [3] = perguntaTunelHorizontal,
  346. [4] = perguntaQuarry,
  347. }
  348.  
  349. funcoesPergunta[escolhaModo]()
  350. end
  351.  
  352. function executaEscolha()
  353. funcoesCava =
  354. {
  355. [1] = cavaCubo,
  356. [2] = cavaTunelVertical,
  357. [3] = cavaTunelHorizontal,
  358. [4] = cavaQuarry,
  359. }
  360.  
  361. funcoesCava[escolhaModo]()
  362. jogaLixoFora()
  363. end
  364.  
  365. -- Main
  366.  
  367. informacaoTitulo("E S C A V A R")
  368.  
  369. print("Escolha o modo de escavação:\n")
  370. imprimirTabela({"Cubo perfeito", "Cubo com altura variável", "Cubo com profundidade variável", "Quarry"})
  371.  
  372. escolhaModo = pedeEscolha(4)
  373.  
  374. perguntaValores()
  375. executaEscolha()
  376.  
  377. agradece(passosGeral)
Advertisement
Add Comment
Please, Sign In to add comment