class 1 ai_boss04_heart_of_warding : default_npc
{
parameter:
	int	GM_ID1 = 4;
	int	GM_ID2 = 5;
	int	GM_ID3 = 6;

handler:
	EventHandler CREATED()
	{
		myself.i_ai0 = 0;
		myself.i_ai1 = 0;
		super;
	}

	EventHandler TALKED(talker)
	{
		myself::ShowPage(talker,"heart_of_warding001.htm");
	}

	EventHandler TIMER_FIRED_EX(timer_id,i0)
	{
		if( timer_id == 3001 )
		{
			if( myself.i_ai1 < 91 )
			{
				gg::SendScriptEvent(myself.c_ai0,0,0);
			}
			if( myself.i_ai1 > 90 && myself.i_ai1 < 136 )
			{
				gg::SendScriptEvent(myself.c_ai1,0,0);
			}
			if( myself.i_ai1 > 135 )
			{
				gg::SendScriptEvent(myself.c_ai2,0,0);
			}
			myself.i_ai0 = 0;
			myself.i_ai1 = 0;
		}
		super;
	}

	EventHandler TELEPORT_REQUESTED(talker,i0,i1,i2,c0,c1,c2,i3,i4)
	{
		i0 = myself::GetGlobalMap(GM_ID1);
		i1 = myself::GetGlobalMap(GM_ID2);
		i2 = myself::GetGlobalMap(GM_ID3);
		if( i0 != -1 && i1 != -1 && i2 != -1 )
		{
			c0 = myself::GetCreatureFromIndex(i0);
			c1 = myself::GetCreatureFromIndex(i1);
			c2 = myself::GetCreatureFromIndex(i2);
			if( c0.alive && c1.alive && c2.alive )
			{
				if( ( c0.db_value == 0 || c0.db_value == 1 ) && ( ( c1.db_value == 0 || c1.db_value == 1 ) && ( c2.db_value == 0 || c2.db_value == 1 ) ) )
				{
					if( myself::OwnItemCount(talker,3865) > 0 )
					{
						myself::DeleteItem1(talker,3865,1);
						i3 = ( 179700 + gg::Rand(700) );
						i4 = ( 113800 + gg::Rand(2100) );
						myself::InstantTeleport(talker,i3,i4,-7709);
						myself.i_ai1 = ( myself.i_ai1 + 1 );
						if( myself.i_ai0 == 0 )
						{
							myself::AddTimerEx(3001,( ( 30 * 60 ) * 1000 ));
							myself.c_ai0 = c0;
							myself.c_ai1 = c1;
							myself.c_ai2 = c2;
							myself.i_ai0 = 1;
						}
					}
					else
					{
						myself::ShowPage(talker,"heart_of_warding004.htm");
					}
				}
				else if( c0.db_value == 2 || c0.db_value == 3 )
				{
					myself::ShowPage(talker,"heart_of_warding003.htm");
				}
			}
			else
			{
				myself::ShowPage(talker,"heart_of_warding002.htm");
			}
		}
		else
		{
			myself::ShowPage(talker,"heart_of_warding002.htm");
		}
	}

}
