public bool TryScore(int score)
        {
            Buzz buzz = this.buzzQueue.Min;

            if (buzz == null)
            {
                // This is a bug we should log when logging is added.
                Debug.Fail($"{nameof(this.TryScore)} should not be called when there are no players in the queue.");
                return(false);
            }

            this.buzzQueue.Remove(buzz);

            // TODO: We may want to limit what score can be, to protect against typos.
            if (!this.scores.TryGetValue(buzz.UserId, out int currentScore))
            {
                currentScore = 0;
            }

            this.scores[buzz.UserId] = currentScore + score;

            ScoreAction action = new ScoreAction(buzz, score);

            this.actions.Push(action);

            return(true);
        }
        public bool AddBuzz(Buzz player)
        {
            lock (this.collectionLock)
            {
                if (player == null || this.alreadyBuzzedPlayers.Contains(player.UserId))
                {
                    return(false);
                }

                this.buzzQueue.Add(player);
                this.alreadyBuzzedPlayers.Add(player.UserId);
            }

            return(true);
        }
Beispiel #3
0
        // We could add players to it, but if the team has buzzed already, we can skip/eject them from the queue
        public bool AddBuzz(Buzz player)
        {
            lock (this.collectionLock)
            {
                Verify.IsNotNull(player, nameof(player));
                string teamId = GetTeamId(player);
                if (player == null ||
                    this.AlreadyBuzzedPlayerIds.Contains(player.UserId) ||
                    this.AlreadyScoredTeamIds.Contains(teamId))
                {
                    return(false);
                }

                this.BuzzQueue.Add(player);
                this.AlreadyBuzzedPlayerIds.Add(player.UserId);
            }

            return(true);
        }
Beispiel #4
0
        public bool AddPlayer(ulong userId)
        {
            // readers cannot add themselves
            if (userId == this.ReaderId)
            {
                return(false);
            }

            Buzz player = new Buzz()
            {
                // TODO: Consider taking this from the message. This would require passing in another parameter.
                Timestamp = DateTime.Now,
                UserId    = userId
            };

            lock (this.phasesLock)
            {
                return(this.CurrentPhase.AddBuzz(player));
            }
        }
Beispiel #5
0
        public virtual bool TryScoreBuzz(int score)
        {
            lock (this.collectionLock)
            {
                Buzz buzz = this.GetNextPlayerToPrompt();
                if (buzz == null)
                {
                    // This is a bug we should log when logging is added.
                    Debug.Fail($"{nameof(this.TryScoreBuzz)} should not be called when there are no players in the queue.");
                    return(false);
                }

                this.BuzzQueue.Remove(buzz);

                ScoreAction action = new ScoreAction(buzz, score);
                this.Actions.Push(action);
                this.AlreadyScoredTeamIds.Add(GetTeamId(buzz));
                return(true);
            }
        }
Beispiel #6
0
        public bool TryGetNextPlayer(out ulong nextPlayerId)
        {
            Buzz next = null;

            lock (this.collectionLock)
            {
                // Only get the next player if there hasn't been a buzz that was correct.
                if (!this.Actions.TryPeek(out ScoreAction action) || action.Score <= 0)
                {
                    next = this.GetNextPlayerToPrompt();
                }
            }

            if (next == null)
            {
                nextPlayerId = 0;
                return(false);
            }

            nextPlayerId = next.UserId;
            return(true);
        }
Beispiel #7
0
 internal static string GetTeamId(Buzz player)
 {
     // If the player isn't on a team, treat them as being on their own team (they're player ID, which should be
     // distinct in Discord)
     return(GetTeamId(player.TeamId, player.UserId));
 }