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

local	indicator_pos_x = -10;
local	indicator_pos_y = -40;

local ObjectTable = GetObjectTable("television");

television = simple_object:new{
	anchor_x=-10,
	anchor_y=70,
	offset_x=6,
	offset_y=-5,
	texture="anim/objects/television/television",
	animation_script="anim/objects/default_animation_script.lua",
	glow_texture="anim/objects/television/television_glow",
	glow_animation_script="anim/objects/default_glow_animation_script.lua",
	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,
	
	--sound_of_messed = "tv",

	messing_state_time = ObjectTable["messing_time"],
	cleaning_state_time = ObjectTable["cleaning_time"],
	stress_inc = ObjectTable["stress_inc"],


}

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

function television:clean_mess_action()
	PlaySound("tv", false);
	PlayCharacterAnimation(self.current_action_character, self.character_messing_animation);
	FlipAnimation(self.current_action_character, self.flipped_animation);
	PlayObjectAnimation(self.object_name, self.object_messing_animation);
	ChangeObjectState(self.object_name, self.messing_state_name);
	self.new_state_start_time = GetCurrentTime();
	if self.sound_of_messing ~= "" then
		PlaySound(self.sound_of_messing, true);
	end	
	self.previous_state = "messing";
end

function television:cleaning_update()
		if self.cleaning_timer_enabled then
			SetCleaningTimerProgress(self.object_name, (GetCurrentTime() - self.new_state_start_time) / self.cleaning_state_time);
		end
		if (GetCurrentTime() - self.new_state_start_time) > self.cleaning_state_time then
			StopSound("tv");
			
			if self.cleaning_timer_enabled then
				SetCleaningTimerVisible(self.object_name, false);
			end
			
			if self.parent_chosen == "dad" then
				if self.sound_of_work_enable then
					StopSound("working_father");
				end
				PlaySound("task_complete_father", false);
			else
				if self.sound_of_work_enable then
					StopSound("working_mother");
				end
				PlaySound("task_complete_mother", false);
			end
			
			PlayCharacterAnimation(self.parent_chosen, self.character_clean_animation);
			FlipAnimation(self.parent_chosen, self.flipped_animation);
			--HideParticle(self.object_name, "powder");
			HideParticle(self.object_name, "powder");
			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;
			FinishCharacterTask(self.parent_chosen);
			PlayObjectAnimation(self.object_name, self.object_clean_animation);
			ChangeObjectState(self.object_name, self.clean_state_name);
			SetCharacterState(self.parent_chosen, "normal");
			
			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
			
			if self.is_a_mess then
				FinishTeamWorkTask(self.parent_chosen, "messes", 1);
			end
			
			self.cleaning_state_time = self.previous_cleaning_state_time;
		end
	--end
end