Esempio n. 1
0
        public void WarningRoute(PlayerContext player, RouteResult route)
        {
            this.DisplayFeature(player);
            var features = this.ComputeRoute(player, route);

            featurePanelManager.WarningFeature(ContextEngine.Instance.gameContext.state, player.features, features);
        }
Esempio n. 2
0
        public void OnViewRoute(CaseManager target, bool enable)
        {
            if (!isHoverGUI && _candidateRoutes != null)
            {
                var player = PlayerEngine.Instance.GetCurrent();
                if (enable)
                {
                    var de = player.currentTurn.de;

                    if (_candidateRoutes.routes.ContainsKey(target.itemDataSource.index))
                    {
                        var routes = _candidateRoutes.routes[target.itemDataSource.index];
                        _candidateRoute = routes
                                          .OrderBy(r => r.nbLineMove)
                                          .ThenByDescending(r => r.route.Count - de)
                                          .ThenBy(r => r.route.Skip(1).Count(c => c.isDangerous)).First();

                        FeatureEngine.Instance.WarningRoute(player, _candidateRoute);
                        BoardEngine.Instance.DrawRoute(_candidateRoute.route, player.GetColor());
                    }
                }
                else
                {
                    if (_candidateRoute != null)
                    {
                        FeatureEngine.Instance.DisplayFeature(player);
                        BoardEngine.Instance.DrawRoute(_candidateRoute.route);
                    }
                }
            }
        }
Esempio n. 3
0
        private FeatureContext ComputeRoute(PlayerContext player, RouteResult route)
        {
            bool isEnd         = false;
            var  hasFinishCase = BoardEngine.Instance.ContainsFinishCase(route.route.Select(r => r.itemDataSource.index));

            if (hasFinishCase)
            {
                if (ContextEngine.Instance.gameContext.state == GameStateType.Qualification)
                {
                    isEnd = true;
                }
                else if (player.lap + 1 == ContextEngine.Instance.gameContext.totalLap)
                {
                    isEnd = true;
                }
            }

            var features = player.features;

            if (!isEnd)
            {
                features = this.ComputeOutOfBend(player.features, route.nbOutOfBend);
                var nbCase = route.route.Count - 1;
                var de     = 0;
                if (player.state == PlayerStateType.Aspiration)
                {
                    de = 3;
                }
                else if (player.state == PlayerStateType.StandOut)
                {
                    de = nbCase;
                }
                else
                {
                    if (player.currentTurn != null)
                    {
                        de = player.currentTurn.de;
                    }
                    else
                    {
                        de = PlayerEngine.Instance.GetTurnHistories(player).Last().de;
                    }
                }
                features = this.ComputeUseBrake(features, de, route.isStandWay, nbCase);
            }
            return(features);
        }
Esempio n. 4
0
 public void ApplyDangerousRoute(PlayerContext player, RouteResult route)
 {
     bool hasChange = false;
     foreach (var current in route.route.Where(c => c.isDangerous))
     {
         var de = RaceEngine.Instance.BlackDice();
         if (de <= 4)
         {
             player.features.handling = player.features.handling - 1;
             hasChange = true;
         }
     }
     if (hasChange)
     {
         this.DisplayFeature(player);
     }
 }
Esempio n. 5
0
        public void ApplyDangerousRoute(PlayerContext player, RouteResult route)
        {
            bool hasChange = false;

            foreach (var current in route.route.Where(c => c.isDangerous))
            {
                var de = RaceEngine.Instance.BlackDice();
                if (de <= 4)
                {
                    player.features.handling = player.features.handling - 1;
                    hasChange = true;
                }
            }
            if (hasChange)
            {
                this.DisplayFeature(player);
            }
        }
Esempio n. 6
0
 public void OnSelectRoute(CaseManager target)
 {
     if (!isHoverGUI && _candidateRoutes != null)
     {
         var dest = _candidateRoute.route.Last();
         if (_candidateRoute == null || !target.itemDataSource.index.Equals(dest.itemDataSource.index))
         {
             this.OnViewRoute(target, true);
         }
         else
         {
             PlayerEngine.Instance.MoveCar(_candidateRoute.route);
             PlayerEngine.Instance.SelectedRoute(_candidateRoute);
             _candidateRoute = null;
             this.CleanCurrent();
         }
     }
 }
Esempio n. 7
0
 public void ApplyRoute(PlayerContext player, RouteResult route)
 {
     player.features = this.ComputeRoute(player, route);
     player.qualification.outOfBend = player.features.outOfBend;
     this.DisplayFeature(player);
 }
Esempio n. 8
0
 public void ApplyRoute(PlayerContext player, RouteResult route)
 {
     player.features = this.ComputeRoute(player, route);
     player.qualification.outOfBend = player.features.outOfBend;
     this.DisplayFeature(player);
 }
Esempio n. 9
0
        private FeatureContext ComputeRoute(PlayerContext player, RouteResult route)
        {
            bool isEnd = false;
            var hasFinishCase = BoardEngine.Instance.ContainsFinishCase(route.route.Select(r => r.itemDataSource.index));
            if (hasFinishCase)
            {
                if (ContextEngine.Instance.gameContext.state == GameStateType.Qualification)
                {
                    isEnd = true;
                }
                else if (player.lap + 1 == ContextEngine.Instance.gameContext.totalLap)
                {
                    isEnd = true;
                }
            }

            var features = player.features;
            if (!isEnd)
            {
                features = this.ComputeOutOfBend(player.features, route.nbOutOfBend);
                var nbCase = route.route.Count - 1;
                var de = 0;
                if (player.state == PlayerStateType.Aspiration)
                {
                    de = 3;
                }
                else if (player.state == PlayerStateType.StandOut)
                {
                    de = nbCase;
                }
                else
                {
                    if (player.currentTurn != null)
                    {
                        de = player.currentTurn.de;
                    }
                    else
                    {
                        de = PlayerEngine.Instance.GetTurnHistories(player).Last().de;
                    }
                }
                features = this.ComputeUseBrake(features, de, route.isStandWay, nbCase);
            }
            return features;
        }
Esempio n. 10
0
 public void WarningRoute(PlayerContext player, RouteResult route)
 {
     this.DisplayFeature(player);
     var features = this.ComputeRoute(player, route);
     featurePanelManager.WarningFeature(ContextEngine.Instance.gameContext.state, player.features, features);
 }
Esempio n. 11
0
        public void SelectedRoute(RouteResult candidate)
        {
            var endCase = candidate.route.Last();
            StandDataSource standData = null;
            if (endCase.standDataSource != null)
            {
                standData = endCase.standDataSource;
            }
            FeatureEngine.Instance.ApplyRoute(_currentPlayer, candidate);

            bool hasNewLap = BoardEngine.Instance.ContainsFinishCase(candidate.route.Select(r => r.itemDataSource.index));
            if (hasNewLap)
            {
                _currentPlayer.lap = _currentPlayer.lap + 1;
            }

            if (endCase.bendDataSource != null)
            {
                if (candidate.nbOutOfBend == 0 && _currentPlayer.state != PlayerStateType.Aspiration)
                {
                    if (_currentPlayer.lastBend == endCase.bendDataSource.name)
                    {
                        _currentPlayer.stopBend = _currentPlayer.stopBend + 1;
                    }
                    else
                    {
                        _currentPlayer.stopBend = 1;
                        _currentPlayer.lastBend = endCase.bendDataSource.name;
                    }
                }
                else if (_currentPlayer.lastBend != endCase.bendDataSource.name)
                {
                    _currentPlayer.stopBend = 0;
                    _currentPlayer.lastBend = endCase.bendDataSource.name;
                }
            }
            else
            {
                _currentPlayer.lastBend = string.Empty;
                _currentPlayer.stopBend = 0;
            }

            FeatureEngine.Instance.ApplyDangerousRoute(_currentPlayer, candidate);

            if (_currentPlayer.state == PlayerStateType.ChoseRoute)
            {
                var turnHistories = this.GetTurnHistories(_currentPlayer);
                if (turnHistories.Any())
                {
                    var previousHistory = turnHistories.Last();
                    if (previousHistory.paths.Any())
                    {
                        BoardEngine.Instance.CleanRoute(previousHistory.paths.SelectMany(p => p.Select(i => BoardEngine.Instance.GetCase(i))).ToList(), _currentPlayer.GetColor());
                    }
                }
                _currentPlayer.currentTurn.paths.Add(candidate.route.Select(r => r.itemDataSource.index).ToList());
                _currentPlayer.currentTurn.outOfBend = candidate.nbOutOfBend;
                if (candidate.nbOutOfBend == 0 && standData == null && !candidate.isBadWay && this.CheckAspiration(candidate.route))
                {
                    _currentPlayer.state = PlayerStateType.Aspiration;
                    this.CheckIsDead(_currentPlayer);
                }
                else
                {
                    this.EndTurn(standData);
                }
            }
            else if (_currentPlayer.state == PlayerStateType.Aspiration || _currentPlayer.state == PlayerStateType.StandOut)
            {
                _currentPlayer.currentTurn.paths.Add(candidate.route.Select(r => r.itemDataSource.index).ToList());
                if (standData == null && !candidate.isBadWay && this.CheckAspiration(candidate.route))
                {
                    _currentPlayer.state = PlayerStateType.Aspiration;
                    this.CheckIsDead(_currentPlayer);
                }
                else
                {
                    this.EndTurn(standData);
                }
            }

            if (_currentPlayer.state == PlayerStateType.EndTurn || _currentPlayer.state == PlayerStateType.Dead)
            {
                var turnHistories = this.GetTurnHistories(_currentPlayer);
                turnHistories.Add(_currentPlayer.currentTurn);
                _currentPlayer.currentTurn = null;
                ContextEngine.Instance.gameContext.lastTurn = DateTime.Now;

                if (ContextEngine.Instance.gameContext.state == GameStateType.Qualification)
                {
                    if (_currentPlayer.lap > 0)
                    {
                        var previousHistory = turnHistories.Last();
                        if (previousHistory.paths.Any())
                        {
                            BoardEngine.Instance.CleanRoute(previousHistory.paths.SelectMany(p => p.Select(i => BoardEngine.Instance.GetCase(i))).ToList(), _currentPlayer.GetColor());
                        }

                        _currentPlayer.qualification.endDate = DateTime.UtcNow;
                        int nbDe = _currentPlayer.qualification.turnHistories.Count - 1;
                        var duration = _currentPlayer.qualification.endDate - _currentPlayer.qualification.startDate;
                        int totalMin = Mathf.FloorToInt((float)duration.TotalMinutes);
                        _currentPlayer.qualification.total = nbDe + totalMin + _currentPlayer.qualification.outOfBend;
                        _currentPlayer.qualification.state = QualificationStateType.Completed;
                        _currentPlayer.state = PlayerStateType.Finish;
                    }
                    else if (_currentPlayer.state == PlayerStateType.Dead)
                    {
                        _currentPlayer.qualification.endDate = DateTime.UtcNow;
                        _currentPlayer.qualification.state = QualificationStateType.Completed;
                        _currentPlayer.qualification.isDead = true;
                    }
                }
                else if (_currentPlayer.lap == ContextEngine.Instance.gameContext.totalLap)
                {
                    _currentPlayer.state = PlayerStateType.Finish;
                    _currentPlayer.position = ContextEngine.Instance.gameContext.players.Where(p => p.state == PlayerStateType.Finish).Count();
                }
                else if (_currentPlayer.state != PlayerStateType.Dead)
                {
                    _currentPlayer.state = PlayerStateType.Waiting;
                }
            }
        }
Esempio n. 12
0
        public void SelectedRoute(RouteResult candidate)
        {
            var             endCase   = candidate.route.Last();
            StandDataSource standData = null;

            if (endCase.standDataSource != null)
            {
                standData = endCase.standDataSource;
            }
            FeatureEngine.Instance.ApplyRoute(_currentPlayer, candidate);

            bool hasNewLap = BoardEngine.Instance.ContainsFinishCase(candidate.route.Select(r => r.itemDataSource.index));

            if (hasNewLap)
            {
                _currentPlayer.lap = _currentPlayer.lap + 1;
            }

            if (endCase.bendDataSource != null)
            {
                if (candidate.nbOutOfBend == 0 && _currentPlayer.state != PlayerStateType.Aspiration)
                {
                    if (_currentPlayer.lastBend == endCase.bendDataSource.name)
                    {
                        _currentPlayer.stopBend = _currentPlayer.stopBend + 1;
                    }
                    else
                    {
                        _currentPlayer.stopBend = 1;
                        _currentPlayer.lastBend = endCase.bendDataSource.name;
                    }
                }
                else if (_currentPlayer.lastBend != endCase.bendDataSource.name)
                {
                    _currentPlayer.stopBend = 0;
                    _currentPlayer.lastBend = endCase.bendDataSource.name;
                }
            }
            else
            {
                _currentPlayer.lastBend = string.Empty;
                _currentPlayer.stopBend = 0;
            }

            FeatureEngine.Instance.ApplyDangerousRoute(_currentPlayer, candidate);

            if (_currentPlayer.state == PlayerStateType.ChoseRoute)
            {
                var turnHistories = this.GetTurnHistories(_currentPlayer);
                if (turnHistories.Any())
                {
                    var previousHistory = turnHistories.Last();
                    if (previousHistory.paths.Any())
                    {
                        BoardEngine.Instance.CleanRoute(previousHistory.paths.SelectMany(p => p.Select(i => BoardEngine.Instance.GetCase(i))).ToList(), _currentPlayer.GetColor());
                    }
                }
                _currentPlayer.currentTurn.paths.Add(candidate.route.Select(r => r.itemDataSource.index).ToList());
                _currentPlayer.currentTurn.outOfBend = candidate.nbOutOfBend;
                if (candidate.nbOutOfBend == 0 && standData == null && !candidate.isBadWay && this.CheckAspiration(candidate.route))
                {
                    _currentPlayer.state = PlayerStateType.Aspiration;
                    this.CheckIsDead(_currentPlayer);
                }
                else
                {
                    this.EndTurn(standData);
                }
            }
            else if (_currentPlayer.state == PlayerStateType.Aspiration || _currentPlayer.state == PlayerStateType.StandOut)
            {
                _currentPlayer.currentTurn.paths.Add(candidate.route.Select(r => r.itemDataSource.index).ToList());
                if (standData == null && !candidate.isBadWay && this.CheckAspiration(candidate.route))
                {
                    _currentPlayer.state = PlayerStateType.Aspiration;
                    this.CheckIsDead(_currentPlayer);
                }
                else
                {
                    this.EndTurn(standData);
                }
            }

            if (_currentPlayer.state == PlayerStateType.EndTurn || _currentPlayer.state == PlayerStateType.Dead)
            {
                var turnHistories = this.GetTurnHistories(_currentPlayer);
                turnHistories.Add(_currentPlayer.currentTurn);
                _currentPlayer.currentTurn = null;
                ContextEngine.Instance.gameContext.lastTurn = DateTime.Now;

                if (ContextEngine.Instance.gameContext.state == GameStateType.Qualification)
                {
                    if (_currentPlayer.lap > 0)
                    {
                        var previousHistory = turnHistories.Last();
                        if (previousHistory.paths.Any())
                        {
                            BoardEngine.Instance.CleanRoute(previousHistory.paths.SelectMany(p => p.Select(i => BoardEngine.Instance.GetCase(i))).ToList(), _currentPlayer.GetColor());
                        }

                        _currentPlayer.qualification.endDate = DateTime.UtcNow;
                        int nbDe     = _currentPlayer.qualification.turnHistories.Count - 1;
                        var duration = _currentPlayer.qualification.endDate - _currentPlayer.qualification.startDate;
                        int totalMin = Mathf.FloorToInt((float)duration.TotalMinutes);
                        _currentPlayer.qualification.total = nbDe + totalMin + _currentPlayer.qualification.outOfBend;
                        _currentPlayer.qualification.state = QualificationStateType.Completed;
                        _currentPlayer.state = PlayerStateType.Finish;
                    }
                    else if (_currentPlayer.state == PlayerStateType.Dead)
                    {
                        _currentPlayer.qualification.endDate = DateTime.UtcNow;
                        _currentPlayer.qualification.state   = QualificationStateType.Completed;
                        _currentPlayer.qualification.isDead  = true;
                    }
                }
                else if (_currentPlayer.lap == ContextEngine.Instance.gameContext.totalLap)
                {
                    _currentPlayer.state    = PlayerStateType.Finish;
                    _currentPlayer.position = ContextEngine.Instance.gameContext.players.Where(p => p.state == PlayerStateType.Finish).Count();
                }
                else if (_currentPlayer.state != PlayerStateType.Dead)
                {
                    _currentPlayer.state = PlayerStateType.Waiting;
                }
            }
        }
Esempio n. 13
0
        public void OnViewRoute(CaseManager target, bool enable)
        {
            if (!isHoverGUI && _candidateRoutes != null)
            {
                var player = PlayerEngine.Instance.GetCurrent();
                if (enable)
                {
                    var de = player.currentTurn.de;

                    if (_candidateRoutes.routes.ContainsKey(target.itemDataSource.index))
                    {
                        var routes = _candidateRoutes.routes[target.itemDataSource.index];
                        _candidateRoute = routes
                            .OrderBy(r => r.nbLineMove)
                            .ThenByDescending(r => r.route.Count - de)
                            .ThenBy(r => r.route.Skip(1).Count(c => c.isDangerous)).First();

                        FeatureEngine.Instance.WarningRoute(player, _candidateRoute);
                        BoardEngine.Instance.DrawRoute(_candidateRoute.route, player.GetColor());
                    }
                }
                else
                {
                    if (_candidateRoute != null)
                    {
                        FeatureEngine.Instance.DisplayFeature(player);
                        BoardEngine.Instance.DrawRoute(_candidateRoute.route);
                    }
                }
            }
        }
Esempio n. 14
0
 public void OnSelectRoute(CaseManager target)
 {
     if (!isHoverGUI && _candidateRoutes != null)
     {
         var dest = _candidateRoute.route.Last();
         if (_candidateRoute == null || !target.itemDataSource.index.Equals(dest.itemDataSource.index))
         {
             this.OnViewRoute(target, true);
         }
         else
         {
             PlayerEngine.Instance.MoveCar(_candidateRoute.route);
             PlayerEngine.Instance.SelectedRoute(_candidateRoute);
             _candidateRoute = null;
             this.CleanCurrent();
         }
     }
 }