public static PaginatedMessage DisplayUserCsgoInventory(SocketCommandContext context)
        {
            string botCommandPrefix = CommandGuildPrefixManager.GetGuildCommandPrefix(context);

            //Reset fields
            embedFieldsMaster      = new List <string>();
            embedPriceFieldsMaster = new List <string>();

            //Get user skins from xml file
            UserSkinStorageRootobject userSkin = new UserSkinStorageRootobject();

            try
            {
                userSkin = XmlManager.FromXmlFile <UserSkinStorageRootobject>(CoreMethod.GetFileLocation("UserSkinStorage.xml"));
            }
            catch (Exception)
            {
            }

            List <UserSkinEntry> foundUserSkins = new List <UserSkinEntry>();

            //Filter userSkinEntries xml file down to skins belonging to sender
            foreach (var userSkinEntry in userSkin.UserSkinEntries)
            {
                //Filter skin search to those owned by user
                if (userSkinEntry.OwnerID == context.Message.Author.Id)
                {
                    foundUserSkins.Add(new UserSkinEntry {
                        OwnerID = context.Message.Author.Id, ClassId = userSkinEntry.ClassId, UnboxDate = userSkinEntry.UnboxDate
                    });
                }
            }

            //Generate fields
            AddSkinFieldEntry(foundUserSkins);

            //Configurate paginated message
            var paginationConfig = new PaginationConfig
            {
                AuthorName = context.Message.Author.ToString().Substring(0, context.Message.Author.ToString().Length - 5) + " Inventory",
                AuthorURL  = context.Message.Author.GetAvatarUrl(),

                Description = $"To sell items, use `{botCommandPrefix} cs sell [name]` \n To sell all items matching filter, use `{botCommandPrefix} cs sellall [name]`",

                DefaultFieldHeader      = "You do not have any skins",
                DefaultFieldDescription = $"Go unbox some with `{botCommandPrefix} case open`",

                Field1Header = "Item Name",
                Field2Header = "Market Value",
            };

            var paginationManager = new PaginationManager();

            //Generate paginated message
            var pager = paginationManager.GeneratePaginatedMessage(embedFieldsMaster, embedPriceFieldsMaster, paginationConfig);

            return(pager);
        }
示例#2
0
        private static void WriteUserSkinDataToFile(List <UserSkinEntry> skinEntries)
        {
            var filteredUserSkin = new UserSkinStorageRootobject
            {
                SkinAmount      = 0,
                UserSkinEntries = skinEntries
            };

            XmlManager.ToXmlFile(filteredUserSkin, CoreMethod.GetFileLocation("UserSkinStorage.xml"));
        }
示例#3
0
 private static void WriteUserSkinDataToFile(UserSkinStorageRootobject skinEntry)
 {
     XmlManager.ToXmlFile(skinEntry, CoreMethod.GetFileLocation("UserSkinStorage.xml"));
 }
示例#4
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);
            }
        }