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

local	indicator_pos_x = 30;
local	indicator_pos_y = 20;

horse_toy = simple_object:new{
	parent_state_action = "leaving_child_to_play",

	character_cleaning_animation = "doing_stuff_up",
	anchor_x = 58,
	anchor_y = 116,
	offset_x=-5,
	offset_y=-5,
	
	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,
	
	cleaning_state_time = 5000;
	
	texture = "",
	animated = false,
	
	show_cleaning_particle = false;
	
	complex_object = true;
}

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

function horse_toy:messing_update()
	if (GetCurrentTime() - self.new_state_start_time) > self.messing_state_time then
		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);
	end
end	

--[[
function horse_toy:dirty_mouse_on()
	if not self.mouse_on then
		self.mouse_on = true;
		if GetCharacterState("dad") == self.parent_state_action then
			ShowDadIcon(self.object_name);
		end
		if GetCharacterState("mom") == self.parent_state_action then
			ShowMomIcon(self.object_name);
		end
		PlayObjectAnimation(self.object_name, self.object_dirty_mouse_on_animation);
	end
end
--]]

function horse_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 and self.object_is_dirty then
		PlayCharacterAnimation(self.parent_chosen, self.character_cleaning_animation);
		PlayObjectAnimation(self.object_name, self.object_cleaning_animation);
		ChangeObjectState(self.object_name, self.cleaning_state_name);
		self.new_state_start_time = GetCurrentTime();
		SetCharacterState(self.parent_chosen, self.cleaning_state_name);
		
		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;
		--PlayObjectAnimation(self.object_name, self.object_dirty_animation);
		--ChangeObjectState(self.object_name, self.dirty_state_name);
		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 horse_toy:cleaning_update()
	if (GetCurrentTime() - self.new_state_start_time) > self.cleaning_state_time then
		if self.parent_chosen == "dad" then
			PlaySound("task_complete_father", false);
		else
			PlaySound("task_complete_mother", false);
		end
		PlayCharacterAnimation(self.parent_chosen, self.character_clean_animation);
		SetCharacterState(self.parent_chosen, "normal");
		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);
		
		FinishCharacterTask(self.current_action_character);
				
		self.cleaning_state_time = self.previous_cleaning_state_time;
	end
end