Пример #1
0
        private void Events_CollectionReady(object sender, EventArgs e)
        {
            if (Type != KunosCareerObjectType.Championship)
            {
                return;
            }

            var points = Events.Sum(x => ChampionshipPointsPerPlace.ElementAtOrDefault(x.TakenPlace - 1));

            if (points == ChampionshipPoints)
            {
                return;
            }

            Logging.Write($"Summary points restored: {points} (was {ChampionshipPoints})");
            ChampionshipPoints = points;
            ChampionshipDrivers.GetById(-1).Points = ChampionshipPoints;
            ChampionshipDriversView.Refresh();
        }
Пример #2
0
        private void LoadProgressFromEntry()
        {
            Func <string, bool> fn = x => KunosCareerProgress.Instance.Completed.Contains(x);

            IsAvailable = RequiredSeries.Length == 0 || (RequiredAnySeries ? RequiredSeries.Any(fn) : RequiredSeries.All(fn));

            foreach (var driver in ChampionshipDrivers)
            {
                driver.Points = 0;
            }

            var entry = KunosCareerProgress.Instance.Entries.GetValueOrDefault(Id);

            if (entry == null)
            {
                CompletedEvents = 0;

                FirstPlaces          = 0;
                SecondPlaces         = 0;
                ThirdPlaces          = 0;
                ChampionshipAiPoints = new int[0];
                ChampionshipPoints   = 0;

                _lastSelectedTimestamp = 0;
            }
            else
            {
                var count = EventsWrappers.Count;
                CompletedEvents = entry.EventsResults.Where(x => x.Key < count).Count(x => x.Value > 0);

                if (Type == KunosCareerObjectType.SingleEvents)
                {
                    FirstPlaces          = entry.EventsResults.Count(x => x.Key < count && x.Value == 3);
                    SecondPlaces         = entry.EventsResults.Count(x => x.Key < count && x.Value == 2);
                    ThirdPlaces          = entry.EventsResults.Count(x => x.Key < count && x.Value == 1);
                    ChampionshipAiPoints = new int[0];
                    ChampionshipPoints   = 0;
                }
                else
                {
                    FirstPlaces          = entry.EventsResults.Count(x => x.Key < count && x.Value == 1);
                    SecondPlaces         = entry.EventsResults.Count(x => x.Key < count && x.Value == 2);
                    ThirdPlaces          = entry.EventsResults.Count(x => x.Key < count && x.Value == 3);
                    ChampionshipAiPoints = ChampionshipDrivers.Select((x, i) => entry.AiPoints.GetValueOrDefault(i)).ToList();
                    ChampionshipPoints   = entry.Points ?? 0;

                    for (var i = 0; i < ChampionshipAiPoints.Count; i++)
                    {
                        var driverEntry = ChampionshipDrivers.GetByIdOrDefault(i);
                        if (driverEntry != null)
                        {
                            driverEntry.Points = ChampionshipAiPoints[i];
                        }
                        else
                        {
                            Logging.Warning("Missing driver entry with ID=" + i);
                        }
                    }

                    var place = 0;
                    foreach (var driver in ChampionshipDrivers.OrderBy(x => x.Points))
                    {
                        driver.TakenPlace = place++;
                    }

                    ChampionshipDrivers.GetById(-1).Points = ChampionshipPoints;
                }

                _lastSelectedTimestamp = entry.LastSelectedTimestamp;

                if (EventsManager?.IsScanned == true)
                {
                    _selectedEvent = EventsManager.GetByNumber(entry.SelectedEvent) ?? _selectedEvent;
                    OnPropertyChanged(nameof(SelectedEvent));
                }
            }

            ChampionshipDriversView.Refresh();
            OnPropertyChanged(nameof(LastSelectedTimestamp));

            if (EventsManager != null)
            {
                foreach (var eventObject in EventsManager.LoadedOnly)
                {
                    eventObject.LoadProgress();
                }
            }
        }