private void OnRaceFinished(object sender, GameEndedArgs e) { RaiseEntriesChanged(); var basic = e.StartProperties.BasicProperties; var bestLap = e.Result?.GetExtraByType <Game.ResultExtraBestLap>(); var carId = basic?.CarId; var trackId = basic?.TrackId; if (trackId != null && basic.TrackConfigurationId != null) { trackId = $@"{trackId}/{basic.TrackConfigurationId}"; } TimeSpan?time; if (SettingsHolder.Drive.WatchForSharedMemory) { var last = PlayerStatsManager.Instance.Last; if (last == null) { Logging.Warning("Race finished, but PlayerStatsManager.Instance.Last is missing"); return; } if (carId == null) { carId = last.CarId; } if (trackId == null) { trackId = last.TrackId; } var sharedTime = last.BestLap; if (!sharedTime.HasValue) { Logging.Warning("No laptime has been set"); return; } time = sharedTime.Value; } else { time = carId == null || trackId == null || bestLap == null || bestLap.IsCancelled ? (TimeSpan?)null : bestLap.Time; } if (time.HasValue && carId != null && trackId != null) { AddEntry(carId, trackId, DateTime.Now, time.Value).Forget(); } else { Logging.Warning($"Can’t save new lap time: time={time}, car={carId}, track={trackId}"); } }
private void OnRaceFinished(object sender, GameEndedArgs e) { var basic = e.StartProperties.BasicProperties; var bestLap = e.Result?.GetExtraByType <Game.ResultExtraBestLap>(); var carId = basic?.CarId; var trackId = basic?.TrackId; if (trackId != null && basic.TrackConfigurationId != null) { trackId = $@"{trackId}/{basic.TrackConfigurationId}"; } var time = carId == null || trackId == null || bestLap == null || bestLap.IsCancelled ? (TimeSpan?)null : bestLap.Time; if (SettingsHolder.Drive.WatchForSharedMemory) { var last = PlayerStatsManager.Instance.Last; if (last != null) { if (carId == null) { carId = last.CarId; } if (trackId == null) { trackId = last.TrackId; } var sharedTime = last.BestLap; if (sharedTime.HasValue) { time = sharedTime.Value; } } } if (time.HasValue && carId != null && trackId != null) { Logging.Here(); AddEntry(new LapTimeEntry(SourceId, carId, trackId, DateTime.Now, time.Value)); NewEntryAdded?.Invoke(this, EventArgs.Empty); } else { Logging.Warning($"Can’t save new lap time: time={time}, car={carId}, track={trackId}"); } }
private void OnGameEnded(object sender, GameEndedArgs e) { Active = false; EnsureStoppedLater().Forget(); }
private async void OnGameWrapperEnded(object sender, GameEndedArgs e) { await Task.Delay(5000); _raceStartedByCm = false; }
private void OnRaceFinished(object sender, GameEndedArgs e) { RaiseEntriesChanged(); var basic = e.StartProperties.BasicProperties; var carId = basic?.CarId; var trackId = basic?.TrackId; if (trackId != null && basic.TrackConfigurationId != null) { trackId = $@"{trackId}/{basic.TrackConfigurationId}"; } TimeSpan?time; if (e.Result?.GetExtraByType <Game.ResultExtraDrag>() != null) { if (CarsManager.Instance.GetById(carId ?? "")?.UseCustomData == true && e.StartProperties.GetAdditional <CarCustomDataHelper>() != null) { Logging.Warning("Race finished, but custom data was enabled"); return; } time = e.Result.Sessions?.Where(x => x.Type == Game.SessionType.Drag) .SelectMany(x => x.BestLaps?.Where(y => y.CarNumber == 0) ?? new Game.ResultBestLap[0]) .MinEntryOrDefault(x => x.Time)?.Time; } else if (SettingsHolder.Drive.WatchForSharedMemory) { var last = PlayerStatsManager.Instance.Last; if (last == null) { Logging.Warning("Race finished, but PlayerStatsManager.Instance.Last is missing"); return; } if (last.IsSpoiled) { Logging.Warning("Race finished, but PlayerStatsManager.Instance.Last is spoiled: " + last.SpoiledReason); return; } if (carId == null) { carId = last.CarId; } if (trackId == null) { trackId = last.TrackId; } var sharedTime = last.BestLap; if (!sharedTime.HasValue) { Logging.Warning("No laptime has been set"); return; } time = sharedTime.Value; } else { var bestLap = e.Result?.GetExtraByType <Game.ResultExtraBestLap>(); time = carId == null || trackId == null || bestLap == null || bestLap.IsCancelled ? (TimeSpan?)null : bestLap.Time; } if (time.HasValue && carId != null && trackId != null) { AddEntry(carId, trackId, DateTime.Now, time.Value).Ignore(); } else { Logging.Warning($"Can’t save new lap time: time={time}, car={carId}, track={trackId}"); } }
private void OnGameEnded(object sender, GameEndedArgs args) { IsGameEnded = true; GameResultText = args.WinnerColor == _yourColor ? "Congratulations! You are winner!" : "You have lose."; }