コード例 #1
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**"));
                }
            }
        }
コード例 #2
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)
            {
            }
        }
コード例 #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");
            }
        }
コード例 #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");
            }
        }
コード例 #5
0
        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);
                    }
                }
            }
        }