示例#1
0
        public bool TryRemovePlayer(string characterId)
        {
            //if (!ContainsPlayer(characterId))
            //{
            //    return false;
            //}

            //var player = Players.FirstOrDefault(p => p.Id == characterId);
            if (!PlayersMap.TryRemove(characterId, out var player))
            {
                return(false);
            }

            //Players.RemoveAll(p => p.Id == characterId);
            Players.Remove(player);

            //_playerIds.RemoveAll(id => id == characterId);
            //PlayersMap.TryRemove(characterId, out var playerOut);

            //ParticipatingPlayers.RemoveAll(p => p.Id == characterId);
            ParticipatingPlayers.Remove(player);

            ParticipatingPlayersMap.TryRemove(player.Id, out Player removedPlayer);

            //EventAggregateTracker.SubtractFromHistory(player.EventAggregateTracker);
            RemovePlayerObjectiveTicksFromTeamAggregate(player); // TODO: remove this when Objective Ticks are saved to DB

            return(true);
        }
示例#2
0
        private void HandleMatchWon()
        {
            IsGameRunning = false;

            var playersThatHaveWon = ParticipatingPlayers.Where(m => m.IsWinner).ToList();

            if (ParticipatingPlayers.Count == 1)
            {
                playersThatHaveWon.First().WinMessage = "PRACTICE COMPLETE";
            }
            else if (playersThatHaveWon.Count == 1)
            {
                playersThatHaveWon.First().WinMessage = "MATCH WON";
            }
            else
            {
                foreach (var player in playersThatHaveWon)
                {
                    player.WinMessage = "MATCH DRAWN";
                }
            }

            _matchWon = true;

            var playersToCalculate = ParticipatingPlayers.Where(m => m.PlayerDetails != null).ToList();

            _currentGameService.CloseMatch(GetGameParameters());

            _currentStatisticsService.CalculatePlayerStatistics(SelectedGame.Id, playersToCalculate);

            MessageBus.Current.SendMessage(playersToCalculate);
        }
示例#3
0
        public void ResetMatchData()
        {
            ClearEventAggregateHistory();

            ParticipatingPlayers.Clear();
            ParticipatingPlayersMap.Clear();
        }
示例#4
0
        private void UndoCommandHandler()
        {
            IsAcceptOpen = false;

            // If no one has scored we are at the start
            if (!_currentGameService.HasAnyOneScored(ParticipatingPlayers.ToList()))
            {
                return;
            }

            if (ParticipatingPlayers[_currentPlayer].DartsToThrow < 3)
            {
                // Score has not yet been accepted so just cancel the dialog
                RejectScoreCommandHandler();
                return;
            }

            _currentPlayer--;

            if (_currentPlayer < 0)
            {
                _currentPlayer = ParticipatingPlayers.Count - 1;
            }

            if (!ParticipatingPlayers[_currentPlayer].UndoItems.Any())
            {
                return;
            }

            _currentGameService.Undo(GetGameParameters());

            ParticipatingPlayers[_currentPlayer].RemoveDartScores();

            var turnNumber =
                ParticipatingPlayers[_currentPlayer].Scores[ParticipatingPlayers[_currentPlayer].Scores.Count - 1]
                .TurnNumber;

            for (var index = ParticipatingPlayers[_currentPlayer].Scores.Count - 1; index >= 0; index--)
            {
                var score = ParticipatingPlayers[_currentPlayer].Scores[index];

                if (score.TurnNumber == turnNumber)
                {
                    ParticipatingPlayers[_currentPlayer].Scores.Remove(score);
                }
            }

            SetCurrentPlayer(_currentPlayer);

            AnalyseScoreForHints();
        }
示例#5
0
        public bool TryRemovePlayer(string characterId)
        {
            if (!PlayersMap.TryRemove(characterId, out var player))
            {
                return(false);
            }

            Players.Remove(player);

            ParticipatingPlayers.Remove(player);

            ParticipatingPlayersMap.TryRemove(player.Id, out Player removedPlayer);

            RemovePlayerObjectiveTicksFromTeamAggregate(player); // TODO: remove this when Objective Ticks are saved to DB

            return(true);
        }
示例#6
0
        public RewindOperation(IEnumerable <Player> players, IEnumerable <Ghost> ghosts, Action onComplete)
        {
            _onComplete = onComplete;
            ParticipatingPlayers.AddRange(players);
            RemainingPlayers.AddRange(players);

            ParticipatingGhosts.AddRange(ghosts);
            RemainingGhosts.AddRange(ghosts);


            //Kill all projectiles
            var projectiles = Scene.Current.FindGameObjects <Projectile>();

            foreach (var item in projectiles)
            {
                item.DisposeLater();
            }

            //And remove all active status effects.
            foreach (var item in ParticipatingPlayers)
            {
                item.RemoveAllStatusEffects();
            }



            //Turn on replay for all players.
            foreach (var player in ParticipatingPlayers)
            {
                DisablePlayer(player);
                player.TimeBody.StartRewind(2, true, () =>
                {
                    FinishPlayerDeathRewind(player);
                });
            }


            //Turn on replay for all ghosts.
            foreach (var ghost in ParticipatingGhosts)
            {
                ghost.TimeBody.StartRewind(2, false, () =>
                {
                    FinishGhostDeathRewind(ghost);
                });
            }
        }
示例#7
0
        private void InitialiseParticipatingPlayers()
        {
            ParticipatingPlayers.Clear();

            for (var i = 1; i <= SelectedPlayers; i++)
            {
                var player = new Player(i);

                // Set up the player details for each participant
                if (ConfiguredPlayers.Count >= i)
                {
                    player.CurrentScore  = SelectedGame.GetStartingScore(ConfiguredPlayers[i - 1].PlayerDetails);
                    player.PlayerDetails = ConfiguredPlayers[i - 1].PlayerDetails;
                }
                else
                {
                    player.CurrentScore = SelectedGame.GetStartingScore(null);
                }

                ParticipatingPlayers.Add(player);
            }
        }
示例#8
0
        private void StopGame()
        {
            ParticipatingPlayers.Clear();
            SetIsBust(false);
            SetIsGameShot(false);
            IsGameRunning  = false;
            IsBoardEnabled = false;
            Enabled        = false;
            ClearDarts();
            _dartTotal = 0;
            ResetCheckOutHints();
            MatchDetails = string.Empty;

            foreach (var participatingPlayer in ParticipatingPlayers)
            {
                participatingPlayer.InitPlayer(SelectedSet, SelectedLeg, SelectedGame.StartingScore, true);

                participatingPlayer.RemoveScore();
            }

            // Hide all the darts
            MessageBus.Current.SendMessage(Visibility.Collapsed);
        }
示例#9
0
        private void SetLeaderMessage()
        {
            // 1 player practice then no leader
            if (ParticipatingPlayers.Count == 1)
            {
                return;
            }

            // Check to see if there is a leader.
            var currentHighScore =
                ParticipatingPlayers.Select(participatingPlayer => participatingPlayer.GetCurrentGameScore())
                .Concat(new[] { 0 })
                .Max();

            var shouldSetLeader = ParticipatingPlayers.Count(m => m.GetCurrentGameScore() >= currentHighScore) == 1;

            foreach (var player in ParticipatingPlayers)
            {
                player.LeaderMessage = player.GetCurrentGameScore() >= currentHighScore && shouldSetLeader
                    ? "LEADER"
                    : string.Empty;
            }
        }
示例#10
0
        private void ProcessWonGame()
        {
            var soundToPlay = "gs.wav";
            var soundToSay  = "GAME SHOT";

            var winners = _currentGameService.GetVictoriousPlayers(GetGameParameters());

            GetCurrentPlayer().IsGameShot = true;

            ResetCheckOutHints();

            // Determine if any other player is a joint winner
            var playersThatHaveWon =
                ParticipatingPlayers.Where(m => m.CurrentScore == winners.First().CurrentScore &&
                                           m.SetsWon == winners.First().SetsWon&&
                                           m.LegsWon == winners.First().LegsWon).ToList();

            foreach (var victoriousPlayer in playersThatHaveWon)
            {
                victoriousPlayer.IsWinner = true;

                // Update current score
                victoriousPlayer.LegsWon++;

                victoriousPlayer.CummulativeLegsWon++;
            }

            // Update legs played for all players
            foreach (var player in ParticipatingPlayers)
            {
                player.LegsPlayed++;
                player.CurrentDartCount = 0;
            }

            if (playersThatHaveWon.First().LegsWon == SelectedLeg)
            {
                soundToPlay = "gss.wav";
                soundToSay  = "GAME SHOT AND THE SET";

                foreach (var player in ParticipatingPlayers)
                {
                    player.LegsWon = 0;
                }

                // Update current score
                foreach (var victoriousPlayer in playersThatHaveWon)
                {
                    victoriousPlayer.SetsWon++;
                }

                if (playersThatHaveWon.First().SetsWon == SelectedSet)
                {
                    HandleMatchWon();
                    soundToPlay = "gsm.wav";
                    soundToSay  = "GAME SHOT AND THE MATCH";
                }
            }

            foreach (var player in ParticipatingPlayers)
            {
                player.LeaderMessage = string.Empty;
            }

            StartNextGame();

            var nextPlayerSound = playersThatHaveWon.First().SetsWon == SelectedSet ? null : $"tfplayer{_currentPlayer + 1}.wav";

            var nextPlayerText = playersThatHaveWon.First().SetsWon == SelectedSet
                ? null
                : $"{GetCurrentPlayerName()} TO THROW FIRST";

            CommentaryPlayer.Play(new Commentary
            {
                PlaySounds = _configurationData.PlaySounds,
                SoundFiles = new[] { soundToPlay, nextPlayerSound },
                SoundTexts = new[] { soundToSay, nextPlayerText }
            });
        }