class 1 tvt_manager : citizen
{
parameter:
	string DoorName1 = "aden_colosseum_002_001";
	string DoorName2 = "aden_colosseum_001_001";
	string DoorName3 = "aden_colosseum_002_002";
	string DoorName4 = "aden_colosseum_001_002";
	string BattleZoneName = "colosseum_battle_tvt";
	string StartZone1 = "colosseum_peace_tvt1";
	string StartZone2 = "colosseum_peace_tvt2";
	int instkick_x = 147445;
	int instkick_y = 28400;
	int instkick_z = -2264;
	int	HourToStart1 = 16;
	int	HourToEnd1 = 17;
	int	HourToStart2 = 17;
	int	HourToEnd2 = 18;
	int	HourToStart3 = 18;
	int	HourToEnd3 = 19;
	int	LevelStart1 = 20;
	int	LevelEnd1 = 40;	
	int	LevelStart2 = 41;
	int	LevelEnd2 = 60;	
	int	LevelStart3 = 61;
	int	LevelEnd3 = 85;	
	int	TimeToReg = 120;
	int	TimeToPrepare = 120;
	int	TimeToFight = 120;
	int RegistrationDelay = 2;
	int	bNeedDispellAll = 1;
	int	bNeedDespawnSummon = 1;
	int RewardItem = 57;
	int RewardCount = 10000;

handler:
	EventHandler CREATED()
	{
		myself::InitializeTVT(BattleZoneName,StartZone1,StartZone2);
//		myself::TVTEventAddDoor(DoorName1,1,0);
//		myself::TVTEventAddDoor(DoorName2,1,0);
//		myself::TVTEventAddDoor(DoorName3,1,0);
//		myself::TVTEventAddDoor(DoorName4,1,0);
		myself.i_ai0 = 0;
	}

	EventHandler TALKED(talker,fhtml0)
	{
		i0 = talker.level;
		i1 = gg::GetDateTime(0,3);
		i2 = 0;

		if ( i1 >= HourToStart1 && i1 < HourToEnd1 )
		{ 
			if (i0 >= LevelStart1 && i0 <= LevelEnd1 )
			{
			}
			else
			{
				myself::FHTML_SetFileName(fhtml0,"tvtevent_not_level.htm");
				myself::FHTML_SetInt(fhtml0,"level1",LevelStart1);
				myself::FHTML_SetInt(fhtml0,"level2",LevelEnd1);
				i2 = 1;
			}
			
		} else if ( i1 >= HourToStart2 && i1 < HourToEnd2 )
		{
			if (i0 >= LevelStart2 && i0 <= LevelEnd2 )
			{
			}
			else
			{
				myself::FHTML_SetFileName(fhtml0,"tvtevent_not_level.htm");
				myself::FHTML_SetInt(fhtml0,"level1",LevelStart2);
				myself::FHTML_SetInt(fhtml0,"level2",LevelEnd2);
				i2 = 1;
			}
		} else if ( i1 >= HourToStart3 && i1 < HourToEnd3 )
		{
			if (i0 >= LevelStart3 && i0 <= LevelEnd3 )
			{
			}
			else
			{
				myself::FHTML_SetFileName(fhtml0,"tvtevent_not_level.htm");
				myself::FHTML_SetInt(fhtml0,"level1",LevelStart3);
				myself::FHTML_SetInt(fhtml0,"level2",LevelEnd3);
				i2 = 1;
			}
		}
		else
		{
			myself::FHTML_SetFileName(fhtml0,"tvtevent_not_time.htm");
			i2 = 1;
		}
		
		if (i2 == 1)
		{
				myself::FHTML_SetInt(fhtml0,"LevelStart1",LevelStart1);
				myself::FHTML_SetInt(fhtml0,"LevelEnd1",LevelEnd1);
				myself::FHTML_SetInt(fhtml0,"LevelStart2",LevelStart2);
				myself::FHTML_SetInt(fhtml0,"LevelEnd2",LevelEnd2);
				myself::FHTML_SetInt(fhtml0,"LevelStart3",LevelStart3);
				myself::FHTML_SetInt(fhtml0,"LevelEnd3",LevelEnd3);
				myself::FHTML_SetInt(fhtml0,"HourToStart1", HourToStart1);
				myself::FHTML_SetInt(fhtml0,"HourToEnd1",HourToEnd1);
				myself::FHTML_SetInt(fhtml0,"HourToStart2", HourToStart2);
				myself::FHTML_SetInt(fhtml0,"HourToEnd2",HourToEnd2);
				myself::FHTML_SetInt(fhtml0,"HourToStart3", HourToStart3);
				myself::FHTML_SetInt(fhtml0,"HourToEnd3",HourToEnd3);
				myself::ShowFHTML(talker,fhtml0);
				return;
		}
		
		if( myself.i_ai0 == 0 )
		{
			myself::FHTML_SetFileName(fhtml0,"tvtevent000.htm");
			myself::FHTML_SetInt(fhtml0,"timetoreg",TimeToReg);
			myself::FHTML_SetInt(fhtml0,"timetoprepare",TimeToPrepare);
			myself::FHTML_SetInt(fhtml0,"timetofight",TimeToFight);
			myself::ShowFHTML(talker,fhtml0);
			return;
		}
		
		if( myself.i_ai0 == 1 )
		{
			myself::ShowPage(talker,"tvtevent_complete.htm");
			return;
		}

		if( myself.i_ai0 == 2 )
		{
			myself::ShowPage(talker,"tvtevent_reg.htm");
			return;
		}

		myself::ShowPage(talker,"tvtevent_start.htm");
	}

	EventHandler MENU_SELECTED(talker,state,ask,reply,gg,i0)
	{
		if( ask == 9991 )
		{
			if( reply == 0 )
			{
				if ( myself.i_ai0 == 0)
				{
					i0 = gg::GetDateTime(0,4) + RegistrationDelay;
					i1 = gg::GetDateTime(0,3);
					i2 = gg::GetDateTime(0,2);
					i3 = gg::GetDateTime(0,1);
					i4 = gg::GetDateTime(0,0);
					if (i0 > 59)
					{
						i1 = i1 + 1;
						i0 = i0 - 60;
					}
					myself::Say("Registration will start at " + myself::IntToStr(i4) + "/" + myself::IntToStr(i3) + "/" + myself::IntToStr(i2) + " " + myself::IntToStr(i1) + " " + myself::IntToStr(i0));
			  		myself::CreateOneTimeTVT(i4,i3,i2,i1,i0,TimeToReg,TimeToPrepare,TimeToFight,bNeedDispellAll,bNeedDespawnSummon);
					gg::Announce("TVT Event initialization complete");
					myself.i_ai0 = 1;
					myself::ShowPage(talker,"tvtevent_complete.htm");
				}
				else
				{
					myself::ShowPage(talker,"tvtevent_start.htm");
				}
			}
		}
		if( ask == 999 )
		{
			if( reply == 0 )
			{
				if( state == 0 )
				{
					gg::Announce("TvT event start complete");
				}
				if( state == 1 )
				{
					gg::Announce("ERROR Detected when initializing TVT Event");
					myself.i_ai0 = 0;
				}
			}
			if( reply == 1 )
			{
				gg::Announce("Registration Open for TVT Event");
				myself.i_ai0 = 2;
			}
			if( reply == 2 )
			{
				myself::Castle_GateOpenClose2(DoorName1,1);
				myself::Castle_GateOpenClose2(DoorName2,1);
				myself::Castle_GateOpenClose2(DoorName3,1);
				myself::Castle_GateOpenClose2(DoorName4,1);
				myself::InstantTeleportInMyTerritory(instkick_x,instkick_y,instkick_z,10);
				gg::Announce("Registration time has passed");
				myself.i_ai0 = 3;
			}
			if( reply == 3 )
			{
				myself::Castle_GateOpenClose2(DoorName1,0);
				myself::Castle_GateOpenClose2(DoorName4,0);
				gg::Announce("TVT Event battle begin");
				myself.i_ai0 = 4;
			}
			if( reply == 4 )
			{
				myself::Castle_GateOpenClose2(DoorName1,0);
				myself::Castle_GateOpenClose2(DoorName2,0);
				myself::Castle_GateOpenClose2(DoorName3,0);
				myself::Castle_GateOpenClose2(DoorName4,0);
				gg::Announce("TVT Event no player registred");
				myself.i_ai0 = 0;
			}
			if( reply == 5 )
			{
				myself::Castle_GateOpenClose2(DoorName1,0);
				myself::Castle_GateOpenClose2(DoorName2,0);
				myself::Castle_GateOpenClose2(DoorName3,0);
				myself::Castle_GateOpenClose2(DoorName4,0);
				gg::Announce("TVT Event command 1 win");
				myself::NpcTVTGiveItemToTeam(1,RewardItem,RewardCount);
				myself.i_ai0 = 0;
			}
			if( reply == 6 )
			{
				myself::Castle_GateOpenClose2(DoorName1,0);
				myself::Castle_GateOpenClose2(DoorName2,0);
				myself::Castle_GateOpenClose2(DoorName3,0);
				myself::Castle_GateOpenClose2(DoorName4,0);
				gg::Announce("TVT Event command 2 win");
				myself::NpcTVTGiveItemToTeam(2,RewardItem,RewardCount);
				myself.i_ai0 = 0;
			}
			if( reply == 7 )
			{
				myself::Castle_GateOpenClose2(DoorName1,0);
				myself::Castle_GateOpenClose2(DoorName2,0);
				myself::Castle_GateOpenClose2(DoorName3,0);
				myself::Castle_GateOpenClose2(DoorName4,0);
				gg::Announce("TVT Event no winner");
				myself.i_ai0 = 0;
			}
		}
		if( ask == 2010 )
		{
			if( reply == 1 && myself.i_ai0 == 2 )
			{
				i0 = myself::OwnItemCount(talker,@adena);
				if(i0>50000000)
				{
					myself::DeleteItem1(talker,@adena,50000000);
					myself::RegisterTVTUser(talker);
					myself::ShowPage(talker,"tvtevent_reg_comp.htm");
				}
				else
				{
					myself::ShowPage(talker,"tvt_not_enough_money.htm");
				}
			}
			else
			{
				myself::ShowPage(talker,"tvtevent_start.htm");
			}
		}
	}

}
