-- author: rafftnix
-- date: 16.12.2012


StartMotorSawEvent = {};
StartMotorSawEvent_mt = Class(StartMotorSawEvent, Event);
InitEventClass(StartMotorSawEvent, "StartMotorSawEvent");
function StartMotorSawEvent:emptyNew()
    local self = Event:new(StartMotorSawEvent_mt);
    self.className="StartMotorSawEvent";
    return self;
end;

function StartMotorSawEvent:new(object, player)
    local self = StartMotorSawEvent:emptyNew(); 
    self.object = object; 
	self.player = player;
    return self;
end;

function StartMotorSawEvent:writeStream(streamId, connection)
    streamWriteInt32(streamId, networkGetObjectId(self.object));
    streamWriteInt32(streamId, networkGetObjectId(self.player));
end;

function StartMotorSawEvent:readStream(streamId, connection)
    self.object = networkGetObject(streamReadInt32(streamId));
    self.player = networkGetObject(streamReadInt32(streamId));
    self:run(connection);
end;

function StartMotorSawEvent:run(connection)
	self.object:startMotorSaw(self.player, true);
	if not connection:getIsServer() then
		g_server:broadcastEvent(StartMotorSawEvent:new(self.object, self.player), nil, connection, self.object);
	end; 
end;

function StartMotorSawEvent.sendEvent(object, player, noEventSend)
	if noEventSend == nil or noEventSend == false then  
		if g_server ~= nil then   
			g_server:broadcastEvent(StartMotorSawEvent:new(object, player), nil, nil, object); 
		else  
			g_client:getServerConnection():sendEvent(StartMotorSawEvent:new(object, player)); 
		end;
	end;
end;

