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

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

vec3_t dist;
vec3_t lookForward;
vec3_t lookBack;

vec3_t spos;

void ON_CREATE()
{
	dist.Assign(0.0, -100.0, 0.0);
	lookBack.Assign(1.0, 0.0, 0.0);
	lookForward.Assign(0.0, -1.0, 0.0);
	
//	SetProperty("TonerAqwa", true);
}

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

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

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

void ON_COMMAND(int lparam, int rparam)
{
	if (lparam == KDSM_NEIG) // запрос от Соседа
	{
		LINK* neib = scene.FindObjectByName("02Neibour");

		if (!GetProperty("TonerAqwa"))
		{
			WriteLog("______________Я ПРИШООООЛ КОРМИТЬ РЫБОК___________");
			PersJob* job = AddNeighbourStackJob(neib);

			AddHardAnimation(job, "02_05_Fishing.eza", 2);           				// кормим рыбок
			AddHardEvent(job, self, 0, 14, 10);    //sound
		}
		else
		{
			WriteLog("_________покормим рыбок тонером");
			SetProperty("TonerAqwa", false);
			PersJob* job = AddNeighbourStackJob(neib);

			AddHardAnimation(job, "02_05_Fishing.eza", 1);           				// кормим рыбок
			AddHardEvent(job, self, 0, 14, 10);    //sound
			AddFreeAnimation(job, 4, lookForward); 			// злимся
			AddFreeAnimation(job, 0, lookBack);    			// разворачиваемся
			AddFreeAnimation(job, 7, lookBack);    			// чиним

			if (!GetProperty("TonerQuestComplete"))
			{
				AddEvent(job, self, 2, 2);
				AddEvent(job, self, 4, 51);
				SetProperty("TonerQuestComplete", true);
			}
		}
	}
	 if (lparam == EMC_EVENT)
	 {
		if (rparam == 2)
		{
			AddPrize();
			AddAngryLevel(30);
		}
		if (rparam == 10)
		{
			LINK* neib = scene.FindObjectByName("02Neibour");
			spos.Assign(0, 0, 0);
			sound.CreateSource( neib, "23", 4, 0, 0, spos, 1.0 );
		}
		if (rparam == 51)
		{
			EndGameTest();
		}
	 }
}
