local LEVER_DOWN = 7
local LEVER_UP = 5

local function leversState(self)
    local ret = true
    for i, lever in ipairs(self.levers) do
        local arrowImg = "CUSTOM_ARROWSIGN_" .. (self.goodPos[i] == LEVER_UP and "U" or "D")
        if lever.State ~= self.goodPos[i] and lever.State ~= self.goodPos2[i] then
            ret = false
        else
            arrowImg = arrowImg .. "_HL"
        end
        self.arrows[i]:SetImage(arrowImg)
    end
    return ret
end

function main(self)
	if self.State == 0 then
        self.goodPos = {LEVER_UP, LEVER_DOWN, LEVER_DOWN, LEVER_UP, LEVER_UP, LEVER_DOWN, LEVER_UP}
        self.goodPos2 = {LEVER_UP, 0, 0, LEVER_UP, LEVER_UP, 0, LEVER_UP}
        self.timeDelay = 0
		self.Flags.AlwaysActive, self.DrawFlags.NoDraw = true, true
		self.State = 1
	end

	if self.State == 1 then
		self.levers = {
            GetObject(4893),
		    GetObject(4894),
		    GetObject(4987),
		    GetObject(4989),
		    GetObject(4988),
		    GetObject(4990),
		    GetObject(4991)
        }
        self.arrows = {
            GetObject(4766),
		    GetObject(4767),
		    GetObject(4768),
		    GetObject(4769),
		    GetObject(4773),
		    GetObject(4772),
		    GetObject(4771)
        }
		self.State = 2
	end

	if self.State == 2 and leversState(self) and GetTime() > self.timeDelay then
        self.steam = CreateObject{X = 51931, Y = 11987, Z = 2000, name = "SteamBlower", Height = 700}
        self.timeDelay = GetTime() + 1000
        self.State = 6
	end

	if self.State == 6 and not leversState(self) and GetTime() > self.timeDelay then
        self.steam:Destroy()
        self.timeDelay = GetTime() + 1000
        self.State = 2
	end

end
