class 1 magistrates_keeper : royal_rush_npc
{
handler:
	EventHandler TALK_SELECTED(fhtml0,talker)
	{
		if( _from_choice == 0 )
		{
			if( myself::HaveMemo(talker,620) == 1 )
			{
				_choiceN = ( _choiceN + 1 );
				_code = 0;
				myself::AddChoice(0,"Four Goblets (Continue)");
			}
			if( _choiceN > 1 )
			{
				myself::ShowChoicePage(talker,1);
				return;
			}
		}
		if( _from_choice || _choiceN == 1 )
		{
			if( _code == 0 )
			{
				if( _from_choice == 0 || myself::HaveMemo(talker,620) == 1 )
				{
					myself::SetCurrentQuestID(620);
					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,"magistrates_keeper_q0620_01.htm");
				}
			}
			return;
		}
		super;
	}

	EventHandler MENU_SELECTED(ask,c0,c1,fhtml0,i0,i1,i2,party0,reply,talker)
	{
		if( ask == 620 )
		{
			myself::SetCurrentQuestID(620);
			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( ask == 620 )
		{
			if( reply == 1 )
			{
				if( myself::HaveMemo(talker,620) )
				{
					i0 = gg::GetDateTime(0,4);
					c0 = myself::Party_GetLeader(talker);
					party0 = myself::GetParty(talker);
					i1 = myself::Party_GetCount(talker);
					if( i0 >= 0 && i0 < 55 )
					{
						myself::ShowPage(talker,"magistrates_keeper_q0620_02.htm");
					}
					else if( myself::IsNullParty(party0) || i1 < 4 )
					{
						myself::ShowPage(talker,"magistrates_keeper_q0620_04.htm");
					}
					else if( talker != c0 )
					{
						myself::ShowPage(talker,"magistrates_keeper_q0620_03.htm");
					}
					else
					{
						for(i2 = 0; i2 < i1; i2 = ( i2 + 1 ))
						{
							c1 = myself::Party_GetCreature(talker,i2);
							if( myself::OwnItemCount(c1,7075) == 0 )
							{
								myself::FHTML_SetFileName(fhtml0,"magistrates_keeper_q0620_05.htm");
								myself::FHTML_SetStr(fhtml0,"member1",c1.name);
								myself::ShowFHTML(talker,fhtml0);
								return;
							}
							else if( myself::HaveMemo(c1,620) == 0 )
							{
								myself::FHTML_SetFileName(fhtml0,"magistrates_keeper_q0620_06.htm");
								myself::FHTML_SetStr(fhtml0,"member1",c1.name);
								myself::ShowFHTML(talker,fhtml0);
								return;
							}
						}
						if( myself.av_quest0::CompareExchange(1,0) == 1 )
						{
							myself::ShowPage(talker,"magistrates_keeper_q0620_07.htm");
						}
						else
						{
							for(i2 = 0; i2 < i1; i2 = ( i2 + 1 ))
							{
								c1 = myself::Party_GetCreature(talker,i2);
								if( myself::OwnItemCount(c1,7262) == 0 )
								{
									myself::GiveItem1(c1,7261,1);
								}
								myself::DeleteItem1(c1,7075,1);
								myself::SetMemoStateEx(c1,620,1,1);
								myself::DeleteItem1(c1,7260,myself::OwnItemCount(c1,7260));
							}
							myself::TeleportParty(party0.id,175615,-82365,-7216,1000,0);
							myself::AddLog(9,talker,4);
						}
					}
				}
			}
		}
		super;
	}

}
