require( "scripts/objects/get_something_object.lua" );

local	indicator_pos_x = 21;
local	indicator_pos_y = -29;

local ObjectTable = GetObjectTable("toy");

--[[
local	diaper_x = "0";
local	diaper_y = "-70";
local	diaper_layer = "1";
--]]

toy = get_something_object:new{
	parent_final_state = "holding_toy";
	object_dirty_animation = "dirty",
	stuff_name = "toy_basket";
	character_cleaning_animation = "doing_bow_up";
	flipped_animation = true;
	cleaning_state_time = 0,
	messing_state_time = 0,
	
	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,
	
	animation_script="anim/objects/toy_default_animation_script.lua",
	
	stress_inc_enabled = false;
	
	mask = true;
	maskX = 5;
	maskY = 0;
	maskWidth = 70;
	maskHeight = 50;
	maskAlpha = 0.01;
	
	click_enable = false;
	set_click_enable = false;

	messing_state_time = 0,
	cleaning_state_time = ObjectTable["cleaning_time"],

}

function toy:messing_update()
	if (GetCurrentTime() - self.new_state_start_time) > self.messing_state_time then
		if self.sound_of_messing ~= "" then
			StopSound(self.sound_of_messing);
		end
		PlayCharacterAnimation(self.current_action_character, self.character_dirty_animation);
		FlipAnimation(self.current_action_character, self.flipped_animation);
		FinishCharacterTask(self.current_action_character);
		ChangeObjectState(self.object_name, self.dirty_state_name);
		
		n = GetNumberOfToysOnTheFloor();
		SetNumberOfToysOnTheFloor(n + 1);
	end
end	

function toy:parent_action()	
	self.parent_is_coming = false;
	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 or
	GetCharacterState(self.parent_chosen) == "holding_toy") and	self.object_is_dirty then
		if self.parent_chosen == "dad" then
			PlaySound("working_father", true);
		else
			PlaySound("working_mother", true);
		end
		PlayCharacterAnimation(self.parent_chosen, self.character_cleaning_animation);
		FlipAnimation(self.parent_chosen, self.flipped_animation);
		PlayObjectAnimation(self.object_name, self.object_cleaning_animation);
		
		if self.show_cleaning_particle then
			ShowParticle(self.object_name, "effects/powder.lua", "0", "0");
		end
		
		ChangeObjectState(self.object_name, self.cleaning_state_name);
		SetCharacterState(self.parent_chosen, self.cleaning_state_name);
		self.new_state_start_time = GetCurrentTime();
		
		self:get_cleaning_state_time();
	else
		if self.no_stress_power then
			HideNoStressIcon(self.object_name);
		end
		self.no_stress_power = false;
		--AddCharacterStress(self.parent_chosen, self.stress_inc);
		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);			
			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 toy:cleaning_update()
	if (GetCurrentTime() - self.new_state_start_time) > self.cleaning_state_time then
		if self.parent_chosen == "dad" then
			StopSound("working_father");
			PlaySound("task_complete_father", false);
		else
			StopSound("working_mother");
			PlaySound("task_complete_mother", false);
		end
		PlayCharacterAnimation(self.parent_chosen, self.character_clean_animation);
		ShowCharacterStuff(self.parent_chosen, self.stuff_name, self.stuff_x, self.stuff_y, self.stuff_layer);
		SetCharacterState(self.parent_chosen, self.parent_final_state);
		--AddCharacterStress(self.parent_chosen, self.stress_inc);
		IncrementNumberOfHoldingItems(self.parent_chosen);
		FinishCharacterTask(self.parent_chosen);
		
		if self.no_stress_power then
			HideNoStressIcon(self.object_name);
		end
		self.no_stress_power = false;
		
		PlayObjectAnimation(self.object_name, self.object_clean_animation);		
		ChangeObjectState(self.object_name, self.clean_state_name);
		
		
		self.cleaning_state_time = self.previous_cleaning_state_time;
		
		FinishTeamWorkTask(self.parent_chosen, "messes" ,1);
	end
end