Beispiel #1
0
        /// <summary>
        /// Processes the types and extracts item and mobile information
        /// </summary>
        /// <param name="types">A list of types to process</param>
        /// <param name="items">An array list that will hold the extracted items</param>
        /// <param name="mobiles">An array list that will hold the extracted mobiles</param>
        /// <param name="table">The StringDictionary item providing information about the classes location</param>
        private static void ProcessTypes(ArrayList types, ArrayList items, ArrayList mobiles, StringDictionary table)
        {
            foreach (Type t in types)
            {
                if (t.IsSpecialName)
                {
                    continue;
                }

                if ((typeof(Item)).IsAssignableFrom(t))
                {
                    // Item
                    BoxItem item = BoxItem.FromType(t);

                    if (item != null)
                    {
                        item.FileName = table[item.Name.ToLower()];
                        items.Add(item);
                    }
                }
                else if ((typeof(Mobile)).IsAssignableFrom(t))
                {
                    // Mobile
                    BoxMobile mobile = BoxMobile.FromType(t);

                    if (mobile != null)
                    {
                        mobile.FileName = table[mobile.Name.ToLower()];
                        mobiles.Add(mobile);
                    }
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// Gets a BoxMobile object from a type
        /// </summary>
        /// <param name="t">The type to evaluate</param>
        /// <returns>A BoxMobile object or null if the type can't be constructed properly</returns>
        public static BoxMobile FromType(Type t)
        {
            ConstructorInfo[] ctors = t.GetConstructors();

            bool      constructable = false;
            BoxMobile mobile        = null;

            foreach (ConstructorInfo c in ctors)
            {
                if (BoxUtil.IsConstructable(c))
                {
                    constructable = true;
                    break;
                }
            }

            if (constructable)
            {
                mobile        = new BoxMobile();
                mobile.m_Name = t.Name;

                foreach (ConstructorInfo c in ctors)
                {
                    if (BoxUtil.IsConstructable(c))
                    {
                        ParameterInfo[] pms = c.GetParameters();

                        if (pms.Length == 0)
                        {
                            try
                            {
                                Mobile theMobile = (Mobile)Activator.CreateInstance(t);

                                mobile.m_Art = theMobile.Body.BodyID;
                                mobile.Hue   = theMobile.Hue;

                                if (theMobile != null)
                                {
                                    theMobile.Delete();
                                }
                            }
                            catch
                            {
                                // TODO : Logging?
                                return(null);
                            }
                        }
                        else if (pms.Length == 1 && (pms[0].ParameterType == typeof(string)))
                        {
                            mobile.CanBeNamed = true;
                        }
                    }
                }
            }

            return(mobile);
        }
Beispiel #3
0
        public int CompareTo(object obj)
        {
            BoxMobile mob = obj as BoxMobile;

            if (mob != null)
            {
                return(m_Name.CompareTo(mob.m_Name));
            }
            else
            {
                return(0);
            }
        }
Beispiel #4
0
        private static void DoNode(TreeNode node, SearchResults results, string text)
        {
            foreach (TreeNode subNode in node.Nodes)
            {
                DoNode(subNode, results, text);
            }
            // Issue 10 - Update the code to Net Framework 3.5 - http://code.google.com/p/pandorasbox3/issues/detail?id=10 - Smjert
            if (node.Tag != null && node.Tag is List <object> )
            {
                List <object> list = node.Tag as List <object>;
                // Issue 10 - End

                for (int i = 0; i < list.Count; i++)
                {
                    object o = list[i];

                    if (o is BoxMobile)
                    {
                        BoxMobile mob = o as BoxMobile;

                        if (mob.Name.ToLower().IndexOf(text.ToLower()) > -1)
                        {
                            Result res = new Result(node, i);
                            results.Add(res);
                        }
                    }
                    else if (o is BoxItem)
                    {
                        BoxItem item = o as BoxItem;

                        if (item.Name.ToLower().IndexOf(text.ToLower()) > -1)
                        {
                            Result res = new Result(node, i);
                            results.Add(res);
                        }
                    }
                }
            }
        }
Beispiel #5
0
        public int CompareTo(object obj)
        {
            BoxMobile cmp = obj as BoxMobile;

            return(m_Name.CompareTo(cmp.m_Name));
        }
Beispiel #6
0
		/// <summary>
		/// Gets a BoxMobile object from a type
		/// </summary>
		/// <param name="t">The type to evaluate</param>
		/// <returns>A BoxMobile object or null if the type can't be constructed properly</returns>
		public static BoxMobile FromType( Type t )
		{
			ConstructorInfo[] ctors = t.GetConstructors();

			bool constructable = false;
			BoxMobile mobile = null;

			foreach ( ConstructorInfo c in ctors )
			{
				if ( BoxUtil.IsConstructable( c ) )
				{
					constructable = true;
					break;
				}
			}

			if ( constructable )
			{
				mobile = new BoxMobile();
				mobile.m_Name = t.Name;

				foreach ( ConstructorInfo c in ctors )
				{
					if ( BoxUtil.IsConstructable( c ) )
					{
						ParameterInfo[] pms = c.GetParameters();

						if ( pms.Length == 0 )
						{
							try
							{
								Mobile theMobile = (Mobile) Activator.CreateInstance( t );

								mobile.m_Art = theMobile.Body.BodyID;
								mobile.Hue = theMobile.Hue;

								if ( theMobile != null )
								{
									theMobile.Delete();
								}
							}
							catch
							{
								// TODO : Logging?
								return null;
							}
						}
						else if ( pms.Length == 1 && ( pms[ 0 ].ParameterType == typeof( string ) ) )
						{
							mobile.CanBeNamed = true;
						}
					}
				}
			}

			return mobile;
		}