SHOW:
|
|
- or go back to the newest paste.
1 | ||
2 | - | local r = require("robot") --Привычнее на r вместо robot |
2 | + | local r = require("robot") |
3 | local component = require("component") | |
4 | local inventory = component.inventory_controller | |
5 | ||
6 | local inventorySize = r.inventorySize() | |
7 | local myPosition = {x = 1, y = 1} | |
8 | local positionForReturn = {x = 1, y = 1} | |
9 | local slot = 0 | |
10 | local barrel = {hop = 0, wheat = 0, capsules = 30, timeInHours = 0, x = 1, y = 1, quantity = 0, remainingQuantity = 0} | |
11 | - | local firstStart = true |
11 | + | |
12 | --Функции | |
13 | local function errorAndPrint(reason) | |
14 | - | print("Произошла ошибка: "..reason.."\nПозиции робота:\nX: "..myPosition.x.."\nY: "..myPosition.y) |
14 | + | print("Произошла ошибка: "..reason.."\nПозиции робота:\nX: "..myPosition.x.."\nY: "..myPosition.y) |
15 | - | --debug |
15 | + | os.exit() |
16 | - | print(positionForReturn.x, positionForReturn.y) |
16 | + | |
17 | - | print(barrel.x, barrel.y) |
17 | + | |
18 | - | os.exit() |
18 | + | |
19 | for i = 1 + slot, 9 + slot, 4 do -- Будет брать 1, 5, 9 слоты, потом 2, 6, 10 и т.д. | |
20 | r.select(i) | |
21 | if r.count() ~= 0 then | |
22 | - | for i = 1 + slot, 9 + slot, 4 do -- Будет брать 1, 5, 9 слоты, потом 2, 6, 10 и т.д. |
22 | + | inventory.equip() |
23 | - | r.select(i) |
23 | + | if r.use() ~= nil then |
24 | - | inventory.equip() |
24 | + | errorAndPrint("Не удалось положить ингредиенты\nв бочку.") |
25 | - | if r.use() ~= nil then |
25 | + | end |
26 | - | errorAndPrint("Не удалось положить ингредиенты\nв бочку.") |
26 | + | end |
27 | - | end |
27 | + | end |
28 | - | end |
28 | + | if slot ~= 3 then |
29 | - | if slot ~= 3 then |
29 | + | slot = slot + 1 |
30 | - | slot = slot + 1 |
30 | + | else |
31 | - | else |
31 | + | slot = 0 |
32 | - | slot = 0 |
32 | + | end |
33 | - | end |
33 | + | |
34 | ||
35 | local function nextFreeBarrel() | |
36 | if myPosition.x == barrel.x then | |
37 | - | if myPosition.x == barrel.x then |
37 | + | positionForReturn.x, positionForReturn.y = 1, myPosition.y + 1 |
38 | - | positionForReturn.x, positionForReturn.y = 1, myPosition.y + 1 |
38 | + | else |
39 | - | else |
39 | + | positionForReturn.x, positionForReturn.y = myPosition.x + 1, myPosition.y |
40 | - | positionForReturn.x, positionForReturn.y = myPosition.x + 1, myPosition.y |
40 | + | end |
41 | - | end |
41 | + | |
42 | ||
43 | local function suckUpAndCheck(quantity, slot) | |
44 | r.select(slot) | |
45 | - | r.select(slot) |
45 | + | while quantity ~= r.count() do |
46 | - | while quantity ~= r.count() do |
46 | + | if not r.suckUp(quantity - r.count()) then |
47 | - | if not r.suckUp(quantity - r.count()) then |
47 | + | errorAndPrint("Недостаточно предметов.") |
48 | - | errorAndPrint("Недостаточно предметов.") |
48 | + | end |
49 | - | end |
49 | + | end |
50 | - | end |
50 | + | |
51 | ||
52 | local function goForward(steps) -- Ходить сколько нужно, больше одного раза. | |
53 | for i = 1, steps do | |
54 | - | for i = 1, steps do |
54 | + | r.forward() |
55 | - | r.forward() |
55 | + | end |
56 | - | print("Идём вперёд "..i) |
56 | + | |
57 | - | end |
57 | + | |
58 | local function goBack(steps) | |
59 | for i = 1, steps do | |
60 | r.back() | |
61 | - | for i = 1, steps do |
61 | + | end |
62 | - | r.back() |
62 | + | |
63 | - | end |
63 | + | |
64 | local function getItemsOnBase(quantityStacks) --От 1 до 4 | |
65 | for i = 1, quantityStacks do | |
66 | suckUpAndCheck(barrel.hop, i) | |
67 | - | for i = 1, quantityStacks do |
67 | + | end |
68 | - | suckUpAndCheck(barrel.hop, i) |
68 | + | r.turnLeft() |
69 | - | end |
69 | + | r.forward() |
70 | - | r.turnLeft() |
70 | + | for i = 5, quantityStacks + 4 do |
71 | - | r.forward() |
71 | + | suckUpAndCheck(barrel.wheat, i) |
72 | - | for i = 5, quantityStacks + 4 do |
72 | + | end |
73 | - | suckUpAndCheck(barrel.wheat, i) |
73 | + | r.forward() |
74 | - | end |
74 | + | for i = 9, quantityStacks + 8 do |
75 | - | r.forward() |
75 | + | suckUpAndCheck(barrel.capsules, i) |
76 | - | for i = 9, quantityStacks + 8 do |
76 | + | end |
77 | - | suckUpAndCheck(barrel.capsules, i) |
77 | + | goBack(2) |
78 | - | end |
78 | + | r.turnRight() |
79 | - | goBack(2) |
79 | + | r.forward() |
80 | - | r.turnRight() |
80 | + | |
81 | - | r.forward() |
81 | + | |
82 | local function moveToX1() | |
83 | if myPosition.x ~= 1 then | |
84 | r.turnRight() | |
85 | - | if myPosition.x ~= 1 then |
85 | + | goForward(myPosition.x - 1) |
86 | - | r.turnRight() |
86 | + | r.turnLeft() |
87 | - | goForward(myPosition.x - 1) |
87 | + | myPosition.x = 1 |
88 | - | r.turnLeft() |
88 | + | end |
89 | - | myPosition.x = 1 |
89 | + | |
90 | - | end |
90 | + | |
91 | local function GoToBase() | |
92 | nextFreeBarrel() | |
93 | moveToX1() | |
94 | - | nextFreeBarrel() |
94 | + | for i = 1, myPosition.y - 1 do |
95 | - | print(myPosition.x, myPosition.y) |
95 | + | r.down() |
96 | - | moveToX1() |
96 | + | end |
97 | - | for i = 1, myPosition.y - 1 do |
97 | + | myPosition.y = 1 |
98 | - | r.down() |
98 | + | r.back() |
99 | - | end |
99 | + | |
100 | - | myPosition.y = 1 |
100 | + | |
101 | - | r.back() |
101 | + | |
102 | for i = 1, positionForReturn.y - 1 do | |
103 | r.up() | |
104 | end | |
105 | - | for i = 1, positionForReturn.y - 1 do |
105 | + | if positionForReturn.x ~= 1 then |
106 | - | r.up() |
106 | + | r.turnLeft() |
107 | - | end |
107 | + | goForward(positionForReturn.x - 1) |
108 | - | if positionForReturn.x ~= 1 then |
108 | + | r.turnRight() |
109 | - | r.turnLeft() |
109 | + | end |
110 | - | goForward(positionForReturn.x - 1) |
110 | + | myPosition.x, myPosition.y = positionForReturn.x, positionForReturn.y |
111 | - | r.turnRight() |
111 | + | |
112 | - | end |
112 | + | |
113 | - | myPosition.x, myPosition.y = positionForReturn.x, positionForReturn.y |
113 | + | |
114 | r.turnLeft() | |
115 | r.forward() | |
116 | r.turnRight() | |
117 | - | r.turnLeft() |
117 | + | myPosition.x = myPosition.x + 1 |
118 | - | r.forward() |
118 | + | |
119 | - | r.turnRight() |
119 | + | |
120 | - | myPosition.x = myPosition.x + 1 |
120 | + | |
121 | r.up() | |
122 | myPosition.y = myPosition.y + 1 | |
123 | end | |
124 | - | r.up() |
124 | + | |
125 | - | myPosition.y = myPosition.y + 1 |
125 | + | |
126 | for i = 1, inventorySize do | |
127 | r.select(i) | |
128 | if not r.dropUp() then | |
129 | - | for i = 1, inventorySize do |
129 | + | break |
130 | - | r.select(i) |
130 | + | end |
131 | - | if not r.dropUp() then |
131 | + | end |
132 | - | break |
132 | + | |
133 | - | end |
133 | + | |
134 | - | end |
134 | + | |
135 | --Спрашиваем про сорт | |
136 | print([[Выберите сорт пива: | |
137 | 1 - Soup (Похлёбка) | |
138 | 2 - White (Белое) | |
139 | 3 - Без префикса | |
140 | 4 - Dark (Тёмноё) | |
141 | 5 - Black (Чёрное) | |
142 | 6 - Black Stuff]]) | |
143 | ||
144 | local sort = {0, 3, 5, 7, 8, 10} | |
145 | barrel.hop = sort[tonumber(io.read())] | |
146 | barrel.wheat = 10 - barrel.hop | |
147 | sort = nil | |
148 | if barrel.hop == nil then | |
149 | errorAndPrint("введены неправильные данные.") | |
150 | end | |
151 | ||
152 | - | errorAndPrint("введены не правильные данные.") |
152 | + | |
153 | 1 - Black Stuff | |
154 | 2 - Thick | |
155 | 3 - Strong (плохо работает) | |
156 | 4 - Без названия | |
157 | 5 - Lite | |
158 | 6 - Stodge]]) | |
159 | ||
160 | local temp = tonumber(io.read()) | |
161 | local koff = {9, 6, 4.5, 3, 2, 1} | |
162 | if koff[temp] ~= nil then | |
163 | barrel.hop = math.min(math.ceil(barrel.hop * koff[temp]), 64) | |
164 | barrel.wheat = math.min(math.ceil(barrel.wheat * koff[temp]), 64) | |
165 | koff = nil | |
166 | - | barrel.hop = math.min(math.ceil(barrel.hop * koff[temp]), 64) |
166 | + | |
167 | - | barrel.wheat = math.min(math.ceil(barrel.wheat * koff[temp]), 64) |
167 | + | koff = nil |
168 | - | koff = nil |
168 | + | errorAndPrint("введены неправильные данные.") |
169 | end | |
170 | - | koff = nil |
170 | + | |
171 | - | errorAndPrint("введены не правильные данные.") |
171 | + | |
172 | 1 - Brew 0 часов | |
173 | 2 - Youngster 0.5 часа | |
174 | 3 - Beer 2 часа | |
175 | 4 - Ale 12 часов | |
176 | 5 - Dragonblood 24 часа]]) | |
177 | ||
178 | local time = {0, 0.5, 2, 12, 24} | |
179 | barrel.timeInHours = time[tonumber(io.read())] | |
180 | time = nil | |
181 | if barrel.timeInHours == nil then | |
182 | errorAndPrint("введены неправильные данные.") | |
183 | end | |
184 | ||
185 | - | errorAndPrint("введены неправильные данные.") |
185 | + | print([[Точка отсчёта начинается с нижнего правого угла |
186 | С права на лево - x | |
187 | С низу на вверх - y | |
188 | - | print([[Введите кол-во бочек: |
188 | + | |
189 | - | Точка отсчёта начинается с нижнего правого угла |
189 | + | |
190 | ###### | |
191 | ###### | |
192 | Будет записыватся как x = 6, y = 3 | |
193 | Так же если ввести x = 1, y = 1, | |
194 | то робот будет работать только | |
195 | с одной бочкой спереди его | |
196 | Введите кол-во бочек:]]) | |
197 | ||
198 | io.write("x = ") | |
199 | barrel.x = tonumber(io.read()) | |
200 | - | Если вы не разобрались то напишите |
200 | + | |
201 | - | об этом в чат]]) |
201 | + | |
202 | ||
203 | if barrel.x == nil or barrel.y == nil then | |
204 | errorAndPrint("введены не правильные данные.") | |
205 | end | |
206 | ||
207 | barrel.quantity = barrel.x * barrel.y | |
208 | barrel.remainingQuantity = barrel.quantity | |
209 | - | errorAndPrint("введены не правильные данные.") |
209 | + | |
210 | print("Итого на одну бочку:".. | |
211 | "\nХмеля: "..barrel.hop.. | |
212 | "\nПшеницы: "..barrel.wheat.. | |
213 | "\nКапсул: 30".. | |
214 | "\n\nИтого для всех бочек:".. | |
215 | "\nБочек: "..barrel.quantity.. | |
216 | "\nХмеля: "..barrel.quantity * barrel.hop.. | |
217 | "\nПшеницы: "..barrel.quantity * barrel.wheat.. | |
218 | "\nКапсул: "..barrel.x * barrel.y * 30 .. | |
219 | - | "\nИтого:".. |
219 | + | |
220 | "\nУбедитесь в наличии всех ресурсов.".. | |
221 | "Начать? (введите 0 для выхода)") | |
222 | ||
223 | if io.read() == "0" then os.exit() end | |
224 | ||
225 | repeat | |
226 | local numberOfWork = math.min(barrel.remainingQuantity, 4) | |
227 | getItemsOnBase(numberOfWork) | |
228 | GoBackToBarrel() | |
229 | for i = 1, numberOfWork do | |
230 | putInABarrel() | |
231 | - | local numberOfWork = math.min(barrel.remainingQuantity, 4) |
231 | + | if i ~= numberOfWork then |
232 | - | getItemsOnBase(numberOfWork) |
232 | + | if myPosition.x ~= barrel.x then |
233 | - | GoBackToBarrel() |
233 | + | goLeft() |
234 | - | for i = 1, numberOfWork do |
234 | + | else |
235 | - | putInABarrel() |
235 | + | moveToX1() |
236 | - | if i ~= numberOfWork then |
236 | + | if myPosition.y ~= barrel.y then |
237 | - | if myPosition.x ~= barrel.x then |
237 | + | goUp() |
238 | - | goLeft() |
238 | + | end |
239 | - | else |
239 | + | end |
240 | - | moveToX1() |
240 | + | end |
241 | - | if myPosition.y ~= barrel.y then |
241 | + | end |
242 | - | goUp() |
242 | + | GoToBase() |
243 | - | end |
243 | + | barrel.remainingQuantity = barrel.remainingQuantity - numberOfWork |
244 | - | end |
244 | + | |
245 | - | end |
245 | + | |
246 | - | end |
246 | + | print("Ингредиенты загружены.") |
247 | - | GoToBase() |
247 | + | if barrel.timeInHours ~= 0 then |
248 | - | barrel.remainingQuantity = barrel.remainingQuantity - numberOfWork |
248 | + | for i = 0.5, barrel.timeInHours, 0.5 do |
249 | print("Осталось: "..barrel.timeInHours-i.." часов") | |
250 | os.sleep(1800) | |
251 | - | print("Игридиенты загружены, ждите "..barrel.timeInHours.." часов") |
251 | + | end |
252 | - | os.sleep(barrel.timeInHours * 3600 + 300) |
252 | + | os.sleep(300) --5 минут для того, чтобы всё точно сварилось |
253 | end | |
254 | ||
255 | barrel.remainingQuantity = barrel.quantity | |
256 | r.select(1) | |
257 | - | local numberOfWork = math.min(barrel.remainingQuantity, inventorySize - 1) |
257 | + | positionForReturn.x, positionForReturn.y = 1, 1 |
258 | - | GoBackToBarrel() |
258 | + | |
259 | - | for i = 1, numberOfWork do |
259 | + | |
260 | - | r.swing() |
260 | + | local numberOfWork = math.min(barrel.remainingQuantity, inventorySize - 1) |
261 | - | if i ~= numberOfWork then |
261 | + | r.forward() |
262 | - | if myPosition.x ~= barrel.x then |
262 | + | GoBackToBarrel() |
263 | - | goLeft() |
263 | + | for i = 1, numberOfWork do |
264 | - | else |
264 | + | r.swing() |
265 | - | moveToX1() |
265 | + | if i ~= numberOfWork then |
266 | - | if myPosition.y ~= barrel.y then |
266 | + | if myPosition.x ~= barrel.x then |
267 | - | goUp() |
267 | + | goLeft() |
268 | - | end |
268 | + | else |
269 | - | end |
269 | + | moveToX1() |
270 | - | end |
270 | + | if myPosition.y ~= barrel.y then |
271 | - | end |
271 | + | goUp() |
272 | - | GoToBase() |
272 | + | end |
273 | - | r.turnLeft() |
273 | + | end |
274 | - | goForward(3) |
274 | + | end |
275 | - | dropUpAll() |
275 | + | end |
276 | - | goBack(3) |
276 | + | GoToBase() |
277 | - | r.turnRight() |
277 | + | r.turnLeft() |
278 | - | barrel.remainingQuantity = barrel.remainingQuantity - numberOfWork |
278 | + | goForward(3) |
279 | dropUpAll() | |
280 | goBack(3) | |
281 | r.turnRight() | |
282 | barrel.remainingQuantity = barrel.remainingQuantity - numberOfWork | |
283 | until barrel.remainingQuantity == 0 | |
284 | ||
285 | print("Пиво сварено и положено в сундук!") |