Во, заебись майнер

This commit is contained in:
Igor Timofeev 2018-06-20 01:27:29 +03:00
parent 881bbea962
commit d05e66dec3
2 changed files with 213 additions and 175 deletions

View File

@ -29,6 +29,7 @@ AR.fuels = {
AR.droppables = {
["minecraft:cobblestone"] = true,
["minecraft:stone"] = true,
["minecraft:grass"] = true,
["minecraft:dirt"] = true,
["minecraft:gravel"] = true,
@ -47,10 +48,6 @@ AR.tools = {
["minecraft:iron_pickaxe"] = true,
}
AR.toolReplaceDurability = 0.05
AR.zeroPositionReturnEnergy = 0.1
AR.emptySlotsCountDropping = 4
AR.positionX = 0
AR.positionY = 0
AR.positionZ = 0
@ -58,6 +55,22 @@ AR.rotation = 0
--------------------------------------------------------------------------------
function AR.rotatePosition(x, y, z)
if AR.rotation == 0 then
return x, y, z
elseif AR.rotation == 1 then
return z, y, -x
elseif AR.rotation == 2 then
return -x, y, -z
else
return -z, y, x
end
end
function AR.reset()
AR.positionX, AR.positionY, AR.positionZ, AR.rotation = 0, 0, 0, 0
end
function AR.updateProxies()
local name
for name in pairs(AR.requiredProxies) do
@ -68,6 +81,7 @@ function AR.updateProxies()
end
end
AR.reset()
AR.updateProxies()
for key, value in pairs(AR.proxies.robot) do
@ -131,23 +145,22 @@ function AR.moveToPosition(xTarget, yTarget, zTarget)
local xDistance, yDistance, zDistance = xTarget - AR.positionX, yTarget - AR.positionY, zTarget - AR.positionZ
if yDistance ~= 0 then
local direction = yDistance > 0 and sides.up or sides.down
for i = 1, math.abs(yDistance) do
AR.move(direction)
AR.swingAndMove(yDistance > 0 and sides.up or sides.down)
end
end
if xDistance ~= 0 then
AR.turnToRotation(xDistance > 0 and 0 or 2)
for i = 1, math.abs(xDistance) do
AR.move(sides.front)
AR.swingAndMove(sides.front)
end
end
if zDistance ~= 0 then
AR.turnToRotation(zDistance > 0 and 1 or 3)
for i = 1, math.abs(zDistance) do
AR.move(sides.front)
AR.swingAndMove(sides.front)
end
end
end
@ -228,10 +241,9 @@ end
--------------------------------------------------------------------------------
function AR.moveToZeroPosition()
function AR.moveToZeroPosition(noTurn)
AR.moveToPosition(0, AR.positionY, 0)
AR.turnToRotation(0)
AR.dropDroppables()
AR.moveToPosition(0, 0, 0)
end
@ -264,95 +276,65 @@ function AR.getEmptySlotsCount()
end
function AR.dropDroppables(side)
if AR.getEmptySlotsCount() < AR.emptySlotsCountDropping then
print("Trying to drop all shitty resources to free some slots for mining")
for slot = 1, AR.inventorySize() do
local stack = AR.getStackInInternalSlot(slot)
if stack then
for name in pairs(AR.droppables) do
if stack.name == name then
AR.select(slot)
AR.drop(side or sides.down)
end
end
local oldSlot, need = AR.select()
for slot = 1, AR.inventorySize() do
local stack = AR.getStackInInternalSlot(slot)
if stack then
if AR.droppables[stack.name] then
AR.select(slot)
AR.drop(side or sides.down)
need = true
end
end
end
AR.select(1)
if need then
AR.select(oldSlot)
end
end
function AR.dropAll(side, exceptArray)
exceptArray = exceptArray or AR.tools
print("Dropping all mined resources...")
local oldSlot = AR.select()
for slot = 1, AR.inventorySize() do
local stack = AR.getStackInInternalSlot(slot)
if stack then
local droppableItem = true
for exceptItem in pairs(exceptArray) do
if stack.name == exceptItem then
droppableItem = false
break
end
end
if droppableItem then
if not exceptArray[stack.name] then
AR.select(slot)
AR.drop(side)
end
end
end
AR.select(1)
AR.select(oldSlot)
end
function AR.checkToolStatus()
if AR.durability() < AR.toolReplaceDurability then
print("Equipped tool durability lesser then " .. AR.toolReplaceDurability)
local success = false
function AR.checkToolStatus(percent)
if AR.durability() < percent then
print("Equipped tool durability lesser then " .. percent)
for slot = 1, AR.inventorySize() do
local stack = AR.getStackInInternalSlot(slot)
if stack then
for name in pairs(AR.tools) do
if stack.name == name and stack.damage / stack.maxDamage < AR.toolReplaceDurability then
local oldSlot = AR.select()
AR.select(slot)
AR.equip()
AR.select(oldSlot)
success = true
break
end
if stack.damage / stack.maxDamage < percent and AR.tools[stack.name] then
local oldSlot = AR.select()
AR.select(slot)
AR.equip()
AR.select(oldSlot)
print("Tool switched to " .. stack.label)
break
end
end
end
if not success then
AR.moveToZeroPosition()
error("No one useable tool are found in inventory, going back to base")
else
print("Successfullty switched tool to another from inventory")
end
end
end
function AR.checkEnergyStatus()
if computer.energy() / computer.maxEnergy() < AR.zeroPositionReturnEnergy then
print("Low energy level detected")
-- Запоминаем старую позицию, шобы суда вернуться
local x, y, z = AR.positionX, AR.positionY, AR.positionZ
-- Пиздуем на базу за зарядкой
AR.moveToZeroPosition()
-- Заряжаемся, пока энергия не достигнет более-менее максимума
while computer.energy() / computer.maxEnergy() < 0.99 do
print("Charging up: " .. math.floor(computer.energy() / computer.maxEnergy() * 100) .. "%")
os.sleep(1)
end
-- Пиздуем обратно
AR.moveToPosition(x, y, z)
AR.turnToRotation(oldPosition.rotation)
function AR.charge(percent)
while computer.energy() / computer.maxEnergy() < percent do
print("Charging up: " .. math.floor(computer.energy() / computer.maxEnergy() * 100) .. "%")
os.sleep(1)
end
end
@ -360,16 +342,14 @@ function AR.getSlotWithFuel()
for slot = 1, AR.inventorySize() do
local stack = AR.getStackInInternalSlot(slot)
if stack then
for name in pairs(AR.fuels) do
if stack.name == name then
return slot
end
if AR.fuels[stack.name] then
return slot
end
end
end
end
function AR.checkGeneratorStatus()
function AR.checkGeneratorStatus(count)
if AR.proxies.generator then
if AR.proxies.generator.count() == 0 then
print("Generator is empty, trying to find some fuel in inventory")
@ -378,16 +358,43 @@ function AR.checkGeneratorStatus()
print("Found slot with fuel: " .. slot)
local oldSlot = AR.select()
AR.select(slot)
AR.proxies.generator.insert()
AR.proxies.generator.insert(count)
AR.select(oldSlot)
return
else
print("Slot with fuel not found")
print("Slot with fuel not found, skipping")
end
end
end
end
function AR.getWorldRotation()
local initial = AR.proxies.geolyzer.scan(1, 0)[33]
for i = 0, 3 do
if initial > 0 then
if AR.swing(3) and AR.proxies.geolyzer.scan(1, 0)[33] == 0 then
for j = 1, i do
AR.turn(true)
end
return i
end
else
if AR.place(3) and AR.proxies.geolyzer.scan(1, 0)[33] > 0 then
for j = 1, i do
AR.swing(3)
AR.turn(true)
end
AR.swing(3)
return i
end
end
AR.turn(false)
end
end
--------------------------------------------------------------------------------
return AR

View File

@ -1,8 +1,9 @@
local computer, component = require("computer"), require("component")
local minDensity, maxDensity, worldHeight, droppables, tools, computerEnergy, computerMaxEnergy, mathAbs, getComponent =
local minDensity, maxDensity, chunkCount, worldHeight, droppables, tools, computerEnergy, computerMaxEnergy, mathAbs, getComponent =
2,
10,
3,
-64,
{
cobblestone = 1,
@ -107,6 +108,7 @@ end
local function dropAll()
print("Пиздую на базу")
moveTo(0, positionY, 0)
moveTo(0, 0, 0)
print("Ищу сундук")
@ -130,6 +132,7 @@ local function dropAll()
end
end
print("Запускаю софтину")
robotSelect(1)
move(0)
@ -149,119 +152,147 @@ for i = 0, 3 do
turn(false)
end
rotation = 0
local chunkX, chunkZ, chunkRotation, chunkRadius, chunkRadiusCounter, chunkWorldX, chunkWorldZ = 0, 0, 0, 1, 1
for chunk = 1, chunkCount do
chunkWorldX, chunkWorldZ = chunkX * 8, chunkZ * 8
while true do
print("Сканирую")
local scanX, scanZ, i, ores, scanResult, bedrock =
positionX,
positionZ,
1,
{},
geolyzer.scan(
positionX >= 0 and -(positionX % 8) or -7 + (-positionX % 8),
positionZ >= 0 and -(positionZ % 8) or -7 + (-positionZ % 8),
-1,
8,
8,
1
)
print("Пиздую к текущему чанку", chunkX, chunkZ)
moveTo(chunkWorldX, -1, chunkWorldZ)
for z = 0, 7 do
for x = 0, 7 do
if scanResult[i] >= minDensity and scanResult[i] <= maxDensity then
table.insert(ores, x - positionX)
table.insert(ores, z - positionZ)
elseif scanResult[i] < -0.4 then
bedrock = true
break
while true do
print("Сканирую")
local scanX, scanZ, scanIndex, ores, scanResult, bedrock =
positionX,
positionZ,
1,
{},
geolyzer.scan(
chunkWorldX - positionX,
chunkWorldZ - positionZ,
-1,
8,
8,
1
)
for z = 0, 7 do
for x = 0, 7 do
if scanResult[scanIndex] >= minDensity and scanResult[scanIndex] <= maxDensity then
table.insert(ores, chunkWorldX + x)
table.insert(ores, chunkWorldZ + z)
elseif scanResult[scanIndex] < -0.4 then
bedrock = true
break
end
scanIndex = scanIndex + 1
end
i = i + 1
end
end
if bedrock or positionY <= worldHeight then
print("Бедрок чет нашел на Y или низковато опустился", positionY - 1)
break
else
print("Начинаю копать")
move(0)
if bedrock or positionY <= worldHeight then
print("Бедрок чет нашел на Y или низковато опустился", positionY - 1)
break
else
print("Начинаю копать")
move(0)
if #ores > 0 then
print("Нашел вот стока руд", #ores)
while #ores > 0 do
local nearestIndex, nearestDistance, distance = 1, math.huge
for i = 1, #ores, 2 do
distance = math.sqrt((ores[i] - positionX) ^ 2 + (ores[i + 1] - positionZ) ^ 2)
if distance < nearestDistance then
nearestIndex, nearestDistance = i, distance
if #ores > 0 then
print("Нашел вот стока руд", #ores)
while #ores > 0 do
local nearestIndex, nearestDistance, distance = 1, math.huge
for i = 1, #ores, 2 do
distance = math.sqrt((ores[i] - positionX) ^ 2 + (ores[i + 1] - positionZ) ^ 2)
if distance < nearestDistance then
nearestIndex, nearestDistance = i, distance
end
end
print("Пиздую к руде на точку", ores[nearestIndex], positionY, ores[nearestIndex + 1])
moveTo(ores[nearestIndex], positionY, ores[nearestIndex + 1])
for i = 1, 2 do
table.remove(ores, nearestIndex)
end
end
else
print("Ни хуя тут руд нет")
end
end
moveTo(scanX + ores[nearestIndex], positionY, scanZ + ores[nearestIndex + 1])
for i = 1, 2 do
table.remove(ores, nearestIndex)
-- Чекаем генератор
print("Чекаем генератор")
if generator and generator.count() == 0 then
print("Генератор пустой чота")
for i = 1, inventorySize do
robotSelect(i)
if generator.insert() then
print("Генератор заправлен")
break
end
end
end
-- Чекаем инструмент
print("Чекаем инстурмент")
if robot.durability() <= 0.2 then
print("Инструмент хуевый")
for i = 1, inventorySize do
local stack = inventory_controllerGetStackInInternalSlot(i)
if stack and (tools[stack.name] or tools[stack.name:gsub("minecraft:", "")]) and stack.damage / stack.maxDamage < 0.8 then
print("Ща сменю его")
robotSelect(i)
inventory_controller.equip()
break
end
end
end
-- Чекаем зарядку и заполненность инвентаря
print("Чекаю фри слоты или энергию", freeSlots, computerEnergy() / computerMaxEnergy())
local freeSlots = 0
for i = 1, inventorySize do
if robot.count(i) == 0 then
freeSlots = freeSlots + 1
end
end
if freeSlots <= 4 or computerEnergy() / computerMaxEnergy() <= 0.2 then
print("Чота все хуева")
local oldX, oldY, oldZ, oldRotation = positionX, positionY, positionZ, rotation
dropAll()
while computerEnergy() / computerMaxEnergy() < 0.99 do
print("Заряжаюсь", computerEnergy() / computerMaxEnergy())
computer.pullSignal(1)
end
print("Пиздую назад")
moveTo(oldX, oldY, oldZ)
turnTo(oldRotation)
end
end
print("Чанк выкопан, рассчитываю коорды следующего")
chunkX, chunkZ = chunkX + (chunkRotation == 0 and 1 or chunkRotation == 2 and -1 or 0), chunkZ + (chunkRotation == 1 and 1 or chunkRotation == 3 and -1 or 0)
if
(chunkRotation == 0 or chunkRotation == 2) and mathAbs(chunkX) >= chunkRadius or
(chunkRotation == 1 or chunkRotation == 3) and mathAbs(chunkZ) >= chunkRadius
then
chunkRadiusCounter = chunkRadiusCounter + 1
if chunkRadiusCounter > 5 then
chunkRadius, chunkRadiusCounter = chunkRadius + 1, 1
print("Радиус увеличил", chunkRadius)
else
print("Ни хуя тут руд нет")
end
end
-- Чекаем генератор
print("Чекаем генератор")
if generator and generator.count() == 0 then
print("Генератор пустой чота")
for i = 1, inventorySize do
robotSelect(i)
if generator.insert() then
print("Генератор заправлен")
break
chunkRotation = chunkRotation + 1
if chunkRotation > 3 then
chunkRotation = 0
end
print("Паварооот", chunkRotation)
end
end
-- Чекаем инструмент
print("Чекаем инстурмент")
if robot.durability() <= 0.2 then
print("Инструмент хуевый")
for i = 1, inventorySize do
local stack = inventory_controllerGetStackInInternalSlot(i)
if stack and (tools[stack.name] or tools[stack.name:gsub("minecraft:", "")]) and stack.damage / stack.maxDamage < 0.8 then
print("Ща сменю его")
robotSelect(i)
inventory_controller.equip()
break
end
end
end
-- Чекаем зарядку и заполненность инвентаря
print("Чекаю фри слоты или энергию", freeSlots, computerEnergy() / computerMaxEnergy())
local freeSlots = 0
for i = 1, inventorySize do
if robot.count(i) == 0 then
freeSlots = freeSlots + 1
end
end
if freeSlots <= 4 or computerEnergy() / computerMaxEnergy() <= 0.2 then
print("Чота все хуева")
local oldX, oldY, oldZ, oldRotation = positionX, positionY, positionZ, rotation
dropAll()
while computerEnergy() / computerMaxEnergy() < 0.99 do
print("Заряжаюсь", computerEnergy() / computerMaxEnergy())
computer.pullSignal(1)
end
print("Пиздую назад")
moveTo(oldX, oldY, oldZ)
turnTo(oldRotation)
end
end
dropAll()
turnTo(0)
turnTo(0)
print("Усе, епта")