Ejemplo n.º 1
0
        public static bool TryLoadSpellsConverted(string file, out List <Database.Models.World.Spell> results)
        {
            try
            {
                var fileText = File.ReadAllText(file);

                var gdleModel = JsonConvert.DeserializeObject <Models.Spells>(fileText);

                results = new List <Database.Models.World.Spell>();

                foreach (var value in gdleModel.Table.SpellBaseHash)
                {
                    if (GDLEConverter.TryConvert(value.Key, value.Value, out var result))
                    {
                        results.Add(result);
                    }
                }

                return(true);
            }
            catch
            {
                results = null;
                return(false);
            }
        }
Ejemplo n.º 2
0
        public static bool TryLoadRecipePrecursorsConverted(string file, out List <Database.Models.World.CookBook> results)
        {
            try
            {
                var fileText = File.ReadAllText(file);

                var gdleModel = JsonConvert.DeserializeObject <List <Models.RecipePrecursor> >(fileText);

                results = new List <Database.Models.World.CookBook>();

                foreach (var value in gdleModel)
                {
                    if (GDLEConverter.TryConvert(value, out var result))
                    {
                        results.Add(result);
                    }
                }

                return(true);
            }
            catch
            {
                results = null;
                return(false);
            }
        }
Ejemplo n.º 3
0
        private static void TryConvertLandblocks(out List <LandblockInstance> results, out List <LandblockInstanceLink> links, List <Models.Landblock> landblocks)
        {
            results = new List <LandblockInstance>();
            links   = new List <LandblockInstanceLink>();

            foreach (var value in landblocks)
            {
                if (GDLEConverter.TryConvert(value, out var part1, out var part2))
                {
                    foreach (var instance in part1)
                    {
                        foreach (var link in part2)
                        {
                            if (link.ParentGuid == instance.Guid)
                            {
                                instance.LandblockInstanceLink.Add(link);
                            }
                        }

                        results.Add(instance);
                    }

                    foreach (var part in part2)
                    {
                        links.Add(part);

                        var child = results.FirstOrDefault(x => x.Guid == part.ChildGuid);
                        if (child != null)
                        {
                            child.IsLinkChild = true;
                        }
                    }
                }
            }
        }
Ejemplo n.º 4
0
        public static bool TryLoadWieldedTreasureTableConverted(string file, out List <TreasureWielded> results)
        {
            try
            {
                var fileText = File.ReadAllText(file);

                var gdleModel = JsonConvert.DeserializeObject <List <Models.WieldedTreasureTable> >(fileText);

                results = new List <TreasureWielded>();

                foreach (var value in gdleModel)
                {
                    if (GDLEConverter.TryConvert(value, out var result))
                    {
                        results.AddRange(result);
                    }
                }

                return(true);
            }
            catch
            {
                results = null;
                return(false);
            }
        }
Ejemplo n.º 5
0
        public static bool TryLoadRecipeCombinedConverted(string folder, out List <Recipe> recipes, out List <CookBook> cookBooks)
        {
            try
            {
                TryLoadRecipeCombinedInParallel(folder, out var gdleModel);

                if (gdleModel == null)
                {
                    recipes   = null;
                    cookBooks = null;
                    return(false);
                }

                recipes = new List <Recipe>();

                cookBooks = new List <CookBook>();

                foreach (var value in gdleModel)
                {
                    if (GDLEConverter.TryConvert(value.recipe, out var result))
                    {
                        foreach (var precursor in value.precursors)
                        {
                            if (GDLEConverter.TryConvert(precursor, out var result2))
                            {
                                result2.RecipeId = value.key;
                                cookBooks.Add(result2);
                            }
                        }
                        recipes.Add(result);
                    }
                }

                return(true);
            }
            catch
            {
                recipes   = null;
                cookBooks = null;
                return(false);
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// This will sanitize the Guids for ACE use to the following format: 0x7LBID### where ### starts from [startingIdOffset]
        /// </summary>
        public static bool TryLoadWorldSpawnsConverted(string file, out List <LandblockInstance> results, out List <LandblockInstanceLink> links, ushort startingIdOffset = 0)
        {
            try
            {
                var fileText = File.ReadAllText(file);

                var gdleModel = JsonConvert.DeserializeObject <Models.WorldSpawns>(fileText);

                var idChanges = new Dictionary <uint /*LBID*/, Dictionary <uint /*from*/, uint /*to*/> >();

                // First we convert all weenies
                foreach (var landblock in gdleModel.Landblocks)
                {
                    var currentOffset = startingIdOffset;

                    if (!idChanges.ContainsKey(landblock.Key))
                    {
                        idChanges.Add(landblock.Key, new Dictionary <uint, uint>());
                    }

                    foreach (var weenie in landblock.Value.Weenies)
                    {
                        var newGuid = (0x70000000 | ((weenie.Position.ObjCellId & 0xFFFF0000) >> 4) | currentOffset);
                        currentOffset++;

                        if (!idChanges[landblock.Key].ContainsKey(weenie.Id))
                        {
                            idChanges[landblock.Key].Add(weenie.Id, newGuid);
                            weenie.Id = newGuid;
                        }
                    }
                }

                // Then we update all the links
                foreach (var landblock in gdleModel.Landblocks)
                {
                    if (landblock.Value.Links == null)
                    {
                        continue;
                    }

                    foreach (var link in landblock.Value.Links)
                    {
                        if (idChanges[landblock.Key].TryGetValue(link.Source, out var source))
                        {
                            link.Source = source;
                        }
                        else
                        {
                            link.Source = 0;
                        }

                        if (idChanges[landblock.Key].TryGetValue(link.Target, out var target))
                        {
                            link.Target = target;
                        }
                        else
                        {
                            link.Target = 0;
                        }
                    }
                }

                results = new List <LandblockInstance>();
                links   = new List <LandblockInstanceLink>();

                foreach (var value in gdleModel.Landblocks)
                {
                    if (GDLEConverter.TryConvert(value, out var part1, out var part2))
                    {
                        foreach (var instance in part1)
                        {
                            foreach (var link in part2)
                            {
                                if (link.ParentGuid == instance.Guid)
                                {
                                    instance.LandblockInstanceLink.Add(link);
                                }
                            }

                            results.Add(instance);
                        }

                        foreach (var part in part2)
                        {
                            links.Add(part);

                            var child = results.Where(x => x.Guid == part.ChildGuid).FirstOrDefault();
                            if (child != null)
                            {
                                child.IsLinkChild = true;
                            }
                        }
                    }
                }

                return(true);
            }
            catch
            {
                results = null;
                links   = null;
                return(false);
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// This will sanitize the Guids for ACE use to the following format: 0x7LBID### where ### starts from [startingIdOffset]
        /// </summary>
        public static bool TryLoadWorldSpawnsConverted(string file, out List <LandblockInstance> results, out List <LandblockInstanceLink> links, ushort startingIdOffset = 0)
        {
            try
            {
                var fileText = File.ReadAllText(file);

                var gdleModel = JsonConvert.DeserializeObject <Models.WorldSpawns>(fileText);

                var idChanges = new Dictionary <uint /*from*/, uint /*to*/>();

                // First we convert all weenies
                foreach (var landblock in gdleModel.Landblocks)
                {
                    var currentOffset = startingIdOffset;

                    foreach (var weenie in landblock.Value.Weenies)
                    {
                        var newGuid = (0x70000000 | ((weenie.Position.ObjCellId & 0xFFFF0000) >> 4) | currentOffset);
                        currentOffset++;

                        idChanges[weenie.Id] = newGuid;
                        weenie.Id            = newGuid;
                    }
                }

                // Then we update all the links
                foreach (var landblock in gdleModel.Landblocks)
                {
                    if (landblock.Value.Links == null)
                    {
                        continue;
                    }

                    foreach (var link in landblock.Value.Links)
                    {
                        if (idChanges.TryGetValue(link.Source, out var source))
                        {
                            link.Source = source;
                        }
                        else
                        {
                            link.Source = 0;
                        }

                        if (idChanges.TryGetValue(link.Source, out var target))
                        {
                            link.Target = target;
                        }
                        else
                        {
                            link.Target = 0;
                        }
                    }
                }

                results = new List <LandblockInstance>();
                links   = new List <LandblockInstanceLink>();

                foreach (var value in gdleModel.Landblocks)
                {
                    if (GDLEConverter.TryConvert(value, out var part1, out var part2))
                    {
                        foreach (var part in part1)
                        {
                            results.Add(part);
                        }

                        foreach (var part in part2)
                        {
                            links.Add(part);
                        }
                    }
                }

                return(true);
            }
            catch
            {
                results = null;
                links   = null;
                return(false);
            }
        }