Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local component = require("component")
- local reactor = component.br_reactor
- local keyboard = require("keyboard")
- local isConnected = reactor.getConnected()
- local isActive
- local energyStored
- local maxEnergyStored = 10000000
- local percentEnergyStored
- local fuelAmount
- local wasteAmount
- local fuelTemp
- local caseTemp
- local modem = component.modem
- local event = require("event")
- local fs = require("filesystem") --I don't think this one is needed
- local port = 70
- local timeout = 15
- local pullArray = {}
- local timeoutPull = {}
- --local serverAddress = "9955471e-b28f-4001-9d66-79c28c75be2d" whos address is this??????
- local serverAddress = "defb88c6-fe9b-4fd7-a236-c1b956c9023e"
- local kyleTransformer
- local mattTransformer
- local powerString
- local function GetComponent()
- i = 1
- local componentArray = {}
- for k,v in component.list("ie_current_transformer") do
- componentArray[i] = k
- i = i + 1
- end
- return componentArray
- end
- local function OpenModem(port)
- modem.open(port)
- if modem.isOpen(port) then
- print("Successfully opened port " .. port)
- else
- print("Could not open port " .. port .. ", closing program.")
- os.quit()
- end
- end
- local function Quit(port)
- modem.close(port)
- if modem.isOpen(port) == false then
- print("Successfully closed port " .. port .. ", closing program.")
- else
- print("Could not close port " .. port .. ", contact admin.")
- end
- os.quit()
- end
- local function EventPull(timeout)
- local type, _, foreignAddress, port, distance, message = event.pull(timeout)
- local pullArray = {}
- if type == "key_down" then
- if keyboard.isAltDown() then
- Quit()
- end
- elseif type == "modem_message" then
- pullArray[1] = type
- pullArray[2] = foreignAddress
- pullArray[3] = port
- pullArray[4] = distance
- pullArray[5] = message
- print("Message '" .. message .. "' has been recieved from the DNS.")
- end
- return pullArray
- end
- local function SendACK(remoteAddress, port)
- modem.send(remoteAddress, port, "ACK")
- print("ACK has been sent to " .. remoteAddress .. " on port " .. port)
- end
- local function SendTimeout(remoteAddress, port, message, timeout)
- timeoutPull = {}
- while true do
- modem.send(remoteAddress, port, message)
- timeoutPull = EventPull(timeout)
- if timeoutPull[5] == "ACK" then
- print(message)
- break
- end
- end
- end
- local function PowerReactor(percentEnergyStored, isActive, fuelAmount, remoteAddress, port, timeout)
- local offMessage = "Internal bank full, shutting off reactor."
- local onMessage = "Internal bank empty, turning reactor on."
- local fuelMessage = "The reactor is out of fuel and cannot be turned on."
- if percentEnergyStored > 95 and isActive and fuelAmount >= 2000 then
- reactor.setActive(false)
- SendTimeout(remoteAddress, port, offMessage, timeout)
- elseif percentEnergyStored < 15 and isActive == false and fuelAmount >= 2000 then
- reactor.setActive(true)
- SendTimeout(remoteAddress, port, onMessage, timeout)
- elseif fuelAmount < 2000 then
- SendTimeout(remoteAddress, port, fuelMessage, timeout)
- end
- end
- local function CheckConnection(isConnected, remoteAddress, port, timeout)
- if isConnected == false then
- SendTimeout(remoteAddress, port, "Nuclear computer is not connected to the reactor.", timeout)
- Quit()
- end
- end
- local function TransformerSetup()
- local transformerArray = GetComponent()
- local kyle = transformerArray[2]
- print("DEBUG KYLE: " .. kyle)
- local matt = transformerArray[1]
- print("DEBUG MATT: " .. matt)
- mattTransformer = component.proxy(matt)
- kyleTransformer = component.proxy(kyle)
- end
- local function PowerRelay(kyle, matt)
- local kylePower = kyle.getAvgEnergy() * 20
- local mattPower = matt.getAvgEnergy() * 20
- local stringThing = "REACTOR ON/OFF: " .. tostring(isActive) .. "\n" .. "Kyle: " .. kylePower .. " RF/s" .. "\n" .. "Matt: " .. mattPower .. " RF/s"
- return stringThing
- end
- OpenModem(port)
- TransformerSetup()
- CheckConnection(isConnected, serverAddress, port, timeout)
- print("Press Alt to quit. If that doesn't work hit that DANK power button.")
- while true do
- energyStored = reactor.getEnergyStored()
- percentEnergyStored = (energyStored/maxEnergyStored)*100
- isActive = reactor.getActive()
- fuelAmount = reactor.getFuelAmount()
- wasteAmount = reactor.getWasteAmount()
- fuelTemp = reactor.getFuelTemperature()
- caseTemp = reactor.getCasingTemperature()
- fuelIngots = fuelAmount/1000
- if fuelIngots < 10 then
- SendTimeout(serverAddress, port, "Only " .. fuelIngots .. " rods remain in the reactor.", timeout)
- end
- if caseTemp > 2000 or fuelTemp > 2000 then
- SendTimeout(serverAddress, port, "Reactor overheating, shutting off.", timeout)
- reactor.setActive(false)
- end
- PowerReactor(percentEnergyStored, isActive, fuelAmount, serverAddress, port, timeout)
- powerString = PowerRelay(kyleTransformer, mattTransformer, isActive)
- SendTimeout(serverAddress, port, powerString, timeout)
- os.sleep(0.5)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement