InteractiveControlEvent = {};
InteractiveControlEvent_mt = Class(InteractiveControlEvent, Event);

InitEventClass(InteractiveControlEvent, "InteractiveControlEvent");

function InteractiveControlEvent:emptyNew()
    local self = Event:new(InteractiveControlEvent_mt);
    return self;
end;

function InteractiveControlEvent:new(object, interactiveControlID, ICIsOpen)
    local self = InteractiveControlEvent:emptyNew()
    self.object = object;
    self.interactiveControlID = interactiveControlID;
    self.ICIsOpen = ICIsOpen;
    return self;
end;

function InteractiveControlEvent:readStream(streamId, connection)
    -- local id = streamReadInt32(streamId);
    self.object = readNetworkNodeObject(streamId);
    self.interactiveControlID = streamReadInt8(streamId);
    self.ICIsOpen = streamReadBool(streamId);
    -- self.object = networkGetObject(id);
    self:run(connection);
end;

function InteractiveControlEvent:writeStream(streamId, connection)
    -- streamWriteInt32(streamId, networkGetObjectId(self.object));
    writeNetworkNodeObject(streamId, self.object);
    streamWriteInt8(streamId, self.interactiveControlID);
    streamWriteBool(streamId, self.ICIsOpen);
end;

function InteractiveControlEvent:run(connection)
    if self.object ~= nil then
        self.object:actionOnObject(self.interactiveControlID, self.ICIsOpen, true);
        if not connection:getIsServer() then
            g_server:broadcastEvent(InteractiveControlEvent:new(self.object, self.interactiveControlID, self.ICIsOpen), nil, connection, self.object);
        end;
    end;
end;
