public IEnumerable <UgcMarketItem> FindItems(List <string> categories, GenderFlag genderFlag, JobFlag job, string searchString)
    {
        List <UgcMarketItem> items = new();

        foreach (UgcMarketItem item in Items.Values)
        {
            if (!categories.Contains(item.Item.Category) && categories.Count > 0)
            {
                continue;
            }

            if (item.Status != UgcMarketListingStatus.Active)
            {
                continue;
            }

            if (!item.Item.Ugc.Name.ToLower().Contains(searchString) && !item.Tags.Contains(searchString))
            {
                continue;
            }

            // Check items tags if any tags have the searched string
            bool validTag = false;
            foreach (string tag in item.Tags)
            {
                if (tag.ToLower().Contains(searchString.ToLower()))
                {
                    validTag = true;
                }
            }

            if (!validTag)
            {
                continue;
            }

            // check job
            if (!JobHelper.CheckJobFlagForJob(item.Item.RecommendJobs, job))
            {
                continue;
            }

            // check gender
            if (!MeretMarketHelper.CheckGender(genderFlag, item.Item.Id))
            {
                continue;
            }

            items.Add(item);
        }

        return(items);
    }
    public IEnumerable <PremiumMarketItem> FindAllByCategory(MeretMarketSection section, MeretMarketCategory category, GenderFlag gender, JobFlag jobFlag, string searchString)
    {
        List <PremiumMarketItem> items   = new();
        IEnumerable <dynamic>    results = QueryFactory.Query(TableName).Get();

        if (section != MeretMarketSection.All)
        {
            results = QueryFactory.Query(TableName).Where("section", (int)section).Get();
        }

        foreach (dynamic data in results)
        {
            if (category != MeretMarketCategory.None && (MeretMarketCategory)data.category != category)
            {
                continue;
            }

            if (data.parent_market_id != 0)
            {
                continue;
            }
            PremiumMarketItem meretMarketItem = ReadMeretMarketItem(data);

            if (!meretMarketItem.ItemName.ToLower().Contains(searchString.ToLower()))
            {
                continue;
            }

            List <Job> jobs = ItemMetadataStorage.GetRecommendJobs(meretMarketItem.ItemId);
            if (!JobHelper.CheckJobFlagForJob(jobs, jobFlag))
            {
                continue;
            }

            if (!MeretMarketHelper.CheckGender(gender, meretMarketItem.ItemId))
            {
                continue;
            }

            if (meretMarketItem.BannerId != 0)
            {
                meretMarketItem.Banner = DatabaseManager.Banners.FindById(meretMarketItem.BannerId);
            }

            items.Add(meretMarketItem);
        }

        return(items);
    }
示例#3
0
    public List <UGCMarketItem> FindItemsByCategory(List <string> categories, GenderFlag genderFlag, JobFlag job, short sort)
    {
        List <UGCMarketItem> items = new();

        foreach (UGCMarketItem item in Items.Values)
        {
            if (!categories.Contains(item.Item.Category) || item.Status != UGCMarketListingStatus.Active)
            {
                continue;
            }

            // check job
            if (!JobHelper.CheckJobFlagForJob(item.Item.RecommendJobs, job))
            {
                continue;
            }

            // check gender
            Gender itemGender = ItemMetadataStorage.GetGender(item.Item.Id);
            if (!genderFlag.HasFlag(GenderFlag.Male) && !genderFlag.HasFlag(GenderFlag.Female))
            {
                Gender gender = genderFlag.HasFlag(GenderFlag.Male) ? Gender.Male : Gender.Female;
            }

            items.Add(item);
        }

        UGCMarketSort marketSort = (UGCMarketSort)sort;

        switch (marketSort)
        {
        // TODO: Handle Most Popular sorting.
        case UGCMarketSort.MostPopular:
        case UGCMarketSort.TopSeller:
            items = items.OrderByDescending(x => x.SalesCount).ToList();
            break;

        case UGCMarketSort.MostRecent:
            items = items.OrderByDescending(x => x.CreationTimestamp).ToList();
            break;
        }

        return(items);
    }
    public List <BlackMarketListing> GetSearchedListings(List <string> itemCategories, int minLevel, int maxLevel, int rarity, string name, JobFlag jobFlag,
                                                         int minEnchantLevel, int maxEnchantLevel, byte minSockets, byte maxSockets, int startPage, long sort, bool searchStat, List <ItemStat> searchedStats)
    {
        List <BlackMarketListing> allResults = new();

        foreach (BlackMarketListing listing in Listings.Values)
        {
            Item item = listing.Item;

            if (TimeInfo.Now() > listing.ExpiryTimestamp ||
                !itemCategories.Contains(item.BlackMarketCategory) ||
                item.Level < minLevel ||
                item.Level > maxLevel ||
                item.Rarity < rarity ||
                item.EnchantLevel < minEnchantLevel ||
                item.EnchantLevel > maxEnchantLevel ||
                item.Stats.GemSockets.Count < minSockets ||
                item.Stats.GemSockets.Count > maxSockets ||
                !item.Name.ToLower().Contains(name.ToLower()))
            {
                continue;
            }

            // Check job
            if (!JobHelper.CheckJobFlagForJob(item.RecommendJobs, jobFlag))
            {
                continue;
            }

            if (!searchStat)
            {
                allResults.Add(listing);
                continue;
            }

            // find if stats contains all values inside searchedStats
            bool containsAll = true;
            foreach (ItemStat searchedStat in searchedStats)
            {
                ICollection <Dictionary <StatAttribute, ItemStat> > stats = new List <Dictionary <StatAttribute, ItemStat> >();
                stats.Add(item.Stats.Constants);
                stats.Add(item.Stats.Statics);
                stats.Add(item.Stats.Randoms);
                foreach (Dictionary <StatAttribute, ItemStat> statCollection in stats)
                {
                    if (!statCollection.ContainsKey(searchedStat.ItemAttribute))
                    {
                        containsAll = false;
                        break;
                    }
                    if (statCollection[searchedStat.ItemAttribute].Flat < searchedStat.Flat &&
                        statCollection[searchedStat.ItemAttribute].Rate < searchedStat.Rate)
                    {
                        containsAll = false;
                        break;
                    }
                }
            }

            if (containsAll)
            {
                allResults.Add(listing);
            }
        }

        BlackMarketSort blackmarketSort = (BlackMarketSort)sort;

        switch (blackmarketSort)
        {
        case BlackMarketSort.PriceLowToHigh:
            allResults = allResults.OrderBy(x => x.Price).ToList();
            break;

        case BlackMarketSort.PriceHighToLow:
            allResults = allResults.OrderByDescending(x => x.Price).ToList();
            break;

        case BlackMarketSort.LevelLowToHigh:
            allResults = allResults.OrderBy(x => x.Item.Level).ToList();
            break;

        case BlackMarketSort.LevelHighToLow:
            allResults = allResults.OrderByDescending(x => x.Item.Level).ToList();
            break;
        }

        int count  = startPage * 7 - 7;
        int offset = count;
        int limit  = 70 + Math.Min(0, count);

        return(allResults.Skip(offset).Take(limit).ToList());
    }
    public List <BlackMarketListing> GetSearchedListings(List <string> itemCategories, int minLevel, int maxLevel, int rarity, string name, JobFlag jobFlag,
                                                         int minEnchantLevel, int maxEnchantLevel, byte minSockets, byte maxSockets, int startPage, long sort, bool searchStat, List <ItemStat> searchedStats)
    {
        List <BlackMarketListing> allResults = new();

        foreach (BlackMarketListing listing in Listings.Values)
        {
            Item item = listing.Item;

            if (TimeInfo.Now() > listing.ExpiryTimestamp ||
                !itemCategories.Contains(item.BlackMarketCategory) ||
                item.Level < minLevel ||
                item.Level > maxLevel ||
                item.Rarity < rarity ||
                item.Enchants < minEnchantLevel ||
                item.Enchants > maxEnchantLevel ||
                item.Stats.GemSockets.Count < minSockets ||
                item.Stats.GemSockets.Count > maxSockets ||
                !item.Name.ToLower().Contains(name.ToLower()))
            {
                continue;
            }

            // Check job
            if (!JobHelper.CheckJobFlagForJob(item.RecommendJobs, jobFlag))
            {
                continue;
            }

            if (!searchStat)
            {
                allResults.Add(listing);
                continue;
            }

            List <NormalStat>  normalStats  = new();
            List <SpecialStat> specialStats = new();
            foreach (ItemStat stat in item.Stats.BasicStats)
            {
                if (stat is NormalStat normalStat)
                {
                    normalStats.Add(normalStat);
                    continue;
                }
                specialStats.Add((SpecialStat)stat);
            }

            foreach (ItemStat stat in item.Stats.BonusStats)
            {
                if (stat is NormalStat normalStat)
                {
                    normalStats.Add(normalStat);
                    continue;
                }
                specialStats.Add((SpecialStat)stat);
            }

            // find if stats contains all values inside searchedStats
            bool containsAll = true;
            foreach (ItemStat searchedStat in searchedStats)
            {
                if (searchedStat is NormalStat normalStat)
                {
                    if (!normalStats.Any(x => x.ItemAttribute == normalStat.ItemAttribute && x.Flat >= normalStat.Flat && x.Percent >= normalStat.Percent))
                    {
                        containsAll = false;
                        break;
                    }
                }
                else if (searchedStat is SpecialStat specialStat)
                {
                    if (!specialStats.Any(x => x.ItemAttribute == specialStat.ItemAttribute && x.Flat >= specialStat.Flat && x.Percent >= specialStat.Percent))
                    {
                        containsAll = false;
                        break;
                    }
                }
            }

            if (containsAll)
            {
                allResults.Add(listing);
            }
        }

        BlackMarketSort blackmarketSort = (BlackMarketSort)sort;

        switch (blackmarketSort)
        {
        case BlackMarketSort.PriceLowToHigh:
            allResults = allResults.OrderBy(x => x.Price).ToList();
            break;

        case BlackMarketSort.PriceHighToLow:
            allResults = allResults.OrderByDescending(x => x.Price).ToList();
            break;

        case BlackMarketSort.LevelLowToHigh:
            allResults = allResults.OrderBy(x => x.Item.Level).ToList();
            break;

        case BlackMarketSort.LevelHighToLow:
            allResults = allResults.OrderByDescending(x => x.Item.Level).ToList();
            break;
        }

        int count  = startPage * 7 - 7;
        int offset = count;
        int limit  = 70 + Math.Min(0, count);

        return(allResults.Skip(offset).Take(limit).ToList());
    }