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

bad_idle_object = {
	object_name = "",
	
	texture="",
	
	task_idle = true,
	
	animated = true,
	loaduiicons=true,
	indicator_ui_x=0,
	indicator_ui_y=-90,
	dad_ui_x=-125,
	dad_ui_y=-90,
	mom_ui_x=-55,
	mom_ui_y=-90,
	nanny_ui_x=10,
	nanny_ui_y=10,
	
	parent_idle = "",
	
	idle_state_time = 10000,
	minimum_idle_state_time = 1000,
	
	idle_state_start_time = 0,
	
	stop_idle_goal_name = "",
	
	object_to_verify = "",
	
	sound_of_idle = "",
}

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

function bad_idle_object:clean_init()
	PlayObjectAnimation(self.object_name, "invisible");
end

function bad_idle_object:parent_action(parent)
	if self.object_to_verify == "" or GetObjectState(self.object_to_verify) ~= "cleaning" then
		if self.sound_of_idle ~= "" then
			PlaySound(self.sound_of_idle, true);
		end
		ChangeObjectState(self.object_name, "idle");
		self.parent_idle = parent;
		HideCharacter(self.parent_idle);
		setIdleType(self.parent_idle, 2);
	else
		FinishCharacterTask(parent);
	end
end

function bad_idle_object:idle_init()
	IncludeObjectMouseHandler(self.object_name);
	ChangeObjectState(self.object_name, "idle");
	PlayObjectAnimation(self.object_name, "idle");
	self.idle_state_start_time = GetCurrentTime();	
end

function bad_idle_object:idle_update()
	if (GetCurrentTime() - self.idle_state_start_time) > self.minimum_idle_state_time or isCorrected(self.parent_idle) then
		if (GetCurrentTime() - self.idle_state_start_time) > self.idle_state_time or isCorrected(self.parent_idle) or QuantityTasksParent(self.parent_idle) > 1 then
			if isCorrected(self.parent_idle) then
				clearCorrected(self.parent_idle);
			end
			if self.sound_of_idle ~= "" then
				StopSound(self.sound_of_idle);
			end
			ChangeObjectState(self.object_name, "clean");
			ShowCharacter(self.parent_idle);
			FinishCharacterTask(self.parent_idle);
			setIdleType(self.parent_idle, 0);
			self.parent_idle = "";
			RemoveObjectMouseHandler(self.object_name);
			end
		end
	end

function bad_idle_object:click()
	SetParentSelected(self.parent_idle);
end
