Esempio n. 1
0
        public async Task BuyItemFromShop(int item)
        {
            var      user     = ((SocketGuildUser)Context.Message.Author);
            var      userId   = user.Id;
            Shop     shopItem = ObjectUtils.GetShopItem(item);
            UserInfo userInfo = ObjectUtils.GetUserInformation(userId);
            var      embed    = new EmbedBuilder();
            Random   r        = new Random();

            if (userInfo.points < shopItem.cost)
            {
                await ReplyAsync($"User does not have enough points to buy item.");
            }
            else
            {
                DatabaseUtils.DecrementDocument(userId, "points", shopItem.cost);
                DatabaseUtils.IncrementDocument(userId, "totalAttack", shopItem.attack);
                DatabaseUtils.IncrementDocument(userId, "totalDefense", shopItem.defence);
                embed.WithTitle("Item bought!");
                embed.WithThumbnailUrl(user.GetAvatarUrl());
                embed.AddField("Attack", userInfo.totalAttack + shopItem.attack, true);
                embed.AddField("Defense", userInfo.totalDefense + shopItem.defence, true);
                embed.WithColor(new Color(r.Next(0, 256), r.Next(0, 256), r.Next(0, 256)));
                await ReplyAsync("", embed : embed.Build());
            }
        }
        public async Task PayLoan(int amount, [Remainder] string bank)
        {
            var       user      = Context.User;
            UserInfo  userInfo  = ObjectUtils.GetUserInformation(user.Id);
            PointBank pointBank = ObjectUtils.GetPointBank(bank.ToLower());
            var       loans     = Util.CheckIfUserHasLoan(Context.User.Id);

            foreach (var loan in loans)
            {
                if (bank.Equals(loan.Key))
                {
                    if (userInfo.points < amount)
                    {
                        await ReplyAsync($"{user.Username} has {userInfo.points}.\nYou cannot pay {amount}.");

                        return;
                    }
                    else if (amount > loan.Value)
                    {
                        await ReplyAsync($"Loan is {loan.Value}.\nYou cannot pay {amount}.");

                        return;
                    }
                    else if (amount < 1)
                    {
                        await ReplyAsync($"You cannot pay less than 1 point.");

                        return;
                    }
                    else if (amount.Equals(loan.Value))
                    {
                        DatabaseUtils.DecrementDocument(user.Id, "points", amount);
                        pointBank.currentLoans.Remove(user.Id.ToString());
                        Util.UpdateArray("_id", pointBank._id, "currentLoans", user.Id.ToString(), pointBank, "pointBanks", false);
                        await ReplyAsync($"Loan paid back in full to {pointBank._id}");

                        return;
                    }
                    else
                    {
                        DatabaseUtils.DecrementDocument(user.Id, "points", amount);
                        pointBank.currentLoans[user.Id.ToString()] -= amount;
                        Util.UpdateArray("_id", pointBank._id, "currentLoans", user.Id.ToString(), pointBank, "pointBanks", false);
                        await ReplyAsync($"Payment on loan made.\nRemaining balance {pointBank.currentLoans[user.Id.ToString()]}");

                        return;
                    }
                }
            }
            await ReplyAsync("You do not have a loan out for this bank.");
        }
Esempio n. 3
0
        public async Task RollUnder(int UserUnderValue, int bet)
        {
            var          user              = ((SocketGuildUser)Context.Message.Author);
            var          userId            = user.Id;
            var          embed             = new EmbedBuilder();
            UsersEntered userInCompetition = ObjectUtils.GetUsersInCompetition("_id", userId);

            if (UserUnderValue < 2 || UserUnderValue > 99)
            {
                await ReplyAsync($"Undervalue must be between 2 and 99");
            }
            else if (userInCompetition.credits < bet)
            {
                await ReplyAsync($"{user} has {userInCompetition.credits} credits! You cannot bet {bet}!");
            }
            else if (bet <= 0)
            {
                await ReplyAsync($"Bet must bet 1 or more credits");
            }
            else
            {
                Random rand   = new Random(DateTime.Now.Millisecond);
                var    value  = rand.Next(100) + 1;
                double factor = 100 / (double)(UserUnderValue - 1);
                if (UserUnderValue > value) //win
                {
                    var winnings = (bet * factor) - bet;
                    DatabaseUtils.IncrementDocument(userId, "credits", (int)winnings, "competition");
                    embed.WithColor(Color.Green);
                    embed.AddField("Result", "Winner", true);
                    embed.AddField("Random Value", value, true);
                    embed.AddField("Winnings", (int)winnings, true);
                    embed.AddField("Total points", userInCompetition.credits + (int)winnings, true);
                }
                else
                {
                    DatabaseUtils.DecrementDocument(userId, "credits", bet, "competition");
                    embed.WithColor(Color.Red);
                    embed.AddField("Result", "Loser", true);
                    embed.AddField("Random Value", value, true);
                    embed.AddField("Losing", -bet, true);
                    embed.AddField("Total points", userInCompetition.credits - bet, true);
                }
                await ReplyAsync("", embed : embed.Build());
            }
        }
        public async Task TakeLoan(int amount, [Remainder] string bank)
        {
            var          user      = Context.User;
            UserInfo     userInfo  = ObjectUtils.GetUserInformation(user.Id);
            PointBank    pointBank = ObjectUtils.GetPointBank(bank.ToLower());
            EmbedBuilder embed     = new EmbedBuilder();

            if (Util.CheckIfUserHasLoan(user.Id) != null)
            {
                await ReplyAsync("You already have a loan out for this bank!");

                return;
            }
            if (amount < pointBank.minWithdrawal)
            {
                await ReplyAsync($"Cannot take out a loan less than {pointBank.minWithdrawal} points!");
            }
            else if (amount > pointBank.currentCredits)
            {
                await ReplyAsync($"Cannot take out a loan which exceeds the amount of money in the vault!\nCurrent money in the vault is {pointBank.currentCredits}");
            }
            else
            {
                int loanBalance = (int)(amount * (1 + pointBank.interestRate));
                pointBank.currentLoans.Add(user.Id.ToString(), loanBalance);
                var dict = new BsonDocument {
                    { user.Id.ToString(), loanBalance }
                };
                Util.UpdateArray("_id", pointBank._id, "currentLoans", dict, pointBank, "pointBanks");
                DatabaseUtils.IncrementDocument(Context.User.Id, "points", amount);
                DatabaseUtils.DecrementDocument(pointBank._id, "currentCredits", amount, "pointBanks");
                embed.Title = "Succesful loan approval!";
                embed.Color = Color.Green;
                embed.AddField($"{Context.User.ToString()} points", userInfo.points + amount);
                embed.AddField($"{pointBank._id}'s vault value", pointBank.currentCredits - amount);
                await ReplyAsync(embed : embed.Build());
            }
        }
Esempio n. 5
0
        public async Task Bet([Summary("Amount of points to bet")] int bettingPoints, [Summary("Side of coin picked.")] string coinSide)
        {
            var  user   = ((SocketGuildUser)Context.Message.Author);
            var  userId = user.Id;
            bool win    = false;
            var  embed  = new EmbedBuilder();

            embed.WithTitle("Coin Toss");
            UserInfo userInfo = ObjectUtils.GetUserInformation(user.Id);

            if (userInfo != null)
            {
                var currentPoints = userInfo.points;
                if (bettingPoints > currentPoints)
                {
                    await ReplyAsync($"{user} has {currentPoints} points! You cannot bet {bettingPoints}!");
                }
                else if (bettingPoints < 50)
                {
                    await ReplyAsync($"Minimum bet is 50 points");
                }
                else if (!(Util.StringEquals("heads", coinSide) || Util.StringEquals("tails", coinSide)))
                {
                    await ReplyAsync($"Coin sides are ***heads*** or ***tails***.");
                }
                else
                {
                    Random rand   = new Random();
                    var    num    = rand.Next(0, 2);
                    string result = null;
                    if (num == 0)
                    {
                        result = "heads";
                        embed.WithThumbnailUrl("https://upload.wikimedia.org/wikipedia/commons/thumb/a/a0/2006_Quarter_Proof.png/244px-2006_Quarter_Proof.png");
                    }
                    else
                    {
                        result = "tails";
                        embed.WithThumbnailUrl("https://mbtskoudsalg.com/images/quarter-transparent-tail-1.png");
                    }

                    if (Util.StringEquals(result, coinSide))
                    {
                        win = true;
                        DatabaseUtils.DecrementDocument(userId, "loseCoinflipStreak", userInfo.loseCoinflipStreak);
                        DatabaseUtils.IncrementDocument(userId, "winCoinflipStreak", 1);
                        DatabaseUtils.IncrementDocument(userId, "points", bettingPoints);
                        embed.WithColor(Color.Green);
                        embed.AddField("Result", "Winner", true);
                        embed.AddField("Coin side", result, true);
                        embed.AddField("Winning streak", userInfo.winCoinflipStreak + 1, true);
                        embed.AddField("Total points", currentPoints + bettingPoints, true);
                    }
                    else
                    {
                        DatabaseUtils.DecrementDocument(userId, "winCoinflipStreak", userInfo.winCoinflipStreak);
                        DatabaseUtils.IncrementDocument(userId, "loseCoinflipStreak", 1);
                        DatabaseUtils.DecrementDocument(userId, "points", bettingPoints);
                        embed.WithColor(Color.Red);
                        embed.AddField("Result", "Loser", true);
                        embed.AddField("Coin side", result, true);
                        embed.AddField("Losing streak", userInfo.loseCoinflipStreak + 1, true);
                        embed.AddField("Total points", currentPoints - bettingPoints, true);
                    }
                    await ReplyAsync("", embed : embed.Build());

                    await RoleUtils.CoinflipRoles(user, bettingPoints, win, Context.Message.Channel.Id);
                }
            }
        }