Beispiel #1
0
        //TODO : finish implementation.
        //Note to self: remove *.defalted, uncomment the save and use this to handle the meta information.
        static MetafileManager()
        {
            var path = new FileInfo(Path.Combine(ServerContext.StoragePath, "metafile")).FullName;

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


            var files = Directory.GetFiles(path, "*.deflated", SearchOption.TopDirectoryOnly);

            if (files.Length > 0)
            {
                metafiles = new MetafileCollection(files.Length);
                {
                    foreach (var file in files)
                    {
                        var mf = CompressableObject.Load <Metafile>(file, true);
                        mf.Name = mf.Name.Replace(".deflated", string.Empty).Trim();

                        if (mf.Name.StartsWith("NationDesc"))
                        {
                            mf.Nodes = new System.Collections.ObjectModel.Collection <MetafileNode>
                            {
                                new MetafileNode("nation_1", "Lorule"),
                                new MetafileNode("nation_2", "Lividia"),
                                new MetafileNode("nation_3", "Exiles")
                            };
                        }

                        if (mf.Name.StartsWith("SClass"))
                        {
                            mf.Nodes = new System.Collections.ObjectModel.Collection <MetafileNode>
                            {
                                new MetafileNode("Skill")
                            };

                            foreach (var skill in ServerContext.GlobalSkillTemplateCache)
                            {
                                if (skill.Value.Prerequisites != null)
                                {
                                    var nmf = new MetafileNode(skill.Key, skill.Value.Prerequisites.MetaData);
                                    mf.Nodes.Add(nmf);
                                }
                            }
                            mf.Nodes.Add(new MetafileNode("Skill_End"));
                            mf.Nodes.Add(new MetafileNode(""));
                        }


                        //CompressableObject.Save(file, mf);

                        metafiles.Add(mf);
                    }
                }
            }
        }
        private static void LoadQuestDescriptions()
        {
            var dir = ServerContext.StoragePath + "\\Static\\Meta\\Quests";

            if (!Directory.Exists(dir))
            {
                return;
            }

            var loadedNodes = new List <Node>();

            foreach (var file in Directory.GetFiles(dir, "*.txt"))
            {
                var contents = File.ReadAllText(file);

                if (string.IsNullOrEmpty(contents))
                {
                    continue;
                }

                var nodes = JsonConvert.DeserializeObject <List <Node> >(contents);

                if (nodes.Count > 0)
                {
                    loadedNodes.AddRange(nodes);
                }
            }

            var i = 1;

            foreach (var batch in loadedNodes.BatchesOf(712))
            {
                var metaFile = new Metafile {
                    Name = $"SEvent{i}", Nodes = new Collection <MetafileNode>()
                };
                metaFile.Nodes.Add(new MetafileNode("", ""));
                foreach (var node in batch)
                {
                    var metafileNode = new MetafileNode(node.Name, node.Atoms.ToArray());
                    metaFile.Nodes.Add(metafileNode);
                }

                CompileTemplate(metaFile);
                Metafiles.Add(metaFile);
                i++;
            }
        }
        public override void Load(MemoryStream stream)
        {
            using (var reader = new BufferReader(stream))
            {
                int length = reader.ReadUInt16();

                for (var i = 0; i < length; i++)
                {
                    var node     = new MetafileNode(reader.ReadStringA());
                    var atomSize = reader.ReadUInt16();

                    for (var j = 0; j < atomSize; j++)
                    {
                        node.Atoms.Add(
                            reader.ReadStringB());
                    }

                    Nodes.Add(node);
                }
            }

            Hash = Crc32Provider.ComputeChecksum(InflatedData);
            Name = Path.GetFileName(Filename);
        }