예제 #1
0
		public static void RecurseFindCategories( CategoryEntry ce, ArrayList list )
		{
			list.Add( ce );

			for ( int i = 0; i < ce.SubCategories.Length; ++i )
				RecurseFindCategories( ce.SubCategories[i], list );
		}
예제 #2
0
 public CategoryEntry(CategoryEntry parent, string title, CategoryEntry[] subCats)
 {
     Parent        = parent;
     Title         = title;
     SubCategories = subCats;
     Matches       = Array.Empty <Type>();
     Matched       = new ArrayList();
 }
예제 #3
0
        public static void RebuildCategorization_OnCommand(CommandEventArgs e)
        {
            CategoryEntry root = new CategoryEntry(null, "Add Menu", new CategoryEntry[] { Items, Mobiles });

            Export(root, "Data/objects.xml", "Objects");

            e.Mobile.SendMessage("Categorization menu rebuilt.");
        }
예제 #4
0
		public static void RebuildCategorization_OnCommand( CommandEventArgs e )
		{
			CategoryEntry root = new CategoryEntry( null, "Add Menu", new CategoryEntry[]{ Items, Mobiles } );

			Export( root, "Data/objects.xml" );

			e.Mobile.SendMessage( "Categorization menu rebuilt." );
		}
예제 #5
0
 public CategoryEntry(CategoryEntry parent, string title, CategoryEntry[] subCats)
 {
     m_Parent        = parent;
     m_Title         = title;
     m_SubCategories = subCats;
     m_Matches       = new Type[0];
     m_Matched       = new ArrayList();
 }
예제 #6
0
        public CategoryEntry(CategoryEntry parent, CategoryLine[] lines, ref int index)
        {
            m_Parent = parent;

            string text = lines[index].Text;

            int start = text.IndexOf('(');

            if (start < 0)
            {
                throw new FormatException(String.Format("Input string not correctly formatted ('{0}')", text));
            }

            m_Title = text.Substring(0, start).Trim();

            int end = text.IndexOf(')', ++start);

            if (end < start)
            {
                throw new FormatException(String.Format("Input string not correctly formatted ('{0}')", text));
            }

            text = text.Substring(start, end - start);
            string[] split = text.Split(';');

            ArrayList list = new ArrayList();

            for (int i = 0; i < split.Length; ++i)
            {
                Type type = ScriptCompiler.FindTypeByName(split[i].Trim());

                if (type == null)
                {
                    Console.WriteLine("Match type not found ('{0}')", split[i].Trim());
                }
                else
                {
                    list.Add(type);
                }
            }

            m_Matches = (Type[])list.ToArray(typeof(Type));
            list.Clear();

            int ourIndentation = lines[index].Indentation;

            ++index;

            while (index < lines.Length && lines[index].Indentation > ourIndentation)
            {
                list.Add(new CategoryEntry(this, lines, ref index));
            }

            m_SubCategories = (CategoryEntry[])list.ToArray(typeof(CategoryEntry));
            list.Clear();

            m_Matched = list;
        }
예제 #7
0
        public static void RecurseFindCategories(CategoryEntry ce, ArrayList list)
        {
            list.Add(ce);

            for (int i = 0; i < ce.SubCategories.Length; ++i)
            {
                RecurseFindCategories(ce.SubCategories[i], list);
            }
        }
예제 #8
0
        public static void RebuildCategorization_OnCommand(CommandEventArgs e)
        {
            var root = new CategoryEntry(null, "Add Menu", new[] { Items, Mobiles });

            var ceList = new List <CategoryEntry>();

            ceList.AddRange(root.SubCategories);

            Export(ceList, "Data/objects.json");

            e.Mobile.SendMessage("Categorization menu rebuilt.");
        }
예제 #9
0
        public static void Load()
        {
            ArrayList types = new ArrayList();

            AddTypes( Core.Assembly, types );

            for ( int i = 0; i < ScriptCompiler.Assemblies.Length; ++i )
                AddTypes( ScriptCompiler.Assemblies[i], types );

            m_RootItems = Load( types, "Data/items.cfg" );
            m_RootMobiles = Load( types, "Data/mobiles.cfg" );
        }
예제 #10
0
        public static void Load()
        {
            ArrayList types = new ArrayList();

            AddTypes( Core.Assembly, types );

            for( int i = 0; i < ScriptCompiler.Assemblies.Length; ++i )
                AddTypes( ScriptCompiler.Assemblies[i], types );

            m_RootItems = Load( types, "Data/items.cfg" );
            m_RootMobiles = Load( types, "Data/mobiles.cfg" );
        }
예제 #11
0
        public static void Load()
        {
            List <Type> types = new List <Type>();

            AddTypes(Core.Assembly, types);

            for (int i = 0; i < AssemblyHandler.Assemblies.Length; ++i)
            {
                AddTypes(AssemblyHandler.Assemblies[i], types);
            }

            m_RootItems   = Load(types, "Data/items.cfg");
            m_RootMobiles = Load(types, "Data/mobiles.cfg");
        }
예제 #12
0
        public static void Export(CategoryEntry ce, string fileName, string title)
        {
            XmlTextWriter xml = new XmlTextWriter(fileName, Encoding.UTF8);

            xml.Indentation = 1;
            xml.IndentChar  = '\t';
            xml.Formatting  = Formatting.Indented;

            xml.WriteStartDocument(true);

            RecurseExport(xml, ce);

            xml.Flush();
            xml.Close();
        }
예제 #13
0
		public static void Export( CategoryEntry ce, string fileName )
		{
			XmlTextWriter xml = new XmlTextWriter( fileName, System.Text.Encoding.UTF8 );

			xml.Indentation = 1;
			xml.IndentChar = '\t';
			xml.Formatting = Formatting.Indented;

			xml.WriteStartDocument( true );

			RecurseExport( xml, ce );

			xml.Flush();
			xml.Close();
		}
예제 #14
0
        private static CategoryEntry GetDeepestMatch( CategoryEntry root, Type type )
        {
            if( !root.IsMatch( type ) )
                return null;

            for( int i = 0; i < root.SubCategories.Length; ++i )
            {
                CategoryEntry check = GetDeepestMatch( root.SubCategories[i], type );

                if( check != null )
                    return check;
            }

            return root;
        }
예제 #15
0
        private static CategoryEntry Load(List <Type> types, string config)
        {
            CategoryLine[] lines = CategoryLine.Load(config);

            if (lines.Length > 0)
            {
                int           index = 0;
                CategoryEntry root  = new CategoryEntry(null, lines, ref index);

                Fill(root, types);

                return(root);
            }

            return(new CategoryEntry());
        }
예제 #16
0
        private static void Fill( CategoryEntry root, ArrayList list )
        {
            for( int i = 0; i < list.Count; ++i )
            {
                Type type = (Type)list[i];
                CategoryEntry match = GetDeepestMatch( root, type );

                if( match == null )
                    continue;

                try
                {
                    match.Matched.Add( new CategoryTypeEntry( type ) );
                }
                catch
                {
                }
            }
        }
예제 #17
0
        private static CategoryEntry GetDeepestMatch(CategoryEntry root, Type type)
        {
            if (!root.IsMatch(type))
            {
                return(null);
            }

            for (int i = 0; i < root.SubCategories.Length; ++i)
            {
                CategoryEntry check = GetDeepestMatch(root.SubCategories[i], type);

                if (check != null)
                {
                    return(check);
                }
            }

            return(root);
        }
예제 #18
0
        private static void Fill(CategoryEntry root, List <Type> list)
        {
            for (int i = 0; i < list.Count; ++i)
            {
                Type          type  = list[i];
                CategoryEntry match = GetDeepestMatch(root, type);

                if (match == null)
                {
                    continue;
                }

                try
                {
                    match.Matched.Add(new CategoryTypeEntry(type));
                }
                catch
                {
                    // ignored
                }
            }
        }
예제 #19
0
        private static void Fill(CategoryEntry root, ArrayList list)
        {
            for (int i = 0; i < list.Count; ++i)
            {
                Type          type  = (Type)list[i];
                CategoryEntry match = GetDeepestMatch(root, type);

                if (match == null)
                {
                    continue;
                }

                try
                {
                    match.Matched.Add(new CategoryTypeEntry(type));
                }
                catch (Exception e)
                {
                    Diagnostics.ExceptionLogging.LogException(e);
                }
            }
        }
예제 #20
0
		private static void Fill( CategoryEntry root, ArrayList list )
		{
			for ( int i = 0; i < list.Count; ++i )
			{
				Type type = (Type)list[i];
				CategoryEntry match = GetDeepestMatch( root, type );

				if ( match == null )
					continue;

				try
				{
					match.Matched.Add( new CategoryTypeEntry( type ) );
				}
				catch
				{
				}
			}
		}
예제 #21
0
        public static void RecurseExport(XmlTextWriter xml, CategoryEntry ce)
        {
            xml.WriteStartElement("category");

            xml.WriteAttributeString("title", ce.Title);

            ArrayList subCats = new ArrayList(ce.SubCategories);

            subCats.Sort(new CategorySorter());

            for (int i = 0; i < subCats.Count; ++i)
            {
                RecurseExport(xml, (CategoryEntry)subCats[i]);
            }

            ce.Matched.Sort(new CategorySorter());

            for (int i = 0; i < ce.Matched.Count; ++i)
            {
                CategoryTypeEntry cte = (CategoryTypeEntry)ce.Matched[i];

                xml.WriteStartElement("object");

                xml.WriteAttributeString("type", cte.Type.ToString());

                object obj = cte.Object;

                if (obj is Item)
                {
                    Item item = (Item)obj;

                    int itemID = item.ItemID;

                    if (item is BaseAddon && ((BaseAddon)item).Components.Count == 1)
                    {
                        itemID = ((AddonComponent)(((BaseAddon)item).Components[0])).ItemID;
                    }

                    if (itemID >= 0x4000)
                    {
                        itemID = 1;
                    }

                    xml.WriteAttributeString("gfx", XmlConvert.ToString(itemID));

                    int hue = item.Hue & 0x7FFF;

                    if ((hue & 0x4000) != 0)
                    {
                        hue = 0;
                    }

                    if (hue != 0)
                    {
                        xml.WriteAttributeString("hue", XmlConvert.ToString(hue));
                    }

                    item.Delete();
                }
                else if (obj is Mobile)
                {
                    Mobile mob = (Mobile)obj;

                    int itemID = ShrinkTable.Lookup(mob, 1);

                    xml.WriteAttributeString("gfx", XmlConvert.ToString(itemID));

                    int hue = mob.Hue & 0x7FFF;

                    if ((hue & 0x4000) != 0)
                    {
                        hue = 0;
                    }

                    if (hue != 0)
                    {
                        xml.WriteAttributeString("hue", XmlConvert.ToString(hue));
                    }

                    mob.Delete();
                }

                xml.WriteEndElement();
            }

            xml.WriteEndElement();
        }
예제 #22
0
		public static void RecurseExport( XmlTextWriter xml, CategoryEntry ce )
		{
			xml.WriteStartElement( "category" );

			xml.WriteAttributeString( "title", ce.Title );

			ArrayList subCats = new ArrayList( ce.SubCategories );

			subCats.Sort( new CategorySorter() );

			for ( int i = 0; i < subCats.Count; ++i )
				RecurseExport( xml, (CategoryEntry)subCats[i] );

			ce.Matched.Sort( new CategorySorter() );

			for ( int i = 0; i < ce.Matched.Count; ++i )
			{
				CategoryTypeEntry cte = (CategoryTypeEntry)ce.Matched[i];

				xml.WriteStartElement( "object" );

				xml.WriteAttributeString( "type", cte.Type.ToString() );

				object obj = cte.Object;

				if ( obj is Item )
				{
					Item item = (Item)obj;

					int itemID = item.ItemID;

					if ( item is BaseAddon && ((BaseAddon)item).Components.Count == 1 )
						itemID = ((AddonComponent)(((BaseAddon)item).Components[0])).ItemID;

					if ( itemID > TileData.MaxItemValue )
						itemID = 1;

					xml.WriteAttributeString( "gfx", XmlConvert.ToString( itemID ) );

					int hue = item.Hue & 0x7FFF;

					if ( (hue & 0x4000) != 0 )
						hue = 0;

					if ( hue != 0 )
						xml.WriteAttributeString( "hue", XmlConvert.ToString( hue ) );

					item.Delete();
				}
				else if ( obj is Mobile )
				{
					Mobile mob = (Mobile)obj;

					int itemID = ShrinkTable.Lookup( mob, 1 );

					xml.WriteAttributeString( "gfx", XmlConvert.ToString( itemID ) );

					int hue = mob.Hue & 0x7FFF;

					if ( (hue & 0x4000) != 0 )
						hue = 0;

					if ( hue != 0 )
						xml.WriteAttributeString( "hue", XmlConvert.ToString( hue ) );

					mob.Delete();
				}

				xml.WriteEndElement();
			}

			xml.WriteEndElement();
		}
예제 #23
0
		private static CategoryEntry Load( ArrayList types, string config )
		{
			CategoryLine[] lines = CategoryLine.Load( config );

			if ( lines.Length > 0 )
			{
				int index = 0;
				CategoryEntry root = new CategoryEntry( null, lines, ref index );

				Fill( root, types );

				return root;
			}

			return new CategoryEntry();
		}
예제 #24
0
		public CategoryEntry( CategoryEntry parent, CategoryLine[] lines, ref int index )
		{
			m_Parent = parent;

			string text = lines[index].Text;

			int start = text.IndexOf( '(' );

			if ( start < 0 )
				throw new FormatException( String.Format( "Input string not correctly formatted ('{0}')", text ) );

			m_Title = text.Substring( 0, start ).Trim();

			int end = text.IndexOf( ')', ++start );

			if ( end < start )
				throw new FormatException( String.Format( "Input string not correctly formatted ('{0}')", text ) );

			text = text.Substring( start, end-start );
			string[] split = text.Split( ';' );

			ArrayList list = new ArrayList();

			for ( int i = 0; i < split.Length; ++i )
			{
				Type type = ScriptCompiler.FindTypeByName( split[i].Trim() );

				if ( type == null )
					Console.WriteLine( "Match type not found ('{0}')", split[i].Trim() );
				else
					list.Add( type );
			}

			m_Matches = (Type[])list.ToArray( typeof( Type ) );
			list.Clear();

			int ourIndentation = lines[index].Indentation;

			++index;

			while ( index < lines.Length && lines[index].Indentation > ourIndentation )
				list.Add( new CategoryEntry( this, lines, ref index ) );

			m_SubCategories = (CategoryEntry[])list.ToArray( typeof( CategoryEntry ) );
			list.Clear();

			m_Matched = list;
		}
예제 #25
0
        public static void RecurseExport(XmlTextWriter xml, CategoryEntry ce)
        {
            xml.WriteStartElement("category");

            xml.WriteAttributeString("title", ce.Title);

            List <CategoryEntry> subCats = new List <CategoryEntry>(ce.SubCategories);

            subCats.Sort(new CategorySorter());

            for (int i = 0; i < subCats.Count; ++i)
            {
                RecurseExport(xml, subCats[i]);
            }

            ce.Matched.Sort(new CategoryTypeSorter());

            for (int i = 0; i < ce.Matched.Count; ++i)
            {
                CategoryTypeEntry cte = ce.Matched[i];

                xml.WriteStartElement("object");

                xml.WriteAttributeString("type", cte.Type.ToString());

                if (cte.Object is Item item)
                {
                    int itemID = item.ItemID;

                    if (item is BaseAddon addon && addon.Components.Count == 1)
                    {
                        itemID = addon.Components[0].ItemID;
                    }

                    if (itemID > TileData.MaxItemValue)
                    {
                        itemID = 1;
                    }

                    xml.WriteAttributeString("gfx", XmlConvert.ToString(itemID));

                    int hue = item.Hue & 0x7FFF;

                    if ((hue & 0x4000) != 0)
                    {
                        hue = 0;
                    }

                    if (hue != 0)
                    {
                        xml.WriteAttributeString("hue", XmlConvert.ToString(hue));
                    }

                    item.Delete();
                }
                else if (cte.Object is Mobile mob)
                {
                    int itemID = ShrinkTable.Lookup(mob, 1);

                    xml.WriteAttributeString("gfx", XmlConvert.ToString(itemID));

                    int hue = mob.Hue & 0x7FFF;

                    if ((hue & 0x4000) != 0)
                    {
                        hue = 0;
                    }

                    if (hue != 0)
                    {
                        xml.WriteAttributeString("hue", XmlConvert.ToString(hue));
                    }

                    mob.Delete();
                }

                xml.WriteEndElement();
            }

            xml.WriteEndElement();
        }
예제 #26
0
		private static CategoryEntry GetDeepestMatch( CategoryEntry root, Type type )
		{
			if ( !root.IsMatch( type ) )
				return null;

			for ( int i = 0; i < root.SubCategories.Length; ++i )
			{
				CategoryEntry check = GetDeepestMatch( root.SubCategories[i], type );

				if ( check != null )
					return check;
			}

			return root;
		}
예제 #27
0
        public static void RecurseExport(List <CAGJson> list, CategoryEntry ce, string category)
        {
            category = string.IsNullOrWhiteSpace(category) ? ce.Title : $"{category}{ce.Title}";

            if (ce.Matched.Count > 0)
            {
                list.Add(
                    new CAGJson
                {
                    Category = category,
                    Objects  = ce.Matched.Select(
                        cte =>
                    {
                        if (cte.Object is Item item)
                        {
                            var itemID = item.ItemID;

                            if (item is BaseAddon addon && addon.Components.Count == 1)
                            {
                                itemID = addon.Components[0].ItemID;
                            }

                            if (itemID > TileData.MaxItemValue)
                            {
                                itemID = 1;
                            }

                            int?hue = item.Hue & 0x7FFF;

                            if ((hue & 0x4000) != 0)
                            {
                                hue = 0;
                            }

                            return(new CAGObject
                            {
                                Type = cte.Type,
                                ItemID = itemID,
                                Hue = hue == 0 ? null : hue
                            });
                        }

                        if (cte.Object is Mobile m)
                        {
                            var itemID = ShrinkTable.Lookup(m, 1);

                            int?hue = m.Hue & 0x7FFF;

                            if ((hue & 0x4000) != 0)
                            {
                                hue = 0;
                            }

                            return(new CAGObject
                            {
                                Type = cte.Type,
                                ItemID = itemID,
                                Hue = hue == 0 ? null : hue
                            });
                        }

                        throw new InvalidCastException(
                            $"Categorization Type Entry: {cte.Type.Name} is not a valid type."
                            );
                    }
                        )
                               .ToArray()
                }
예제 #28
0
		public CategoryEntry( CategoryEntry parent, string title, CategoryEntry[] subCats )
		{
			m_Parent = parent;
			m_Title = title;
			m_SubCategories = subCats;
			m_Matches = new Type[0];
			m_Matched = new ArrayList();
		}