Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- os.loadAPI("json")
- local sensor = peripheral.wrap("right")
- --local gun1 = peripheral.wrap("manipulator_8")
- --local gun2 = peripheral.wrap("manipulator_9")
- local manips,guns
- local scr_x,scr_y = term.getSize()
- log = {}
- local logscroll = 0
- local logadd = function(input)
- log[#log+1] = {
- txt = input,
- time = os.time(),
- day = os.day(),
- }
- end
- local ts = tostring
- local assignGuns = function()
- manips = {peripheral.find("manipulator")}
- guns = {}
- for a = 1, #manips do
- if manips[a].fire then
- guns[#guns+1] = manips[a]
- end
- end
- end
- assignGuns()
- if #guns == 0 then
- error("you've got no guns")
- end
- local tps = function(vis)
- if term.current().setVisible then
- term.current().setVisible(vis)
- return true
- else
- return false
- end
- end
- local cwrite = function(txt,y)
- local cx,cy = term.getCursorPos()
- term.setCursorPos((scr_x/2)-math.ceil(#txt/2),y or cy)
- return write(txt)
- end
- local function fire(gun, entity)
- local x = entity.x
- local y = entity.y
- local z = entity.z
- local pitch = -math.atan2(y, math.sqrt(x * x + z * z))
- local yaw = math.atan2(-x, y)
- gun.fire(math.deg(yaw), math.deg(pitch), 5)
- sleep(0.2)
- end
- phaneronHit = 0
- -- leave EVERYTHING to me
- local fuckEmUp = function(target)
- assignGuns()
- for a = 1, #guns do
- fire(guns[a],target)
- end
- end
- local safeNames = {
- ["Phaneron"] = true,
- ["Chicken"] = true,
- ["Cow"] = true,
- ["Sheep"] = true,
- ["Horse"] = true,
- ["Item"] = true,
- ["XPOrb"] = true,
- ["Painting"] = true,
- ["Arrow"] = true,
- ["plethora:laser"] = true,
- ["EldidiStroyrr"] = true --teehee
- }
- function isATarget(name)
- --if name == "Phaneron" then
- if safeNames[name] then
- if phaneronHit > 5 then
- error("hit 5 times"..phaneronHit)
- end
- return false
- else
- return true
- end
- end
- term.setBackgroundColor(colors.black)
- term.clear()
- term.setTextColor(term.isColor() and colors.yellow or colors.lightGray)
- cwrite("Phaneron Laser Defence System",2)
- term.setTextColor(colors.gray)
- cwrite("-- None shall pass! --",3)
- term.setTextColor(colors.lightGray)
- cwrite("(lasers: "..#guns..")\n",4)
- term.setTextColor(colors.white)
- print(" Log of worthless peons:\n")
- local doTheSense = function()
- while true do
- local report = sensor.sense()
- for idx, r in pairs(report) do
- if isATarget(r.name) and r.x ~= nil then
- if r.x > 6 then
- logadd("Engaged: '"..r.name.."'")
- os.queueEvent("laserlog_update")
- fuckEmUp(r)
- end
- else
- -- print(json.encode(r))
- end
- end
- end
- end
- local renderLog = function(scroll,topY)
- tps(false)
- for a = topY,scr_y do
- term.setCursorPos(1,a)
- term.clearLine()
- local lpos = scroll+(a-(topY-1))
- if log[lpos] then
- term.blit(ts(lpos)..(" "):rep(#ts(#log)-#ts(lpos)),("8"):rep(#ts(#log)),("7"):rep(#ts(#log)))
- term.write(" "..log[lpos].txt)
- end
- end
- tps(true)
- end
- local endbuf = 6
- local handleGUI = function()
- while true do
- local evt,dir = os.pullEvent()
- if evt == "mouse_scroll" then
- if dir+logscroll >= 0 and dir+logscroll <= (#log-(scr_y-endbuf)) then
- logscroll = dir+logscroll
- renderLog(logscroll,6)
- end
- elseif evt == "laserlog_update" then
- if logscroll >= (#log-(scr_y-endbuf)-1) then
- logscroll = #log-(scr_y-endbuf)
- end
- renderLog(logscroll,6)
- elseif evt == "key" then
- local scrolldist
- if dir == keys.up then
- scrolldist = -1
- elseif dir == keys.down then
- scrolldist = 1
- elseif dir == keys.pageUp then
- scrolldist = -(scr_y-endbuf)
- elseif dir == keys.pageDown then
- scrolldist = scr_y-endbuf
- elseif dir == keys.home then
- scrolldist = -#log
- elseif dir == keys["end"] then
- scrolldist = #log
- else
- scrolldist = 0
- end
- logscroll = math.max(0,math.min(logscroll+scrolldist,#log-(scr_y-endbuf)))
- end
- end
- end
- parallel.waitForAny(doTheSense,handleGUI)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement