Ejemplo n.º 1
0
        public static async void Load()
        {
            if (!Directory.Exists(GetPath()))
            {
                Trace.WriteLine($"DBC folder \"{ GetPath() }\" not found");
                return;
            }
            else
            {
                Trace.WriteLine($"DBC folder \"{ GetPath() }\" found");
            }

            Trace.WriteLine("File name                           LoadTime             Record count");
            Trace.WriteLine("---------------------------------------------------------------------");

            Parallel.ForEach(typeof(DBC).GetProperties(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic), dbc =>
            {
                Type type = dbc.PropertyType.GetGenericArguments()[0];

                if (!type.IsClass)
                {
                    return;
                }

                var startTime = DateTime.Now;
                var attr      = type.GetCustomAttribute <DBFileAttribute>();
                if (attr == null)
                {
                    return;
                }

                var times        = new List <long>();
                var instanceType = typeof(Storage <>).MakeGenericType(type);
                var countGetter  = instanceType.GetProperty("Count").GetGetMethod();
                var instance     = Activator.CreateInstance(instanceType, $"{ GetPath(attr.FileName) }.db2");
                var recordCount  = (int)countGetter.Invoke(instance, new object[] { });

                try
                {
                    dbc.SetValue(dbc.GetValue(null), instance);
                }
                catch (TargetInvocationException tie)
                {
                    if (tie.InnerException is ArgumentException)
                    {
                        throw new ArgumentException($"Failed to load {attr.FileName}.db2: {tie.InnerException.Message}");
                    }
                    throw;
                }

                var endTime = DateTime.Now;
                var span    = endTime.Subtract(startTime);

                Trace.WriteLine($"{ attr.FileName.PadRight(33) } { TimeSpan.FromTicks(span.Ticks).ToString().PadRight(28) } { recordCount.ToString().PadRight(19) }");
            });

            await Task.WhenAll(Task.Run(() =>
            {
                if (AreaTable != null)
                {
                    foreach (var db2Info in AreaTable)
                    {
                        if (db2Info.Value.ParentAreaID != 0 && !Zones.ContainsKey(db2Info.Value.ParentAreaID))
                        {
                            Zones.Add(db2Info.Value.ParentAreaID, db2Info.Value.ZoneName);
                        }
                    }
                }
            }), Task.Run(() =>
            {
                if (MapDifficulty != null)
                {
                    foreach (var mapDifficulty in MapDifficulty)
                    {
                        int difficultyID = 1 << mapDifficulty.Value.DifficultyID;

                        if (MapSpawnMaskStores.ContainsKey(mapDifficulty.Value.MapID))
                        {
                            MapSpawnMaskStores[mapDifficulty.Value.MapID] |= difficultyID;
                        }
                        else
                        {
                            MapSpawnMaskStores.Add(mapDifficulty.Value.MapID, difficultyID);
                        }

                        if (!MapDifficultyStores.ContainsKey(mapDifficulty.Value.MapID))
                        {
                            MapDifficultyStores.Add(mapDifficulty.Value.MapID, new List <int>()
                            {
                                mapDifficulty.Value.DifficultyID
                            });
                        }
                        else
                        {
                            MapDifficultyStores[mapDifficulty.Value.MapID].Add(mapDifficulty.Value.DifficultyID);
                        }
                    }
                }
            }), Task.Run(() =>
            {
                if (CriteriaTree != null && Achievement != null)
                {
                    ICollection <AchievementEntry> achievementLists = Achievement.Values;
                    var achievements = achievementLists.GroupBy(achievement => achievement.CriteriaTree)
                                       .ToDictionary(group => group.Key, group => group.ToList());

                    foreach (var criteriaTree in CriteriaTree)
                    {
                        string result       = "";
                        uint criteriaTreeID = criteriaTree.Value.Parent > 0 ? criteriaTree.Value.Parent : (uint)criteriaTree.Key;

                        List <AchievementEntry> achievementList;
                        if (achievements.TryGetValue(criteriaTreeID, out achievementList))
                        {
                            foreach (var achievement in achievementList)
                            {
                                result = $"AchievementID: {achievement.ID} Description: \"{ achievement.Description }\"";
                            }
                        }

                        if (!CriteriaStores.ContainsKey((ushort)criteriaTree.Value.CriteriaID))
                        {
                            if (criteriaTree.Value.Description != string.Empty)
                            {
                                result += $" - CriteriaDescription: \"{criteriaTree.Value.Description }\"";
                            }

                            CriteriaStores.Add((ushort)criteriaTree.Value.CriteriaID, result);
                        }
                        else
                        {
                            CriteriaStores[(ushort)criteriaTree.Value.CriteriaID] += $" / CriteriaDescription: \"{ criteriaTree.Value.Description }\"";
                        }
                    }
                }
            }), Task.Run(() =>
            {
                if (Faction != null && FactionTemplate != null)
                {
                    foreach (var factionTemplate in FactionTemplate)
                    {
                        if (Faction.ContainsKey(factionTemplate.Value.Faction))
                        {
                            FactionStores.Add((uint)factionTemplate.Key, Faction[factionTemplate.Value.Faction]);
                        }
                    }
                }
            }), Task.Run(() =>
            {
                if (SpellEffect != null)
                {
                    foreach (var effect in SpellEffect)
                    {
                        var tuple = Tuple.Create((uint)effect.Value.SpellID, (uint)effect.Value.EffectIndex);
                        SpellEffectStores[tuple] = effect.Value;
                    }
                }
            }), Task.Run(() =>
            {
                if (PhaseXPhaseGroup != null)
                {
                    foreach (var phase in PhaseXPhaseGroup)
                    {
                        if (!Phases.ContainsKey(phase.Value.PhaseGroupID))
                        {
                            Phases.Add(phase.Value.PhaseGroupID, new List <ushort>()
                            {
                                phase.Value.PhaseID
                            });
                        }
                        else
                        {
                            Phases[phase.Value.PhaseGroupID].Add(phase.Value.PhaseID);
                        }
                    }
                }
            }));
        }
Ejemplo n.º 2
0
        public static void Load()
        {
            Parallel.ForEach(typeof(DBC).GetProperties(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic), dbc =>
            {
                Type type = dbc.PropertyType.GetGenericArguments()[0];

                if (!type.IsClass)
                {
                    return;
                }

                var startTime = DateTime.Now;
                var attr      = type.GetCustomAttribute <DBFileAttribute>();
                if (attr == null)
                {
                    return;
                }

                string pathName  = GetDBCPath(attr.FileName) + ".db2";
                var instanceType = typeof(Storage <>).MakeGenericType(type);
                var countGetter  = instanceType.GetProperty("Count").GetGetMethod();
                dynamic instance = Activator.CreateInstance(instanceType, pathName);
                var recordCount  = (int)countGetter.Invoke(instance, new object[] { });

                try
                {
                    var db2Reader = new DBReader($"{ GetDBCPath(attr.FileName) }.db2");

                    dbc.SetValue(dbc.GetValue(null), instance);
                }
                catch (TargetInvocationException tie)
                {
                    if (tie.InnerException is ArgumentException)
                    {
                        throw new ArgumentException($"Failed to load {attr.FileName}.db2: {tie.InnerException.Message}");
                    }
                    throw;
                }
            });

            if (SpellEffect != null && SpellEffectStores.Count == 0)
            {
                foreach (var effect in SpellEffect)
                {
                    var tuple = Tuple.Create((uint)effect.Value.SpellID, (uint)effect.Value.EffectIndex);
                    SpellEffectStores[tuple] = effect.Value;
                }
            }

            if (MapDifficulty != null && MapDifficultyStores.Count == 0)
            {
                foreach (var mapDifficulty in MapDifficulty)
                {
                    if (MapDifficultyStores.ContainsKey(mapDifficulty.Value.MapID))
                    {
                        MapDifficultyStores[mapDifficulty.Value.MapID] = MapDifficultyStores[mapDifficulty.Value.MapID] + " " + mapDifficulty.Value.DifficultyID;
                    }
                    else
                    {
                        MapDifficultyStores.Add(mapDifficulty.Value.MapID, Convert.ToString(mapDifficulty.Value.DifficultyID));
                    }
                }
            }

            loaded = true;
        }