CalenderEvent = {};
CalenderEvent_mt = Class(CalenderEvent, Event);

InitEventClass(CalenderEvent, "CalenderEvent");

function CalenderEvent:emptyNew()
    local self = Event:new(CalenderEvent_mt);
    return self;
end;

function CalenderEvent:new()
    local self = CalenderEvent:emptyNew();
    return self;
end;

function CalenderEvent:readStreamAll(streamId, connection)
	
	local num1 = streamReadInt16(streamId);
	local num2 = streamReadInt16(streamId);
	local num3 = streamReadInt16(streamId);
	g_currentMission.FarmingTablet.Calendar.Termine[g_currentMission.environment.currentDay] = {};
	
	for i = 1, num1 do
		g_currentMission.FarmingTablet.Calendar.Termine[g_currentMission.environment.currentDay][i] = {};
		g_currentMission.FarmingTablet.Calendar.Termine[g_currentMission.environment.currentDay][i].titel = streamReadString(streamId);
		g_currentMission.FarmingTablet.Calendar.Termine[g_currentMission.environment.currentDay][i].subtitel = streamReadString(streamId);
		g_currentMission.FarmingTablet.Calendar.Termine[g_currentMission.environment.currentDay][i].text = {};
		for j = 1, 10 do
			g_currentMission.FarmingTablet.Calendar.Termine[g_currentMission.environment.currentDay][i].text[j] = streamReadString(streamId);
		end;
	end;
	for i = 1, num2 do
		g_currentMission.FarmingTablet.Calendar.Termine[g_currentMission.environment.currentDay+1][i] = {};
		g_currentMission.FarmingTablet.Calendar.Termine[g_currentMission.environment.currentDay+1][i].titel = streamReadString(streamId);
		g_currentMission.FarmingTablet.Calendar.Termine[g_currentMission.environment.currentDay+1][i].subtitel = streamReadString(streamId);
		g_currentMission.FarmingTablet.Calendar.Termine[g_currentMission.environment.currentDay+1][i].text = {};
		for j = 1, 10 do
			g_currentMission.FarmingTablet.Calendar.Termine[g_currentMission.environment.currentDay+1][i].text[j] = streamReadString(streamId);
		end;
	end;
	for i = 1, num3 do
		g_currentMission.FarmingTablet.Calendar.Termine[g_currentMission.environment.currentDay+2][i] = {};
		g_currentMission.FarmingTablet.Calendar.Termine[g_currentMission.environment.currentDay+2][i].titel = streamReadString(streamId);
		g_currentMission.FarmingTablet.Calendar.Termine[g_currentMission.environment.currentDay+2][i].subtitel = streamReadString(streamId);
		g_currentMission.FarmingTablet.Calendar.Termine[g_currentMission.environment.currentDay+2][i].text = {};
		for j = 1, 10 do
			g_currentMission.FarmingTablet.Calendar.Termine[g_currentMission.environment.currentDay+2][i].text[j] = streamReadString(streamId);
		end;
	end;
	
	self:set(connection);
end;
function CalenderEvent:writeStreamAll(streamId, connection)
	
	local num1 = table.getn(g_currentMission.FarmingTablet.Calendar.Termine[g_currentMission.environment.currentDay]);
	local num2 = table.getn(g_currentMission.FarmingTablet.Calendar.Termine[g_currentMission.environment.currentDay+1]);
	local num3 = table.getn(g_currentMission.FarmingTablet.Calendar.Termine[g_currentMission.environment.currentDay+2]);
	
	streamWriteInt16(streamId, num1);
	streamWriteInt16(streamId, num2);
	streamWriteInt16(streamId, num3);
	
	for i = 1, num1 do
		streamWriteString(streamId, g_currentMission.FarmingTablet.Calendar.Termine[g_currentMission.environment.currentDay][i].titel);
		streamWriteString(streamId, g_currentMission.FarmingTablet.Calendar.Termine[g_currentMission.environment.currentDay][i].subtitel);
		for j = 1, 10 do
			streamWriteString(streamId, g_currentMission.FarmingTablet.Calendar.Termine[g_currentMission.environment.currentDay][i].text[j]);
		end;
	end;
	for i = 1, num2 do
		streamWriteString(streamId, g_currentMission.FarmingTablet.Calendar.Termine[g_currentMission.environment.currentDay+1][i].titel);
		streamWriteString(streamId, g_currentMission.FarmingTablet.Calendar.Termine[g_currentMission.environment.currentDay+1][i].subtitel);
		for j = 1, 10 do
			streamWriteString(streamId, g_currentMission.FarmingTablet.Calendar.Termine[g_currentMission.environment.currentDay+1][i].text[j]);
		end;
	end;
	for i = 1, num3 do
		streamWriteString(streamId, g_currentMission.FarmingTablet.Calendar.Termine[g_currentMission.environment.currentDay+2][i].titel);
		streamWriteString(streamId, g_currentMission.FarmingTablet.Calendar.Termine[g_currentMission.environment.currentDay+2][i].subtitel);
		for j = 1, 10 do
			streamWriteString(streamId, g_currentMission.FarmingTablet.Calendar.Termine[g_currentMission.environment.currentDay+2][i].text[j]);
		end;
	end;
	
end;
function CalenderEvent:set(connection)
	if not connection:getIsServer() then
		g_server:broadcastEvent(CalenderEvent:new());
	end;
end;
function CalenderEvent:readStream(streamId, connection)
	self:readStreamAll(streamId, connection);	
end;
function CalenderEvent:readUpdateStream(streamId, connection)
	self:readStreamAll(streamId, connection);
end;
function CalenderEvent:writeStream(streamId, connection)
	self:writeStreamAll(streamId, connection);	
end;
function CalenderEvent:writeUpdateStream(streamId, connection)
	self:writeStreamAll(streamId, connection);	
end; 

function CalenderEvent:sendEvent()
	g_client:getServerConnection():sendEvent(CalenderEvent:new());
end;

function CalenderEvent:run(connection)

end;