예제 #1
0
        void DoParse(string[] missionFiles)
        {
            Utility.LoadStrings(root);
            Utility.LoadItems(root);

            Dictionary<string, MissionObjects> objects = new Dictionary<string, MissionObjects>();

            foreach (string file in missionFiles) {
                DirectoryInfo levelDir = new DirectoryInfo(file);
                Utility.LoadMissionFile(file);
                string folderName = levelDir.Parent.Name;
                string[] customNameParts = folderName.Split('-');
                objects.Add(customNameParts[0], Utility.MissionFile.Objects[0]);
            }

            CultureInfo ci = new CultureInfo("");
            DoorTemplates templates = new DoorTemplates();

            foreach (var pair in objects) {
                if (pair.Value.Entity == null)
                    continue;

                IEnumerable<Entity> spawns = pair.Value.Entity.Where(e => e.Properties != null &&
                                                                          e.Properties.ServerData != null &&
                                                                          !String.IsNullOrEmpty(e.Properties.ServerData.Key))
                                                              .Select(e => e);
                foreach (Entity entity in spawns) {
                    string key = entity.Properties.ServerData.Key;
                    Item item = Utility.ItemIndex.GetItem(key);

                    var obj = new Door();
                    /*
                    string[] coords = entity.Pos.Split(',');
                    obj.x = Decimal.Parse(coords[0], ci);
                    obj.y = Decimal.Parse(coords[1], ci);
                    obj.z = Decimal.Parse(coords[2], ci);
                    */
                    obj.worldId = ClientLevelMap.mapToId[pair.Key];
                    obj.id = entity.EntityId;
                    obj.closeable = entity.Properties.ServerData.bCloseable;

                    obj.doorKey = new DoorKey()
                    {
                        itemId = item.id,
                        name = Utility.StringIndex.GetString(item.desc),
                        nameId = Utility.StringIndex[item.desc]
                        /*
                        desc = Utility.StringIndex.GetString(item.desc_long)
                        */
                    };
                    string desc = Utility.StringIndex.GetString(item.desc_long);
                    bool removeLogout = (bool)item.remove_when_logout;
                    if (removeLogout) {
                    }
                    if (desc.IndexOf("remove", StringComparison.InvariantCultureIgnoreCase) != -1) {
                    }

                    templates.Doors.Add(obj);
                }
            }

            string outputPath = Path.Combine(root, @"output");
            if (!Directory.Exists(outputPath))
                Directory.CreateDirectory(outputPath);

            var settings = new XmlWriterSettings()
            {
                CheckCharacters = false,
                CloseOutput = false,
                Indent = true,
                IndentChars = "\t",
                NewLineChars = "\n",
                Encoding = new UTF8Encoding(false)
            };

            StringBuilder sb = new StringBuilder();
            foreach (var t in templates.Doors) {
                sb.Append(t.doorKey.itemId.ToString() + ",");
            }

            try {
                using (var fs = new FileStream(Path.Combine(outputPath, "door_templates.xml"),
                                               FileMode.Create, FileAccess.Write))
                using (var writer = XmlWriter.Create(fs, settings)) {
                    XmlSerializer ser = new XmlSerializer(typeof(DoorTemplates));
                    // ser.UnknownAttribute += new XmlAttributeEventHandler(OnUnknownAttribute);
                    // ser.UnknownElement += new XmlElementEventHandler(OnUnknownElement);
                    ser.Serialize(writer, templates);
                }
            } catch (Exception ex) {
                Debug.Print(ex.ToString());
            }
        }
예제 #2
0
        void DoParse(string[] missionFiles)
        {
            Utility.LoadStrings(root);
            Utility.LoadItems(root);

            Dictionary <string, MissionObjects> objects = new Dictionary <string, MissionObjects>();

            foreach (string file in missionFiles)
            {
                DirectoryInfo levelDir = new DirectoryInfo(file);
                Utility.LoadMissionFile(file);
                string   folderName      = levelDir.Parent.Name;
                string[] customNameParts = folderName.Split('-');
                objects.Add(customNameParts[0], Utility.MissionFile.Objects);
            }

            CultureInfo   ci        = new CultureInfo("");
            DoorTemplates templates = new DoorTemplates();

            foreach (var pair in objects)
            {
                if (pair.Value.Entity == null)
                {
                    continue;
                }

                IEnumerable <Entity> spawns = pair.Value.Entity.Where(e => e.Properties != null &&
                                                                      e.Properties.ServerData != null &&
                                                                      !String.IsNullOrEmpty(e.Properties.ServerData.Key))
                                              .Select(e => e);
                foreach (Entity entity in spawns)
                {
                    string key  = entity.Properties.ServerData.Key;
                    Item   item = Utility.ItemIndex.GetItem(key);

                    var obj = new Door();

                    /*
                     * string[] coords = entity.Pos.Split(',');
                     * obj.x = Decimal.Parse(coords[0], ci);
                     * obj.y = Decimal.Parse(coords[1], ci);
                     * obj.z = Decimal.Parse(coords[2], ci);
                     */
                    obj.worldId   = ClientLevelMap.mapToId[pair.Key];
                    obj.id        = entity.EntityId;
                    obj.closeable = entity.Properties.ServerData.bCloseable;

                    obj.doorKey = new DoorKey()
                    {
                        itemId = item.id,
                        name   = Utility.StringIndex.GetString(item.desc),
                        nameId = Utility.StringIndex[item.desc]

                                 /*
                                  * desc = Utility.StringIndex.GetString(item.desc_long)
                                  */
                    };
                    string desc         = Utility.StringIndex.GetString(item.desc_long);
                    bool   removeLogout = (bool)item.remove_when_logout;
                    if (removeLogout)
                    {
                    }
                    if (desc.IndexOf("remove", StringComparison.InvariantCultureIgnoreCase) != -1)
                    {
                    }

                    templates.Doors.Add(obj);
                }
            }

            string outputPath = Path.Combine(root, @"output");

            if (!Directory.Exists(outputPath))
            {
                Directory.CreateDirectory(outputPath);
            }

            var settings = new XmlWriterSettings()
            {
                CheckCharacters = false,
                CloseOutput     = false,
                Indent          = true,
                IndentChars     = "\t",
                NewLineChars    = "\n",
                Encoding        = new UTF8Encoding(false)
            };

            StringBuilder sb = new StringBuilder();

            foreach (var t in templates.Doors)
            {
                sb.Append(t.doorKey.itemId.ToString() + ",");
            }

            try {
                using (var fs = new FileStream(Path.Combine(outputPath, "door_templates.xml"),
                                               FileMode.Create, FileAccess.Write))
                    using (var writer = XmlWriter.Create(fs, settings)) {
                        XmlSerializer ser = new XmlSerializer(typeof(DoorTemplates));
                        // ser.UnknownAttribute += new XmlAttributeEventHandler(OnUnknownAttribute);
                        // ser.UnknownElement += new XmlElementEventHandler(OnUnknownElement);
                        ser.Serialize(writer, templates);
                    }
            } catch (Exception ex) {
                Debug.Print(ex.ToString());
            }
        }