Beispiel #1
0
        public async Task Start()
        {
            if (_gameState != GameState.WaitingForPlayers) // In case someone use the 'Start' command right when the game was about to be launched by itself
            {
                return;
            }
            _gameState = GameState.Running;
            if (HaveMultiplayerLobby())
            {
                // Setup for multiplayer:
                if (await _lobby.LoadNames(_chan as ITextChannel)) // We try to load the nickname of everyone in the lobby
                {
                    var msg = await _chan.SendMessageAsync(_lobby.GetReadyMessage(_guild));

                    var ids = _lobby.GetPlayersId();
                    foreach (var id in ids)
                    {
                        await Program.p.cm.ProgressAchievementAsync(Community.AchievementID.PlayWithFriends, ids.Count, null, msg, id);
                    }
                }
                else
                {
                    _gameState = GameState.Lost;
                    await _chan.SendMessageAsync(Sentences.LobbyLeftChannel(_guild));
                }
                if (_multiType == APreload.MultiplayerType.Elimination)
                {
                    await PostText(Sentences.AnnounceTurn(_guild, _lobby.GetTurnName()));
                }
            }
            await PostAsync();
        }
Beispiel #2
0
 public async Task Start()
 {
     if (_gameState != GameState.WaitingForPlayers) // In case someone use the 'Start' command right when the game was about to be launched by itself
     {
         return;
     }
     _gameState = GameState.Running;
     if (HaveMultiplayerLobby())
     {
         // Setup for multiplayer:
         if (await _lobby.LoadNames(_chan)) // We try to load the nickname of everyone in the lobby
         {
             await _chan.SendMessageAsync(_lobby.GetReadyMessage(_chan.GuildId));
         }
         else
         {
             _gameState = GameState.Lost;
             await _chan.SendMessageAsync(Sentences.LobbyLeftChannel(_chan.GuildId));
         }
         if (_multiType == APreload.MultiplayerType.Elimination)
         {
             await PostText(Sentences.AnnounceTurn(_chan.GuildId, _lobby.GetTurnName()));
         }
     }
     await PostAsync();
 }
Beispiel #3
0
        public async Task LooseAsync(string reason)
        {
            _gameState = GameState.Lost;
            if (HaveMultiplayerLobby()) // Multiplayer scores aren't saved
            {
                if (_multiType == APreload.MultiplayerType.Elimination)
                {
                    _lobby.RemoveCurrentPlayer();
                    if (_lobby.HaveEnoughPlayer())
                    {
                        _gameState = GameState.Running;
                        _startTime = DateTime.Now;
                        await PostText(Sentences.YouLost(_guild) + (reason == null ? "" : reason + Environment.NewLine) + Sentences.AnnounceTurn(_guild, _lobby.GetTurnName()));

                        _postImage = false;
                        return;
                    }
                    await PostText(Sentences.YouLost(_guild) + (reason == null ? "" : reason + Environment.NewLine) + await GetLoose() + Environment.NewLine + Sentences.WonMulti(_guild, _lobby.GetLastStanding()));

                    LeaveVocalChannel();
                }
                else
                {
                    LeaveVocalChannel();
                    throw new ArgumentException("Multiplayer game " + _gameName + " ended in an unexpected way: " + reason);
                }
            }
            else
            {
                IUserMessage gameOverMsg;
                if (reason == null)
                {
                    gameOverMsg = await SaveScores(Sentences.YouLost(_guild) + await GetLoose());
                }
                else
                {
                    gameOverMsg = await SaveScores(Sentences.YouLost(_guild) + reason + Environment.NewLine + await GetLoose());
                }
                if (this is AQuizz)
                {
                    foreach (ulong c in _contributors)
                    {
                        await Program.p.cm.ProgressAchievementAsync(Community.AchievementID.GoodScores, _score, null, gameOverMsg, c);
                    }
                    if (_isShaded != APreload.Shadow.None)
                    {
                        foreach (ulong c in _contributors)
                        {
                            await Program.p.cm.ProgressAchievementAsync(Community.AchievementID.GoodScoresShadow, _score, null, gameOverMsg, c);
                        }
                    }
                }
                LeaveVocalChannel();
            }
        }
Beispiel #4
0
        public async Task CheckCorrectAsync(IUser user, string userAnswer, SocketUserMessage msg)
        {
            if (_gameState != GameState.Running || userAnswer.StartsWith("//") || userAnswer.StartsWith("#"))
            {
                return;
            }
            _checkingAnswer = true;
            if (HaveMultiplayerLobby())          // If is in multiplayer
            {
                if (!_lobby.IsPlayerIn(user.Id)) // Player isn't in the multiplayer lobby
                {
                    return;
                }
                // Check if it's the player's turn (elimination mode only)
                else if (_multiType == APreload.MultiplayerType.Elimination && !_lobby.IsMyTurn(user.Id))
                {
                    await msg.AddReactionAsync(new Emoji("🚫"));

                    _checkingAnswer = false;
                    return;
                }
                // Check if the player is out of tries
                else if (_multiType == APreload.MultiplayerType.BestOf && _bestOfTries.ContainsKey(user.ToString()) && _bestOfTries[user.ToString()] == nbMaxTry - 1)
                {
                    await msg.AddReactionAsync(new Emoji("🚫"));

                    _checkingAnswer = false;
                    return;
                }
            }
            if (_postImage) // Image is being posted
            {
                await msg.AddReactionAsync(new Emoji("❌"));

                _checkingAnswer = false;
                return;
            }
            string error;

            try
            {
                error = await GetCheckCorrectAsync(userAnswer);
            }
            catch (Exception e)
            {
                await _chan.SendMessageAsync("", false, new EmbedBuilder()
                {
                    Color       = Color.Red,
                    Title       = e.GetType().ToString(),
                    Description = Sentences.ExceptionGameCheck(_guild),
                    Footer      = new EmbedFooterBuilder()
                    {
                        Text = e.Message
                    }
                }.Build());

                await Program.p.LogError(new LogMessage(LogSeverity.Error, e.Source, e.Message, e));
                await LooseAsync(null);

                return;
            }
            if (error != null)
            {
                if (error.Length < 5)
                {
                    await msg.AddReactionAsync(new Emoji(error));

                    error = "";
                }
                if (HaveMultiplayerLobby() && _multiType == APreload.MultiplayerType.BestOf)
                {
                    if (_bestOfTries.ContainsKey(user.ToString()))
                    {
                        _bestOfTries[user.ToString()]++;
                    }
                    else
                    {
                        _bestOfTries.Add(user.ToString(), 1);
                    }
                    error += Environment.NewLine + Sentences.TurnsRemaining(_guild, nbMaxTry - _bestOfTries[user.ToString()], user.ToString());
                }
                if (error != "")
                {
                    await PostText(error);
                }
                _checkingAnswer = false;
                return;
            }
            if (!_contributors.Contains(user.Id))
            {
                _contributors.Add(user.Id);
            }
            string finalStr = AnnounceNextTurnInternal();

            if (CongratulateOnGuess())
            {
                finalStr += Sentences.GuessGood(_guild);
            }
            if (HaveMultiplayerLobby())
            {
                if (_multiType == APreload.MultiplayerType.Elimination)
                {
                    await NextTurn();

                    if (finalStr != "")
                    {
                        finalStr += Environment.NewLine;
                    }
                    finalStr += Sentences.AnnounceTurn(_guild, _lobby.GetTurnName());
                }
                else if (_multiType == APreload.MultiplayerType.BestOf)
                {
                    if (_bestOfScore.ContainsKey(user.ToString()))
                    {
                        _bestOfScore[user.ToString()]++;
                    }
                    else
                    {
                        _bestOfScore.Add(user.ToString(), 1);
                    }
                    _bestOfRemainingRounds--;
                    if (_bestOfRemainingRounds == 0)
                    {
                        await BestOfOutOfRound(true);

                        return;
                    }
                    _bestOfTries = new Dictionary <string, int>();
                    finalStr    += Environment.NewLine + Sentences.CurrentScore(_guild) + Environment.NewLine;
                    finalStr    += GetBestOfScore();
                }
            }
            if (_gameState != GameState.Running || _isFound)
            {
                return;
            }
            _isFound = true;
            if (!string.IsNullOrWhiteSpace(finalStr))
            {
                await PostText(finalStr);
            }
            _score++;
            await PostAsync();

            _checkingAnswer = false;
        }
Beispiel #5
0
        public async Task LooseAsync(string reason)
        {
            _gameState = GameState.Lost;
            if (HaveMultiplayerLobby()) // Multiplayer scores aren't saved
            {
                if (_multiType == APreload.MultiplayerType.Elimination)
                {
                    _lobby.RemoveCurrentPlayer();
                    if (_lobby.HaveEnoughPlayer())
                    {
                        _gameState = GameState.Running;
                        _startTime = DateTime.Now;
                        await PostText(Sentences.YouLost(_chan.GuildId) + (reason == null ? "" : reason + Environment.NewLine) + Sentences.AnnounceTurn(_chan.GuildId, _lobby.GetTurnName()));

                        _postImage = false;
                        return;
                    }
                    await PostText(Sentences.YouLost(_chan.GuildId) + (reason == null ? "" : reason + Environment.NewLine) + await GetLoose() + Environment.NewLine + Sentences.WonMulti(_chan.GuildId, _lobby.GetLastStanding()));
                }
                else
                {
                    throw new ArgumentException("Multiplayer game " + _gameName + " ended in an unexpected way: " + reason);
                }
            }
            else
            {
                if (reason == null)
                {
                    await SaveScores(Sentences.YouLost(_chan.GuildId) + await GetLoose());
                }
                else
                {
                    await SaveScores(Sentences.YouLost(_chan.GuildId) + reason + Environment.NewLine + await GetLoose());
                }
            }
        }