private static string GetValue(Game.StartProperties startProperties, [CanBeNull] Game.Result result, string key) {
            if (startProperties.BasicProperties == null) return null;

            switch (key) {
                case "type":
                    return GetType(startProperties, result);
                case "car":
                    return CarsManager.Instance.GetById(startProperties.BasicProperties.CarId)?.DisplayName;
                case "car.id":
                    return startProperties.BasicProperties.CarId;
                case "track":
                    var track = TracksManager.Instance.GetById(startProperties.BasicProperties.TrackId);
                    var config = startProperties.BasicProperties.TrackConfigurationId != null
                            ? track?.GetLayoutByLayoutId(startProperties.BasicProperties.TrackConfigurationId) : track;
                    return config?.Name;
                case "track.id":
                    return startProperties.BasicProperties.TrackId;
                case "date":
                    return startProperties.StartTime.ToString(CultureInfo.CurrentCulture);
                case "date_ac":
                    return GetAcDate(startProperties.StartTime);
                default:
                    return null;
            }
        }
        public static string GetType(Game.StartProperties startProperties, [CanBeNull] Game.Result result) {
            // TODO: drag mode
            if (startProperties.ModeProperties is Game.DriftProperties) {
                return "Drift";
            }

            if (startProperties.ModeProperties is Game.TimeAttackProperties) {
                return "Time Attack";
            }

            if (startProperties.ModeProperties is Game.HotlapProperties) {
                return "Hotlap";
            }

            if (startProperties.ModeProperties is Game.OnlineProperties) {
                return "Online";
            }

            if (startProperties.ModeProperties is Game.PracticeProperties) {
                return "Practice";
            }

            if (result?.Sessions?.Length == 1) {
                return "Race";
            }

            if (result?.Sessions?.Length > 1) {
                return "Weekend";
            }

            return startProperties.ModeProperties is Game.RaceProperties ? "Race" : "Something Unspeakable";
        }
Beispiel #3
0
        public int GetTakenPlace(Game.Result result) {
            if (result == null) return UnremarkablePlace;

            var drift = result.GetExtraByType<Game.ResultExtraDrift>();
            if (drift != null && Type == PlaceConditionsType.Points) {
                return GetTakenPlace(drift.Points);
            }

            var timeAttack = result.GetExtraByType<Game.ResultExtraTimeAttack>();
            if (timeAttack != null && Type == PlaceConditionsType.Points) {
                return GetTakenPlace(timeAttack.Points);
            }

            switch (Type) {
                case PlaceConditionsType.Points:
                    return UnremarkablePlace;
                case PlaceConditionsType.Position:
                    var place = result.Sessions.LastOrDefault(x => x.BestLaps.Any())?.CarPerTakenPlace?.IndexOf(0);
                    return place.HasValue ? GetTakenPlace(place.Value + 1) : UnremarkablePlace;
                case PlaceConditionsType.Time:
                    var time = result.Sessions.LastOrDefault(x => x.BestLaps.Any())?.BestLaps.FirstOrDefault(x => x.CarNumber == 0)?.Time;
                    return time.HasValue ? GetTakenPlace((int)time.Value.TotalMilliseconds) : UnremarkablePlace;
                default:
                    throw new ArgumentOutOfRangeException();
            }
        }
Beispiel #4
0
        internal ReplayHelper(Game.StartProperties startProperties, Game.Result result) {
            OriginalFilename = Path.Combine(FileUtils.GetReplaysDirectory(), ReplayObject.PreviousReplayName);
            RenamedFilename = FileUtils.EnsureUnique(OriginalFilename);
            Name = GetReplayName(startProperties, result);

            IsAvailable = File.Exists(OriginalFilename);
            if (IsAvailable && SettingsHolder.Drive.AutoSaveReplays) {
                IsRenamed = true;
            }
        }
 public override async Task Drive(Game.BasicProperties basicProperties, Game.AssistsProperties assistsProperties,
         Game.ConditionProperties conditionProperties, Game.TrackProperties trackProperties) {
     await StartAsync(new Game.StartProperties {
         BasicProperties = basicProperties,
         AssistsProperties = assistsProperties,
         ConditionProperties = conditionProperties,
         TrackProperties = trackProperties,
         ModeProperties = new Game.TimeAttackProperties {
             Penalties = Penalties
         }
     });
 }
 public override async Task Drive(Game.BasicProperties basicProperties, Game.AssistsProperties assistsProperties,
         Game.ConditionProperties conditionProperties, Game.TrackProperties trackProperties) {
     await StartAsync(new Game.StartProperties {
         BasicProperties = basicProperties,
         AssistsProperties = assistsProperties,
         ConditionProperties = conditionProperties,
         TrackProperties = trackProperties,
         ModeProperties = new Game.HotlapProperties {
             Penalties = Penalties,
             GhostCar = GhostCar,
             GhostCarAdvantage = GhostCarAdvantage,
             RecordGhostCar = SettingsHolder.Drive.AlwaysRecordGhost ? true : (bool?)null
         }
     });
 }
Beispiel #7
0
        void IGameUi.Show(Game.StartProperties properties) {
            _properties = properties;

            ShowDialogWithoutBlocking();
            Model.WaitingStatus = AppStrings.Race_Initializing;
        }
Beispiel #8
0
        private static BaseFinishedData GetFinishedData(Game.StartProperties properties, Game.Result result) {
            var conditions = properties?.GetAdditional<PlaceConditions>();
            var takenPlace = conditions?.GetTakenPlace(result) ?? PlaceConditions.UnremarkablePlace;

            Logging.Debug($"Place conditions: {conditions?.GetDescription()}, result: {result.GetDescription()}");

            {
                var extra = result.GetExtraByType<Game.ResultExtraDrift>();
                if (extra != null) {
                    return new DriftFinishedData {
                        Points = extra.Points,
                        MaxCombo = extra.MaxCombo,
                        MaxLevel = extra.MaxLevel,
                        TakenPlace = takenPlace
                    };
                }
            }

            {
                var extra = result.GetExtraByType<Game.ResultExtraTimeAttack>();
                if (extra != null) {
                    var bestLapTime = result.Sessions.SelectMany(x => from lap in x.BestLaps where lap.CarNumber == 0 select lap.Time).MinOrDefault();
                    return new TimeAttackFinishedData {
                        Points = extra.Points,
                        Laps = result.Sessions.Sum(x => x.LapsTotalPerCar.FirstOrDefault()),
                        BestLapTime = bestLapTime == TimeSpan.Zero ? (TimeSpan?)null : bestLapTime,
                        TakenPlace = takenPlace
                    };
                }
            }

            {
                var extra = result.GetExtraByType<Game.ResultExtraBestLap>();
                if (extra != null && extra.IsNotCancelled && result.Sessions.Length == 1 && result.Players.Length == 1) {
                    var bestLapTime = result.Sessions.SelectMany(x => from lap in x.BestLaps where lap.CarNumber == 0 select lap.Time).MinOrDefault();

                    var sectorsPerSections = result.Sessions.SelectMany(x => from lap in x.Laps where lap.CarNumber == 0 select lap.SectorsTime).ToList();
                    var theoreticallLapTime = sectorsPerSections.FirstOrDefault()?.Select((x, i) => sectorsPerSections.Select(y => y[i]).Min()).Sum();

                    return new HotlapFinishedData {
                        Laps = result.Sessions.Sum(x => x.LapsTotalPerCar.FirstOrDefault()),
                        BestLapTime = bestLapTime == TimeSpan.Zero ? (TimeSpan?)null : bestLapTime,
                        TheoreticallLapTime = theoreticallLapTime,
                        TakenPlace = takenPlace
                    };
                }
            }

            var isOnline = properties?.ModeProperties is Game.OnlineProperties;
            var playerName = isOnline && SettingsHolder.Drive.DifferentPlayerNameOnline ? SettingsHolder.Drive.PlayerNameOnline : SettingsHolder.Drive.PlayerName;

            var sessionsData = (from session in result.Sessions
                                let takenPlaces = session.GetTakenPlacesPerCar()
                                select new SessionFinishedData(session.Name.ApartFromLast(@" Session")) {
                                    PlayerEntries = (
                                            from player in result.Players
                                            let car = CarsManager.Instance.GetById(player.CarId)
                                            let carSkin = car.GetSkinById(player.CarSkinId)
                                            select new { Player = player, Car = car, CarSkin = carSkin }
                                            ).Select((entry, i) => new SessionFinishedData.PlayerEntry {
                                                Name = i == 0 ? playerName : entry.Player.Name,
                                                IsPlayer = i == 0,
                                                Car = entry.Car,
                                                CarSkin = entry.CarSkin,

                                                TakenPlace = takenPlaces.ElementAtOrDefault(i) + 1,
                                                PrizePlace = takenPlaces.Length > 1,
                                                LapsCount = session.LapsTotalPerCar.ElementAtOrDefault(i),
                                                BestLapTime = session.BestLaps.Where(x => x.CarNumber == i).MinEntryOrDefault(x => x.Time)?.Time,
                                                Total = session.Laps.Where(x => x.CarNumber == i).Select(x => x.Time).Sum()
                                            }).OrderBy(x => x.TakenPlace).ToList()
                                }).ToList();

            return sessionsData.Count == 1 ? (BaseFinishedData)sessionsData.First() :
                    sessionsData.Any() ? new SessionsFinishedData(sessionsData) : null;
        }
Beispiel #9
0
 void IGameUi.OnProgress(Game.ProgressState progress) {
     switch (progress) {
         case Game.ProgressState.Preparing:
             Model.WaitingStatus = AppStrings.Race_Preparing;
             break;
         case Game.ProgressState.Launching:
             Model.WaitingStatus = AppStrings.Race_LaunchingGame;
             break;
         case Game.ProgressState.Waiting:
             Model.WaitingStatus = AppStrings.Race_Waiting;
             break;
         case Game.ProgressState.Finishing:
             Model.WaitingStatus = AppStrings.Race_CleaningUp;
             break;
         default:
             throw new ArgumentOutOfRangeException(nameof(progress), progress, null);
     }
 }
Beispiel #10
0
 internal CommonSessionResult(Game.ResultSession parsedData) {
     DisplayName = parsedData.Type.GetDisplayName() ?? parsedData.Name.ApartFromLast(@" Session", StringComparison.OrdinalIgnoreCase);
 }
 public abstract Task Drive(Game.BasicProperties basicProperties,
         Game.AssistsProperties assistsProperties,
         Game.ConditionProperties conditionProperties, Game.TrackProperties trackProperties);
 protected Task StartAsync(Game.StartProperties properties) {
     return GameWrapper.StartAsync(properties);
 }
Beispiel #13
0
            public override async Task Drive(Game.BasicProperties basicProperties, Game.AssistsProperties assistsProperties,
                    Game.ConditionProperties conditionProperties, Game.TrackProperties trackProperties) {
                var selectedCar = CarsManager.Instance.GetById(basicProperties.CarId);
                var selectedTrack = TracksManager.Instance.GetLayoutById(basicProperties.TrackId, basicProperties.TrackConfigurationId);

                IEnumerable<Game.AiCar> botCars;

                try {
                    using (var waiting = new WaitingDialog()) {
                        if (selectedCar == null || !selectedCar.Enabled) {
                            ModernDialog.ShowMessage(AppStrings.Drive_CannotStart_SelectNonDisabled, AppStrings.Drive_CannotStart_Title, MessageBoxButton.OK);
                            return;
                        }

                        if (selectedTrack == null) {
                            ModernDialog.ShowMessage(AppStrings.Drive_CannotStart_SelectTrack, AppStrings.Drive_CannotStart_Title, MessageBoxButton.OK);
                            return;
                        }

                        botCars = await RaceGridViewModel.GenerateGameEntries(waiting.CancellationToken);
                        if (waiting.CancellationToken.IsCancellationRequested) return;

                        if (botCars == null || !botCars.Any()) {
                            ModernDialog.ShowMessage(AppStrings.Drive_CannotStart_SetOpponent, AppStrings.Drive_CannotStart_Title, MessageBoxButton.OK);
                            return;
                        }
                    }
                } catch (TaskCanceledException) {
                    return;
                }

                await StartAsync(new Game.StartProperties {
                    BasicProperties = basicProperties,
                    AssistsProperties = assistsProperties,
                    ConditionProperties = conditionProperties,
                    TrackProperties = trackProperties,
                    ModeProperties = GetModeProperties(botCars)
                });
            }
 protected GameCommandExecutorBase(Game.StartProperties properties) {
     _properties = properties;
 }
Beispiel #15
0
        void IGameUi.OnResult(Game.Result result, ReplayHelper replayHelper) {
            if (result != null && result.NumberOfSessions == 1 && result.Sessions.Length == 1
                    && result.Sessions[0].Type == Game.SessionType.Practice && SettingsHolder.Drive.SkipPracticeResults
                    || _properties?.ReplayProperties != null || _properties?.BenchmarkProperties != null) {
                Close();
                return;
            }

            /* save replay button * /
            Func<string> buttonText = () => replayHelper?.IsReplayRenamed == true ?
                    AppStrings.RaceResult_UnsaveReplay : AppStrings.RaceResult_SaveReplay;

            var saveReplayButton = CreateExtraDialogButton(buttonText(), () => {
                if (replayHelper == null) {
                    Logging.Warning("ReplayHelper=<NULL>");
                    return;
                }

                replayHelper.IsReplayRenamed = !replayHelper.IsReplayRenamed;
            });

            if (replayHelper == null) {
                saveReplayButton.IsEnabled = false;
            } else {
                replayHelper.PropertyChanged += (sender, args) => {
                    if (args.PropertyName == nameof(ReplayHelper.IsReplayRenamed)) {
                        saveReplayButton.Content = buttonText();
                    }
                };
            }

            /* save replay alt button */
            ButtonWithComboBox saveReplayButton;
            if (replayHelper != null) {
                Func<string> buttonText = () => replayHelper.IsRenamed ?
                        AppStrings.RaceResult_UnsaveReplay : AppStrings.RaceResult_SaveReplay;
                Func<string> saveAsText = () => string.Format(replayHelper.IsRenamed ? "Saved as “{0}”" : "Save as “{0}”",
                        replayHelper.Name);

                saveReplayButton = new ButtonWithComboBox {
                    Margin = new Thickness(4, 0, 0, 0),
                    MinHeight = 21,
                    MinWidth = 65,
                    Content = ToolsStrings.Shared_Replay,
                    Command = new AsyncCommand(replayHelper.Play),
                    MenuItems = {
                        new MenuItem { Header = saveAsText(), Command = new DelegateCommand(() => {
                            var newName = Prompt.Show("Save replay as:", "Replay Name", replayHelper.Name, "?", required: true);
                            if (!string.IsNullOrWhiteSpace(newName)) {
                                replayHelper.Name = newName;
                            }

                            replayHelper.IsRenamed = true;
                        }) },
                        new MenuItem { Header = buttonText(), Command = new DelegateCommand(replayHelper.Rename) },
                        new Separator(),
                        new MenuItem {
                            Header = "Share Replay",
                            Command = new AsyncCommand(() => {
                                var car = _properties?.BasicProperties?.CarId == null ? null :
                                        CarsManager.Instance.GetById(_properties.BasicProperties.CarId);
                                var track = _properties?.BasicProperties?.TrackId == null ? null :
                                        TracksManager.Instance.GetById(_properties.BasicProperties.TrackId);
                                return SelectedReplayPage.ShareReplay(replayHelper.Name, replayHelper.Filename, car, track);
                            })
                        },
                    }
                };
                
                replayHelper.PropertyChanged += (sender, args) => {
                    if (args.PropertyName == nameof(ReplayHelper.IsRenamed)) {
                        ((MenuItem)saveReplayButton.MenuItems[0]).Header = saveAsText();
                        ((MenuItem)saveReplayButton.MenuItems[1]).Header = buttonText();
                    }
                };
            } else {
                saveReplayButton = null;
            }

            var tryAgainButton = CreateExtraDialogButton(AppStrings.RaceResult_TryAgain, () => {
                CloseWithResult(MessageBoxResult.None);
                GameWrapper.StartAsync(_properties).Forget();
            });

            Button fixButton = null;

            if (result == null || !result.IsNotCancelled) {
                Model.CurrentState = ViewModel.State.Cancelled;

                var whatsGoingOn = _properties?.GetAdditional<AcLogHelper.WhatsGoingOn>();
                fixButton = this.CreateFixItButton(whatsGoingOn?.Solution);
                Model.ErrorMessage = whatsGoingOn?.GetDescription();
            } else {
                try {
                    Model.CurrentState = ViewModel.State.Finished;
                    Model.FinishedData = GetFinishedData(_properties, result);
                } catch (Exception e) {
                    Logging.Warning(e);

                    Model.CurrentState = ViewModel.State.Error;
                    Model.ErrorMessage = AppStrings.RaceResult_ResultProcessingError;
                    Buttons = new[] { CloseButton };
                    return;
                }
            }

            Buttons = new[] {
                fixButton,
                fixButton == null ? saveReplayButton : null,
                fixButton == null ? tryAgainButton : null,
                CloseButton
            };
        }
 public ReplayCommandExecutor(Game.StartProperties properties) : base(properties) { }
Beispiel #17
0
 public GameFinishedArgs([NotNull] Game.StartProperties startProperties, Game.Result result) {
     StartProperties = startProperties;
     Result = result;
 }