attack program - new

This commit is contained in:
kepler155c
2018-11-23 17:26:26 -05:00
parent d426b80475
commit 8ff38e52b7

View File

@@ -58,6 +58,16 @@ local sensor = device['plethora:sensor']
turtle.setMovementStrategy('goto') turtle.setMovementStrategy('goto')
function Point.iterateClosest(spt, ipts)
local pts = Util.shallowCopy(ipts)
return function()
local pt = Point.closest(spt, pts)
if pt then
return pt
end
end
end
local function dropOff() local function dropOff()
if not chest then if not chest then
return return
@@ -101,18 +111,35 @@ while true do
end) end)
os.sleep(2) --- give a little time for mobs to calm down os.sleep(2) --- give a little time for mobs to calm down
else else
-- this mob doesn't run, attack and follow until dead local attacked = false
local mob = Point.closest(turtle.point, mobs)
repeat local function attack()
if turtle.faceAgainst(mob) then if turtle.attack() then
repeat until not turtle.attack() attacked = true
return attacked
end end
end
for mob in Point.iterateClosest(turtle.point, mobs) do
-- this mob doesn't run, attack and follow until dead
if turtle.faceAgainst(mob) then
repeat
repeat until not turtle.attack()
mob = sensor.getMetaByID(mob.id) mob = sensor.getMetaByID(mob.id)
if mob then if not mob then
break
end
normalize(mob) normalize(mob)
if not turtle.faceAgainst(mob) then
break
end end
until not mob until not mob
end end
if attacked then
break
end
end
end
end end
dropOff() dropOff()