Beispiel #1
0
        public static async Task SellAllInventoryItemAsync(SocketCommandContext Context)
        {
            //Get price data
            var rootSkinData = CsgoDataHandler.GetRootWeaponSkin();
            var userSkin     = XmlManager.FromXmlFile <UserSkinStorageRootobject>(CoreMethod.GetFileLocation("UserSkinStorage.xml"));

            try
            {
                long weaponSkinValue = GetItemValue(userSkin.UserSkinEntries, rootSkinData);

                //Give user credits
                UserCreditsHandler.AddCredits(Context, weaponSkinValue, true);

                //Remove skin from inventory
                var filteredUserSkinEntries = userSkin.UserSkinEntries.Where(s => s.OwnerID == Context.Message.Author.Id).Where(s => s.OwnerID != Context.Message.Author.Id).ToList();

                //Write to file
                WriteUserSkinDataToFile(filteredUserSkinEntries);

                //Send receipt
                await Context.Channel.SendMessageAsync(
                    UserInteraction.BoldUserName(Context) + $", you sold your inventory" +
                    $" for **{UserBankingHandler.CreditCurrencyFormatter(weaponSkinValue)} Credits** " +
                    $"| A total of **{UserBankingHandler.CreditCurrencyFormatter(UserCreditsTaxHandler.TaxCollector(weaponSkinValue))} Credits was taken off as tax**");
            }
            catch (Exception)
            {
            }
        }
        public async Task SlotBalanceAsync()
        {
            long userCredits = UserCreditsHandler.GetUserCredits(Context);

            await Context.Message.Channel.SendMessageAsync(
                $"**{Context.Message.Author.ToString().Substring(0, Context.Message.Author.ToString().Length - 5)}**," +
                $" You have **{UserBankingHandler.CreditCurrencyFormatter(userCredits)} Credits**");
        }
Beispiel #3
0
        public static async Task SellAllSelectedInventoryItemAsync(SocketCommandContext Context, string itemMarketHash)
        {
            //Get skin data
            var rootSkinData = CsgoDataHandler.GetRootWeaponSkin();
            var userSkin     = XmlManager.FromXmlFile <UserSkinStorageRootobject>(CoreMethod.GetFileLocation("UserSkinStorage.xml"));

            try
            {
                //Find ALL user selected items, make sure it is owned by user
                var selectedSkinToSell = userSkin.UserSkinEntries
                                         .Where(s => s.MarketName.ToLower().Contains(itemMarketHash.ToLower()))
                                         .Where(s => s.OwnerID == Context.Message.Author.Id).ToList();

                //Get item prices
                long weaponSkinValue = GetItemValue(selectedSkinToSell, rootSkinData);

                //Give user credits
                UserCreditsHandler.AddCredits(Context, weaponSkinValue, true);

                //Remove skin from inventory
                List <string> filterUserSkinNames = new List <string>();
                foreach (var item in selectedSkinToSell)
                {
                    //Remove items that were selected to be sold
                    userSkin.UserSkinEntries.Remove(item);

                    filterUserSkinNames.Add(item.MarketName);
                }

                //Write to file
                WriteUserSkinDataToFile(userSkin);

                //Send receipt
                await Context.Channel.SendMessageAsync(
                    UserInteraction.BoldUserName(Context) + $", you sold your \n`{string.Join("\n", filterUserSkinNames)}`" +
                    $" for **{UserBankingHandler.CreditCurrencyFormatter(weaponSkinValue)} Credits** " +
                    $"| A total of **{UserBankingHandler.CreditCurrencyFormatter(UserCreditsTaxHandler.TaxCollector(weaponSkinValue))} Credits was taken off as tax**");
            }
            catch (Exception)
            {
                //Send error if user does not have item
                await Context.Channel.SendMessageAsync($"**{Context.Message.Author.ToString().Substring(0, Context.Message.Author.ToString().Length - 5)}**, you do not have `{itemMarketHash}` in your inventory");
            }
        }
Beispiel #4
0
        //Sell
        public static async Task SellInventoryItemAsync(SocketCommandContext Context, string itemMarketHash)
        {
            //Get skin data
            var rootWeaponSkin = CsgoDataHandler.GetRootWeaponSkin();
            var rootUserSkin   = XmlManager.FromXmlFile <UserSkinStorageRootobject>(CoreMethod.GetFileLocation("UserSkinStorage.xml"));

            try
            {
                //Find user selected item, make sure it is owned by user
                var selectedSkinToSell = rootUserSkin.UserSkinEntries
                                         .Where(s => s.MarketName.ToLower().Contains(itemMarketHash.ToLower()))
                                         .Where(s => s.OwnerID == Context.Message.Author.Id)
                                         .FirstOrDefault();

                //Get item price
                long weaponSkinValue = Convert.ToInt64(rootWeaponSkin.ItemsList.Values.Where(s => s.Name == selectedSkinToSell.MarketName).FirstOrDefault().Price.AllTime.Average);

                //Give user credits
                UserCreditsHandler.AddCredits(Context, weaponSkinValue, true);

                //Remove skin from inventory
                var filteredUserSkinEntries = rootUserSkin.UserSkinEntries.Where(s => s.OwnerID == Context.Message.Author.Id).Where(s => s.ClassId != selectedSkinToSell.ClassId).ToList();

                //Write to file
                WriteUserSkinDataToFile(filteredUserSkinEntries);

                //Send receipt
                await Context.Channel.SendMessageAsync(
                    UserInteraction.BoldUserName(Context) + $", you sold your `{selectedSkinToSell.MarketName}`" +
                    $" for **{UserBankingHandler.CreditCurrencyFormatter(weaponSkinValue)} Credits** " +
                    $"| A total of **{UserBankingHandler.CreditCurrencyFormatter(UserCreditsTaxHandler.TaxCollector(weaponSkinValue))} Credits was taken off as tax**");
            }
            catch (Exception)
            {
                //Send error if user does not have item
                await Context.Channel.SendMessageAsync($"**{Context.Message.Author.ToString().Substring(0, Context.Message.Author.ToString().Length - 5)}**, you do not have `{itemMarketHash}` in your inventory");
            }
        }
Beispiel #5
0
        public static async Task UserGambling(SocketCommandContext context, SocketMessage message, long gambleAmount)
        {
            //Tell off the user if they are trying to gamble 0 dollars
            if (gambleAmount <= 0)
            {
                await message.Channel.SendMessageAsync(UserInteraction.BoldUserName(context) + ", Quack, you have to gamble **1 or more** credits");
            }
            else
            {
                //Get user credits to list
                var userCreditStorage = UserDataManager.GetUserStorage();

                //Money subtractor
                if ((userCreditStorage.UserInfo[context.Message.Author.Id].UserBankingStorage.Credit - gambleAmount) < 0)
                {
                    await message.Channel.SendMessageAsync(UserInteraction.BoldUserName(context) + $", you broke quack, you do not have enough credits || **" + UserBankingHandler.CreditCurrencyFormatter(userCreditStorage.UserInfo[context.Message.Author.Id].UserBankingStorage.Credit) + " Credits**");
                }
                else
                {
                    //Calculate outcome (userCredits - amountGambled + AmountReturned)
                    long returnAmount = CalculateUserGamblingOutcome(gambleAmount);

                    long userReturnAmount = userCreditStorage.UserInfo[context.Message.Author.Id].UserBankingStorage.Credit - gambleAmount + returnAmount;

                    //Send outcome & calculate taxes
                    //Write credits to file
                    UserCreditsHandler.SetCredits(
                        context,
                        userReturnAmount - await UserCreditsTaxHandler.TaxCollectorAsync(context, returnAmount, UserInteraction.BoldUserName(context) + $", you gambled **{UserBankingHandler.CreditCurrencyFormatter(gambleAmount)} credits** and made **{UserBankingHandler.CreditCurrencyFormatter(returnAmount)} credits**"));
                }
            }
        }
Beispiel #6
0
        //Daily
        public static async Task GiveDailyCreditsAsync(SocketCommandContext context)
        {
            //Get user storage
            var userStorage = UserDataManager.GetUserStorage();

            //If 24 hours has passed
            if (userStorage.UserInfo[context.Message.Author.Id].UserDailyLastUseStorage.DateTime.AddHours(24) < DateTime.UtcNow)
            {
                //Add credits
                UserCreditsHandler.AddCredits(context, long.Parse(SettingsManager.RetrieveFromConfigFile("dailyAmount")));

                //Write last use date
                userStorage.UserInfo[context.Message.Author.Id].UserDailyLastUseStorage.DateTime = DateTime.UtcNow;


                //Write new credits and last redeem date to file
                userStorage = UserDataManager.GetUserStorage();
                userStorage.UserInfo[context.Message.Author.Id].UserDailyLastUseStorage.DateTime = DateTime.UtcNow;
                UserDataManager.WriteUserStorage(userStorage);


                //Send channel message confirmation
                await context.Message.Channel.SendMessageAsync(UserInteraction.BoldUserName(context) + ", you have redeemed your daily **" + UserBankingHandler.CreditCurrencyFormatter(long.Parse(SettingsManager.RetrieveFromConfigFile("dailyAmount"))) + " Credits!**");
            }
            else
            {
                await context.Message.Channel.SendMessageAsync(UserInteraction.BoldUserName(context) + ", you quacker, it has not yet been 24 hours since you last redeemed");
            }
        }
        public static async Task BuyUserStocksAsync(SocketCommandContext Context, string tickerSymbol, long buyAmount)
        {
            var marketStockStorage = XmlManager.FromXmlFile <MarketStockStorage>(CoreMethod.GetFileLocation(@"\MarketStocksValue.xml"));

            foreach (var stock in marketStockStorage.MarketStock)
            {
                //Get the user selected stock from storage
                if (stock.StockTicker == tickerSymbol)
                {
                    //Sets buystockExists to true so it won't send a warning saying stock does not exist
                    bool buyStockExists = true;

                    //Get user portfolio
                    var userStocksStorage = XmlManager.FromXmlFile <UserStockStorage>(CoreMethod.GetFileLocation(@"\UserStocks") + @"\" + Context.User.Id.ToString() + ".xml");

                    //Calculate stock price
                    long stockTotalCost = stock.StockPrice * buyAmount;

                    //Return error if stock value is currently at 0
                    if (stock.StockPrice <= 0)
                    {
                        await Context.Message.Channel.SendMessageAsync($"There are no available sellers for stock **{tickerSymbol}**");
                    }
                    //Check if user can buy stock
                    else if (UserCreditsHandler.GetUserCredits(Context) - stockTotalCost < 0)
                    {
                        await Context.Message.Channel.SendMessageAsync($"You do not have enough credits to buy **{buyAmount} {tickerSymbol}** stocks at price of **{UserBankingHandler.CreditCurrencyFormatter(stock.StockPrice)} each** totaling **{UserBankingHandler.CreditCurrencyFormatter(stockTotalCost)} Credits**");
                    }
                    //Check if user is buying 0 or less stocks
                    else if (buyAmount < 1)
                    {
                        await Context.Message.Channel.SendMessageAsync($"You must buy **1 or more** stocks");
                    }
                    else
                    {
                        //Subtract user balance
                        UserCreditsHandler.AddCredits(Context, Convert.ToInt64(-stockTotalCost));


                        //Check if user already has some of stock currently buying
                        //If true, Calculates new user stock total
                        long newStockAmount = buyAmount;
                        foreach (var userStock in userStocksStorage.UserStock)
                        {
                            if (userStock.StockTicker == tickerSymbol)
                            {
                                newStockAmount += userStock.StockAmount;
                            }
                        }


                        //Send user receipt
                        await Context.Message.Channel.SendMessageAsync($"You purchased **{buyAmount} {tickerSymbol}** stocks at price of **{stock.StockPrice} each** totaling **{stockTotalCost} Credits**");


                        //Add existing user stocks to list
                        var userStockStorage = XmlManager.FromXmlFile <UserStockStorage>(CoreMethod.GetFileLocation(@"\UserStocks") + @"\" + Context.User.Id.ToString() + ".xml");
                        List <UserStock> userStockStorageList = new List <UserStock>();

                        foreach (var userStock in userStockStorage.UserStock)
                        {
                            if (userStock.StockTicker != tickerSymbol)
                            {
                                userStockStorageList.Add(userStock);
                            }
                        }

                        //Add new stock
                        userStockStorageList.Add(new UserStock {
                            StockTicker = tickerSymbol, StockAmount = newStockAmount, StockBuyPrice = stock.StockPrice
                        });

                        //Write user stock amount
                        var userStockRecord = new UserStockStorage
                        {
                            UserStock = userStockStorageList
                        };

                        XmlManager.ToXmlFile(userStockRecord, CoreMethod.GetFileLocation(@"\UserStocks") + @"\" + Context.User.Id.ToString() + ".xml");
                    }

                    //Send warning if stock does not exist
                    if (buyStockExists == false)
                    {
                        await Context.Message.Channel.SendMessageAsync($"Stock **{tickerSymbol}** does not exist in the market");
                    }
                }
            }
        }
        public static async Task SellUserStocksAsync(SocketCommandContext Context, string tickerSymbol, long sellAmount)
        {
            var marketStockStorage = XmlManager.FromXmlFile <MarketStockStorage>(CoreMethod.GetFileLocation(@"\MarketStocksValue.xml"));

            foreach (var stock in marketStockStorage.MarketStock)
            {
                if (stock.StockTicker == tickerSymbol)
                {
                    //Get user portfolio
                    var userStockStorage = XmlManager.FromXmlFile <UserStockStorage>(CoreMethod.GetFileLocation(@"\UserStocks") + @"\" + Context.User.Id.ToString() + ".xml");

                    //Check if user is selling more stocks than they have
                    try
                    {
                        long userStockAmount = 0;
                        long stockTotalWorth = 0;
                        foreach (var userStock in userStockStorage.UserStock)
                        {
                            if (userStock.StockTicker == tickerSymbol)
                            {
                                userStockAmount = userStock.StockAmount;
                                stockTotalWorth = sellAmount * stock.StockPrice;
                            }
                        }

                        if (userStockAmount - sellAmount < 0)
                        {
                            await Context.Message.Channel.SendMessageAsync($"You do not have enough **{tickerSymbol}** stocks to sell || **{userStockAmount} Stocks**");
                        }
                        //Check if user is selling 0 or less stocks
                        else if (sellAmount < 1)
                        {
                            await Context.Message.Channel.SendMessageAsync($"You must sell **1 or more** stocks");
                        }
                        else
                        {
                            //Add user balance
                            UserCreditsHandler.AddCredits(
                                Context,
                                //Subtract tax deductions
                                stockTotalWorth - await UserCreditsTaxHandler.TaxCollectorAsync(
                                    Context,
                                    stockTotalWorth,
                                    $"You sold **{sellAmount} {tickerSymbol}** stocks totaling **{UserBankingHandler.CreditCurrencyFormatter(stockTotalWorth)} Credits**"));

                            //Send user receipt

                            long newStockAmount = userStockAmount - sellAmount;

                            //Write user stock amount
                            //Add existing user stocks to list
                            List <UserStock> userStockStorageList = new List <UserStock>();

                            foreach (var userStock in userStockStorage.UserStock)
                            {
                                if (userStock.StockTicker != tickerSymbol)
                                {
                                    userStockStorageList.Add(userStock);
                                }
                            }

                            //Add newly sold stock
                            userStockStorageList.Add(new UserStock {
                                StockTicker = tickerSymbol, StockAmount = newStockAmount, StockBuyPrice = stock.StockPrice
                            });

                            //Write user stock amount
                            var userStockRecord = new UserStockStorage
                            {
                                UserStock = userStockStorageList
                            };

                            XmlManager.ToXmlFile(userStockRecord, CoreMethod.GetFileLocation(@"\UserStocks") + @"\" + Context.User.Id.ToString() + ".xml");
                        }
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.StackTrace);
                    }
                }
            }
        }
Beispiel #9
0
        //Buy
        public static async Task BuyItemFromMarketAsync(SocketCommandContext context, string itemMarketHash)
        {
            //Get skin data
            var rootWeaponSkins = CsgoDataHandler.GetRootWeaponSkin();

            try
            {
                UserSkinEntry selectedMarketSkin = new UserSkinEntry();

                //Get market skin cost
                long weaponSkinValue = Convert.ToInt64(rootWeaponSkins.ItemsList.Values.Where(s => s.Name.ToLower().Contains(itemMarketHash.ToLower())).FirstOrDefault().Price.AllTime.Average);

                //Add tax markup :)
                weaponSkinValue += Convert.ToInt64(weaponSkinValue * float.Parse(SettingsManager.RetrieveFromConfigFile("taxRate")));



                bool userSpecifiedSkinExistsInMarket = false;

                //Make sure skin exists in market
                foreach (var marketSkin in rootWeaponSkins.ItemsList.Values)
                {
                    //If it does exist, get info on it
                    if (marketSkin.Name.ToLower().Contains(itemMarketHash.ToLower()))
                    {
                        userSpecifiedSkinExistsInMarket = true;

                        selectedMarketSkin.ClassId    = marketSkin.Classid;
                        selectedMarketSkin.OwnerID    = context.Message.Author.Id;
                        selectedMarketSkin.UnboxDate  = DateTime.UtcNow;
                        selectedMarketSkin.MarketName = marketSkin.Name;
                    }
                }
                //Send error if skin does not exist
                if (userSpecifiedSkinExistsInMarket == false)
                {
                    await context.Message.Channel.SendMessageAsync(UserInteraction.BoldUserName(context) + $", `{itemMarketHash}` does not exist in the current skin market");
                }
                //Make sure user has enough credits to buy skin
                else if (UserCreditsHandler.GetUserCredits(context) < weaponSkinValue)
                {
                    await context.Message.Channel.SendMessageAsync($"**{context.Message.Author.ToString().Substring(0, context.Message.Author.ToString().Length - 5)}**, you do not have enough credits to buy`{itemMarketHash}` | **{UserCreditsHandler.GetUserCredits(context)} Credits**");
                }
                else
                {
                    //Checks are true, now give user skin and remove credits

                    //Remove user credits
                    UserCreditsHandler.AddCredits(context, -weaponSkinValue, true);

                    //Add skin to inventory
                    var userSkins = XmlManager.FromXmlFile <UserSkinStorageRootobject>(CoreMethod.GetFileLocation("UserSkinStorage.xml"));

                    userSkins.UserSkinEntries.Add(selectedMarketSkin);

                    var filteredUserSkin = new UserSkinStorageRootobject
                    {
                        SkinAmount      = 0,
                        UserSkinEntries = userSkins.UserSkinEntries
                    };

                    XmlManager.ToXmlFile(filteredUserSkin, CoreMethod.GetFileLocation("UserSkinStorage.xml"));

                    //Send receipt
                    await context.Channel.SendMessageAsync(
                        UserInteraction.BoldUserName(context) + $", you bought`{selectedMarketSkin.MarketName}`" +
                        $" for **{UserBankingHandler.CreditCurrencyFormatter(weaponSkinValue)} Credits**");
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.StackTrace);
            }
        }