class 2 manage_teleport_dungeon : default_maker
{
parameter:
	int	hunting_level_index = -1;
	int	room_index = -1;
	string	manager_npc_name = "KIN";

handler:
	EventHandler ON_START(i0,def0)
	{
		if( manager_npc_name == "KIN" )
		{
			gg::Announce("Error!! Did not become the manager NPC designation from the clearance of dimension.");
		}
		def0 = myself::GetSpawnDefineByNick(manager_npc_name);
		if( gg::IsNull(def0) == 0 )
		{
			if( myself::IncreaseTotal(def0.total) )
			{
				def0::IncCount(def0.total);
				def0::Spawn(def0.total,0);
			}
		}
		else
		{
			gg::Announce("Error!! There is not a possibility of seeking manager NPC from the clearance of dimension.");
		}
		myself.i_ai0 = 0;
	}

	EventHandler ON_SCRIPT_EVENT(script_event_arg1,script_event_arg2,script_event_arg3,def0,i0,i1)
	{
		switch(script_event_arg1)
		{
			case 0:
			{
				myself.i_ai0 = 0;
				for(i0 = 0; i0 < myself.def_count; i0 = ( i0 + 1 ))
				{
					def0 = myself::GetSpawnDefine(i0);
					if( gg::IsNull(def0) == 0 )
					{
						if( gg::IsSameString(def0.name,manager_npc_name) == 0 )
						{
							def0::Despawn();
						}
					}
				}
				break;
			}
			case 1:
			{
				if( myself.i_ai0 == 0 )
				{
					myself.i_ai0 = 1;
					for(i0 = 0; i0 < myself.def_count; i0 = ( i0 + 1 ))
					{
						def0 = myself::GetSpawnDefine(i0);
						if( gg::IsNull(def0) == 0 )
						{
							if( gg::IsSameString(def0.name,manager_npc_name) == 0 )
							{
								if( myself::IncreaseTotal(def0.total) )
								{
									def0::IncCount(def0.total);
									def0::Spawn(def0.total,0);
								}
							}
						}
					}
				}
				break;
			}
			case 3:
			{
				myself.i_ai0 = 0;
				for(i0 = 0; i0 < myself.def_count; i0 = ( i0 + 1 ))
				{
					def0 = myself::GetSpawnDefine(i0);
					if( gg::IsNull(def0) == 0 )
					{
						if( gg::IsSameString(def0.name,manager_npc_name) )
						{
							def0::SendScriptEvent(script_event_arg1,0,0);
						}
						else
						{
							def0::Despawn();
						}
					}
				}
				break;
			}
			case 2:
			{
				for(i0 = 0; i0 < myself.def_count; i0 = ( i0 + 1 ))
				{
					def0 = myself::GetSpawnDefine(i0);
					if( gg::IsNull(def0) == 0 )
					{
						if( gg::IsSameString(def0.name,manager_npc_name) )
						{
							def0::SendScriptEvent(script_event_arg1,0,0);
						}
					}
				}
				break;
			}
		}
		super;
	}

	EventHandler ON_NPC_DELETED(deleted_def,i0,i1,maker0)
	{
		myself::DecreaseTotal(1);
		deleted_def::DecCount(1);
		if( myself.i_ai0 == 1 )
		{
			if( myself::IncreaseTotal(1) )
			{
				deleted_def::IncCount(1);
				deleted_def::Spawn(1,deleted_def.respawn_time);
			}
		}
	}

	EventHandler ON_NPC_CREATED(created_def,created_npc,maker0)
	{
		if( myself.i_ai0 == 0 )
		{
			if( gg::IsSameString(created_def.UNKNOWN_VAR_90,manager_npc_name) == 0 )
			{
				myself::DecreaseTotal(1);
				created_def::DecCount(1);
				created_def::Despawn();
			}
		}
	}

}
