Exemplo n.º 1
0
        private static int GetNewId()
        {
            if (UsedIds != null && UsedIds.Any())
            {
                var idFooSample = UsedIds.OrderBy(it => it).LastOrDefault();

                idFooSample = ++idFooSample;
                UsedIds.Add(idFooSample);
                return(idFooSample);
            }

            UsedIds = new List <int>()
            {
                1
            };
            return(1);
        }
Exemplo n.º 2
0
    static void ProcessXml(Stream stream)
    {
        XElement root = XElement.Load(stream);

        foreach (var elem in root.Elements("Ground"))
        {
            short  type = (short)Utils.FromString(elem.Attribute("type").Value);
            string id   = elem.Attribute("id").Value;

            UsedIds.Add(type);

            TypeToId[type]      = id;
            IdToType[id]        = type;
            TypeToElement[type] = elem;

            TileDescs[type] = new TileDesc(elem);
        }
        foreach (var elem in root.Elements("Object"))
        {
            if (elem.Element("Class") == null)
            {
                continue;
            }
            string cls  = elem.Element("Class").Value;
            short  type = (short)Utils.FromString(elem.Attribute("type").Value);
            string id   = elem.Attribute("id").Value;

            UsedIds.Add(type);

            TypeToId[type]      = id;
            IdToType[id]        = type;
            TypeToElement[type] = elem;

            if (cls == "Equipment" || cls == "Dye" || cls == "Pet")
            {
                ItemDescs[type] = new Item(elem);
                if (elem.Element("Shop") != null)
                {
                    XElement shop = elem.Element("Shop");
                    ItemShops[type]  = shop.Element("Name").Value;
                    ItemPrices[type] = Utils.FromString(shop.Element("Price").Value);
                }
            }
            if (cls == "Character" || cls == "GameObject" || cls == "Wall" ||
                cls == "ConnectedWall" || cls == "CaveWall" || cls == "Portal")
            {
                ObjectDescs[type] = new ObjectDesc(elem);
            }
            if (cls == "Portal")
            {
                try
                {
                    PortalDescs[type] = new PortalDesc(elem);
                }
                catch (Exception e)
                {
                    Console.WriteLine("Error for portal: " + type + " id: " + id);

                    /*3392,1792,1795,1796,1805,1806,1810,1825 -- no location, assume nexus?*
                     *  Tomb Portal of Cowardice,  Dungeon Portal,  Portal of Cowardice,  Realm Portal,  Glowing Portal of Cowardice,  Glowing Realm Portal,  Nexus Portal,  Locked Wine Cellar Portal*/
                }
            }

            XElement key = elem.Element("Key");
            if (key != null)
            {
                Keys.Add(type);
                KeyPrices[type] = Utils.FromString(key.Value);
            }
        }
        foreach (var elem in root.Elements("Dungeon"))
        {
            string name     = elem.Attribute("name").Value;
            short  portalid = (short)Utils.FromString(elem.Attribute("type").Value);

            IdToDungeon[portalid] = name;
            DungeonDescs[name]    = new DungeonDesc(elem);
        }
    }
Exemplo n.º 3
0
    public static string ProcessModXml(Stream stream, string dir)
    {
        XElement root = XElement.Load(stream);

        foreach (var elem in root.Elements("Ground"))
        {
            short  type = 0x3000;
            string id   = elem.Attribute("id").Value;

            if (!ItemIds.ContainsKey(id))
            {
                for (var i = 0x3001; i < 0xffff; i++)
                {
                    if (!UsedIds.Contains((short)i))
                    {
                        ItemIds.Add(id, (short)i);
                        UsedIds.Add((short)i);
                    }
                }
            }
            type = ItemIds[id];

            elem.SetAttributeValue("type", type);

            TypeToId[type]      = id;
            IdToType[id]        = type;
            TypeToElement[type] = elem;

            TileDescs[type] = new TileDesc(elem);
        }
        foreach (var elem in root.Elements("Object"))
        {
            if (elem.Element("Class") == null)
            {
                continue;
            }
            string cls  = elem.Element("Class").Value;
            short  type = 0x4000;
            string id   = elem.Attribute("id").Value;

            if (!ItemIds.ContainsKey(id))
            {
                for (var i = 0x4001; i < 0xffff; i++)
                {
                    if (!UsedIds.Contains((short)i))
                    {
                        ItemIds.Add(id, (short)i);
                        UsedIds.Add((short)i);
                        break;
                    }
                }
            }
            type = ItemIds[id];

            Console.Out.WriteLine("(" + new DirectoryInfo(dir).Name + ") Adding mod object: " + id + " (" + type.ToString() + ")");
            if (File.Exists(dir + ds + id + ".png"))
            {
                Console.Out.WriteLine("(" + new DirectoryInfo(dir).Name + ") Adding mod texture: " + id);

                if (elem.Element("RemoteTexture") != null)
                {
                    elem.Element("RemoteTexture").Remove();
                }
                if (elem.Element("Texture") != null)
                {
                    elem.Element("Texture").Remove();
                }

                XElement texElem = new XElement("RemoteTexture",
                                                new XElement("Instance",
                                                             new XText("production")
                                                             ),
                                                new XElement("Id",
                                                             new XText("mod:" + id)
                                                             )
                                                );

                elem.Add(texElem);

                try
                {
                    ModTextures.Add(id, File.ReadAllBytes(dir + ds + id + ".png"));
                }
                catch { Console.Out.WriteLine("(" + new DirectoryInfo(dir).Name + ") Error adding texture: " + id); }
            }

            elem.SetAttributeValue("type", type);

            TypeToId[type]      = id;
            IdToType[id]        = type;
            TypeToElement[type] = elem;

            if (cls == "Equipment" || cls == "Dye" || cls == "Pet")
            {
                ItemDescs[type] = new Item(elem);
                if (elem.Element("Shop") != null)
                {
                    XElement shop = elem.Element("Shop");
                    ItemShops[type]  = shop.Element("Name").Value;
                    ItemPrices[type] = Utils.FromString(shop.Element("Price").Value);
                }
            }
            if (cls == "Character" || cls == "GameObject" || cls == "Wall" ||
                cls == "ConnectedWall" || cls == "CaveWall" || cls == "Portal")
            {
                ObjectDescs[type] = new ObjectDesc(elem);
            }
            if (cls == "Portal")
            {
                try
                {
                    PortalDescs[type] = new PortalDesc(elem);
                }
                catch (Exception e)
                {
                    Console.WriteLine("Error for portal: " + type + " id: " + id);

                    /*3392,1792,1795,1796,1805,1806,1810,1825 -- no location, assume nexus?*
                     *  Tomb Portal of Cowardice,  Dungeon Portal,  Portal of Cowardice,  Realm Portal,  Glowing Portal of Cowardice,  Glowing Realm Portal,  Nexus Portal,  Locked Wine Cellar Portal*/
                }
            }

            XElement key = elem.Element("Key");
            if (key != null)
            {
                Keys.Add(type);
                KeyPrices[type] = Utils.FromString(key.Value);
            }
        }
        foreach (var elem in root.Elements("Dungeon"))
        {
            string name     = elem.Attribute("name").Value;
            short  portalid = (short)Utils.FromString(elem.Attribute("type").Value);

            IdToDungeon[portalid] = name;
            DungeonDescs[name]    = new DungeonDesc(elem);
        }
        using (StringWriter sw = new StringWriter())
        {
            root.Save(sw);
            return(sw.ToString());
        }
    }