Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local r = require("robot") --Привычнее на r вместо robot
- local component = require("component")
- local inventory = component.inventory_controller
- local inventorySize = r.inventorySize()
- local myPosition = {x = 1, y = 1}
- local positionForReturn = {x = 1, y = 1}
- local slot = 0
- local barrel = {hop = 0, wheat = 0, capsules = 30, timeInHours = 0, x = 1, y = 1, quantity = 0, remainingQuantity = 0}
- local firstStart = true
- --Функции
- local function errorAndPrint(reason)
- print("Произошла ошибка: "..reason.."\nПозиции робота:\nX: "..myPosition.x.."\nY: "..myPosition.y)
- --debug
- print(positionForReturn.x, positionForReturn.y)
- print(barrel.x, barrel.y)
- os.exit()
- end
- local function putInABarrel()
- for i = 1 + slot, 9 + slot, 4 do -- Будет брать 1, 5, 9 слоты, потом 2, 6, 10 и т.д.
- r.select(i)
- inventory.equip()
- if r.use() ~= nil then
- errorAndPrint("Не удалось положить ингредиенты\nв бочку.")
- end
- end
- if slot ~= 3 then
- slot = slot + 1
- else
- slot = 0
- end
- end
- local function nextFreeBarrel()
- if myPosition.x == barrel.x then
- positionForReturn.x, positionForReturn.y = 1, myPosition.y + 1
- else
- positionForReturn.x, positionForReturn.y = myPosition.x + 1, myPosition.y
- end
- end
- local function suckUpAndCheck(quantity, slot)
- r.select(slot)
- while quantity ~= r.count() do
- if not r.suckUp(quantity - r.count()) then
- errorAndPrint("Недостаточно предметов.")
- end
- end
- end
- local function goForward(steps) -- Ходить сколько нужно, больше одного раза.
- for i = 1, steps do
- r.forward()
- print("Идём вперёд "..i)
- end
- end
- local function goBack(steps)
- for i = 1, steps do
- r.back()
- end
- end
- local function getItemsOnBase(quantityStacks) --От 1 до 4
- for i = 1, quantityStacks do
- suckUpAndCheck(barrel.hop, i)
- end
- r.turnLeft()
- r.forward()
- for i = 5, quantityStacks + 4 do
- suckUpAndCheck(barrel.wheat, i)
- end
- r.forward()
- for i = 9, quantityStacks + 8 do
- suckUpAndCheck(barrel.capsules, i)
- end
- goBack(2)
- r.turnRight()
- r.forward()
- end
- local function moveToX1()
- if myPosition.x ~= 1 then
- r.turnRight()
- goForward(myPosition.x - 1)
- r.turnLeft()
- myPosition.x = 1
- end
- end
- local function GoToBase()
- nextFreeBarrel()
- print(myPosition.x, myPosition.y)
- moveToX1()
- for i = 1, myPosition.y - 1 do
- r.down()
- end
- myPosition.y = 1
- r.back()
- end
- local function GoBackToBarrel()
- for i = 1, positionForReturn.y - 1 do
- r.up()
- end
- if positionForReturn.x ~= 1 then
- r.turnLeft()
- goForward(positionForReturn.x - 1)
- r.turnRight()
- end
- myPosition.x, myPosition.y = positionForReturn.x, positionForReturn.y
- end
- local function goLeft()
- r.turnLeft()
- r.forward()
- r.turnRight()
- myPosition.x = myPosition.x + 1
- end
- local function goUp()
- r.up()
- myPosition.y = myPosition.y + 1
- end
- local function dropUpAll()
- for i = 1, inventorySize do
- r.select(i)
- if not r.dropUp() then
- break
- end
- end
- end
- --Спрашиваем про сорт
- print([[Выберите сорт пива:
- 1 - Soup (Похлёбка)
- 2 - White (Белое)
- 3 - Без префикса
- 4 - Dark (Тёмноё)
- 5 - Black (Чёрное)
- 6 - Black Stuff]])
- local sort = {0, 3, 5, 7, 8, 10}
- barrel.hop = sort[tonumber(io.read())]
- barrel.wheat = 10 - barrel.hop
- sort = nil
- if barrel.hop == nil then
- errorAndPrint("введены не правильные данные.")
- end
- print([[Введите соотношение пшеницы + хмеля/капсулы воды
- 1 - Black Stuff
- 2 - Thick
- 3 - Strong (плохо работает)
- 4 - Без названия
- 5 - Lite
- 6 - Stodge]])
- local temp = tonumber(io.read())
- local koff = {9, 6, 4.5, 3, 2, 1}
- if koff[temp] ~= nil then
- barrel.hop = math.min(math.ceil(barrel.hop * koff[temp]), 64)
- barrel.wheat = math.min(math.ceil(barrel.wheat * koff[temp]), 64)
- koff = nil
- else
- koff = nil
- errorAndPrint("введены не правильные данные.")
- end
- print([[Введите время настаивания.
- 1 - Brew 0 часов
- 2 - Youngster 0.5 часа
- 3 - Beer 2 часа
- 4 - Ale 12 часов
- 5 - Dragonblood 24 часа]])
- local time = {0, 0.5, 2, 12, 24}
- barrel.timeInHours = time[tonumber(io.read())]
- time = nil
- if barrel.timeInHours == nil then
- errorAndPrint("введены неправильные данные.")
- end
- print([[Введите кол-во бочек:
- Точка отсчёта начинается с нижнего правого угла
- С права на лево - x
- С низу на вверх - y
- Пример:
- ######
- ######
- ######
- Будет записыватся как x = 6, y = 3
- Так же если ввести x = 1, y = 1,
- то робот будет работать только
- с одной бочкой спереди его
- Если вы не разобрались то напишите
- об этом в чат]])
- io.write("x = ")
- barrel.x = tonumber(io.read())
- io.write("y = ")
- barrel.y = tonumber(io.read())
- if barrel.x == nil or barrel.y == nil then
- errorAndPrint("введены не правильные данные.")
- end
- barrel.quantity = barrel.x * barrel.y
- barrel.remainingQuantity = barrel.quantity
- print("Итого на одну бочку:"..
- "\nХмеля: "..barrel.hop..
- "\nПшеницы: "..barrel.wheat..
- "\nКапсул: 30"..
- "\nИтого:"..
- "\nБочек: "..barrel.quantity..
- "\nХмеля: "..barrel.quantity * barrel.hop..
- "\nПшеницы: "..barrel.quantity * barrel.wheat..
- "\nКапсул: "..barrel.x * barrel.y * 30 ..
- "\nВремя: "..barrel.timeInHours.." часов"..
- "\nУбедитесь в наличии всех ресурсов."..
- "Начать? (введите 0 для выхода)")
- if io.read() == "0" then os.exit() end
- repeat
- local numberOfWork = math.min(barrel.remainingQuantity, 4)
- getItemsOnBase(numberOfWork)
- GoBackToBarrel()
- for i = 1, numberOfWork do
- putInABarrel()
- if i ~= numberOfWork then
- if myPosition.x ~= barrel.x then
- goLeft()
- else
- moveToX1()
- if myPosition.y ~= barrel.y then
- goUp()
- end
- end
- end
- end
- GoToBase()
- barrel.remainingQuantity = barrel.remainingQuantity - numberOfWork
- until barrel.remainingQuantity == 0
- print("Игридиенты загружены, ждите "..barrel.timeInHours.." часов")
- os.sleep(barrel.timeInHours * 3600 + 300)
- barrel.remainingQuantity = barrel.quantity
- repeat
- local numberOfWork = math.min(barrel.remainingQuantity, inventorySize - 1)
- GoBackToBarrel()
- for i = 1, numberOfWork do
- r.swing()
- if i ~= numberOfWork then
- if myPosition.x ~= barrel.x then
- goLeft()
- else
- moveToX1()
- if myPosition.y ~= barrel.y then
- goUp()
- end
- end
- end
- end
- GoToBase()
- r.turnLeft()
- goForward(3)
- dropUpAll()
- goBack(3)
- r.turnRight()
- barrel.remainingQuantity = barrel.remainingQuantity - numberOfWork
- until barrel.remainingQuantity == 0
- print("Пиво сварено и положено в сундук!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement