require( "scripts/common/simple_object.lua" );

local	indicator_pos_x = 4;
local	indicator_pos_y = -14;

schoolagedwaiting = simple_object:new{
	anchor_x=0,
	anchor_y=100,
	--offset_x=40,
	--offset_y=40,
	animated = true,
	indicator_ui_x=indicator_pos_x,
	indicator_ui_y=indicator_pos_y,
	dad_ui_x=indicator_pos_x-35,
	dad_ui_y=indicator_pos_y,
	mom_ui_x=indicator_pos_x-35,
	mom_ui_y=indicator_pos_y,
	messing_state_time = 0,
	cleaning_state_time = 0,
	book_x = "20",
	book_y = "-100",
	book_layer = "1",
	
	show_cleaning_particle = false;
	
	complex_object = true;
	
	stress_inc_enabled = false;
	
	check_teamwork = true;
	finish_teamwork = true;
	teamworktask_name = "orderstudy";
}

function schoolagedwaiting:new(o)
	o = o or {}   -- create object if user does not provide one
	setmetatable(o, self)
	self.__index = self
	return o
end

function schoolagedwaiting:messing_update()
	if (GetCurrentTime() - self.new_state_start_time) > self.messing_state_time then
		ShowCharacterStuff(self.current_action_character, "book", self.book_x, self.book_y, self.book_layer);
		HideCharacter(self.current_action_character);		
		ChangeObjectState(self.object_name, self.dirty_state_name);
		ShowBreakSign("study");
	end
end	

function schoolagedwaiting:parent_action()
	self.parent_is_coming = false;
	--DebugOut(""..self.object_name.." parent_action");
	--DebugOut("parent_action");
	if self.parent_chosen == "dad" then
		HideDadIcon(self.object_name);
	else
		HideMomIcon(self.object_name);
	end
	RemoveObjectFromClickedList(self.object_name);
	if GetCharacterState(self.parent_chosen) == self.parent_state_action and self.object_is_dirty then
		--PlayCharacterAnimation(self.parent_chosen, self.character_cleaning_animation);
		--FlipAnimation(self.parent_chosen, self.flipped_animation);
		--PlayObjectAnimation("tv", "clean");
		
		ChangeObjectState(self.object_name, self.cleaning_state_name);
		self.new_state_start_time = GetCurrentTime();
		SetCharacterState(self.parent_chosen, self.cleaning_state_name);
		
		ShowNextTaskIcon("estante1");
		
		PlayObjectAnimation("estante1", "dirty");
		ChangeObjectState("estante1", "dirty");	
				
		self:get_cleaning_state_time();
	else
		ShowMiss(self.object_name);
		if self.no_stress_power then
			HideNoStressIcon(self.object_name);
		end
		self.no_stress_power = false;
		IncludeObjectMouseHandler(self.object_name);
		FinishCharacterTask(self.parent_chosen);
		
		self.parent_chosen = "";
		self.click_enable = self.set_click_enable;
		--if self.object_is_dirty then
		--	ChangeObjectState(self.object_name, self.dirty_state_name);
		--end
		
		if self.object_is_dirty then
			--ChangeObjectState(self.object_name, self.dirty_state_name);			
			IncludeObjectMouseHandler(self.object_name);			
			self.click_enable = true;
			PlayObjectAnimation(self.object_name, self.object_dirty_animation);	
			--PlayGlowAnimation(self.object_name, "dirty");
		end
	end
end
	
function schoolagedwaiting:cleaning_update()
	if (GetCurrentTime() - self.new_state_start_time) > self.cleaning_state_time then
		if self.stress_inc_enabled and not self.no_stress_power then
			AddCharacterStress(self.parent_chosen, self.stress_inc);
		end
		if self.no_stress_power then
			HideNoStressIcon(self.object_name);
		end
		self.no_stress_power = false;
				
		ShowCharacter(self.current_action_character);
		HideCharacterStuff(self.current_action_character);
		FinishCharacterTask(self.current_action_character);
		
		PlayCharacterAnimation(self.parent_chosen, self.character_clean_animation);
		SetCharacterState(self.parent_chosen, self.parent_state_action);
		FinishCharacterTask(self.parent_chosen);
		
		PlayObjectAnimation(self.object_name, self.object_clean_animation);
		ChangeObjectState(self.object_name, self.clean_state_name);
		
		if self.finish_teamwork then
			FinishTeamWorkTask(self.parent_chosen, self.teamworktask_name, 1);
		end
		
		if self.check_teamwork then
			ShowTeamWorkIcon(self.object_name, 2);
			--ShowTeamWorkIcon(self.object_name, "mom", false);		
		end
		
		self.new_state_start_time = GetCurrentTime();
	end
end

