class 1 rift_watcher_6 : teleport_dungeon_admit_npc
{
handler:
	EventHandler MENU_SELECTED(LevelNumber,ask,c0,c1,fhtml0,i0,i1,i2,i3,i4,i5,i6,party0,reply,rlist0,room0,talker)
	{
		if( ask == 635 )
		{
			myself::SetCurrentQuestID(635);
			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 == 635 )
		{
			if( reply == 1 )
			{
				party0 = myself::GetParty(talker);
				c0 = myself::Party_GetLeader(talker);
				i0 = myself::Party_GetCount(talker);
				i1 = 0;
				i3 = -1;
				if( gg::IsNull(party0) )
				{
					myself::ShowPage(talker,"rift_watcher_1_q0635_01.htm");
				}
				else if( c0 != talker )
				{
					myself::FHTML_SetFileName(fhtml0,"rift_watcher_1_q0635_02.htm");
					myself::FHTML_SetStr(fhtml0,"name",c0.name);
					myself::ShowFHTML(talker,fhtml0);
				}
				else
				{
					i6 = myself::GetCurrentTick();
					for(i2 = 0; i2 < i0; i2 = ( i2 + 1 ))
					{
						c1 = myself::Party_GetCreature(talker,i2);
						if( myself::GetMemoCount(c1) > 25 && myself::HaveMemo(c1,635) == 0 )
						{
							i1 = 2;
							myself::FHTML_SetFileName(fhtml0,"rift_watcher_1_q0635_03a.htm");
							myself::FHTML_SetStr(fhtml0,"name",c1.name);
							myself::ShowFHTML(talker,fhtml0);
						}
						else if( myself::OwnItemCount(c1,7079) < 36 )
						{
							i5 = myself::GetMemoStateEx(c1,635,1);
							if( myself::GetMemoState(c1,635) != 2 || ( i6 - i5 ) > 3600 )
							{
								i1 = 1;
								myself::FHTML_SetFileName(fhtml0,"rift_watcher_1_q0635_03.htm");
								myself::FHTML_SetStr(fhtml0,"name",c1.name);
								myself::ShowFHTML(talker,fhtml0);
							}
						}
					}
					if( i1 == 0 )
					{
						rlist0 = gg::GetRoomInfoList(LevelName);
						if( gg::IsNull(rlist0) )
						{
							myself::Say("Error!! It will not be able to inquire room information.");
						}
						else
						{
							i3 = -1;
							i5 = 0;
							for(i4 = 0; i4 < 8; i4 = ( i4 + 1 ))
							{
								room0 = rlist0::GetRoomInfo(i4);
								if( room0.status.value == 1 )
								{
									if( room0.party_id == party0.id )
									{
										i3 = -2;
									}
								}
								else
								{
									i5 = ( i5 + 1 );
								}
							}
							if( i3 != -2 && i5 >= 3 )
							{
								i3 = -1;
								for(i4 = 0; i4 < 8; i4 = ( i4 + 1 ))
								{
									if( i3 == -1 )
									{
										i5 = gg::Rand(8);
										room0 = rlist0::GetRoomInfo(i5);
										if( room0.status.value == 0 )
										{
											room0.status::Exchange(1);
											i3 = i5;
										}
									}
								}
								if( i3 == -1 )
								{
									for(i4 = 0; i4 < 8; i4 = ( i4 + 1 ))
									{
										if( i3 == -1 )
										{
											room0 = rlist0::GetRoomInfo(i4);
											if( room0.status.value == 0 )
											{
												room0.status::Exchange(1);
												i3 = i4;
											}
										}
									}
								}
								room0::SetParty(party0.id);
								switch(i3)
								{
									case 0:
									{
										myself::TeleportParty(room0.party_id,PosX0,PosY0,myself::FloatToInt(myself.sm.z),2000,0);
										break;
									}
									case 1:
									{
										myself::TeleportParty(room0.party_id,PosX1,PosY1,myself::FloatToInt(myself.sm.z),2000,0);
										break;
									}
									case 2:
									{
										myself::TeleportParty(room0.party_id,PosX2,PosY2,myself::FloatToInt(myself.sm.z),2000,0);
										break;
									}
									case 3:
									{
										myself::TeleportParty(room0.party_id,PosX3,PosY3,myself::FloatToInt(myself.sm.z),2000,0);
										break;
									}
									case 4:
									{
										myself::TeleportParty(room0.party_id,PosX4,PosY4,myself::FloatToInt(myself.sm.z),2000,0);
										break;
									}
									case 5:
									{
										myself::TeleportParty(room0.party_id,PosX5,PosY5,myself::FloatToInt(myself.sm.z),2000,0);
										break;
									}
									case 6:
									{
										myself::TeleportParty(room0.party_id,PosX6,PosY6,myself::FloatToInt(myself.sm.z),2000,0);
										break;
									}
									case 7:
									{
										myself::TeleportParty(room0.party_id,PosX7,PosY7,myself::FloatToInt(myself.sm.z),2000,0);
										break;
									}
								}
							}
						}
						if( i3 == -1 )
						{
							myself::ShowPage(talker,"rift_watcher_1_q0635_04.htm");
						}
						else if( i3 == -2 )
						{
							myself::ShowPage(talker,"rift_watcher_1_q0635_08.htm");
						}
						else
						{
							i6 = gg::GetTimeOfDay();
							for(i2 = 0; i2 < i0; i2 = ( i2 + 1 ))
							{
								if( myself::DistFromMe(c0) <= 1500 )
								{
									c1 = myself::Party_GetCreature(talker,i2);
									if( myself::GetMemoState(c1,635) == 2 )
									{
										myself::SetMemoState(c1,635,0);
									}
									else
									{
										myself::DeleteItem1(c1,7079,36);
									}
									myself::SetMemoState(c1,635,i6);
									if( c1 == c0 )
									{
										myself::SetMemoStateEx(c1,635,1,1);
										myself::AddLogEx(7,c1,i3,LevelNumber);
									}
									else
									{
										myself::SetMemoStateEx(c1,635,1,0);
									}
								}
							}
							myself::ShowPage(talker,"rift_watcher_1_q0635_05.htm");
						}
					}
				}
			}
			if( reply == 2 )
			{
				myself::RemoveMemo(talker,505);
				i0 = myself::GetMemoStateEx(talker,255,1);
				i1 = ( i0 % 10000 );
				i2 = ( ( ( i0 - i1 ) + 5 ) / 10000 );
				myself::ShowPage(talker,"rift_watcher_1_q0635_06.htm");
				myself::RemoveMemo(talker,635);
				myself::AddLog(2,talker,635);
				if( i1 >= 95 && i1 < 195 )
				{
					switch(gg::Rand(2))
					{
						case 0:
						{
							myself::InstantTeleport(talker,-82340,151575,-3120);
							break;
						}
						case 1:
						{
							myself::InstantTeleport(talker,-82392,151584,-3120);
							break;
						}
					}
				}
				else if( i1 >= 195 && i1 < 295 )
				{
					switch(gg::Rand(2))
					{
						case 0:
						{
							myself::InstantTeleport(talker,-14727,124002,-3112);
							break;
						}
						case 1:
						{
							myself::InstantTeleport(talker,-14727,124012,-3112);
							break;
						}
					}
				}
				else if( i1 >= 295 && i1 < 395 )
				{
					switch(gg::Rand(2))
					{
						case 0:
						{
							myself::InstantTeleport(talker,18501,144673,-3056);
							break;
						}
						case 1:
						{
							myself::InstantTeleport(talker,18523,144624,-3056);
							break;
						}
					}
				}
				else if( i1 >= 395 && i1 < 495 )
				{
					switch(gg::Rand(2))
					{
						case 0:
						{
							myself::InstantTeleport(talker,81572,148580,-3464);
							break;
						}
						case 1:
						{
							myself::InstantTeleport(talker,81571,148641,-3464);
							break;
						}
					}
				}
				else if( i1 >= 495 && i1 < 595 )
				{
					switch(gg::Rand(2))
					{
						case 0:
						{
							myself::InstantTeleport(talker,112441,220149,-3544);
							break;
						}
						case 1:
						{
							myself::InstantTeleport(talker,112452,220204,-3592);
							break;
						}
					}
				}
				else if( i1 >= 595 && i1 < 695 )
				{
					switch(gg::Rand(2))
					{
						case 0:
						{
							myself::InstantTeleport(talker,82842,54613,-1520);
							break;
						}
						case 1:
						{
							myself::InstantTeleport(talker,82791,54616,-1520);
							break;
						}
					}
				}
				else if( i1 >= 695 && i1 < 795 )
				{
					switch(gg::Rand(2))
					{
						case 0:
						{
							myself::InstantTeleport(talker,147528,28899,-2264);
							break;
						}
						case 1:
						{
							myself::InstantTeleport(talker,147528,28962,-2264);
							break;
						}
					}
				}
				else if( i1 >= 795 && i1 < 895 )
				{
					switch(gg::Rand(2))
					{
						case 0:
						{
							myself::InstantTeleport(talker,116651,77512,-2688);
							break;
						}
						case 1:
						{
							myself::InstantTeleport(talker,116597,77539,-2688);
							break;
						}
					}
				}
				else if( i1 >= 995 && i1 < 1095 )
				{
					myself::InstantTeleport(talker,149968,-56645,-2976);
				}
				else if( i1 >= 1095 && i0 < 1195 )
				{
					myself::InstantTeleport(talker,44505,-48331,-792);
				}
				else if( i2 == 1 )
				{
					myself::InstantTeleport(talker,-41443,210030,-5080);
				}
				else if( i2 == 2 )
				{
					myself::InstantTeleport(talker,-52850,-250270,-7904);
				}
				else if( i2 == 3 )
				{
					myself::InstantTeleport(talker,45160,123605,-5408);
				}
				else if( i2 == 4 )
				{
					myself::InstantTeleport(talker,46488,170184,-4976);
				}
				else if( i2 == 5 )
				{
					myself::InstantTeleport(talker,111521,173905,-5432);
				}
				else if( i2 == 6 )
				{
					myself::InstantTeleport(talker,-20554,-250788,-8160);
				}
				else if( i2 == 7 )
				{
					myself::InstantTeleport(talker,-21482,77253,-5168);
				}
				else if( i2 == 8 )
				{
					myself::InstantTeleport(talker,140688,79565,-5424);
				}
				else if( i2 == 9 )
				{
					myself::InstantTeleport(talker,-52007,78986,-4736);
				}
				else if( i2 == 10 )
				{
					myself::InstantTeleport(talker,118547,132669,-4824);
				}
				else if( i2 == 11 )
				{
					myself::InstantTeleport(talker,172562,-17730,-4896);
				}
				else if( i2 == 12 )
				{
					myself::InstantTeleport(talker,83344,209110,-5432);
				}
				else if( i2 == 13 )
				{
					myself::InstantTeleport(talker,-19154,13415,-4896);
				}
				else if( i2 == 14 )
				{
					myself::InstantTeleport(talker,12947,-248487,-9576);
				}
			}
			if( reply == 3 )
			{
				if( myself::GetSSQStatus() == 1 )
				{
					if( myself::GetSSQPart(talker) != 2 )
					{
						switch(gg::Rand(3))
						{
							case 0:
							{
								myself::InstantTeleport(talker,-81328,86536,-5152);
								break;
							}
							case 1:
							{
								myself::InstantTeleport(talker,-81262,86468,-5152);
								break;
							}
							case 2:
							{
								myself::InstantTeleport(talker,-81248,86582,-5152);
								break;
							}
						}
						myself::ShowPage(talker,"rift_watcher_1_q0635_10.htm");
					}
					else if( myself::GetSSQPart(talker) == 2 )
					{
						switch(gg::Rand(3))
						{
							case 0:
							{
								myself::InstantTeleport(talker,-80316,111356,-4896);
								break;
							}
							case 1:
							{
								myself::InstantTeleport(talker,-80226,111290,-4896);
								break;
							}
							case 2:
							{
								myself::InstantTeleport(talker,-80217,111435,-4896);
								break;
							}
						}
						myself::ShowPage(talker,"rift_watcher_1_q0635_10.htm");
					}
					else
					{
						myself::ShowPage(talker,"rift_watcher_1_q0635_11.htm");
					}
				}
				else
				{
					myself::ShowPage(talker,"rift_watcher_1_q0635_12.htm");
				}
			}
		}
		super;
	}

}
