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


discipline_kids_left_dirty_no_animation = discipline_kids_left_dirty:new{
	object_name="",
	
	anchor_y = 1000,
	
	dad_ui_x=-21,
	dad_ui_y=-71,
	mom_ui_x=-21,
	mom_ui_y=-71,
	
	character_messing_animation = "",
	object_left_dirty = "";
	object_dad_disciplining = "";
	object_mom_disciplining = "";
	--object_child_being_disciplined = "schoolageddiscipline1";
	parent_node_discipline = "";
	
	texture="anim/objects/fall_floor/fall_floor",
	animation_script="anim/objects/default_animation_script.lua",
	glow_texture="anim/objects/fall_floor/fall_floor_glow",
	glow_animation_script="anim/objects/default_glow_animation_script.lua",
	
	animated = true,
	
	mask = true;
	maskX = 0;
	maskY = -30;
	maskWidth = 92;
	maskHeight = 90;
	maskAlpha = 0.01;
	
	cleaning_state_time = 5000;
	messing_state_time = 10000;
	
	flipped_animation = true;
}


function discipline_kids_left_dirty_no_animation:ready_to_be_disciplined()	
	HideCharacter(self.parent_chosen);
	--HideCharacter(self.current_action_character);
		
	if DecideDisciplineWay(self.parent_chosen) == 0 then
		self.discipline_way = "good";
	else
		self.discipline_way = "bad";
	end	
	
	if self.parent_chosen == "dad" then
		ChangeObjectState(self.object_dad_disciplining, self.discipline_way);
	else
		ChangeObjectState(self.object_mom_disciplining, self.discipline_way);
	end
	
	--ChangeObjectState(self.object_child_being_disciplined, self.discipline_way);
	PlayCharacterAnimation(self.current_action_character, "idle");
	
	ChangeObjectState(self.object_name, self.cleaning_state_name);
	self.new_state_start_time = GetCurrentTime();
end

function discipline_kids_left_dirty_no_animation:child_give_up()
	FinishCharacterTask(self.current_action_character);
	ChangeObjectState(self.object_name, self.clean_state_name);
	
end

function discipline_kids_left_dirty:dirty_update()
	if (GetCurrentTime() - self.new_state_start_time) > self.messing_state_time and self.click_enable then
		if self.sound_of_messing ~= "" then
			StopSound(self.sound_of_messing);
		end
		--ChangeObjectState(self.object_left_dirty, "dirty");
		RemoveCharacterOnObject(self.current_action_character);
		FinishCharacterTask(self.current_action_character);
		
		PlayObjectAnimation(self.object_name, self.object_clean_animation);
		PlayGlowAnimation(self.object_name, "clean");		
		
		ChangeObjectState(self.object_name, self.clean_state_name);
		--ChangeObjectState(self.object_name, "childgiveup");
	end
end

function discipline_kids_left_dirty_no_animation:cleaning_update()
		if self.cleaning_timer_enabled then
			SetCleaningTimerProgress(self.object_name, (GetCurrentTime() - self.new_state_start_time) / self.cleaning_state_time);
		end
		--DebugOut("CLEANING STATE TIME    :     "..self.cleaning_state_time);
		if (GetCurrentTime() - self.new_state_start_time) > self.cleaning_state_time then
			if self.sound_of_cleaning ~= "" then
				StopSound(self.sound_of_cleaning);
			end
			if self.sound_of_messed ~= "" then
				StopSound(self.sound_of_messed);
			end
			
			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);
			
			ChangeObjectState(self.object_name, self.clean_state_name);
			SetCharacterState(self.parent_chosen, "normal");
			
			FinishTeamWorkTask(self.parent_chosen, "disciplines", 1);
			
			if self.discipline_way == "good" then
				FinishTeamWorkTask(self.parent_chosen, "disciplinesnoyelling", 1);
			end
			
			if self.check_teamwork then
				ShowTeamWorkIcon(self.object_name, 2);
				--ShowTeamWorkIcon(self.object_name, "mom", false);		
			end
			
			--self.cleaning_state_time = self.previous_cleaning_state_time;
			
			--NEW
			if self.parent_chosen == "dad" then
				ChangeObjectState(self.object_dad_disciplining, "transition");
				PlayObjectAnimation(self.object_dad_disciplining, "invisible");
			else
				ChangeObjectState(self.object_mom_disciplining, "transition");
				PlayObjectAnimation(self.object_mom_disciplining, "invisible");
			end
			
			ShowCharacter(self.parent_chosen);
			
			FinishCharacterTask(self.current_action_character);
			ShowCharacter(self.current_action_character);
			--NEW
			
			
			if self.discipline_way == "good" then
				DisciplineKids();
			end
		end
	--end
end

function discipline_kids_left_dirty_no_animation:parent_action()	
	self.parent_is_coming = false;
	DebugOut("discipline_kids:parent_action:"..self.object_name);
	
	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
		if self.sound_of_work_enable then
			if self.parent_chosen == "dad" then
				--PlaySound("working_father", true);
			else
				--PlaySound("working_mother", true);
			end
		end
		PlayObjectAnimation(self.object_name, self.object_cleaning_animation);
		
		--ChangeObjectState(self.object_left_dirty, "dirty");
		LoadCharacterTask(self.current_action_character, gotonodeanddo, self.node_of_discipline, self.object_name);
		FinishCharacterTask(self.current_action_character);
		RemoveCharacterOnObject(self.current_action_character);
		
		PlayObjectAnimation(self.object_name, self.object_clean_animation);
		PlayGlowAnimation(self.object_name, "clean");		
		
		ChangeObjectState(self.object_name, "waitingchild");
		SetCharacterState(self.parent_chosen, self.cleaning_state_name);
		
		if self.cleaning_timer_enabled then
			SetCleaningTimerVisible(self.object_name, true);
		end
		
		if self.sound_of_messing ~= "" then
			StopSound(self.sound_of_messing);
		end
		
		if self.sound_of_cleaning ~= "" then
			PlaySound(self.sound_of_cleaning, true);
		end
	else
		ShowMiss(self.object_name);
		if self.stress_inc_enabled and not self.no_stress_power then
			AddFutureCharacterStress(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);
		self.parent_chosen = "";
		self.click_enable = self.set_click_enable;
		if self.object_is_dirty then
			IncludeObjectMouseHandler(self.object_name);			
			self.click_enable = true;
			PlayObjectAnimation(self.object_name, self.object_dirty_animation);
		else
			if self.click_enable then
				IncludeObjectMouseHandler(self.object_name);
			end
		end
	end
end

function discipline_kids_left_dirty_no_animation:clean_mess_action()
	if self.object_to_verify == "" or GetObjectState(self.object_to_verify) ~= "cleaning" then
		PlayCharacterAnimation(self.current_action_character, self.character_messing_animation);
		FlipAnimation(self.current_action_character, self.flipped_animation);
		ChangeObjectState(self.object_name, self.dirty_state_name);
		PutCharacterOnObject(self.current_action_character, self.object_name);
		
		if self.sound_of_messing ~= "" then
			PlaySound(self.sound_of_messing, true);
		end
		--LoadCharacterTask(self.current_action_character, gotonodeanddo, self.node_of_discipline, self.object_name);
	else
		--LoadCharacterTask(self.current_action_character, gotonodeanddo, self.node_of_discipline, "idle");
		FinishCharacterTask(self.current_action_character);
	end
end
