ExpandEvent = {};
ExpandEvent_mt = Class(ExpandEvent, Event);
InitEventClass(ExpandEvent, "ExpandEvent"); 

function ExpandEvent:emptyNew()
    local self = Event:new(ExpandEvent_mt);
    self.className = "ExpandEvent";
    return self;
end;

function ExpandEvent:new(object, isExpand)
    self.object = object;
  	self.isExpand = isExpand;
    return self;
end;
  
function ExpandEvent:readStream(streamId, connection)
    local id = streamReadInt32(streamId);
   	self.isExpand = streamReadBool(streamId);
    self.object = networkGetObject(id);
    self:run(connection);
end;
   
function ExpandEvent:writeStream(streamId, connection)
    streamWriteInt32(streamId, networkGetObjectId(self.object));
  	streamWriteBool(streamId, self.isExpand);
end;
  
function ExpandEvent:run(connection)
      self.object:expand(self.isExpand, true);
      if not connection:getIsServer() then
         g_server:broadcastEvent(ExpandEvent:new(self.object, self.isExpand), nil, connection, self.object);
      end;
end;
   
function ExpandEvent.sendEvent(vehicle, isExpand, noEventSend)
      if isExpand ~= vehicle.isExpanded then
          if noEventSend == nil or not noEventSend then
               if g_server ~= nil then
                   g_server:broadcastEvent(ExpandEvent:new(vehicle, isExpand), nil, nil, vehicle);
               else
                  g_client:getServerConnection():sendEvent(ExpandEvent:new(vehicle, isExpand));
              end;
           end;
      end;
end;