예제 #1
0
        public static void RefreshRootWeaponSkin()
        {
            //Clear root Weapon skin
            rootWeaponSkin = null;

            //Get root weapon data again
            GetRootWeaponSkin();
        }
예제 #2
0
        private static long GetItemValue(List <UserSkinEntry> userSkins, RootSkinData rootSkinData)
        {
            long weaponSkinValue = 0;

            foreach (var item in userSkins)
            {
                weaponSkinValue += Convert.ToInt64(rootSkinData.ItemsList.Values.Where(s => s.Name == item.MarketName).FirstOrDefault().Price.AllTime.Average);
            }

            return(weaponSkinValue);
        }
예제 #3
0
        /// <summary>
        /// Gathers weapon skin data, if it has not been processed, it will process it
        /// </summary>
        /// <returns></returns>
        public static RootSkinData GetRootWeaponSkin()
        {
            if (rootWeaponSkin == null)
            {
                Stopwatch stopwatch = new Stopwatch();
                stopwatch.Start();
                EventLogger.LogMessage("Gathering CS:GO skin data, this may take a while");


                RootSkinData rootWeaponSkinTemp = new RootSkinData();
                //Read skin data from local json file
                using (StreamReader r = new StreamReader(CoreMethod.GetFileLocation("skinData.json")))
                {
                    string json           = r.ReadToEnd();
                    var    rootWeaponSkin = RootSkinData.FromJson(json);

                    rootWeaponSkinTemp = rootWeaponSkin;
                }

                //It json has not been formatted yet for use, format it
                if (!rootWeaponSkinTemp.Processed)
                {
                    EventLogger.LogMessage("CS:GO skin data has not been formatted yet, formatting... this WILL take a while");

                    //Sort items
                    foreach (var skin in rootWeaponSkinTemp.ItemsList.Values)
                    {
                        //Multiply all prices by 100 to remove decimals on price
                        if (skin.Price != null)
                        {
                            rootWeaponSkinTemp.ItemsList[skin.Name].Price.AllTime.Average = skin.Price.AllTime.Average * 100;
                        }
                        else
                        {
                            rootWeaponSkinTemp.ItemsList = rootWeaponSkinTemp.ItemsList.Where(s => s.Key != skin.Name).ToDictionary(x => x.Key, y => y.Value);
                        }

                        //Sort each skin into corropsonding cases
                        //Read from case data config
                        var skinCases = CsgoUnboxingHandler.csgoContiners;

                        //Find the container for each skin
                        foreach (var skinCase in skinCases.Containers)
                        {
                            //Check for each skin in each container
                            foreach (var skinCaseItem in skinCase.ContainerEntries)
                            {
                                List <string> comparisonItems = new List <string>();

                                //if FN, MW, ETC, it will find all skin conditions + stattrak

                                //For above, append statements for wear
                                if (!skinCase.IsSouvenir)
                                {
                                    comparisonItems.Add(skinCaseItem.SkinName + " (Factory New)");
                                    comparisonItems.Add(skinCaseItem.SkinName + " (Minimal Wear)");
                                    comparisonItems.Add(skinCaseItem.SkinName + " (Field-Tested)");
                                    comparisonItems.Add(skinCaseItem.SkinName + " (Well-Worn)");
                                    comparisonItems.Add(skinCaseItem.SkinName + " (Battle-Scarred)");

                                    //Add StatTrak\u2122 before to check for stattrak
                                    comparisonItems.Add("StatTrak\u2122 " + skinCaseItem.SkinName + " (Factory New)");
                                    comparisonItems.Add("StatTrak\u2122 " + skinCaseItem.SkinName + " (Minimal Wear)");
                                    comparisonItems.Add("StatTrak\u2122 " + skinCaseItem.SkinName + " (Field-Tested)");
                                    comparisonItems.Add("StatTrak\u2122 " + skinCaseItem.SkinName + " (Well-Worn)");
                                    comparisonItems.Add("StatTrak\u2122 " + skinCaseItem.SkinName + " (Battle-Scarred)");

                                    //KNIVES

                                    //\u2605 for knives
                                    comparisonItems.Add("\u2605 " + skinCaseItem.SkinName + " (Factory New)");
                                    comparisonItems.Add("\u2605 " + skinCaseItem.SkinName + " (Minimal Wear)");
                                    comparisonItems.Add("\u2605 " + skinCaseItem.SkinName + " (Field-Tested)");
                                    comparisonItems.Add("\u2605 " + skinCaseItem.SkinName + " (Well-Worn)");
                                    comparisonItems.Add("\u2605 " + skinCaseItem.SkinName + " (Battle-Scarred)");

                                    //\u2605 StatTrak\u2122 for knife stattrak
                                    comparisonItems.Add("\u2605 StatTrak\u2122 " + skinCaseItem.SkinName + " (Factory New)");
                                    comparisonItems.Add("\u2605 StatTrak\u2122 " + skinCaseItem.SkinName + " (Minimal Wear)");
                                    comparisonItems.Add("\u2605 StatTrak\u2122 " + skinCaseItem.SkinName + " (Field-Tested)");
                                    comparisonItems.Add("\u2605 StatTrak\u2122 " + skinCaseItem.SkinName + " (Well-Worn)");
                                    comparisonItems.Add("\u2605 StatTrak\u2122 " + skinCaseItem.SkinName + " (Battle-Scarred)");
                                }

                                //Souvenir
                                else if (skinCase.IsSouvenir)
                                {
                                    comparisonItems.Add("Souvenir " + skinCaseItem.SkinName + " (Factory New)");
                                    comparisonItems.Add("Souvenir " + skinCaseItem.SkinName + " (Minimal Wear)");
                                    comparisonItems.Add("Souvenir " + skinCaseItem.SkinName + " (Field-Tested)");
                                    comparisonItems.Add("Souvenir " + skinCaseItem.SkinName + " (Well-Worn)");
                                    comparisonItems.Add("Souvenir " + skinCaseItem.SkinName + " (Battle-Scarred)");
                                }

                                //Check for possible matches, matching CASE skin name
                                foreach (var comparisonItem in comparisonItems)
                                {
                                    //Use UnicodeLiteralConverter.DecodeToNonAsciiCharacters() before comparason to decode unicode
                                    if (UnicodeLiteralConverter.DecodeToNonAsciiCharacters(skin.Name) == UnicodeLiteralConverter.DecodeToNonAsciiCharacters(comparisonItem))
                                    {
                                        //If skin.Cases is null, create a new list
                                        if (skin.Cases == null)
                                        {
                                            skin.Cases = new List <Case>();
                                        }

                                        //If item matches, set the cases property of the item to current name of the case it is checking
                                        skin.Cases.Add(new Case
                                        {
                                            CaseName       = skinCase.Name,
                                            CaseCollection = skinCase.CollectionName
                                        });
                                        break;
                                    }
                                }
                            }
                        }
                    }
                    rootWeaponSkinTemp.Processed = true;

                    //Write results to skin data file
                    string jsonToWrite = JsonConvert.SerializeObject(rootWeaponSkinTemp);
                    CoreMethod.WriteStringToFile(jsonToWrite, true, CoreMethod.GetFileLocation("skinData.json"));
                }

                rootWeaponSkin = rootWeaponSkinTemp;

                stopwatch.Stop();
                EventLogger.LogMessage($"Gathering CS:GO skin data, this may take a while --- Done! - Took {stopwatch.Elapsed.TotalMilliseconds} milliseconds");
            }


            return(rootWeaponSkin);
        }
 public static string ToJson(this RootSkinData self) => JsonConvert.SerializeObject(self, DuckBot.Modules.Csgo.Converter.Settings);
예제 #5
0
        /// <summary>
        /// Fetches and randomly retrieves a skin item of specified type
        /// </summary>
        /// <param name="itemListType">Type file</param>
        /// <param name="skinData">Skin data to look through</param>
        /// <returns></returns>
        public static SkinDataItem GetItem(ItemListType itemListType, RootSkinData skinData, SocketCommandContext context, bool byPassCaseFilter)
        {
            List <KeyValuePair <string, SkinDataItem> > sortedResult = new List <KeyValuePair <string, SkinDataItem> >();

            //Get user from dictionary
            if (!CsgoUnboxingHandler.userSelectedCase.TryGetValue(context.Message.Author.Id, out var userSelectedCaseName))
            {
                //Default to danger zone case if user has not made a selection
                CsgoUnboxingHandler.userSelectedCase.Add(context.Message.Author.Id, "Danger Zone Case");
            }

            //Filter skins to those in user's case
            string selectedCase = CsgoUnboxingHandler.csgoContiners.Containers.Where(s => s.Name == CsgoUnboxingHandler.userSelectedCase[context.Message.Author.Id]).Select(s => s.Name).FirstOrDefault();

            //Add skins matching user's case to sorted result
            if (byPassCaseFilter == false)
            {
                //Find items matching filter case criteria, add to sortedResult ...!!!!Store this in the future to make this process more efficient
                foreach (var item in skinData.ItemsList)
                {
                    if (item.Value.Cases != null)
                    {
                        foreach (var item2 in item.Value.Cases)
                        {
                            if (item2.CaseName == selectedCase)
                            {
                                sortedResult.Add(item);
                            }
                        }
                    }
                }
            }
            else
            {
                //If bypass is true, sorted result is just root skinData
                //sortedResult = skinData.ItemsList.ToDictionary(x => x.Key, y => y.Value).ToList();

                //Add collection items, E.g Mirage collection, Nuke collection for drop, which has null for casesName
                foreach (var item in skinData.ItemsList)
                {
                    if (item.Value.Cases != null)
                    {
                        foreach (var item2 in item.Value.Cases)
                        {
                            if (item2.CaseName == null)
                            {
                                sortedResult.Add(item);
                            }
                        }
                    }
                }
            }


            //Filter by rarity
            sortedResult = sortedResult.Where(s => s.Value.Rarity == itemListType.Rarity).ToList();

            //If weaponType is not null, filter by weapon type
            if (itemListType.WeaponType != null)
            {
                sortedResult = sortedResult
                               .Where(s => s.Value.WeaponType == itemListType.WeaponType).ToList();
            }

            //If blackListWeaponType is not null, filter by weapon type
            if (itemListType.BlackListWeaponType != null)
            {
                sortedResult = sortedResult
                               .Where(s => s.Value.WeaponType != itemListType.BlackListWeaponType).ToList();
            }

            //If case is not a souvenir, filter out souvenir items, if it is, filter out non souvenir items
            if (byPassCaseFilter == false && CsgoUnboxingHandler.csgoContiners.Containers.Where(c => c.Name == selectedCase).FirstOrDefault().IsSouvenir)
            {
                //True
                sortedResult = sortedResult.Where(s => s.Value.Name.ToLower().Contains("souvenir")).ToList();
            }
            else
            {
                //False
                sortedResult = sortedResult.Where(s => !s.Value.Name.ToLower().Contains("souvenir")).ToList();
            }

            //Filter out stattrak, stickers, music kits, and graffiti
            sortedResult = sortedResult
                           .Where(s => !s.Value.Name.ToLower().Contains("stattrak"))
                           .Where(s => !s.Value.Name.ToLower().Contains("sticker"))
                           .Where(s => !s.Value.Name.ToLower().Contains("music kit"))
                           .Where(s => !s.Value.Name.ToLower().Contains(" pin"))
                           .Where(s => !s.Value.Name.ToLower().Contains("graffiti")).ToList();


            //Randomly select a skin from the filtered list of possible skins
            var selectedSkin = sortedResult[rand.Next(sortedResult.Count())];

            bool giveStatTrak = CalculateStatTrakDrop();

            //Give stattrak
            if (giveStatTrak == true)
            {
                var selectedStatTrakItem = skinData.ItemsList
                                           .Where(s => s.Value.Name.ToLower().Contains(selectedSkin.Value.Name.ToLower()))
                                           .Where(s => s.Value.Name.ToLower().Contains("stattrak")).FirstOrDefault();

                //If filter was unsuccessful at finding stattrak, do not assign item
                if (selectedStatTrakItem.Value != null)
                {
                    selectedSkin = selectedStatTrakItem;
                }
            }
            return(selectedSkin.Value);
        }