Example #1
0
        public async Task Command(int bet)
        {
            if (bet < 5)
            {
                throw new ArgumentOutOfRangeException(nameof(bet), "Your bet must be at least `5` points.");
            }

            User user = await DatabaseQueries.GetOrCreateUserAsync(Context.User.Id);

            if (bet > MAX_BET && !user.IsPremium)
            {
                await SendBasicErrorEmbedAsync($"Sorry, but only premium subscribers may bet more than " +
                                               $"`{MAX_BET:N0}` points.");

                return;
            }

            if (bet > MAX_PREMIUM_BET && user.IsPremium)
            {
                await SendBasicErrorEmbedAsync($"Sorry, but you may not bet more than " +
                                               $"`{MAX_PREMIUM_BET:N0}` points.");

                return;
            }

            if (user.Points < bet)
            {
                await SendBasicErrorEmbedAsync($"You don't have enough points to perform this action.\n" +
                                               $"Current points: `{user.Points:N0}` points.");

                return;
            }

            var r    = new Random();
            int roll = r.Next(101);

            if (roll > 100)
            {
                roll = 100;
            }

            if (user.IsPremium)
            {
                roll = (int)(roll * 1.05);
            }

            RollResult rollResult = GetRollResult(roll);
            int        payout     = GetPayout(rollResult, bet);
            bool       winner;

            var embed = new KaguyaEmbedBuilder
            {
                Title = $"Kaguya Betting: "
            };

            switch (rollResult)
            {
            case RollResult.LOSS:
                winner            = false;
                embed.Title      += "Loser";
                embed.Description = $"{Context.User.Mention} rolled `{roll}` and lost their bet of " +
                                    $"`{bet:N0}` points! Better luck next time!";

                break;

            default:
                winner            = true;
                embed.Title      += "Winner!";
                embed.Description = $"{Context.User.Mention} rolled `{roll}` and won " +
                                    $"`{payout:N0}` points, **`{GetMultiplier(rollResult)}x`** their bet!";

                break;
            }

            user = user.AddPoints((uint)payout);
            var gh = new GambleHistory
            {
                UserId = user.UserId,
                Action = GambleAction.BET_ROLL,
                Bet    = bet,
                Payout = payout,
                Roll   = roll,
                Time   = DateTime.Now.ToOADate(),
                Winner = winner
            };

            await DatabaseQueries.InsertAsync(gh);

            await DatabaseQueries.UpdateAsync(user);

            List <GambleHistory> allGh = await DatabaseQueries.GetAllForUserAsync <GambleHistory>(user.UserId);

            var footer = new EmbedFooterBuilder
            {
                Text = $"New points balance: {user.Points:N0} | Lifetime Bets: {allGh.Count:N0}"
            };

            embed.Footer = footer;
            embed.SetColor(GetEmbedColorBasedOnRoll(rollResult));

            await SendEmbedAsync(embed);
        }
Example #2
0
        public async Task Command(int points, string input)
        {
            User user = await DatabaseQueries.GetOrCreateUserAsync(Context.User.Id);

            Server server = await DatabaseQueries.GetOrCreateServerAsync(Context.Guild.Id);

            if (points < 100)
            {
                await SendBasicErrorEmbedAsync($"{Context.User.Mention} The minimum bet for this game is `100` points.");

                return;
            }

            if (points > 50000 && !user.IsPremium && !server.IsPremium)
            {
                await SendBasicErrorEmbedAsync($"{Context.User.Mention} Sorry, you must be either an active " +
                                               $"[Kaguya Premium]({ConfigProperties.KAGUYA_STORE_URL}) subscriber " +
                                               $"or be present in a server in which Kaguya Premium is active to bet " +
                                               $"more than `50,000` points.");

                return;
            }

            if (points > 500000 && (user.IsPremium || server.IsPremium))
            {
                await SendBasicErrorEmbedAsync($"{Context.User.Mention} Sorry, the maximum points you may bet regardless " +
                                               $"of [Kaguya Premium]({ConfigProperties.KAGUYA_STORE_URL}) " +
                                               $"status is `500,000` points.");

                return;
            }

            if (user.Points < points)
            {
                await SendBasicErrorEmbedAsync($"{Context.User.Mention} You do not have enough points to perform this action.\n\n" +
                                               $"Attempted to bet: `{points:N0}` points.\n" +
                                               $"Available balance: `{user.Points:N0}`");

                return;
            }

            var r             = new Random();
            int rollOne       = r.Next(2, 7); //upper-bound integer is exclusive while lower-bound is inclusive.
            int rollTwo       = r.Next(2, 7);
            int combinedScore = rollOne + rollTwo;

            DicePrediction prediction = GetDicePrediction(input);
            DiceOutcome    outcome    = GetDiceOutcome(combinedScore);

            bool winner = (int)prediction == (int)outcome;
            int  payout = GetWinningPayout(points, outcome);

            EmbedColor eColor = winner ? EmbedColor.GOLD : EmbedColor.GRAY;

            if (winner)
            {
                user.Points += payout;
            }
            else
            {
                payout       = -points;
                user.Points += payout; // We are adding a negative number.
            }

            var gambleH = new GambleHistory
            {
                UserId = user.UserId,
                Action = GambleAction.DICE_ROLL,
                Bet    = points,
                Payout = payout,
                Roll   = combinedScore,
                Time   = DateTime.Now.ToOADate(),
                Winner = winner,
                User   = user
            };

            await DatabaseQueries.InsertAsync(gambleH);

            string formattedPayout = winner ? $"+{payout:N0}" : $"-{points:N0}";
            var    embed           = new KaguyaEmbedBuilder(eColor)
            {
                Title       = "Dice Roll",
                Description = DiceDescription(rollOne, rollTwo, points, winner, outcome, prediction),
                Footer      = new EmbedFooterBuilder
                {
                    Text = $"New Points Balance: {user.Points:N0} ({formattedPayout})"
                }
            };

            await SendEmbedAsync(embed);

            await DatabaseQueries.UpdateAsync(user);
        }