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> 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")); } }