Advertisement
lucasmontec

reactorController

Apr 6th, 2020
380
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.33 KB | None | 0 0
  1. local monitor = peripheral.find("monitor")
  2. local reactor = peripheral.find("BigReactors-Reactor")
  3. local core = peripheral.find("draconic_rf_storage")
  4.  
  5. local rodSize = 4
  6.  
  7. function clear()
  8.     term.clear()
  9.     term.setBackgroundColor(colors.black)
  10.     term.setCursorPos(1,1)
  11. end
  12.  
  13. function drawRods(sx, sy)
  14.  
  15.     local controlRods = reactor.getNumberOfControlRods()
  16.  
  17.     for i=1,controlRods do
  18.         term.setCursorPos(1,1)
  19.         local percent = reactor.getControlRodLevel(i-1)/100.0
  20.        
  21.         local h = math.floor(percent*rodSize)
  22.        
  23.         if percent == 1 then
  24.             h = rodSize-1
  25.         end
  26.        
  27.         local left = (rodSize-h)-1
  28.         local x = sx+i*2
  29.         local y = sy
  30.        
  31.         if i > 10 then
  32.             y = y + rodSize+1
  33.             x = sx + (i-10)*2
  34.         end
  35.        
  36.         --write(tostring(i)..' '..tostring(h))
  37.         --x,y,width,height
  38.         paintutils.drawFilledBox(x, y, x, y+h, colours.green)
  39.        
  40.         if percent < 1 then
  41.           paintutils.drawFilledBox(x, y+h, x, (y+h)+left, colours.red)
  42.         end
  43.     end
  44.  
  45.     term.setBackgroundColor(colours.black)
  46. end
  47.  
  48. function drawHeader()
  49.     local activeText = "Active"
  50.    
  51.     if not reactor.getActive() then
  52.         activeText = "Disabled"
  53.     end
  54.    
  55.     write("Reactor "..activeText.."\n")
  56. end
  57.  
  58. function discordNotify(botName, message)
  59.     local postData = "{ \"username\" : \""..botName.."\", \"content\" : \""..message.."\"}"
  60.     local headers = {
  61.         ["Content-Type"] = "application/json"
  62.     }
  63.  
  64.  write(postData)
  65.     -- Make a HTTP request
  66.     local request,err = http.post("https://discordapp.com/api/webhooks/696901545643606046/Ki7Un8TIliV9qpMNtOaWdevL_z1YcRYw-kpZsVo18TvueOqI3UesNowY2b5ZlZhYq4Zj", postData, headers)
  67.    
  68.  if not request then error(err) end
  69.  
  70.  request.close()
  71. end
  72.  
  73. function notifyStatus(fuelPercent)
  74.            
  75.     local activeText = "Active"
  76.  
  77.     if not reactor.getActive() then
  78.         activeText = "Disabled"
  79.     end
  80.  
  81.     energyStored = core.getEnergyStored()
  82.     energyMax = core.getMaxEnergyStored()
  83.     energyTransfer = core.getTransferPerTick()
  84.  
  85.     energyPercent = math.floor((energyStored*1.0/energyMax)*100.0)
  86.  
  87.     --Reactor
  88.     info = "#Current Reactor Info\\n==================\\n\\n"
  89.     info = info.."Status: "..activeText.."\\n"
  90.     info = info.."Fuel: "..reactor.getFuelAmount().." mb "..fuelPercent.."%\\n"
  91.     info = info.."Energy last Tick: "..reactor.getEnergyProducedLastTick().." RF\\n\\n"
  92.    
  93.     --Core
  94.     if energyStored < 1000 then
  95.         --Nothing
  96.     elseif energyStored < 1000000 then
  97.         energyStored = tostring(round((energyStored/1000),1)).."K"
  98.     elseif energyStored < 1000000000 then
  99.         energyStored = tostring(round((energyStored/1000000),1)).."M"
  100.     elseif energyStored < 1000000000000 then
  101.         energyStored = tostring(round((energyStored/1000000000),1)).."G"
  102.     elseif energyStored < 1000000000000000 then
  103.         energyStored = tostring(round((energyStored/1000000000000),1)).."T"
  104.     elseif energyStored < 1000000000000000000 then
  105.         energyStored = tostring(round((energyStored/1000000000000000),1)).."P"
  106.     elseif energyStored < 1000000000000000000000 then
  107.         energyStored = tostring(round((energyStored/1000000000000000000),1)).."E"
  108.     end
  109.    
  110.     info = info.."#Core Info\\n==================\\n\\n"
  111.     info = info.."Energy stored: "..energyStored.." RF "..energyPercent.."%\\n"
  112.     info = info.."Current energy transfer: "..energyTransfer.." RF/t"
  113.    
  114.     if fuelPercent < 10 then
  115.         info = info.."\\n\\nAlert: Fuel bellow 10%!"
  116.     end
  117.  
  118.     discordNotify("Base Report", "```md\\n"..info.."```")    
  119. end
  120.  
  121. term.redirect(monitor)
  122. monitor.setTextScale(0.5)
  123.  
  124. local updates = 0
  125. local screenUpdateEvery = 10
  126.  
  127. local notifySent = false
  128.  
  129. while true do
  130.     if updates >= screenUpdateEvery then
  131.         clear()
  132.         drawHeader()
  133.         drawRods(1, 4)
  134.        
  135.         updates = 0
  136.     end
  137.  
  138.     local time = textutils.formatTime(os.time("local"), true)
  139.  
  140.     local fuelPercent = math.floor((reactor.getFuelAmount()*1.0/reactor.getFuelAmountMax())*100.0)
  141.  
  142.     --Send reactor status twice a day
  143.     if not notifySent and (time == "17:00" or time == "10:00") then
  144.         notifySent = true
  145.        
  146.         notifyStatus(fuelPercent)
  147.     end
  148.    
  149.     --Prevent multiple notify per hour
  150.     if notifySent and (time == "18:00" or time == "11:00") then
  151.         notifySent = false
  152.     end
  153.  
  154.  --notifyReactorStatus(fuelPercent)
  155.  
  156.     sleep(1)
  157.     updates = updates + 1
  158. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement