#include scener
#include input
#include kdsqueststate
#include kds3

export ON_CREATE;
export ON_LBUTTONDOWN;
export ON_COMMAND;
export ON_SETFOCUS;
export ON_KILLFOCUS;

vec3_t dist;

void ON_CREATE()
{
	 dist.Assign(0.0, -120.0, 0.0);
}

void ON_LBUTTONDOWN()
{
	ObjectClick(0, dist, self);
}

void ON_KILLFOCUS()
{
	SetKdsCursor(CURSOR_NORMAL);
	SetFocusObject(NULL, "");
}

void ON_SETFOCUS()
{
	if (ActiveItem())
	{
		SetKdsCursor(CURSOR_USE);
	}
	else
	{
		SetKdsCursor(CURSOR_EYES);
	}
	SetFocusObject(self, "TELEFON");
}

void ON_COMMAND(int lparam, int rparam)
{
	if (lparam == EMC_WOODY_QUERY) // запрос от Вуди
	{
		LINK* woody = scene.FindObjectByName("01Hero");
		
		vec3_t lookBack;
		vec3_t lookForward;

		lookBack.Assign(0.0, 1.0, 0.0);
		lookForward.Assign(0.0, -1.0, 0.0);

		if (ActiveItem()) // выбран ли предмет в инвентаре
		{
			if (isItemActive("KLEY"))
			{
				RemoveItem("KLEY");	//удаляем скотч из инвентаря
				PersJob* woodyJob = AddAnimationStackJob(woody);
				AddFreeAnimation(woodyJob, 8, lookBack); // Aha!
				AddFreeAnimation(woodyJob, 2, lookBack); // Manipulate
				AddEvent(woodyJob, self, 1, 5);
			}
			else
			{
				PersJob* woodyJob = AddAnimationStackJob(woody);
				AddFreeAnimation(woodyJob, 7, lookForward); // What?
			}
			ResetActiveItem();
		}
		else
		{
			// Никакой предмет не выбран, действие "ПОСМОТРЕТЬ"
			vec3_t look;
			look.Assign(0.0, -100.0, 0.0);
			SetLook(woody, look);
			WoodyTalk("TELEFON_SHOW", 5000);
		}
	}

	 if (lparam == EMC_EVENT)
	 {
		if (rparam == 5)
		{
			SetProperty("KleyTelefon", true);
		}
	 }

}
