Ejemplo n.º 1
0
        private StandingOverviewViewModel CreateStandingOverviewViewModel(ChampionshipDto championship)
        {
            var standingOverviewViewModel = _viewModelFactory.Create <StandingOverviewViewModel>();

            standingOverviewViewModel.FromModel(championship.Drivers);
            return(standingOverviewViewModel);
        }
Ejemplo n.º 2
0
        public void AddResultsForCurrentSession(ChampionshipDto championship, SimulatorDataSet dataSet, bool shiftPlayerToLastPlace)
        {
            var currentEvent   = championship.GetCurrentOrLastEvent();
            var currentSession = currentEvent.Sessions[championship.CurrentSessionIndex];

            currentSession.SessionResult = CreateResultDto(championship, dataSet, shiftPlayerToLastPlace);
        }
Ejemplo n.º 3
0
 public void UpdateChampionship(ChampionshipDto championshipDto)
 {
     AllChampionshipsDto.Championships.RemoveAll(x => x.ChampionshipGlobalId == championshipDto.ChampionshipGlobalId);
     AllChampionshipsDto.Championships.Add(championshipDto);
     _championshipsRepository.Save(AllChampionshipsDto);
     ChampionshipUpdated?.Invoke(this, new ChampionshipEventArgs(championshipDto));
 }
Ejemplo n.º 4
0
 public void FillScoring(ChampionshipDto championshipDto, ChampionshipCreationViewModel championshipCreationViewModel)
 {
     championshipDto.Scoring = championshipCreationViewModel.SessionsDefinitionViewModel.SessionsDefinitions.Select(x => new ScoringDto()
     {
         Scoring = x.Scoring.ToList(),
     }).ToList();
 }
        private void CreateNewChampionship()
        {
            _championshipCreated = true;
            ChampionshipDto newChampionshipDto = _championshipFactory.Create(_championshipCreationViewModel);

            _newChampionshipCallback(newChampionshipDto);
            //_dialogWindow.Close();
        }
Ejemplo n.º 6
0
        public void EventFinished(ChampionshipDto championship)
        {
            if (championship != null)
            {
                _championshipsPool.UpdateChampionship(championship);
            }

            ReEvaluateChampionships(_sessionEventProvider.LastDataSet);
        }
Ejemplo n.º 7
0
        public RequirementResultKind Evaluate(ChampionshipDto championshipDto, SimulatorDataSet dataSet)
        {
            if (championshipDto.ChampionshipState == ChampionshipState.NotStarted)
            {
                return(RequirementResultKind.CanMatch);
            }

            return(dataSet.PlayerInfo.CarClassName == championshipDto.ClassName ? RequirementResultKind.PerfectMatch : RequirementResultKind.DoesNotMatch);
        }
Ejemplo n.º 8
0
        public void OpenChampionshipDetailsWindow(ChampionshipDto championship)
        {
            var detailViewModel = _viewModelFactory.Create <ChampionshipDetailViewModel>();

            detailViewModel.FromModel(championship);
            Window window = _windowService.OpenWindow(detailViewModel, "Championships Details", WindowState.Maximized, SizeToContent.Manual, WindowStartupLocation.CenterOwner);

            detailViewModel.ChampionshipSessionsResults.CloseCommand = new RelayCommand(() => CloseWindow(window));
        }
Ejemplo n.º 9
0
        private void UpdateResultsName(ChampionshipDto championship)
        {
            var driverDictionary = championship.GetGuidToDriverDictionary();

            foreach (var driverResult in championship.GetAllResults().SelectMany(x => x.DriverSessionResult))
            {
                driverResult.DriverName = driverDictionary[driverResult.DriverGuid].LastUsedName;
            }
        }
Ejemplo n.º 10
0
        public string GetDescription(ChampionshipDto championshipDto)
        {
            if (championshipDto.ChampionshipState == ChampionshipState.NotStarted)
            {
                return(championshipDto.AiNamesCanChange ? "Use the opponents count, you would like to run the whole championship with. Their names do not matter." : "Use opponents, you would like to run the championship with. Their names need to match for all races");
            }

            return(championshipDto.AiNamesCanChange ? $"Requires {championshipDto.TotalDrivers - 1} opponents. Opponents names can change from previous event." : $"Requires {championshipDto.TotalDrivers - 1} opponents. Opponents names has to be the same, as in previous events. Check championship details if you need the list of all drivers.");
        }
Ejemplo n.º 11
0
        public void ShowLastEvenResultWindow(ChampionshipDto championship)
        {
            var sessionCompletedViewmodel = _viewModelFactory.Create <SessionCompletedViewModel>();

            (EventDto eventDto, SessionDto sessionDto) = championship.GetLastSessionWithResults();
            var lastResult = sessionDto.SessionResult;

            if (lastResult == null)
            {
                return;
            }

            sessionCompletedViewmodel.Title = "Session Completed";

            var podiumViewModel = _viewModelFactory.Create <PodiumViewModel>();

            podiumViewModel.FromModel(lastResult);

            var driversFinishViewModel = _viewModelFactory.Create <SessionResultViewModel>();

            driversFinishViewModel.Header = "Session Results";
            driversFinishViewModel.FromModel(lastResult);

            var driversNewStandingsViewModel = _viewModelFactory.Create <DriversNewStandingsViewModel>();

            driversNewStandingsViewModel.EventTitleViewModel.FromModel((championship, eventDto, sessionDto));
            driversNewStandingsViewModel.EventTitleViewModel.ChampionshipName = "Current Standings";
            driversNewStandingsViewModel.FromModel(lastResult);

            sessionCompletedViewmodel.Screens.Add(podiumViewModel);
            sessionCompletedViewmodel.Screens.Add(driversFinishViewModel);
            sessionCompletedViewmodel.Screens.Add(driversNewStandingsViewModel);


            if (championship.ChampionshipState == ChampionshipState.Finished)
            {
                DriverDto player = championship.Drivers.First(x => x.IsPlayer);
                if (player.Position <= 3)
                {
                    var trophyViewModel = _viewModelFactory.Create <TrophyViewModel>();
                    trophyViewModel.Position   = player.Position;
                    trophyViewModel.DriverName = player.LastUsedName;
                    sessionCompletedViewmodel.Screens.Add(trophyViewModel);
                }
                var championshipFinalStandings = _viewModelFactory.Create <StandingOverviewViewModel>();
                championshipFinalStandings.Header = "Final Standing: ";
                championshipFinalStandings.FromModel(championship.Drivers.OrderBy(x => x.Position));
                sessionCompletedViewmodel.Screens.Add(championshipFinalStandings);
            }

            Window window = _windowService.OpenWindow(sessionCompletedViewmodel, "Session Completed", WindowState.Maximized, SizeToContent.Manual, WindowStartupLocation.CenterOwner);

            sessionCompletedViewmodel.CloseCommand = new RelayCommand(() => CloseWindow(window));
        }
Ejemplo n.º 12
0
        public RequirementResultKind Evaluate(ChampionshipDto championshipDto, SimulatorDataSet dataSet)
        {
            var currentEvent = championshipDto.Events[championshipDto.CurrentEventIndex];

            if (currentEvent.IsTrackNameExact)
            {
                return(currentEvent.TrackName == dataSet.SessionInfo.TrackInfo.TrackFullName ? RequirementResultKind.PerfectMatch : RequirementResultKind.DoesNotMatch);
            }

            return(RequirementResultKind.CanMatch);
        }
Ejemplo n.º 13
0
        public string GetDescription(ChampionshipDto championshipDto)
        {
            if (championshipDto.ChampionshipState == ChampionshipState.Finished)
            {
                return(string.Empty);
            }

            EventDto eventDto = championshipDto.Events[championshipDto.CurrentEventIndex];

            return(eventDto.IsTrackNameExact ? $"Track has to be {eventDto.TrackName}" : $"Track should be {eventDto.TrackName}, but different track can be used.");
        }
Ejemplo n.º 14
0
        public string GetDescription(ChampionshipDto championshipDto)
        {
            if (championshipDto.ChampionshipState == ChampionshipState.Finished)
            {
                return(string.Empty);
            }

            SessionDto sessionDto = championshipDto.Events[championshipDto.CurrentEventIndex].Sessions[championshipDto.CurrentSessionIndex];

            return($"Session length should be {sessionDto.DistanceDescription}, but this is not enforced.");
        }
Ejemplo n.º 15
0
        private void DnfSelectedChampionshipSession()
        {
            if (_championshipOverviewViewModel.SelectedChampionship == null)
            {
                return;
            }

            ChampionshipDto selectedChampionship = _championshipOverviewViewModel.SelectedChampionship.OriginalModel;

            _championshipManipulator.CommitLastSessionResults(selectedChampionship);
            _championshipsPool.UpdateChampionship(selectedChampionship);

            ShowLastEvenResultWindow(selectedChampionship);
        }
Ejemplo n.º 16
0
        private void InitializeDrivers(ChampionshipDto championship, SimulatorDataSet dataSet)
        {
            int position = 0;
            List <DriverInfo> eligibleDrivers = dataSet.DriversInfo.Where(x => x.CarClassId == dataSet.PlayerInfo.CarClassId).ToList();

            championship.ClassName    = dataSet.PlayerInfo.CarClassName;
            championship.TotalDrivers = eligibleDrivers.Count;
            championship.Drivers      = eligibleDrivers.Select(x => new DriverDto()
            {
                LastUsedName = x.DriverName,
                IsPlayer     = x.IsPlayer,
                Position     = ++position,
                LastCarName  = x.CarName,
            }).ToList();
        }
Ejemplo n.º 17
0
        public RequirementResultKind Evaluate(ChampionshipDto championshipDto, SimulatorDataSet dataSet)
        {
            if (championshipDto.ChampionshipState == ChampionshipState.NotStarted)
            {
                return(RequirementResultKind.CanMatch);
            }

            List <string> filteredDrivers = dataSet.DriversInfo.Where(x => x.CarClassId == dataSet.PlayerInfo.CarClassId).Select(x => x.DriverName).ToList();

            if (championshipDto.AiNamesCanChange)
            {
                return(championshipDto.Drivers.Count == filteredDrivers.Count ? RequirementResultKind.PerfectMatch : RequirementResultKind.DoesNotMatch);
            }

            return(filteredDrivers.All(x => championshipDto.Drivers.Any(y => y.LastUsedName == x)) ? RequirementResultKind.PerfectMatch : RequirementResultKind.DoesNotMatch);
        }
Ejemplo n.º 18
0
        public ChampionshipDto Create(ChampionshipCreationViewModel championshipCreationViewModel)
        {
            ChampionshipDto championship = new ChampionshipDto()
            {
                ChampionshipState = ChampionshipState.NotStarted,
                SimulatorName     = championshipCreationViewModel.SelectedSimulator,
                ChampionshipName  = championshipCreationViewModel.ChampionshipTitle,
                AiNamesCanChange  = championshipCreationViewModel.AiNamesCanChange
            };

            FillEvents(championship, championshipCreationViewModel);
            FillScoring(championship, championshipCreationViewModel);
            championship.NextTrack   = championship.Events[0].TrackName;
            championship.TotalEvents = championship.Events.Count * championship.Events[0].Sessions.Count;
            return(championship);
        }
Ejemplo n.º 19
0
        public void ShowWelcomeScreen(SimulatorDataSet dataSet, ChampionshipDto championship)
        {
            var eventStartingViewModel = _viewModelFactory.Create <EventStartingViewModel>();

            EventDto   currentEvent   = championship.GetCurrentOrLastEvent();
            SessionDto currentSession = currentEvent.Sessions[championship.CurrentSessionIndex];

            eventStartingViewModel.EventTitleViewModel.FromModel((championship, currentEvent, currentSession));

            eventStartingViewModel.Screens.Add(CreateTrackOverviewViewModel(dataSet, championship));
            eventStartingViewModel.Screens.Add(CreateStandingOverviewViewModel(championship));

            Window window = _windowService.OpenWindow(eventStartingViewModel, "Event Starting", WindowState.Maximized, SizeToContent.Manual, WindowStartupLocation.CenterOwner);

            eventStartingViewModel.CloseCommand = new RelayCommand(() => CloseWindow(window));
        }
        public RequirementResultKind EvaluateChampionship(ChampionshipDto championship, SimulatorDataSet simulatorData)
        {
            List <RequirementResultKind> evaluationResult = _conditions.Select(x => x.Evaluate(championship, simulatorData)).ToList();

            if (evaluationResult.Any(x => x == RequirementResultKind.DoesNotMatch))
            {
                return(RequirementResultKind.DoesNotMatch);
            }

            if (evaluationResult.All(x => x == RequirementResultKind.PerfectMatch))
            {
                return(RequirementResultKind.PerfectMatch);
            }

            return(RequirementResultKind.CanMatch);
        }
Ejemplo n.º 21
0
        public void CommitLastSessionResults(ChampionshipDto championship)
        {
            var currentEvent         = championship.GetCurrentOrLastEvent();
            var currentSession       = currentEvent.Sessions[championship.CurrentSessionIndex];
            var guidDriverDictionary = championship.GetGuidToDriverDictionary();

            if (currentSession.SessionResult == null)
            {
                return;
            }

            foreach (DriverSessionResultDto driverSessionResultDto in currentSession.SessionResult.DriverSessionResult)
            {
                DriverDto driverDto = guidDriverDictionary[driverSessionResultDto.DriverGuid];
                driverDto.TotalPoints = driverSessionResultDto.TotalPoints;
                driverDto.Position    = driverSessionResultDto.AfterEventPosition;
            }
            AdvanceChampionship(championship);
        }
Ejemplo n.º 22
0
        public void StartNextEvent(ChampionshipDto championship)
        {
            Logger.Info($"Starting new Event {championship.ChampionshipName}");
            _runningChampionship = championship;
            if (_runningChampionship.ChampionshipState == ChampionshipState.NotStarted)
            {
                _championshipManipulator.StartChampionship(championship, _sessionEventProvider.LastDataSet);
            }
            else
            {
                _championshipManipulator.UpdateAiDriversNames(championship, _sessionEventProvider.LastDataSet);
            }

            _championshipManipulator.StartNextEvent(championship, _sessionEventProvider.LastDataSet);
            InitializePropertiesOnSessionStart(_sessionEventProvider.LastDataSet);

            IsChampionshipActive = true;
            ShowWelcomeScreen(_sessionEventProvider.LastDataSet);
        }
Ejemplo n.º 23
0
        private void SessionEventProviderOnPlayerFinishStateChanged(object sender, DataSetArgs e)
        {
            if (!IsChampionshipActive)
            {
                return;
            }

            if (e.DataSet.PlayerInfo.FinishStatus == DriverFinishStatus.Finished && _sessionEventProvider.BeforeLastDataSet?.SessionInfo?.SessionType == SessionType.Race && _isSessionRace && !_hasPlayerFinished)
            {
                _hasPlayerFinished = true;
                _championshipManipulator.AddResultsForCurrentSession(_runningChampionship, e.DataSet);
                _championshipManipulator.CommitLastSessionResults(_runningChampionship);
                _championshipDialogProvider.ShowLastEvenResultWindow(_runningChampionship);
                FinishCurrentEvent(e.DataSet);
                _runningChampionship = null;
            }

            _hasPlayerFinished = e.DataSet.PlayerInfo.FinishStatus == DriverFinishStatus.Finished;
        }
Ejemplo n.º 24
0
        private void AdvanceChampionship(ChampionshipDto championship)
        {
            var currentEvent = championship.GetCurrentOrLastEvent();

            championship.CurrentSessionIndex = (championship.CurrentSessionIndex + 1) % currentEvent.Sessions.Count;
            if (championship.CurrentSessionIndex == 0)
            {
                currentEvent.EventStatus = EventStatus.Finished;
                championship.CurrentEventIndex++;
                currentEvent = championship.GetCurrentOrLastEvent();

                if (currentEvent.EventStatus == EventStatus.NotStarted)
                {
                    currentEvent.EventStatus = EventStatus.InProgress;
                }
                championship.NextTrack = currentEvent.TrackName;
            }

            championship.ChampionshipState = championship.CurrentEventIndex >= championship.Events.Count ? ChampionshipState.Finished : ChampionshipState.Started;
        }
Ejemplo n.º 25
0
        public void UpdateAiDriversNames(ChampionshipDto championship, SimulatorDataSet dataSet)
        {
            List <DriverDto>  driverPool      = championship.Drivers.Where(x => !x.IsPlayer).ToList();
            List <DriverInfo> driversToAssign = dataSet.DriversInfo.Where(x => !x.IsPlayer && x.CarClassId == dataSet.PlayerInfo.CarClassId).ToList();

            //First iteration = use previous names
            foreach (DriverInfo driver in driversToAssign.ToList())
            {
                var driverMatch = driverPool.FirstOrDefault(x => x.LastUsedName == driver.DriverName);
                if (driverMatch == null)
                {
                    continue;
                }


                driverPool.Remove(driverMatch);
                driversToAssign.Remove(driver);
            }

            //Second iteration, try find drivers that previously used that name
            foreach (DriverInfo driver in driversToAssign.ToList())
            {
                var driverMatch = driverPool.FirstOrDefault(x => x.OtherNames.Contains(driver.DriverName));
                if (driverMatch == null)
                {
                    continue;
                }


                driverMatch.SetAnotherName(driver.DriverName);
                driverPool.Remove(driverMatch);
                driversToAssign.Remove(driver);
            }

            for (int i = 0; i < driverPool.Count; i++)
            {
                driverPool[i].SetAnotherName(driversToAssign[i].DriverName);
            }

            UpdateResultsName(championship);
        }
Ejemplo n.º 26
0
        private SessionResultDto CreateResultDto(ChampionshipDto championship, SimulatorDataSet dataSet, bool shiftPlayerToLastPlace)
        {
            var scoring = championship.Scoring[championship.CurrentSessionIndex];
            Dictionary <string, int> positionMap = CreateFinishPositionDictionary(dataSet.DriversInfo.Where(x => x.CarClassId == dataSet.PlayerInfo.CarClassId).ToList(), shiftPlayerToLastPlace);
            SessionResultDto         resultDto   = new SessionResultDto();

            foreach (DriverDto championshipDriver in championship.Drivers)
            {
                DriverInfo sessionDriver = dataSet.DriversInfo.FirstOrDefault(x => x.DriverName == championshipDriver.LastUsedName);
                if (sessionDriver == null)
                {
                    Logger.Error($"Driver {championshipDriver.LastUsedName} not found");
                    throw new InvalidOperationException($"Driver {championshipDriver.LastUsedName} not found");
                }
                int position = positionMap[sessionDriver.DriverName];
                DriverSessionResultDto driverResult = new DriverSessionResultDto()
                {
                    DriverGuid          = championshipDriver.GlobalKey,
                    DriverName          = championshipDriver.LastUsedName,
                    FinishPosition      = position,
                    PointsGain          = position <= scoring.Scoring.Count ? scoring.Scoring[position - 1] : 0,
                    BeforeEventPosition = championshipDriver.Position,
                    IsPlayer            = championshipDriver.IsPlayer,
                };
                driverResult.TotalPoints = championshipDriver.TotalPoints + driverResult.PointsGain;

                resultDto.DriverSessionResult.Add(driverResult);
            }

            DriverSessionResultComparer   comparer = new DriverSessionResultComparer(championship);
            List <DriverSessionResultDto> driversAfterRaceOrdered = resultDto.DriverSessionResult.OrderBy(x => x, comparer).ToList();

            for (int i = 0; i < driversAfterRaceOrdered.Count; i++)
            {
                driversAfterRaceOrdered[i].AfterEventPosition = i + 1;
            }

            return(resultDto);
        }
Ejemplo n.º 27
0
        private void FillEvents(ChampionshipDto championshipDto, ChampionshipCreationViewModel championshipCreationViewModel)
        {
            List <SessionDefinitionViewModel> sessionDefinitionViewModels = championshipCreationViewModel.SessionsDefinitionViewModel.SessionsDefinitions.ToList();

            championshipDto.Events = championshipCreationViewModel.CalendarDefinitionViewModel.CalendarViewModel.CalendarEntries.Select(x => CreateEvent(x, sessionDefinitionViewModels)).ToList();
        }
Ejemplo n.º 28
0
 public ChampionshipEventArgs(ChampionshipDto championshipDto)
 {
     ChampionshipDto = championshipDto;
 }
Ejemplo n.º 29
0
 public void AddNewChampionship(ChampionshipDto championshipDto)
 {
     AllChampionshipsDto.Championships.Add(championshipDto);
     _championshipsRepository.Save(AllChampionshipsDto);
     ChampionshipAdded?.Invoke(this, new ChampionshipEventArgs(championshipDto));
 }
Ejemplo n.º 30
0
 public string GetDescription(ChampionshipDto championshipDto)
 {
     return(championshipDto.ChampionshipState == ChampionshipState.NotStarted ? "Use class you would like to run the whole championship with." : $"Use one of the cars from class: {championshipDto.ClassName} ");
 }