class 1 shilen_s_stone_statue1 : default_npc
{
parameter:
	int	GM_ID1 = 9;

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

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

	EventHandler TALK_SELECTED(talker)
	{
		if( _from_choice == 0 )
		{
			if( myself::HaveMemo(talker,641) == 0 && myself::GetOneTimeQuestFlag(talker,126) == 1 )
			{
				_choiceN = ( _choiceN + 1 );
				_code = 0;
				myself::AddChoice(0,"Attack Sailren!");
			}
			if( myself::HaveMemo(talker,641) == 1 && myself::GetMemoState(talker,641) == 2 && myself::OwnItemCount(talker,8782) >= 30 && myself::GetOneTimeQuestFlag(talker,126) == 1 )
			{
				_choiceN = ( _choiceN + 1 );
				_code = 1;
				myself::AddChoice(1,"Attack Sailren! ( In progress )");
			}
			if( myself::HaveMemo(talker,641) == 1 && myself::GetMemoState(talker,641) == 1 && myself::OwnItemCount(talker,8782) < 30 && myself::GetOneTimeQuestFlag(talker,126) == 1 )
			{
				_choiceN = ( _choiceN + 1 );
				_code = 2;
				myself::AddChoice(2,"Attack Sailren! ( In progress )");
			}
			if( myself::HaveMemo(talker,641) == 0 && myself::GetOneTimeQuestFlag(talker,126) == 0 )
			{
				_choiceN = ( _choiceN + 1 );
				_code = 3;
				myself::AddChoice(0,"Attack Sailren!");
			}
			if( myself::HaveMemo(talker,126) == 1 && myself::GetMemoState(talker,126) == 18 )
			{
				_choiceN = ( _choiceN + 1 );
				_code = 4;
				myself::AddChoice(4,"In the Name of Evil Part 2 - In Progress");
			}
			if( myself::HaveMemo(talker,126) == 1 && myself::GetMemoState(talker,126) == 19 )
			{
				_choiceN = ( _choiceN + 1 );
				_code = 5;
				myself::AddChoice(5,"In the Name of Evil Part 2 - In Progress");
			}
			if( myself::HaveMemo(talker,126) == 1 && myself::GetMemoState(talker,126) == 20 )
			{
				_choiceN = ( _choiceN + 1 );
				_code = 6;
				myself::AddChoice(6,"In the Name of Evil Part 2 - In Progress");
			}
			if( myself::HaveMemo(talker,126) == 1 && myself::GetMemoState(talker,126) == 21 )
			{
				_choiceN = ( _choiceN + 1 );
				_code = 7;
				myself::AddChoice(7,"In the Name of Evil Part 2 - In Progress");
			}
		}
		if( _choiceN > 1 )
		{
			myself::ShowChoicePage(talker,1);
			return;
		}
		if( _from_choice || _choiceN == 1 )
		{
			switch(_code)
			{
				case 0:
				{
					if( _from_choice == 0 || ( myself::HaveMemo(talker,641) == 0 && myself::GetOneTimeQuestFlag(talker,126) == 1 ) )
					{
						myself::SetCurrentQuestID(641);
						if( myself::GetInventoryInfo(talker,0) >= ( myself::GetInventoryInfo(talker,1) * 0.800000 ) || myself::GetInventoryInfo(talker,2) >= ( myself::GetInventoryInfo(talker,3) * 0.800000 ) )
						{
							myself::ShowSystemMessage(talker,1118);
							return;
						}
						if( talker.level >= 77 )
						{
							myself::ShowPage(talker,"statue_of_shilen_q0641_01.htm");
						}
						else
						{
							myself::ShowPage(talker,"statue_of_shilen_q0641_03.htm");
						}
					}
					break;
				}
				case 1:
				{
					if( _from_choice == 0 || ( myself::HaveMemo(talker,641) == 1 && myself::OwnItemCount(talker,8782) >= 30 && myself::GetOneTimeQuestFlag(talker,126) == 1 ) )
					{
						myself::SetCurrentQuestID(641);
						if( myself::GetInventoryInfo(talker,0) >= ( myself::GetInventoryInfo(talker,1) * 0.800000 ) || myself::GetInventoryInfo(talker,2) >= ( myself::GetInventoryInfo(talker,3) * 0.800000 ) )
						{
							myself::ShowSystemMessage(talker,1118);
							return;
						}
						myself::ShowPage(talker,"statue_of_shilen_q0641_07.htm");
					}
					break;
				}
				case 2:
				{
					if( _from_choice == 0 || ( myself::HaveMemo(talker,641) == 1 && myself::OwnItemCount(talker,8782) < 30 && myself::GetOneTimeQuestFlag(talker,126) == 1 ) )
					{
						myself::SetCurrentQuestID(641);
						if( myself::GetInventoryInfo(talker,0) >= ( myself::GetInventoryInfo(talker,1) * 0.800000 ) || myself::GetInventoryInfo(talker,2) >= ( myself::GetInventoryInfo(talker,3) * 0.800000 ) )
						{
							myself::ShowSystemMessage(talker,1118);
							return;
						}
						myself::ShowPage(talker,"statue_of_shilen_q0641_06.htm");
					}
					break;
				}
				case 3:
				{
					if( _from_choice == 0 || ( myself::HaveMemo(talker,641) == 0 && myself::GetOneTimeQuestFlag(talker,126) == 0 ) )
					{
						myself::ShowPage(talker,"statue_of_shilen_q0641_02.htm");
					}
					break;
				}
				case 4:
				{
					myself::ShowPage(talker,"statue_of_shilen_q0126_02.htm");
					break;
				}
				case 5:
				{
					myself::ShowPage(talker,"statue_of_shilen_q0126_05.htm");
					break;
				}
				case 6:
				{
					myself::ShowPage(talker,"statue_of_shilen_q0126_13.htm");
					break;
				}
				case 7:
				{
					myself::ShowPage(talker,"statue_of_shilen_q0126_20.htm");
					break;
				}
			}
			return;
		}
		super;
	}

	EventHandler MENU_SELECTED(ask,reply,talker)
	{
		if( ask == 641 )
		{
			myself::SetCurrentQuestID(641);
			if( myself::GetInventoryInfo(talker,0) >= ( myself::GetInventoryInfo(talker,1) * 0.800000 ) || myself::GetInventoryInfo(talker,2) >= ( myself::GetInventoryInfo(talker,3) * 0.800000 ) )
			{
				myself::ShowSystemMessage(talker,1118);
				return;
			}
			if( reply == 2 )
			{
				myself::ShowPage(talker,"statue_of_shilen_q0641_04.htm");
			}
			if( reply == 4 )
			{
				myself::RemoveMemo(talker,641);
				myself::SoundEffect(talker,"ItemSound.quest_finish");
				myself::DeleteItem1(talker,8782,myself::OwnItemCount(talker,8782));
				myself::GiveItem1(talker,8784,1);
				myself::AddLog(3,talker,641);
				myself::SoundEffect(talker,"ItemSound.quest_finish");
				myself::ShowPage(talker,"statue_of_shilen_q0641_08.htm");
			}
		}
		if( ask == 126 )
		{
			myself::SetCurrentQuestID(126);
			if( myself::GetInventoryInfo(talker,0) >= ( myself::GetInventoryInfo(talker,1) * 0.800000 ) || myself::GetInventoryInfo(talker,2) >= ( myself::GetInventoryInfo(talker,3) * 0.800000 ) )
			{
				myself::ShowSystemMessage(talker,1118);
				return;
			}
			if( reply == 1 )
			{
				myself::SetMemoState(talker,126,19);
				myself::SetFlagJournal(talker,126,19);
				myself::ShowPage(talker,"statue_of_shilen_q0126_05.htm");
				myself::SoundEffect(talker,"ItemSound.quest_middle");
				return;
			}
			if( reply == 2 )
			{
				myself::SetMemoState(talker,126,20);
				myself::SetFlagJournal(talker,126,20);
				myself::ShowPage(talker,"statue_of_shilen_q0126_13.htm");
				myself::SoundEffect(talker,"ItemSound.quest_middle");
				return;
			}
			if( reply == 3 )
			{
				myself::SetMemoState(talker,126,21);
				myself::SetFlagJournal(talker,126,21);
				myself::DeleteItem1(talker,8783,myself::OwnItemCount(talker,8783));
				myself::ShowPage(talker,"statue_of_shilen_q0126_19.htm");
				myself::SoundEffect(talker,"ItemSound.quest_middle");
				return;
			}
		}
	}

	EventHandler QUEST_ACCEPTED(quest_id,talker)
	{
		if( quest_id == 641 )
		{
			myself::SetCurrentQuestID(641);
			if( myself::GetInventoryInfo(talker,0) >= ( myself::GetInventoryInfo(talker,1) * 0.800000 ) || myself::GetInventoryInfo(talker,2) >= ( myself::GetInventoryInfo(talker,3) * 0.800000 ) )
			{
				myself::ShowSystemMessage(talker,1118);
				return;
			}
			if( ( myself::GetCurrentTick() - talker.quest_last_reward_time ) > 1 )
			{
				talker.quest_last_reward_time = myself::GetCurrentTick();
				myself::SetMemo(talker,quest_id);
				myself::SetMemoState(talker,quest_id,1);
				myself::SoundEffect(talker,"ItemSound.quest_accept");
				myself::ShowPage(talker,"statue_of_shilen_q0641_05.htm");
				myself::AddLog(1,talker,641);
				myself::SetFlagJournal(talker,641,1);
				myself::ShowQuestMark(talker,641);
			}
			return;
		}
		super;
	}

	EventHandler TIMER_FIRED_EX(timer_id,i0)
	{
		if( timer_id == 3001 )
		{
			gg::SendScriptEvent(myself.c_ai0,0,0);
			myself.i_ai0 = 0;
			myself.i_ai1 = 0;
		}
		super;
	}

	EventHandler TELEPORT_REQUESTED(talker,i0,i1,i2,c0,party0)
	{
		i0 = myself::GetGlobalMap(GM_ID1);
		if( i0 != -1 )
		{
			c0 = myself::GetCreatureFromIndex(i0);
			if( c0.alive )
			{
				if( c0.db_value == 0 || c0.db_value == 1 )
				{
					i1 = myself::Party_GetLeader(talker);
					party0 = myself::GetParty(talker);
					if( myself::IsNullParty(party0) )
					{
						myself::ShowPage(talker,"statue_of_shilen002.htm");
					}
					else if( myself::OwnItemCount(i1,8784) >= 1 )
					{
						if( myself.i_ai0 == 0 )
						{
							myself::DeleteItem1(i1,8784,1);
							myself::TeleportParty(party0.id,26931,-7331,-1976,1000,0);
							if( myself.i_ai0 == 0 )
							{
								myself::AddTimerEx(3001,( ( 2 * 60 ) * 1000 ));
								myself.c_ai0 = c0;
								myself.i_ai0 = 1;
							}
						}
						else
						{
							myself::ShowPage(talker,"statue_of_shilen006.htm");
						}
					}
					else
					{
						myself::ShowPage(talker,"statue_of_shilen003.htm");
					}
				}
				else if( c0.db_value == 2 || c0.db_value == 3 || myself.i_ai0 == 1 )
				{
					myself::ShowPage(talker,"statue_of_shilen006.htm");
				}
			}
			else
			{
				myself::ShowPage(talker,"statue_of_shilen005.htm");
			}
		}
		else
		{
			myself::ShowPage(talker,"statue_of_shilen005.htm");
		}
	}

}
