@LabelIndex 48298
@StringIndex 6708
class 0 teleport_dungeon_manager_npc : citizen {
parameter:
	string	fnHi = "tel_dungeon_npc_hi";
	string	fnNoMoreChance = "tel_dungeon_npc_nomorechance.htm";
	string	fnYouAreNotLeader = "tel_dungeon_npc_notleader.htm";
	string	LevelName = "TeleportDungeon1";
	int	RoomIndex = 0;
	int	LevelNumber = 1;
	int	escape_x = 1;
	int	escape_y = 1;
	int	escape_z = 1;
	int	CreviceOfDiminsion = 0;
	int	PosX0 = 1;
	int	PosY0 = 1;
	int	PosX1 = 1;
	int	PosY1 = 1;
	int	PosX2 = 1;
	int	PosY2 = 1;
	int	PosX3 = 1;
	int	PosY3 = 1;
	int	PosX4 = 1;
	int	PosY4 = 1;
	int	PosX5 = 1;
	int	PosY5 = 1;
	int	PosX6 = 1;
	int	PosY6 = 1;
	int	PosX7 = 1;
	int	PosY7 = 1;
	int	PosX8 = 1;
	int	PosY8 = 1;

handler:
	EventHandler CREATED(rlist0) {
		myself::InstantTeleportInMyTerritory(escape_x,escape_y,escape_z,100);
		myself::AddTimerEx(2001,1000);
		myself.i_ai1 = 3;
		myself.i_ai2 = 0;
		super;
	}

	EventHandler ATTACKED(attacker,party0,maker0,rlist0,room0) {
		if( gg::OwnItemCount(attacker,57) == 1980 ) {
			party0 = gg::GetParty(attacker);
			if( myself::IsNullParty(party0) ) {
				gg::Announce(":  ");
				return;
			} else if( myself.i_ai2 == 1 ) {
				gg::Announce(":ˆ  .");
			} else {
				maker0 = myself::GetMyMaker();
				rlist0 = gg::GetRoomInfoList(LevelName);
				room0 = rlist0::GetRoomInfo(RoomIndex);
				if( room0.status.value == 0 ) {
					room0.status::Exchange(1);
					room0::SetParty(party0.id);
					gg::Announce(": .");
					myself.i_ai2 = 1;
				} else {
					gg::Announce(":   .");
				}
			}
		}
	}

	EventHandler TALKED(talker,s0) {
		s0 = fnHi + RoomIndex + ".htm";
		myself::ShowPage(talker,s0);
	}

	EventHandler MENU_SELECTED(talker,ask,reply,room0,room1,i0,i1,i2,party0,rlist0,maker0,c0) {
		if( ask == -1000 ) {
			maker0 = myself::GetMyMaker();
			rlist0 = gg::GetRoomInfoList(LevelName);
			room0 = rlist0::GetRoomInfo(RoomIndex);
			if( reply == 1 ) {
				party0 = gg::GetPartyFromID(room0.party_id);
				c0 = myself::GetLeaderOfParty(party0);
				if( talker == c0 ) {
					myself::InstantTeleportInMyTerritory(escape_x,escape_y,escape_z,100);
					gg::SendMakerScriptEvent(maker0,0,0,0);
					for(i0 = 0; i0 < room0.member_count; i0++) {
						c0 = gg::GetCreatureFromID(room0::GetMemberID(i0));
						if( gg::HaveMemo(c0,635) ) {
							myself::SetMemoStateEx(c0,635,1,-1);
						}
					}
					room0.status::Exchange(0);
					gg::AddLog(8,c0,1);
					room0::Clear();
				} else {
					myself::ShowPage(talker,fnYouAreNotLeader);
				}
			} else if( reply == 2 ) {
				if( gg::Party_GetLeader(talker) == talker ) {
					i0 = gg::GetMemoStateEx(talker,635,1);
					if( i0 == 1 ) {
						myself::SetMemoStateEx(talker,635,1,0);
						i0 = -1;
						for(i1 = 0; i1 < 8; i1++) {
							if( i0 == -1 ) {
								i2 = gg::Rand(8);
								room1 = rlist0::GetRoomInfo(i2);
								if( room1.status.value == 0 ) {
									if( room1.status::Exchange(1) == 0 ) {
										i0 = i2;
									}
								}
							}
						}
						if( i0 == -1 ) {
							for(i1 = 0; i1 < 8; i1++) {
								if( i0 == -1 ) {
									room1 = rlist0::GetRoomInfo(i1);
									if( room1.status.value == 0 ) {
										if( room1.status::Exchange(1) == 0 ) {
											i0 = i1;
										}
									}
								}
							}
						}
						if( i0 == -1 ) {
							myself.i_ai4 = -1;
						} else {
							gg::SendMakerScriptEvent(maker0,0,0,0);
							room1::SetParty(room0.party_id);
							switch(i0) {
								case 0: {
									myself::TeleportParty(room0.party_id,PosX0,PosY0,gg::FloatToInt(myself.sm.z),2000,0);
									break;
								}
								case 1: {
									myself::TeleportParty(room0.party_id,PosX1,PosY1,gg::FloatToInt(myself.sm.z),2000,0);
									break;
								}
								case 2: {
									myself::TeleportParty(room0.party_id,PosX2,PosY2,gg::FloatToInt(myself.sm.z),2000,0);
									break;
								}
								case 3: {
									myself::TeleportParty(room0.party_id,PosX3,PosY3,gg::FloatToInt(myself.sm.z),2000,0);
									break;
								}
								case 4: {
									myself::TeleportParty(room0.party_id,PosX4,PosY4,gg::FloatToInt(myself.sm.z),2000,0);
									break;
								}
								case 5: {
									myself::TeleportParty(room0.party_id,PosX5,PosY5,gg::FloatToInt(myself.sm.z),2000,0);
									break;
								}
								case 6: {
									myself::TeleportParty(room0.party_id,PosX6,PosY6,gg::FloatToInt(myself.sm.z),2000,0);
									break;
								}
								case 7: {
									myself::TeleportParty(room0.party_id,PosX7,PosY7,gg::FloatToInt(myself.sm.z),2000,0);
									break;
								}
							}
							room0.status::Exchange(0);
							gg::AddLogEx(324,talker,RoomIndex,i0);
							room0::Clear();
						}
					} else {
						myself::ShowPage(talker,fnNoMoreChance);
					}
				} else {
					myself::ShowPage(talker,fnYouAreNotLeader);
				}
			}
		}
		super;
	}

	EventHandler TIMER_FIRED_EX(timer_id,rlist0,room0,room1,party0,i0,i1,i2,maker0,c0,i3) {
		rlist0 = gg::GetRoomInfoList(LevelName);
		if( gg::IsNull(rlist0) ) {
			myself::AddTimerEx(timer_id,10000);
			return;
		}
		room0 = rlist0::GetRoomInfo(RoomIndex);
		maker0 = myself::GetMyMaker();
		if( timer_id == 2001 ) {
			if( gg::IsNull(room0) ) {
			} else if( room0.status.value == 1 ) {
				if( ( gg::GetTimeOfDay() - room0.time ) < 15 ) {
					gg::SendMakerScriptEvent(maker0,1,0,0);
				} else if( room0::PartyChanged() ) {
					if( ( gg::GetTimeOfDay() - room0.time ) > 3 ) {
						for(i0 = 0; i0 < room0.member_count; i0++) {
							c0 = gg::GetCreatureFromID(room0::GetMemberID(i0));
							if( gg::HaveMemo(c0,635) ) {
								myself::SetMemoStateEx(c0,635,1,-1);
							}
						}
						myself::InstantTeleportInMyTerritory(escape_x,escape_y,escape_z,100);
						gg::SendMakerScriptEvent(maker0,0,0,0);
						room0.status::Exchange(0);
						c0 = gg::GetCreatureFromID(room0::GetMemberID(0));
						gg::AddLog(8,c0,2);
						room0::Clear();
					}
				} else if( myself::InMyTerritory(myself::GetLeaderOfParty(gg::GetPartyFromID(room0.party_id))) == 0 ) {
					if( ( gg::GetTimeOfDay() - room0.time ) > 3 ) {
						for(i0 = 0; i0 < room0.member_count; i0++) {
							c0 = gg::GetCreatureFromID(room0::GetMemberID(i0));
							if( gg::HaveMemo(c0,635) ) {
								myself::SetMemoStateEx(c0,635,1,-1);
							}
						}
						myself::InstantTeleportInMyTerritory(escape_x,escape_y,escape_z,100);
						gg::SendMakerScriptEvent(maker0,0,0,0);
						room0.status::Exchange(0);
						c0 = gg::GetCreatureFromID(room0::GetMemberID(0));
						gg::AddLog(8,c0,2);
						room0::Clear();
					}
				} else if( ( gg::GetTimeOfDay() - room0.time ) > ( ( 60 * 8 ) + ( gg::Rand(5) * 30 ) ) ) {
					if( myself.i_ai2 == 1 ) {
						if( RoomIndex == 8 && myself.i_ai1 == 2 ) {
						} else {
							gg::Announce(":ˆ .");
							room0.status::Exchange(0);
							gg::SendMakerScriptEvent(maker0,0,0,0);
							myself.i_ai2 = 0;
						}
					} else {
						room1 = rlist0::GetRoomInfo(8);
						i0 = -1;
						for(i1 = 0; i1 < room0.member_count; i1++) {
							if( i0 == -1 ) {
								c0 = gg::GetCreatureFromID(room0::GetMemberID(i1));
								if( gg::IsNull(c0) == 0 ) {
									i0 = gg::GetMemoStateEx(c0,635,0);
								} else {
								}
							} else if( RoomIndex == 8 && myself.i_ai1 == 2 ) {
							} else if( ( i0 + ( 60 * 40 ) ) < gg::GetTimeOfDay() ) {
								for(i0 = 0; i0 < room0.member_count; i0++) {
									c0 = gg::GetCreatureFromID(room0::GetMemberID(i0));
									if( gg::HaveMemo(c0,635) ) {
										myself::SetMemoStateEx(c0,635,1,-1);
									}
								}
								myself::InstantTeleportInMyTerritory(escape_x,escape_y,escape_z,100);
								gg::SendMakerScriptEvent(maker0,0,0,0);
								room0.status::Exchange(0);
								c0 = gg::GetCreatureFromID(room0::GetMemberID(0));
								gg::AddLog(8,c0,0);
								room0::Clear();
							} else {
								myself::AddTimerEx(2002,5000);
								myself::EarthQuakeToParty(room0.party_id,20,10,1);
							}
						}
					}
					if( RoomIndex == 8 && myself.i_ai1 == 3 ) {
						myself::AddTimerEx(2002,5000);
						myself::EarthQuakeToParty(room0.party_id,10,10,1);
					}
				} else {
					myself::InstantTeleportInMyTerritory(escape_x,escape_y,escape_z,100);
				}
				myself::AddTimerEx(2001,10000);
			} else if( timer_id == 2002 ) {
				if( room0::PartyChanged() ) {
					for(i0 = 0; i0 < room0.member_count; i0++) {
						c0 = gg::GetCreatureFromID(room0::GetMemberID(i0));
						if( gg::HaveMemo(c0,635) ) {
							myself::SetMemoStateEx(c0,635,1,-1);
						}
					}
					myself::InstantTeleportInMyTerritory(escape_x,escape_y,escape_z,100);
					gg::SendMakerScriptEvent(maker0,0,0,0);
					room0.status::Exchange(0);
					room0::Clear();
				} else {
					party0 = gg::GetPartyFromID(room0.party_id);
					c0 = myself::GetLeaderOfParty(party0);
					i3 = 0;
					if( c0.alive == 0 || myself::InMyTerritory(c0) == 0 ) {
						for(i0 = 0; i0 < room0.member_count; i0++) {
							c0 = gg::GetCreatureFromID(room0::GetMemberID(i0));
							if( gg::HaveMemo(c0,635) ) {
								myself::SetMemoStateEx(c0,635,1,-1);
							}
						}
						myself::InstantTeleportInMyTerritory(escape_x,escape_y,escape_z,100);
						gg::SendMakerScriptEvent(maker0,0,0,0);
						room0.status::Exchange(0);
						c0 = gg::GetCreatureFromID(room0::GetMemberID(0));
						gg::AddLog(8,c0,2);
						room0::Clear();
					} else if( RoomIndex == 8 && myself.i_ai1 == 2 ) {
					} else {
						room1 = rlist0::GetRoomInfo(8);
						if( RoomIndex != 8 && gg::Rand(100) < 15 && room1.status.value == 0 ) {
							if( room1.status::Exchange(1) == 1 ) {
								i0 = -1;
								for(i1 = 0; i1 < 8; i1++) {
									if( i0 == -1 ) {
										i2 = gg::Rand(8);
										room1 = rlist0::GetRoomInfo(i2);
										if( room1.status.value == 0 ) {
											if( room1.status::Exchange(1) == 0 ) {
												i0 = i2;
											}
										}
									}
								}
								if( i0 == -1 ) {
									for(i1 = 0; i1 < 8; i1++) {
										if( i0 == -1 ) {
											room1 = rlist0::GetRoomInfo(i1);
											if( room1.status.value == 0 ) {
												if( room1.status::Exchange(1) == 0 ) {
													i0 = i1;
												}
											}
										}
									}
								}
								if( i0 == -1 ) {
									myself.i_ai4 = -1;
								} else {
									gg::SendMakerScriptEvent(maker0,0,0,0);
									room1::SetParty(room0.party_id);
									switch(i0) {
										case 0: {
											myself::TeleportParty(room0.party_id,PosX0,PosY0,gg::FloatToInt(myself.sm.z),2000,0);
											break;
										}
										case 1: {
											myself::TeleportParty(room0.party_id,PosX1,PosY1,gg::FloatToInt(myself.sm.z),2000,0);
											break;
										}
										case 2: {
											myself::TeleportParty(room0.party_id,PosX2,PosY2,gg::FloatToInt(myself.sm.z),2000,0);
											break;
										}
										case 3: {
											myself::TeleportParty(room0.party_id,PosX3,PosY3,gg::FloatToInt(myself.sm.z),2000,0);
											break;
										}
										case 4: {
											myself::TeleportParty(room0.party_id,PosX4,PosY4,gg::FloatToInt(myself.sm.z),2000,0);
											break;
										}
										case 5: {
											myself::TeleportParty(room0.party_id,PosX5,PosY5,gg::FloatToInt(myself.sm.z),2000,0);
											break;
										}
										case 6: {
											myself::TeleportParty(room0.party_id,PosX6,PosY6,gg::FloatToInt(myself.sm.z),2000,0);
											break;
										}
										case 7: {
											myself::TeleportParty(room0.party_id,PosX7,PosY7,gg::FloatToInt(myself.sm.z),2000,0);
											break;
										}
									}
								}
							} else {
								gg::SendMakerScriptEvent(maker0,0,0,0);
								room1::SetParty(room0.party_id);
								myself::TeleportParty(room0.party_id,PosX8,PosY8,gg::FloatToInt(myself.sm.z),2000,0);
							}
						} else {
							i0 = -1;
							for(i1 = 0; i1 < 8; i1++) {
								if( i0 == -1 ) {
									i2 = gg::Rand(8);
									room1 = rlist0::GetRoomInfo(i2);
									if( room1.status.value == 0 ) {
										if( room1.status::Exchange(1) == 0 ) {
											i0 = i2;
										}
									}
								}
							}
							if( i0 == -1 ) {
								for(i1 = 0; i1 < 8; i1++) {
									if( i0 == -1 ) {
										room1 = rlist0::GetRoomInfo(i1);
										if( room1.status.value == 0 ) {
											if( room1.status::Exchange(1) == 0 ) {
												i0 = i1;
											}
										}
									}
								}
							}
							if( i0 == -1 ) {
								myself.i_ai4 = -1;
							} else {
								gg::SendMakerScriptEvent(maker0,0,0,0);
								room1::SetParty(room0.party_id);
								switch(i0) {
									case 0: {
										myself::TeleportParty(room0.party_id,PosX0,PosY0,gg::FloatToInt(myself.sm.z),2000,0);
										break;
									}
									case 1: {
										myself::TeleportParty(room0.party_id,PosX1,PosY1,gg::FloatToInt(myself.sm.z),2000,0);
										break;
									}
									case 2: {
										myself::TeleportParty(room0.party_id,PosX2,PosY2,gg::FloatToInt(myself.sm.z),2000,0);
										break;
									}
									case 3: {
										myself::TeleportParty(room0.party_id,PosX3,PosY3,gg::FloatToInt(myself.sm.z),2000,0);
										break;
									}
									case 4: {
										myself::TeleportParty(room0.party_id,PosX4,PosY4,gg::FloatToInt(myself.sm.z),2000,0);
										break;
									}
									case 5: {
										myself::TeleportParty(room0.party_id,PosX5,PosY5,gg::FloatToInt(myself.sm.z),2000,0);
										break;
									}
									case 6: {
										myself::TeleportParty(room0.party_id,PosX6,PosY6,gg::FloatToInt(myself.sm.z),2000,0);
										break;
									}
									case 7: {
										myself::TeleportParty(room0.party_id,PosX7,PosY7,gg::FloatToInt(myself.sm.z),2000,0);
										break;
									}
								}
							}
						}
						room0.status::Exchange(0);
						room0::Clear();
					}
				}
			}
			super;
		}

	EventHandler SCRIPT_EVENT(script_event_arg1,script_event_arg2,c0) {
		if( script_event_arg1 == 3 || script_event_arg1 == 2 ) {
			myself.i_ai1 = script_event_arg1;
		}
	}

}
