AnimalDealerLoadSettingsEvent = {};
AnimalDealerLoadSettingsEvent_mt = Class(AnimalDealerLoadSettingsEvent, Event);
InitEventClass(AnimalDealerLoadSettingsEvent, "AnimalDealerLoadSettingsEvent");

AnimalDealerLoadSettingsEvent.NUM_BITS_SETTINGS_MINMAX = 1;

---Create instance of Event class
function AnimalDealerLoadSettingsEvent.emptyNew()
    local self = Event.new(AnimalDealerLoadSettingsEvent_mt);
    return self;
end;

---Create new instance of event
function AnimalDealerLoadSettingsEvent.new(onOff, minMax)
    local self = AnimalDealerLoadSettingsEvent.emptyNew();
    self.minMax = minMax;
    return self;
end;

---Called on client side on join
function AnimalDealerLoadSettingsEvent:readStream(streamId, connection)
    if g_server == nil then
        self.minMax = streamReadInt8(streamId, AnimalDealerLoadSettingsEvent.NUM_BITS_SETTINGS_MINMAX);
        
        self:run(connection);
    end;
end;

---Called on server side on join
function AnimalDealerLoadSettingsEvent:writeStream(streamId, connection)
	if g_additionalContractTypes.settings["animalDealerMission_minMax"] ~= nil then
		streamWriteInt8(streamId, g_additionalContractTypes.settings["animalDealerMission_minMax"], AnimalDealerLoadSettingsEvent.NUM_BITS_SETTINGS_MINMAX);
	end;	
end;

---Run action on receiving side
function AnimalDealerLoadSettingsEvent:run(connection)
	if g_server ~= nil then
		g_server:broadcastEvent(AnimalDealerLoadSettingsEvent.new(g_additionalContractTypes.settings["animalDealerMission_minMax"]), false);				
		return;
	end;   
	if self.minMax ~= nil then
		g_additionalContractTypes.typ["animalDealerMission"]:setMaxNumInstance(self.minMax);			
	end;
end;


