Esempio n. 1
0
    public static bool CheckJobFlagForJob(List <Job> jobs, JobFlag jobFlag)
    {
        if (!jobs.Contains(Job.None) && jobFlag != JobFlag.All)
        {
            // TODO: Handle more than one flag.
            Job job = jobFlag switch
            {
                JobFlag.Beginner => Job.Beginner,
                JobFlag.Knight => Job.Knight,
                JobFlag.Berserker => Job.Berserker,
                JobFlag.Wizard => Job.Wizard,
                JobFlag.Priest => Job.Priest,
                JobFlag.Archer => Job.Archer,
                JobFlag.HeavyGunner => Job.HeavyGunner,
                JobFlag.Thief => Job.Thief,
                JobFlag.Assassin => Job.Assassin,
                JobFlag.Runeblade => Job.Runeblade,
                JobFlag.Striker => Job.Striker,
                JobFlag.SoulBinder => Job.SoulBinder,
                _ => Job.None
            };

            if (!jobs.Contains(job))
            {
                return(false);
            }
        }

        return(true);
    }
}
Esempio n. 2
0
        public async Task <IHttpActionResult> CreateJobFlag(JobFlag entity)
        {
            _userId = User.Identity.GetUserId();

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            // UPdate Tracker
            var jobTracker = await context.JobTrackers.FindAsync(entity.JobTrackerId);

            var updateJobTracker = jobTracker;

            updateJobTracker.IsFlag = true;
            var t0UpdateJobTracker = await UpdateJobTracker(updateJobTracker.Id, updateJobTracker);

            // Create JobFlag
            entity.CreatedById  = _userId;
            entity.CreatedOn    = DateTime.Now;
            entity.ModifiedById = _userId;
            entity.ModifiedOn   = DateTime.Now;
            entity.ResolvedById = _userId;

            context.JobFlags.Add(entity);
            await context.SaveChangesAsync();

            return(Ok <JobFlag>(entity));
        }
Esempio n. 3
0
 public PremiumMarketItem(dynamic data)
 {
     MarketId                 = data.market_id;
     Section                  = (MeretMarketSection)data.section;
     BannerId                 = data.banner_id ?? 0;
     BonusQuantity            = data.bonus_quantity;
     Category                 = (MeretMarketCategory)data.category;
     Duration                 = data.duration;
     Flag                     = (MeretMarketItemFlag)data.flag;
     ItemId                   = data.item_id;
     ItemName                 = data.item_name;
     JobRequirement           = (JobFlag)data.job_requirement;
     MaxLevelRequirement      = data.max_level_requirement;
     MinLevelRequirement      = data.min_level_requirement;
     PCCafe                   = data.pc_cafe;
     ParentMarketId           = data.parent_market_id;
     PromoBannerBeginTime     = data.promo_banner_begin_time;
     PromoBannerEndTime       = data.promo_banner_end_time;
     PromoFlag                = (MeretMarketPromoFlag)data.promo_flag;
     PromoName                = data.promo_name;
     Quantity                 = data.quantity;
     Rarity                   = data.rarity;
     RequiredAchievementGrade = data.required_achievement_grade;
     RequiredAchievementId    = data.required_achievement_id;
     RestockUnavailable       = data.restock_unavailable;
     Price                    = data.price;
     SalePrice                = data.sale_price;
     SellBeginTime            = data.sell_begin_time;
     SellEndTime              = data.sell_end_time;
     ShowSaleTime             = data.show_sale_time;
     TokenType                = (MeretMarketCurrencyType)data.token_type;
     SalesCount               = data.sales_count;
     CreationTimestamp        = data.creation_time;
     AdditionalQuantities     = new();
 }
Esempio n. 4
0
    private static void HandleOpenUGCMarket(GameSession session, PacketReader packet, MeretMarketCategoryMetadata metadata)
    {
        GenderFlag gender = (GenderFlag)packet.ReadByte();
        JobFlag    job    = (JobFlag)packet.ReadInt();
        short      sortBy = packet.ReadByte();

        List <UGCMarketItem> items = GameServer.UGCMarketManager.FindItemsByCategory(metadata.ItemCategories, gender, job, sortBy);

        session.Send(MeretMarketPacket.LoadUGCShopCategory(items));
    }
Esempio n. 5
0
    private static void HandleSearch(GameSession session, PacketReader packet)
    {
        int     minCategoryId   = packet.ReadInt();
        int     maxCategoryId   = packet.ReadInt();
        int     minLevel        = packet.ReadInt();
        int     maxLevel        = packet.ReadInt();
        JobFlag job             = (JobFlag)packet.ReadInt();
        int     rarity          = packet.ReadInt();
        int     minEnchantLevel = packet.ReadInt();
        int     maxEnchantLevel = packet.ReadInt();
        byte    minSockets      = packet.ReadByte();
        byte    maxSockets      = packet.ReadByte();
        string  name            = packet.ReadUnicodeString();
        int     startPage       = packet.ReadInt();
        long    sort            = packet.ReadLong();

        packet.ReadShort();
        bool additionalOptionsEnabled = packet.ReadBool();

        List <ItemStat> stats = new();

        if (additionalOptionsEnabled)
        {
            packet.ReadByte(); // always 1
            for (int i = 0; i < 3; i++)
            {
                int statId = packet.ReadInt();
                int value  = packet.ReadInt();
                if (value == 0)
                {
                    continue;
                }

                ItemStat stat = ReadStat(statId, value);
                if (stat == null)
                {
                    continue;
                }

                stats.Add(stat);
            }
        }

        List <string>             itemCategories = BlackMarketTableMetadataStorage.GetItemCategories(minCategoryId, maxCategoryId);
        List <BlackMarketListing> searchResults  = GameServer.BlackMarketManager.GetSearchedListings(itemCategories, minLevel, maxLevel, rarity, name, job,
                                                                                                     minEnchantLevel, maxEnchantLevel, minSockets, maxSockets, startPage, sort, additionalOptionsEnabled, stats);

        session.Send(BlackMarketPacket.SearchResults(searchResults));
    }
Esempio n. 6
0
    private static void HandleOpenShop(GameSession session, PacketReader packet)
    {
        MeretMarketCategory category = (MeretMarketCategory)packet.ReadInt();
        GenderFlag          gender   = (GenderFlag)packet.ReadByte();
        JobFlag             job      = (JobFlag)packet.ReadInt();
        MeretMarketSort     sortBy   = (MeretMarketSort)packet.ReadByte();
        string searchString          = packet.ReadUnicodeString();
        int    startPage             = packet.ReadInt();

        packet.ReadInt(); // repeat page?
        MeretMarketSection section = ReadMarketSection(packet.ReadByte());

        packet.ReadByte();
        byte itemsPerPage = packet.ReadByte();

        MeretMarketTab metadata = MeretMarketCategoryMetadataStorage.GetTabMetadata(section, (int)category);

        if (metadata is null)
        {
            return;
        }

        List <MeretMarketItem> items = new();

        switch (section)
        {
        case MeretMarketSection.UgcMarket:
            items.AddRange(GameServer.UgcMarketManager.FindItems(metadata.ItemCategories, gender, job, searchString));
            break;

        case MeretMarketSection.PremiumMarket:
        case MeretMarketSection.RedMeretMarket:
            items.AddRange(DatabaseManager.MeretMarket.FindAllByCategory(section, category, gender, job, searchString));
            break;
        }

        int totalItems = items.Count;

        items = MeretMarketHelper.MarketItemsSorted(items, sortBy);
        items = MeretMarketHelper.TakeLimit(items, startPage, itemsPerPage);

        session.Send(MeretMarketPacket.LoadShopCategory(items, totalItems));
    }
    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());
    }
Esempio n. 9
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);
    }
Esempio n. 10
0
    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);
    }