Beispiel #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();
        }
Beispiel #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();
                }
            }
        }
Beispiel #3
0
        private void LoadOpponents()
        {
            if (Type != KunosCareerObjectType.Championship)
            {
                return;
            }

            InitializeEventsManager();
            var firstEvent = GetFirstEventOrNull();

            if (firstEvent == null)
            {
                AddError(AcErrorType.Data_KunosCareerEventsAreMissing, DisplayName);
            }

            var ini     = new IniFile(OpponentsIniFilename);
            var drivers = LinqExtension.RangeFrom(1).Select(x => $"AI{x}").TakeWhile(ini.ContainsKey).Select(x => ini[x]).Select((section, id) => {
                var model = section.GetNonEmpty("MODEL");
                if (model == null)
                {
                    Logging.Error($"Section AI{id + 1}: MODEL is required, fallback to default");
                    model = CarsManager.Instance.GetDefault()?.Id ?? "";
                }

                var skin = section.GetNonEmpty("SKIN");
                if (skin == null)
                {
                    Logging.Error($"Section AI{id + 1}: SKIN is required, fallback to default");
                }

                var car = CarsManager.Instance.GetById(model);
                CarSkinObject carSkin;
                if (car == null)
                {
                    AddError(AcErrorType.Data_KunosCareerCarIsMissing, section.GetNonEmpty("MODEL"));
                    carSkin = null;
                }
                else
                {
                    carSkin = skin == null ? car.GetFirstSkinOrNull() : car.GetSkinByIdFromConfig(skin);
                    if (carSkin == null)
                    {
                        if (!KunosEventObjectBase.OptionIgnoreMissingSkins)
                        {
                            AddError(AcErrorType.Data_KunosCareerCarSkinIsMissing, car.DisplayName, section.GetNonEmpty("SKIN"));
                        }

                        carSkin = (CarSkinObject)car.SkinsManager.WrappersList.RandomElementOrDefault()?.Loaded();
                    }
                }

                return(new ChampionshipDriverEntry {
                    Id = id,
                    Name = section.GetPossiblyEmpty("DRIVER_NAME"),
                    Nationality = section.GetPossiblyEmpty("NATIONALITY"),
                    AiLevel = section.GetInt("AI_LEVEL", 100),
                    SetupId = section.GetPossiblyEmpty("SETUP"),
                    Car = car,
                    CarSkin = carSkin
                });
            }).Prepend(new ChampionshipDriverEntry {
                Id          = -1,
                Name        = SettingsHolder.Drive.PlayerName,
                Nationality = SettingsHolder.Drive.PlayerNationality,
                Car         = firstEvent?.CarObject,
                CarSkin     = firstEvent?.CarSkin,
                IsPlayer    = true
            });

            ChampionshipDrivers.ReplaceEverythingBy(drivers);
        }