public async Task <Message> PlayRoulette(ulong userId, string arguments)
        {
            var argument = arguments != null
                ? arguments.ToUpper().TrimStart().Split(' ')
                : new string[0];

            var isNumber = false;
            var nmbBet   = -1;
            var nmbGuess = 0;

            if (argument.Length >= 2)
            {
                isNumber = int.TryParse(argument[0], out nmbGuess);
                if (argument[1].Trim() == "ALL")
                {
                    nmbBet = await _usersConnector.GetCredits(userId);
                }
                else if (argument[1].Trim() == "HALF")
                {
                    nmbBet = await _usersConnector.GetCredits(userId) / 2;
                }
                else
                {
                    nmbBet = _betSizeParser.Parse(argument[1]);
                }
            }

            var selectedOption = argument[0].ToUpper();

            var credWon = 0;

            if (nmbBet != -1)
            {
                var curCred = await _usersConnector.GetCredits(userId);

                if (curCred < nmbBet)
                {
                    return(_messagesHelper.NotEnoughCredits("Roulette"));
                }
                await _usersConnector.TakeCredits(userId, nmbBet);

                var rewardMulti = 0;
                var hasWon      = false;
                var random      = new Random();
                var number      = random.Next(0, 37);
                var exp         = ExpHelpers.CalculateBet((await _usersConnector.GetUser(userId)).Level, nmbBet);
                var expResult   = await _usersConnector.CommandGiveUserExp(userId, exp);

                var result = Roulette.GetResult(number);

                if (isNumber)
                {
                    if (nmbGuess == result.Number)
                    {
                        hasWon      = true;
                        rewardMulti = 36;
                    }
                }
                else
                {
                    switch (selectedOption)
                    {
                    case "RED":
                        if (result.Color.ToUpper() == "RED")
                        {
                            hasWon      = true;
                            rewardMulti = 2;
                        }

                        break;

                    case "BLACK":
                        if (result.Color.ToUpper() == "BLACK")
                        {
                            hasWon      = true;
                            rewardMulti = 2;
                        }

                        break;

                    case "ODD":
                        if (result.OddOrEven.ToUpper() == "ODD")
                        {
                            hasWon      = true;
                            rewardMulti = 2;
                        }

                        break;

                    case "EVEN":
                        if (result.OddOrEven.ToUpper() == "EVEN")
                        {
                            hasWon      = true;
                            rewardMulti = 2;
                        }

                        break;

                    default:
                        return(_messagesHelper.InvalidArguments(new[] { "<Red|Black|Odd|Even|Number> <Bet>" },
                                                                "!roulette", "Roulette"));
                    }
                }

                await _gameHistoryConnector.AddGameHistory(new GameHistory
                {
                    GameName        = "roulette",
                    HasWon          = hasWon,
                    CoinsDifference = credWon,
                    UserId          = userId
                });

                Message responseBuilder;
                if (hasWon)
                {
                    credWon = nmbBet * rewardMulti;
                    await _usersConnector.GiveCredits(userId, credWon);

                    responseBuilder = _messagesHelper.WinInformation(credWon, $"Result: {result.OddOrEven} {result.Color} {result.Number} | Your bet: {selectedOption}", "Roulette");
                }
                else
                {
                    responseBuilder = _messagesHelper.LoseInformation(nmbBet, $"Result: {result.OddOrEven} {result.Color} {result.Number} | Your bet: {selectedOption}", "Roulette");
                }

                return(_messagesHelper.AddCoinsBalanceAndExpInformation(responseBuilder, expResult,
                                                                        await _usersConnector.GetCredits(userId)));
            }

            return(_messagesHelper.InvalidArguments(new[] { "<Red|Black|Odd|Even|Number> <Bet>" }, "!roulette",
                                                    "Roulette"));
        }
        public async Task <Message> PlayCoinflip(string argument, ulong userId)
        {
            var arguments = argument.ToUpper().TrimStart().Split(' ');

            if (arguments.Length != 2)
            {
                return(_messagesHelper.InvalidArguments(new[] { "<Head|Tail>", "<Bet>" }, "CoinFlip"));
            }

            var option = arguments[0] == "HEAD" || arguments[0] == "TAIL" ? arguments[0] : "";
            var amount = arguments[1].Trim();

            if (string.IsNullOrWhiteSpace(option) || string.IsNullOrWhiteSpace(amount))
            {
                return(_messagesHelper.InvalidArguments(new[] { "<Head|Tail>", "<Bet>" }, "CoinFlip"));
            }

            var bet = amount switch
            {
                "ALL" => await _usersConnector.GetCredits(userId),
                "HALF" => await _usersConnector.GetCredits(userId) / 2,
                _ => _betSizeParser.Parse(arguments[1])
            };

            if (bet == -1)
            {
                return(_messagesHelper.Error("Check your arguments (whether bet size does not equal 0 for example)!"));
            }

            if (await _usersConnector.TakeCredits(userId, bet))
            {
                var rnd    = new Random();
                var hasWon = (Convert.ToBoolean(rnd.Next(0, 2)) ? "HEAD" : "TAIL") == option;

                var exp       = ExpHelpers.CalculateBet((await _usersConnector.GetUser(userId)).Level, bet);
                var expResult = await _usersConnector.CommandGiveUserExp(userId, exp);

                if (hasWon)
                {
                    await _usersConnector.GiveCredits(userId, bet * 2);
                }

                var embed = hasWon
                    ? _messagesHelper.WinInformation(bet, title: "CoinFlip")
                    : _messagesHelper.LoseInformation(bet, title: "CoinFlip");

                _messagesHelper.AddCoinsBalanceInformation(embed, await _usersConnector.GetCredits(userId));
                if (expResult.DidUserLevelUp)
                {
                    embed = _messagesHelper.AddLevelUpMessage(embed);
                }

                await _gameHistoryConnector.AddGameHistory(new GameHistory
                {
                    GameName        = "coinflip",
                    HasWon          = hasWon,
                    CoinsDifference = hasWon ? bet : bet * -1,
                    UserId          = userId
                });

                return(embed);
            }

            return(_messagesHelper.NotEnoughCredits("CoinFlip"));
        }
    }
Exemple #3
0
        public async Task <Message> PlaySlots(ulong userId, string arguments)
        {
            var argument = arguments.ToUpper().TrimStart().Split(' ');

            if (argument.Length == 1)
            {
                var bet = argument[0].Trim() switch
                {
                    "ALL" => await _usersConnector.GetCredits(userId),
                    "HALF" => await _usersConnector.GetCredits(userId) / 2,
                    _ => _betSizeParser.Parse(argument[0])
                };
                if (bet == -1)
                {
                    return(_messagesHelper.InvalidArguments(new[] { "slots <Bet>" }, "!slots", "Slots"));
                }
                if (await _usersConnector.TakeCredits(userId, bet))
                {
                    var hasWon = false;

                    var result = Slots.GetResult();

                    var pointsResult = Slots.GetPointsFromResult(result, bet);

                    var message = "";

                    if (pointsResult > 0)
                    {
                        hasWon = true;
                        if (Slots.IsJackpot(result))
                        {
                            message = "\n" + "JACKPOT!!! You won " + pointsResult + " points!";
                        }
                        else if (Slots.IsDouble(result))
                        {
                            message = "\n" + "DOUBLE! You won " + pointsResult + " points!";
                        }
                        await _usersConnector.GiveCredits(userId, pointsResult + bet);
                    }

                    var exp       = ExpHelpers.CalculateBet((await _usersConnector.GetUser(userId)).Level, bet);
                    var expResult = await _usersConnector.CommandGiveUserExp(userId, exp);

                    await _gameHistoryConnector.AddGameHistory(new GameHistory
                    {
                        GameName        = "slots",
                        HasWon          = hasWon,
                        CoinsDifference = hasWon ? pointsResult : bet * -1,
                        UserId          = userId
                    });

                    return(_messagesHelper.AddCoinsBalanceAndExpInformation(hasWon
                            ? _messagesHelper.Success(
                                                                                "You've won!\nResult: " + result.EmojiOne + " " + result.EmojiTwo + " " +
                                                                                result.EmojiThree
                                                                                + message, "Slots")
                            : _messagesHelper.LoseInformation(bet, "Slots"), expResult,
                                                                            await _usersConnector.GetCredits(userId)));
                }

                return(_messagesHelper.NotEnoughCredits("Slots"));
            }

            return(_messagesHelper.InvalidArguments(new[] { "slots <Bet>" }, "!slots", "Slots"));
        }
    }
        public async Task <Message> GetCurrentCreditStatus(ulong userId)
        {
            var credits = await _usersConnector.GetCredits(userId);

            return(_messagesHelper.AddCoinsBalanceInformation(_messagesHelper.Information(""), credits));
        }