This repository was archived by the owner on Jan 15, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathminer.lua
More file actions
229 lines (182 loc) · 5.15 KB
/
miner.lua
File metadata and controls
229 lines (182 loc) · 5.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
local robot = require("robot")
local towers = {}
towers[1] = {x = 3, y = 3, r = 7, farmBlocks = 36, groundBlocks = 168, name = "Маленький"}
towers[2] = {x = 4, y = 3, r = 9, farmBlocks = 48, groundBlocks = 270, name = "Средне-маленький"}
towers[3] = {x = 4, y = 4, r = 9, farmBlocks = 64, groundBlocks = 288, name = "Средний"}
towers[4] = {x = 5, y = 3, r = 11, farmBlocks = 60, groundBlocks = 379, name = "Средне-большой"}
towers[5] = {x = 5, y = 4, r = 11, farmBlocks = 80, groundBlocks = 419, name = "Средне-большой (увелич.)"}
towers[6] = {x = 5, y = 5, r = 11, farmBlocks = 100, groundBlocks = 440, name = "Большой"}
function getUserTower()
print("\nРазмеры ферм:")
for i, tower in pairs(towers) do
print(i .. ") " .. tower.name .. " (" .. tower.x .. "x" .. tower.y .. "x4) Площадь рассадки: " .. tower.groundBlocks)
end
print("\nВведите номер фермы:")
return towers[tonumber(io.read())]
end
function getBlocksStatus(tower)
if tower.farmBlocks < 65 then
print("\nПоложите БЛОКИ ФЕРМЫ (" .. tower.farmBlocks .. ") в 1-ый слот")
else
print("\nПоложите БЛОКИ ФЕРМЫ (" .. tower.farmBlocks .. ") в 1-ый и 2-ой слоты")
end
print("Положите БЛОКИ ПОВЕРХНОСТИ (" .. tower.groundBlocks .. ") начиная с 3-его и в последующие слоты")
print("\nВсе блоки на месте? [y/n]")
if io.read() == "y" then
local blocks = 0
for i=1, robot.inventorySize() do
blocks = blocks + robot.count(i)
end
if blocks >= tower.farmBlocks + tower.groundBlocks then
return true
else
return 'restart'
end
else
return false
end
end
function buildTower(tower)
print("\n -- Начинаю строительство башни -- ")
robot.select(1)
robot.up()
turn = "right"
for z=1, 4 do
for y=1, tower.y do
for x=1, tower.x do
chechInventory()
robot.placeDown()
if x ~= tower.x then
robot.forward()
end
end
if y ~= tower.y then
if turn == "right" then
robot.turnRight()
robot.forward()
robot.turnRight()
turn = "left"
elseif turn == "left" then
robot.turnLeft()
robot.forward()
robot.turnLeft()
turn = "right"
end
end
end
if z ~= 4 then
robot.up()
robot.turnAround()
end
end
print("\n -- Cтроительство башни завершено -- \n")
end
function buildPlatform(tower)
print("\n -- Начинаю строительство платформы -- ")
robot.select(3)
robot.forward()
buildPlatformPart(tower.r, tower.y, false)
buildPlatformPart(tower.r, tower.x, true)
buildPlatformPart(tower.r, tower.y, true)
buildPlatformPart(tower.r, tower.x, true)
for i=1, tower.r + 1 do
robot.forward()
end
print("\n -- Cтроительство платформы завершено -- \n")
end
function buildPlatformPart(radius, length, inverted)
-- Переменные
if inverted == true then
turn = "right"
if length % 2 == 0 then
skipOneBlock = true
else
skipOneBlock = false
end
else
turn = "left"
if length % 2 == 0 then
skipOneBlock = false
else
skipOneBlock = true
end
end
-- Прямоугольник
for l=1, length do
for r=1, radius do
chechInventory()
robot.placeDown()
if r ~= radius then
robot.forward()
end
end
if l ~= length then
if turn == "right" then
robot.turnRight()
robot.forward()
robot.turnRight()
turn = "left"
elseif turn == "left" then
robot.turnLeft()
robot.forward()
robot.turnLeft()
turn = "right"
end
end
end
-- Лесенка
for rr=1, radius do
if turn == "right" then
robot.turnRight()
robot.forward()
robot.turnRight()
turn = "left"
elseif turn == "left" then
robot.turnLeft()
robot.forward()
robot.turnLeft()
turn = "right"
end
if skipOneBlock == true then
robot.forward()
skipOneBlock = false
else
skipOneBlock = true
end
for r=1, radius - rr do
chechInventory()
robot.placeDown()
if r ~= radius - rr then
robot.forward()
end
end
end
if skipOneBlock == true then
robot.turnAround()
robot.forward()
end
robot.turnLeft()
end
function chechInventory()
if robot.count() == 0 then
robot.select(robot.select()+1)
end
end
function start()
-- Получить башню пользователя
local tower = getUserTower()
-- Все блоки на месте?
while true do
local status = getBlocksStatus(tower)
if status == false then
return
elseif status == true then
break
end
print("\nНедостаточно ресурсов!\n")
end
buildTower(tower)
buildPlatform(tower)
print("\nМультиферма построена!")
end
start()