Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local component = require("component")
- local robot = require("robot")
- local computer = require("computer")
- local event = require('event')
- local term = require('term')
- local magnit = component.tractor_beam
- local inventory = component.inventory_controller
- local geolyzer = component.geolyzer
- --Переменные
- local maxSlot = 32
- local timer_harvest = true
- local stop_looting = false
- local maxEnergy = computer.maxEnergy()
- local energy = computer.energy()
- local percentEnergy = math.ceil((100*energy)/maxEnergy)
- local need_percent = 100 - percentEnergy;
- local charge_tool = ""
- local motiga_use = 0
- local pila_use = 0
- local droped = false
- local seeded = false
- local felled = false
- local charged = false
- local chargedTool = false
- local position = { x =0,y=0 }
- local stop_check_inv = false
- local suckLoopI = 0
- local suckLoopEnd = true
- local movingDrop = false
- function checkBlock()
- local block_name = component.geolyzer.analyze(3).name
- local index = string.find(block_name, ":")
- local name = string.sub(block_name, index+1)
- return name
- end
- --moving function start
- function moveFront()
- local moved = robot.forward()
- if moved == true then
- os.sleep(1)
- return true
- else
- moveFront()
- end
- end
- function moveBack()
- local moved = robot.back()
- if moved == true then
- os.sleep(1)
- return true
- else
- moveBack()
- end
- end
- function moveUp()
- local moved = robot.up()
- if moved == true then
- os.sleep(1)
- return true
- else
- moveUp()
- end
- end
- function moveDown()
- local moved = robot.down()
- if moved == true then
- os.sleep(1)
- return true
- else
- moveDown()
- end
- end
- function moveToCharge()
- robot.turnAround()
- for i = 1, 4 do
- moveFront()
- end
- robot.turnAround()
- charging()
- end
- function moveToHarvest()
- local block_name = component.geolyzer.analyze(0).name
- local index = string.find(block_name, ":")
- local name = string.sub(block_name, index+1)
- if name == "tile.BlockSkyStone" or name == "obsidian" then
- timer_harvest = true
- sowing()
- else
- for i = 1, 4 do
- moveFront()
- end
- timer_harvest = true
- sowing()
- end
- end
- function returnToJob()
- movingDrop = false
- if charged == true then
- print("charged")
- for i = 1, 4 do
- moveFront()
- end
- timer_harvest = true
- charged = false
- harvest()
- end
- if chargedTool == true then
- print("chargedTool")
- chargedTool = false
- robot.turnLeft()
- for i = 1, 2 do
- moveFront()
- end
- robot.turnLeft()
- for i = 1, 2 do
- moveFront()
- end
- if suckLoopEnd == false then
- print(" Дайте инструмент в 1 слот, саженцы во 2, пилу в руки и наберите команду app")
- for i = 1, 4 do
- moveBack()
- end
- robot.select(1)
- inventory.equip()
- print("Берём пилу")
- return false
- end
- if seeded == true then
- robot.select(1)
- inventory.equip() -- берем в руки пилу
- imer_harvest = true
- chargedTool = false
- harvest()
- else
- if motiga_use < 4 then
- robot.select(1)
- inventory.equip() -- берем в руки мотыгу
- robot.use()
- robot.use()
- robot.use()
- robot.use()
- motiga_use = 0
- seeded = true
- robot.select(1)
- inventory.equip() -- берем в руки пилу
- timer_harvest = true
- chargedTool = false
- harvest()
- end
- end
- end
- if droped == true then
- print("droped")
- robot.turnLeft()
- for i=1, 6 do
- moveFront()
- end
- robot.turnLeft()
- moveDown()
- droped = false
- timer_harvest = true
- stop_check_inv = false
- harvest()
- end
- end
- function suckLoop()
- suckLoopI = suckLoopI +1
- print(" suckLoop"..suckLoopI)
- if robot.suck() == false then
- if suckLoopI > 50 then
- suckLoopI = 0
- suckLoopEnd = false
- term.clear()
- return false
- end
- os.sleep(1)
- suckLoop()
- end
- end
- function moveToChargeTool(tool)
- charge_tool = tool
- -- 1 slot = мотыга
- -- equip slot = пила
- robot.turnLeft()
- for i = 1, 5 do
- moveFront()
- end
- robot.turnLeft()
- for i = 1, 2 do
- moveUp()
- end
- for i = 1, 3 do
- moveFront()
- end
- robot.select(1) -- меняем местами с саженцами
- inventory.equip()
- robot.dropDown()
- os.sleep(10)
- robot.turnLeft()
- for i = 1, 3 do
- moveFront()
- end
- robot.turnLeft()
- moveFront()
- for i = 1, 2 do
- moveDown()
- end
- robot.turnAround()
- if charge_tool == "pila" then
- os.sleep(70)
- else
- os.sleep(10)
- end
- -- забираем заряженый предмет
- if robot.suck() == false then
- print(" Запуск suckLoop")
- suckLoop()
- if suckLoopEnd == false then
- print(" Насяльника, я не смог забрать инструмент после зарядки :(")
- end
- end
- inventory.equip()
- if charge_tool == "motiga" then
- robot.select(2)
- inventory.equip()
- robot.select(1)
- robot.transferTo(2)
- end
- if charge_tool == "pila" then
- robot.select(1)
- inventory.equip()
- end
- chargedTool = true
- returnToJob()
- end
- function backToStart()
- local y = position.y
- for i = 1, y do
- moveDown()
- position.y = position.y -1
- end
- moveBack()
- position.x = position.x -1
- sowing()
- end
- function movingToDrop()
- if not movingDrop then
- movingDrop = true
- robot.turnLeft()
- for i =1, 6 do
- moveFront()
- end
- moveUp()
- robot.turnLeft()
- for i = 4, maxSlot do
- robot.select(i)
- robot.drop(64)
- os.sleep(2)
- end
- robot.select(1)
- droped = true
- returnToJob()
- end
- end
- --moving function end
- function checkInventory()
- if stop_check_inv == false then
- if robot.count(maxSlot) > 0 then
- timer_harvest = false
- stop_check_inv = true
- return true
- else
- return false
- end
- end
- end
- function calcEnergy()
- maxEnergy = computer.maxEnergy()
- energy = computer.energy()
- percentEnergy = math.ceil((100*energy)/maxEnergy)
- need_percent = 100 - percentEnergy;
- end
- function charging()
- local fulltime = 60
- calcEnergy()
- local stop_time = math.ceil(fulltime*need_percent)/100
- os.sleep(stop_time)
- charged = true
- returnToJob()
- end
- function checkEnergy()
- calcEnergy()
- if percentEnergy < 10 then
- return false
- else
- return true
- end
- end
- function checkTool()
- local tool = robot.durability()
- if tool < 0.1 then
- return false
- else
- return true
- end
- end
- function swingUp()
- local checkWood = true
- checkWood = robot.swingUp()
- pila_use = pila_use +1
- if checkTool() == false then
- moveToChargeTool("pila")
- return true
- end
- if checkWood == true then
- moveUp()
- position.y = position.y +1
- swingUp()
- else
- -- Дерево срублено
- while magnit.suck() do
- magnit.suck()
- end
- felled = true
- backToStart()
- end
- end
- function swingFront()
- local checkWood = false
- local action = "air"
- checkWood,action = robot.swing()
- if checkTool() == false then
- moveToChargeTool("pila")
- return true
- end
- if action == "block" then
- swingFront()
- else
- -- Дерево срублено
- os.sleep(2)
- while component.tractor_beam.suck() do
- component.tractor_beam.suck()
- end
- seeded = false
- felled = true
- if checkInventory() then
- movingToDrop()
- end
- sowing()
- end
- end
- function harvest()
- if checkEnergy() == false then
- timer_harvest = false --Останавливаем сбор
- moveToCharge()
- return false
- end
- if timer_harvest == true then
- swingFront()
- else
- end
- end
- function isBlock()
- local block = checkBlock()
- if block == "sapling" then
- robot.swing()
- return true
- end
- if block == "log" then
- robot.swing()
- isBlock()
- end
- end
- function sowing()
- if checkEnergy() == false then
- timer_harvest = false --Останавливаем сбор
- moveToCharge()
- return false
- end
- isBlock()
- robot.select(2) -- саженцы
- inventory.equip()
- local placed,action = robot.use()
- if placed == true then
- robot.select(1) -- мотыга
- inventory.equip()
- if checkTool() == false then
- moveToChargeTool("motiga")--идём заряжать мотыгу
- return true
- end
- robot.use()
- motiga_use = motiga_use +1
- if checkTool() == false then
- moveToChargeTool("motiga")--идём заряжать мотыгу
- return true
- end
- robot.use()
- motiga_use = motiga_use +1
- if checkTool() == false then
- moveToChargeTool("motiga")--идём заряжать мотыгу
- return true
- end
- robot.use()
- motiga_use = motiga_use +1
- if checkTool() == false then
- moveToChargeTool("motiga")--идём заряжать мотыгу
- return true
- end
- robot.use()
- motiga_use = motiga_use +1
- if checkTool() == false then
- moveToChargeTool("motiga")--идём заряжать мотыгу
- return true
- end
- motiga_use = 0
- seeded = true
- felled = false
- robot.select(2) -- берём пилу
- inventory.equip()
- robot.select(1)
- robot.transferTo(2) -- возвращаем порядок слотов
- if checkTool() == false then
- moveToChargeTool("pila")--идём заряжать пилу
- return true
- end
- harvest()
- else
- robot.select(2) -- пила
- inventory.equip()
- sowing()
- end
- end
- moveToHarvest()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement