Пример #1
0
        public NightfallManifestModel GetD2NightFall(DateTime date)
        {
            NightfallManifestGroupModel nightfallManifest = null;
            var nightfall = db2.D2Nightfalls.FirstOrDefault(d => d.day == date.Day && d.month == date.Month && d.year == date.Year);

            if (nightfall == null)
            {
                nightfallManifest = CreateD2NightFall(date, true);
                nightfall         = db2.D2Nightfalls.FirstOrDefault(d => d.day == date.Day && d.month == date.Month && d.year == date.Year);
            }

            if (nightfall != null)
            {
                if (nightfallManifest == null)
                {
                    nightfallManifest = CreateD2NightFall(date, false);
                }

                var model = new NightfallManifestModel
                {
                    Hash      = nightfall.missionid,
                    Name      = nightfallManifest.Activity.displayProperties.name,
                    PgcrIcon  = nightfallManifest.Activity.pgcrImage,
                    Modifiers = nightfallManifest.Modifiers.Select(m => new UnclassifiedModifier()
                    {
                        Name = m.displayProperties.name, Description = m.displayProperties.description, Icon = m.displayProperties.icon
                    }).ToList(),
                    Challenges = nightfallManifest.Challenges.Select(m => new UnclassifiedChallenge()
                    {
                        Name = m.displayProperties.name, Description = m.displayProperties.description
                    }).ToList(),
                };

                return(model);
            }

            return(null);
        }
Пример #2
0
        private NightfallManifestGroupModel CreateD2NightFall(DateTime date, bool createNew)
        {
            var nightfallDefinition = new NightfallManifestGroupModel();

            var mileStones = DestinyDailyApiManager.BungieApi.GetMilestones();

            if (mileStones.ErrorCode > 1)
            {
                return(null);
            }

            var activityManifest  = DestinyDailyApiManager.BungieApi.GetPlumbing <Dictionary <long, ActivityDefinition> >("DestinyActivityDefinition");
            var modifierManifest  = DestinyDailyApiManager.BungieApi.GetPlumbing <Dictionary <long, ModifierDefinition> >("DestinyActivityModifierDefinition");
            var objectiveManifest = DestinyDailyApiManager.BungieApi.GetPlumbing <Dictionary <long, ModifierDefinition> >("DestinyObjectiveDefinition");
            var vendorManifest    = DestinyDailyApiManager.BungieApi.GetPlumbing <Dictionary <long, VendorDefinition> >("DestinyVendorDefinition");

            foreach (var milestone in mileStones.Response)
            {
                var milestoneDetails = activityManifest[milestone.Value.availableQuests[0].activity.activityHash];
                if (milestoneDetails.displayProperties.name.Contains("Nightfall"))
                {
                    if (createNew)
                    {
                        var newEntry = new D2Nightfall()
                        {
                            missionid = milestoneDetails.hash,
                            day       = date.Day,
                            month     = date.Month,
                            year      = date.Year
                        };
                        db2.D2Nightfalls.Add(newEntry);
                        db2.SaveChanges();
                    }

                    nightfallDefinition.Activity = milestoneDetails;

                    foreach (var modifier in milestone.Value.availableQuests[0].activity.modifierHashes)
                    {
                        if (createNew)
                        {
                            var modifierEntry = new D2NightfallModifier()
                            {
                                modfierid = modifier,
                                day       = date.Day,
                                month     = date.Month,
                                year      = date.Year
                            };
                            db2.D2NightfallModifiers.Add(modifierEntry);
                            db2.SaveChanges();
                        }

                        var classifiedOverride = db2.ClassifiedOverrides.FirstOrDefault(c => c.id == modifier);
                        if (classifiedOverride != null)
                        {
                            var overrideManifest = new ModifierDefinition()
                            {
                                hash = modifier,
                                displayProperties = new DisplayProperties()
                                {
                                    name        = classifiedOverride.name,
                                    description = classifiedOverride.desc
                                }
                            };
                            nightfallDefinition.Modifiers.Add(overrideManifest);
                        }
                        else
                        {
                            nightfallDefinition.Modifiers.Add(modifierManifest[modifier]);
                        }
                    }

                    var tiers = milestone.Value.availableQuests[0].challenges.Select(c => c.activityHash).First();
                    foreach (var challenge in milestone.Value.availableQuests[0].challenges.Where(c => c.activityHash == tiers))
                    {
                        if (createNew)
                        {
                            var challengeEntry = new D2NightfallChallenge()
                            {
                                objectiveid = challenge.objectiveHash,
                                day         = date.Day,
                                month       = date.Month,
                                year        = date.Year
                            };
                            db2.D2NightfallChallenges.Add(challengeEntry);
                            db2.SaveChanges();
                        }

                        nightfallDefinition.Challenges.Add(objectiveManifest[challenge.objectiveHash]);
                    }

                    return(nightfallDefinition);
                }
            }
            return(null);
        }