Exemplo n.º 1
0
        public void RemoveFromBazaar(long bazaarItemId)
        {
            // we are not supposed to save each removal! we will only save them on Save() function.

            // there should never be 2 objects with same id in the bazaar!
            BazaarItemLink bazaaritem = BazaarList.SingleOrDefault(s => s.BazaarItem.BazaarItemId.Equals(bazaarItemId));

            if (bazaaritem != null)
            {
                BazaarList.Remove(bazaaritem);

                // we will propably need to also update the iteminstance.
            }
            else
            {
                // something is wrong, log as suspicious activity or some kind of weird behavior. the
                // item if sent by game should always be in the BazaarList, unless it was somehow
                // bought before the client got updated info.
            }
        }
Exemplo n.º 2
0
        public void RefreshBazaar(long bazaarItemId)
        {
            BazaarItemDTO  bzdto  = DAOFactory.BazaarItemDAO.LoadById(bazaarItemId);
            BazaarItemLink bzlink = BazaarList[bazaarItemId];

            // maybe we shouldnt lock the entire list.
            lock (BazaarList)
            {
                if (bzdto != null)
                {
                    CharacterDTO chara = DAOFactory.CharacterDAO.LoadById(bzdto.SellerId);
                    if (bzlink != null)
                    {
                        // why do we do this update? this is a copy of code from ServerManager
                        BazaarList.Remove(bzlink);
                        bzlink.BazaarItem        = bzdto;
                        bzlink.OwnerName         = chara.Name;
                        bzlink.Item              = new ItemInstance(DAOFactory.ItemInstanceDAO.LoadById(bzdto.ItemInstanceId));
                        BazaarList[bazaarItemId] = bzlink;
                    }
                    else
                    {
                        BazaarItemLink item = new BazaarItemLink
                        {
                            BazaarItem = bzdto
                        };
                        if (chara != null)
                        {
                            item.OwnerName = chara.Name;
                            item.Item      = new ItemInstance(DAOFactory.ItemInstanceDAO.LoadById(bzdto.ItemInstanceId));
                        }
                        BazaarList[bazaarItemId] = item;
                    }
                }
                else if (bzlink != null)
                {
                    BazaarList.Remove(bzlink);
                }
            }
            InBazaarRefreshMode = false;
        }
Exemplo n.º 3
0
        public void Initialize()
        {
            BazaarList = new ThreadSafeSortedList <long, BazaarItemLink>();
            OrderablePartitioner <BazaarItemDTO> bazaarPartitioner = Partitioner.Create(DAOFactory.BazaarItemDAO.LoadAll(), EnumerablePartitionerOptions.NoBuffering);

            Parallel.ForEach(bazaarPartitioner, new ParallelOptions {
                MaxDegreeOfParallelism = 8
            }, bazaarItem =>
            {
                BazaarItemLink item = new BazaarItemLink
                {
                    BazaarItem = bazaarItem
                };
                CharacterDTO chara = DAOFactory.CharacterDAO.LoadById(bazaarItem.SellerId);
                if (chara != null)
                {
                    item.OwnerName = chara.Name;
                    item.Item      = new ItemInstance(DAOFactory.ItemInstanceDAO.LoadById(bazaarItem.ItemInstanceId));
                }
                BazaarList[item.BazaarItem.BazaarItemId] = item;
            });
            Logger.Info(string.Format(Language.Instance.GetMessageFromKey("BAZAAR_LOADED"), BazaarList.Count));
        }
        private void ExecuteHandler(ClientSession session)
        {
            SpinWait.SpinUntil(() => !ServerManager.Instance.InBazaarRefreshMode);
            string list = string.Empty;

            BazaarItemLink[] billist = new BazaarItemLink[ServerManager.Instance.BazaarList.Count + 20];
            ServerManager.Instance.BazaarList.CopyTo(billist);
            foreach (BazaarItemLink bz in billist.Where(s => s != null && s.BazaarItem.SellerId == session.Character.CharacterId).Skip(Index * 50).Take(50))
            {
                if (bz.Item != null)
                {
                    int  soldedAmount = bz.BazaarItem.Amount - bz.Item.Amount;
                    int  amount       = bz.BazaarItem.Amount;
                    bool package      = bz.BazaarItem.IsPackage;
                    bool isNosbazar   = bz.BazaarItem.MedalUsed;
                    long price        = bz.BazaarItem.Price;
                    long minutesLeft  = (long)(bz.BazaarItem.DateStart.AddHours(bz.BazaarItem.Duration) - DateTime.UtcNow).TotalMinutes;
                    byte status       = minutesLeft >= 0 ? (soldedAmount < amount ? (byte)BazaarType.OnSale : (byte)BazaarType.Solded) : (byte)BazaarType.DelayExpired;
                    if (status == (byte)BazaarType.DelayExpired)
                    {
                        minutesLeft = (long)(bz.BazaarItem.DateStart.AddHours(bz.BazaarItem.Duration).AddDays(isNosbazar ? 30 : 7) - DateTime.UtcNow).TotalMinutes;
                    }
                    string info = string.Empty;
                    if (bz.Item.Item.Type == InventoryType.Equipment)
                    {
                        info = bz.Item?.GenerateEInfo().Replace(' ', '^').Replace("e_info^", string.Empty);
                    }
                    if (Filter == 0 || Filter == status)
                    {
                        list += $"{bz.BazaarItem.BazaarItemId}|{bz.BazaarItem.SellerId}|{bz.Item.ItemVNum}|{soldedAmount}|{amount}|{(package ? 1 : 0)}|{price}|{status}|{minutesLeft}|{(isNosbazar ? 1 : 0)}|0|{bz.Item.Rare}|{bz.Item.Upgrade}|{info} ";
                    }
                }
            }

            session.SendPacket($"rc_slist {Index} {list}");
        }
Exemplo n.º 5
0
        public string GenerateRCBList(CBListPacket packet)
        {
            string itembazar = string.Empty;

            List <string>         itemssearch = packet.ItemVNumFilter == "0" ? new List <string>() : packet.ItemVNumFilter.Split(' ').ToList();
            List <BazaarItemLink> bzlist      = new List <BazaarItemLink>();

            BazaarItemLink[] billist = new BazaarItemLink[ServerManager.Instance.BazaarList.Count + 20];
            ServerManager.Instance.BazaarList.CopyTo(billist);
            foreach (BazaarItemLink bz in billist)
            {
                if (bz?.Item == null)
                {
                    continue;
                }

                switch (packet.TypeFilter)
                {
                case BazaarListType.Weapon:
                    if (bz.Item.Item.Type == InventoryType.Equipment && bz.Item.Item.ItemType == ItemType.Weapon)
                    {
                        if (packet.SubTypeFilter == 0 || ((bz.Item.Item.Class + 1 >> packet.SubTypeFilter) & 1) == 1)
                        {
                            if (packet.LevelFilter == 0 || packet.LevelFilter == 11 && bz.Item.Item.IsHeroic || bz.Item.Item.LevelMinimum < packet.LevelFilter * 10 + 1 && bz.Item.Item.LevelMinimum >= packet.LevelFilter * 10 - 9)    //Level filter
                            {
                                if (packet.RareFilter == 0 || packet.RareFilter == bz.Item.Rare + 1)
                                {
                                    if (packet.UpgradeFilter == 0 || packet.UpgradeFilter == bz.Item.Upgrade + 1)
                                    {
                                        bzlist.Add(bz);
                                    }
                                }
                            }
                        }
                    }
                    break;

                case BazaarListType.Armor:
                    if (bz.Item.Item.Type == InventoryType.Equipment && bz.Item.Item.ItemType == ItemType.Armor)
                    {
                        if (packet.SubTypeFilter == 0 || ((bz.Item.Item.Class + 1 >> packet.SubTypeFilter) & 1) == 1)
                        {
                            if (packet.LevelFilter == 0 || packet.LevelFilter == 11 && bz.Item.Item.IsHeroic || bz.Item.Item.LevelMinimum < packet.LevelFilter * 10 + 1 && bz.Item.Item.LevelMinimum >= packet.LevelFilter * 10 - 9)    //Level filter
                            {
                                if (packet.RareFilter == 0 || packet.RareFilter == bz.Item.Rare + 1)
                                {
                                    if (packet.UpgradeFilter == 0 || packet.UpgradeFilter == bz.Item.Upgrade + 1)
                                    {
                                        bzlist.Add(bz);
                                    }
                                }
                            }
                        }
                    }
                    break;

                case BazaarListType.Equipment:
                    if (bz.Item.Item.Type == InventoryType.Equipment && bz.Item.Item.ItemType == ItemType.Fashion)
                    {
                        if (packet.SubTypeFilter == 0 || packet.SubTypeFilter == 2 && bz.Item.Item.EquipmentSlot == EquipmentType.Mask || packet.SubTypeFilter == 1 && bz.Item.Item.EquipmentSlot == EquipmentType.Hat || packet.SubTypeFilter == 6 && bz.Item.Item.EquipmentSlot == EquipmentType.CostumeHat || packet.SubTypeFilter == 5 && bz.Item.Item.EquipmentSlot == EquipmentType.CostumeSuit || packet.SubTypeFilter == 3 && bz.Item.Item.EquipmentSlot == EquipmentType.Gloves || packet.SubTypeFilter == 4 && bz.Item.Item.EquipmentSlot == EquipmentType.Boots)
                        {
                            if (packet.LevelFilter == 0 || packet.LevelFilter == 11 && bz.Item.Item.IsHeroic || bz.Item.Item.LevelMinimum < packet.LevelFilter * 10 + 1 && bz.Item.Item.LevelMinimum >= packet.LevelFilter * 10 - 9)    //Level filter
                            {
                                bzlist.Add(bz);
                            }
                        }
                    }
                    break;

                case BazaarListType.Jewelery:
                    if (bz.Item.Item.Type == InventoryType.Equipment && bz.Item.Item.ItemType == ItemType.Jewelery)
                    {
                        if (packet.SubTypeFilter == 0 || packet.SubTypeFilter == 2 && bz.Item.Item.EquipmentSlot == EquipmentType.Ring || packet.SubTypeFilter == 1 && bz.Item.Item.EquipmentSlot == EquipmentType.Necklace || packet.SubTypeFilter == 5 && bz.Item.Item.EquipmentSlot == EquipmentType.Amulet || packet.SubTypeFilter == 3 && bz.Item.Item.EquipmentSlot == EquipmentType.Bracelet || packet.SubTypeFilter == 4 && (bz.Item.Item.EquipmentSlot == EquipmentType.Fairy || bz.Item.Item.ItemType == ItemType.Box && bz.Item.Item.ItemSubType == 5))
                        {
                            if (packet.LevelFilter == 0 || packet.LevelFilter == 11 && bz.Item.Item.IsHeroic || bz.Item.Item.LevelMinimum < packet.LevelFilter * 10 + 1 && bz.Item.Item.LevelMinimum >= packet.LevelFilter * 10 - 9)    //Level filter
                            {
                                bzlist.Add(bz);
                            }
                        }
                    }
                    break;

                case BazaarListType.Specialist:
                    if (bz.Item.Item.Type == InventoryType.Equipment)
                    {
                        if (bz.Item.Item.ItemType == ItemType.Box && bz.Item.Item.ItemSubType == 2)
                        {
                            if (bz.Item is BoxInstance boxInstance)
                            {
                                if (packet.SubTypeFilter == 0)
                                {
                                    if (packet.LevelFilter == 0 || ((BoxInstance)bz.Item).SpLevel < packet.LevelFilter * 10 + 1 && ((BoxInstance)bz.Item).SpLevel >= packet.LevelFilter * 10 - 9)
                                    {
                                        if (packet.UpgradeFilter == 0 || packet.UpgradeFilter == bz.Item.Upgrade + 1)
                                        {
                                            if (packet.SubTypeFilter == 0 || packet.SubTypeFilter == 1 && ((BoxInstance)bz.Item).HoldingVNum == 0 || packet.SubTypeFilter == 2 && ((BoxInstance)bz.Item).HoldingVNum != 0)
                                            {
                                                bzlist.Add(bz);
                                            }
                                        }
                                    }
                                }
                                else if (boxInstance.HoldingVNum == 0)
                                {
                                    if (packet.SubTypeFilter == 1)
                                    {
                                        if (packet.LevelFilter == 0 || ((BoxInstance)bz.Item).SpLevel < packet.LevelFilter * 10 + 1 && ((BoxInstance)bz.Item).SpLevel >= packet.LevelFilter * 10 - 9)
                                        {
                                            if (packet.UpgradeFilter == 0 || packet.UpgradeFilter == bz.Item.Upgrade + 1)
                                            {
                                                if (packet.SubTypeFilter == 0 || packet.SubTypeFilter == 1 && ((BoxInstance)bz.Item).HoldingVNum == 0 || packet.SubTypeFilter == 2 && ((BoxInstance)bz.Item).HoldingVNum != 0)
                                                {
                                                    bzlist.Add(bz);
                                                }
                                            }
                                        }
                                    }
                                }
                                else if (packet.SubTypeFilter == 2 && ServerManager.Instance.GetItem(boxInstance.HoldingVNum).Morph == 10 ||
                                         packet.SubTypeFilter == 3 && ServerManager.Instance.GetItem(boxInstance.HoldingVNum).Morph == 11 ||
                                         packet.SubTypeFilter == 4 && ServerManager.Instance.GetItem(boxInstance.HoldingVNum).Morph == 2 ||
                                         packet.SubTypeFilter == 5 && ServerManager.Instance.GetItem(boxInstance.HoldingVNum).Morph == 3 ||
                                         packet.SubTypeFilter == 6 && ServerManager.Instance.GetItem(boxInstance.HoldingVNum).Morph == 13 ||
                                         packet.SubTypeFilter == 7 && ServerManager.Instance.GetItem(boxInstance.HoldingVNum).Morph == 5 ||
                                         packet.SubTypeFilter == 8 && ServerManager.Instance.GetItem(boxInstance.HoldingVNum).Morph == 12 ||
                                         packet.SubTypeFilter == 9 && ServerManager.Instance.GetItem(boxInstance.HoldingVNum).Morph == 4 ||
                                         packet.SubTypeFilter == 10 && ServerManager.Instance.GetItem(boxInstance.HoldingVNum).Morph == 7 ||
                                         packet.SubTypeFilter == 11 && ServerManager.Instance.GetItem(boxInstance.HoldingVNum).Morph == 15 ||
                                         packet.SubTypeFilter == 12 && ServerManager.Instance.GetItem(boxInstance.HoldingVNum).Morph == 6 ||
                                         packet.SubTypeFilter == 13 && ServerManager.Instance.GetItem(boxInstance.HoldingVNum).Morph == 14 ||
                                         packet.SubTypeFilter == 14 && ServerManager.Instance.GetItem(boxInstance.HoldingVNum).Morph == 9 ||
                                         packet.SubTypeFilter == 15 && ServerManager.Instance.GetItem(boxInstance.HoldingVNum).Morph == 8 ||
                                         packet.SubTypeFilter == 16 && ServerManager.Instance.GetItem(boxInstance.HoldingVNum).Morph == 1 ||
                                         packet.SubTypeFilter == 17 && ServerManager.Instance.GetItem(boxInstance.HoldingVNum).Morph == 16 ||
                                         packet.SubTypeFilter == 18 && ServerManager.Instance.GetItem(boxInstance.HoldingVNum).Morph == 17 ||
                                         packet.SubTypeFilter == 19 && ServerManager.Instance.GetItem(boxInstance.HoldingVNum).Morph == 18 ||
                                         packet.SubTypeFilter == 20 && ServerManager.Instance.GetItem(boxInstance.HoldingVNum).Morph == 19 ||
                                         packet.SubTypeFilter == 21 && ServerManager.Instance.GetItem(boxInstance.HoldingVNum).Morph == 20 ||
                                         packet.SubTypeFilter == 22 && ServerManager.Instance.GetItem(boxInstance.HoldingVNum).Morph == 21 ||
                                         packet.SubTypeFilter == 23 && ServerManager.Instance.GetItem(boxInstance.HoldingVNum).Morph == 22 ||
                                         packet.SubTypeFilter == 24 && ServerManager.Instance.GetItem(boxInstance.HoldingVNum).Morph == 23 ||
                                         packet.SubTypeFilter == 25 && ServerManager.Instance.GetItem(boxInstance.HoldingVNum).Morph == 24 ||
                                         packet.SubTypeFilter == 26 && ServerManager.Instance.GetItem(boxInstance.HoldingVNum).Morph == 25 ||
                                         packet.SubTypeFilter == 27 && ServerManager.Instance.GetItem(boxInstance.HoldingVNum).Morph == 26 ||
                                         packet.SubTypeFilter == 28 && ServerManager.Instance.GetItem(boxInstance.HoldingVNum).Morph == 27 ||
                                         packet.SubTypeFilter == 29 && ServerManager.Instance.GetItem(boxInstance.HoldingVNum).Morph == 28)
                                {
                                    if (packet.LevelFilter == 0 || ((BoxInstance)bz.Item).SpLevel < packet.LevelFilter * 10 + 1 && ((BoxInstance)bz.Item).SpLevel >= packet.LevelFilter * 10 - 9)
                                    {
                                        if (packet.UpgradeFilter == 0 || packet.UpgradeFilter == bz.Item.Upgrade + 1)
                                        {
                                            if (packet.SubTypeFilter == 0 || packet.SubTypeFilter == 1 && ((BoxInstance)bz.Item).HoldingVNum == 0 || packet.SubTypeFilter >= 2 && ((BoxInstance)bz.Item).HoldingVNum != 0)
                                            {
                                                bzlist.Add(bz);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                    break;

                case BazaarListType.Pet:
                    if (bz.Item.Item.Type == InventoryType.Equipment)
                    {
                        if (bz.Item.Item.ItemType == ItemType.Box && bz.Item.Item.ItemSubType == 0)
                        {
                            if (bz.Item is BoxInstance boxinstanced && (packet.LevelFilter == 0 || boxinstanced.SpLevel < packet.LevelFilter * 10 + 1 && boxinstanced.SpLevel >= packet.LevelFilter * 10 - 9))
                            {
                                if (packet.SubTypeFilter == 0 || packet.SubTypeFilter == 1 && ((BoxInstance)bz.Item).HoldingVNum == 0 || packet.SubTypeFilter == 2 && ((BoxInstance)bz.Item).HoldingVNum != 0)
                                {
                                    bzlist.Add(bz);
                                }
                            }
                        }
                    }
                    break;

                case BazaarListType.Npc:
                    if (bz.Item.Item.Type == InventoryType.Equipment)
                    {
                        if (bz.Item.Item.ItemType == ItemType.Box && bz.Item.Item.ItemSubType == 1)
                        {
                            if (bz.Item is BoxInstance box && (packet.LevelFilter == 0 || box.SpLevel < packet.LevelFilter * 10 + 1 && box.SpLevel >= packet.LevelFilter * 10 - 9))
                            {
                                if (packet.SubTypeFilter == 0 || packet.SubTypeFilter == 1 && ((BoxInstance)bz.Item).HoldingVNum == 0 || packet.SubTypeFilter == 2 && ((BoxInstance)bz.Item).HoldingVNum != 0)
                                {
                                    bzlist.Add(bz);
                                }
                            }
                        }
                    }
                    break;

                case BazaarListType.Shell:
                    if (bz.Item.Item.Type == InventoryType.Equipment)
                    {
                        if (bz.Item.Item.ItemType == ItemType.Shell)
                        {
                            if (packet.SubTypeFilter == 0 || bz.Item.Item.ItemSubType == bz.Item.Item.ItemSubType + 1)
                            {
                                if (packet.RareFilter == 0 || packet.RareFilter == bz.Item.Rare + 1)
                                {
                                    if (bz.Item is BoxInstance box && (packet.LevelFilter == 0 || box.SpLevel < packet.LevelFilter * 10 + 1 && box.SpLevel >= packet.LevelFilter * 10 - 9))
                                    {
                                        bzlist.Add(bz);
                                    }
                                }
                            }
                        }
                    }
                    break;

                case BazaarListType.Main:
                    if (bz.Item.Item.Type == InventoryType.Main)
                    {
                        if (packet.SubTypeFilter == 0 || packet.SubTypeFilter == 1 && bz.Item.Item.ItemType == ItemType.Main || packet.SubTypeFilter == 2 && bz.Item.Item.ItemType == ItemType.Upgrade || packet.SubTypeFilter == 3 && bz.Item.Item.ItemType == ItemType.Production || packet.SubTypeFilter == 4 && bz.Item.Item.ItemType == ItemType.Special || packet.SubTypeFilter == 5 && bz.Item.Item.ItemType == ItemType.Potion || packet.SubTypeFilter == 6 && bz.Item.Item.ItemType == ItemType.Event)
                        {
                            bzlist.Add(bz);
                        }
                    }
                    break;

                case BazaarListType.Usable:
                    if (bz.Item.Item.Type == InventoryType.Etc)
                    {
                        if (packet.SubTypeFilter == 0 || packet.SubTypeFilter == 1 && bz.Item.Item.ItemType == ItemType.Food || packet.SubTypeFilter == 2 && bz.Item.Item.ItemType == ItemType.Snack || packet.SubTypeFilter == 3 && bz.Item.Item.ItemType == ItemType.Magical || packet.SubTypeFilter == 4 && bz.Item.Item.ItemType == ItemType.Part || packet.SubTypeFilter == 5 && bz.Item.Item.ItemType == ItemType.Teacher || packet.SubTypeFilter == 6 && bz.Item.Item.ItemType == ItemType.Sell)
                        {
                            bzlist.Add(bz);
                        }
                    }
                    break;

                case BazaarListType.Other:
                    if (bz.Item.Item.Type == InventoryType.Equipment)
                    {
                        if (bz.Item.Item.ItemType == ItemType.Box && !bz.Item.Item.Flag9)
                        {
                            bzlist.Add(bz);
                        }
                    }
                    break;

                case BazaarListType.Vehicle:
                    if (bz.Item.Item.ItemType == ItemType.Box && bz.Item.Item.ItemSubType == 4)
                    {
                        if (bz.Item is BoxInstance box && (packet.SubTypeFilter == 0 || packet.SubTypeFilter == 1 && box.HoldingVNum == 0 || packet.SubTypeFilter == 2 && box.HoldingVNum != 0))
                        {
                            bzlist.Add(bz);
                        }
                    }
                    break;

                default:
                    bzlist.Add(bz);
                    break;
                }
            }
            List <BazaarItemLink> bzlistsearched = bzlist.Where(s => itemssearch.Contains(s.Item.ItemVNum.ToString())).ToList();

            //price up price down quantity up quantity down
            List <BazaarItemLink> definitivelist = itemssearch.Any() ? bzlistsearched : bzlist;

            switch (packet.OrderFilter)
            {
            case 0:
                definitivelist = definitivelist.OrderBy(s => s.Item.Item.Name).ThenBy(s => s.BazaarItem.Price).ToList();
                break;

            case 1:
                definitivelist = definitivelist.OrderBy(s => s.Item.Item.Name).ThenByDescending(s => s.BazaarItem.Price).ToList();
                break;

            case 2:
                definitivelist = definitivelist.OrderBy(s => s.Item.Item.Name).ThenBy(s => s.BazaarItem.Amount).ToList();
                break;

            case 3:
                definitivelist = definitivelist.OrderBy(s => s.Item.Item.Name).ThenByDescending(s => s.BazaarItem.Amount).ToList();
                break;

            default:
                definitivelist = definitivelist.OrderBy(s => s.Item.Item.Name).ToList();
                break;
            }
            foreach (BazaarItemLink bzlink in definitivelist.Where(s => (s.BazaarItem.DateStart.AddHours(s.BazaarItem.Duration) - DateTime.Now).TotalMinutes > 0 && s.Item.Amount > 0).Skip(packet.Index * 50).Take(50))
            {
                long   time = (long)(bzlink.BazaarItem.DateStart.AddHours(bzlink.BazaarItem.Duration) - DateTime.Now).TotalMinutes;
                string info = string.Empty;
                if (bzlink.Item.Item.Type == InventoryType.Equipment)
                {
                    if (bzlink.Item is WearableInstance wear)
                    {
                        wear.EquipmentOptions.Clear();
                        wear.EquipmentOptions.AddRange(DAOFactory.EquipmentOptionDAO.GetOptionsByWearableInstanceId(wear.Id));
                    }
                    info = (bzlink.Item.Item.EquipmentSlot != EquipmentType.Sp ?
                            (bzlink.Item as WearableInstance).GenerateEInfo() : bzlink.Item.Item.SpType == 0 && bzlink.Item.Item.ItemSubType == 4 ?
                            (bzlink.Item as SpecialistInstance).GeneratePslInfo() : (bzlink.Item as SpecialistInstance).GenerateSlInfo()).Replace(' ', '^').Replace("slinfo^", "").Replace("e_info^", "");
                }

                itembazar += $"{bzlink.BazaarItem.BazaarItemId}|{bzlink.BazaarItem.SellerId}|{bzlink.Owner}|{bzlink.Item.Item.VNum}|{bzlink.Item.Amount}|{(bzlink.BazaarItem.IsPackage ? 1 : 0)}|{bzlink.BazaarItem.Price}|{time}|2|0|{bzlink.Item.Rare}|{bzlink.Item.Upgrade}|{info} ";
            }

            return($"rc_blist {packet.Index} {itembazar} ");
        }
Exemplo n.º 6
0
        public string GenerateRCBList(CBListPacket packet)
        {
            if (packet == null || packet.ItemVNumFilter == null)
            {
                return(string.Empty);
            }
            string itembazar = string.Empty;

            List <string>         itemssearch = packet.ItemVNumFilter == "0" ? new List <string>() : packet.ItemVNumFilter.Split(' ').ToList();
            List <BazaarItemLink> bzlist      = new List <BazaarItemLink>();

            BazaarItemLink[] billist = new BazaarItemLink[ServerManager.Instance.BazaarList.Count + 20];
            ServerManager.Instance.BazaarList.CopyTo(billist);
            foreach (BazaarItemLink bz in billist)
            {
                if (bz?.Item == null)
                {
                    continue;
                }

                switch (packet.TypeFilter)
                {
                case BazaarListType.Weapon:
                    if (bz.Item.Item.Type == InventoryType.Equipment && bz.Item.Item.ItemType == ItemType.Weapon)
                    {
                        if (packet.SubTypeFilter == 0 || ((bz.Item.Item.Class + 1 >> packet.SubTypeFilter) & 1) == 1)
                        {
                            if (packet.LevelFilter == 0 || (packet.LevelFilter == 11 && bz.Item.Item.IsHeroic) || (bz.Item.Item.LevelMinimum < (packet.LevelFilter * 10) + 1 && bz.Item.Item.LevelMinimum >= (packet.LevelFilter * 10) - 9))    //Level filter
                            {
                                if (packet.RareFilter == 0 || packet.RareFilter == bz.Item.Rare + 1)
                                {
                                    if (packet.UpgradeFilter == 0 || packet.UpgradeFilter == bz.Item.Upgrade + 1)
                                    {
                                        bzlist.Add(bz);
                                    }
                                }
                            }
                        }
                    }

                    break;

                case BazaarListType.Armor:
                    if (bz.Item.Item.Type == InventoryType.Equipment && bz.Item.Item.ItemType == ItemType.Armor)
                    {
                        if (packet.SubTypeFilter == 0 || ((bz.Item.Item.Class + 1 >> packet.SubTypeFilter) & 1) == 1)
                        {
                            if (packet.LevelFilter == 0 || (packet.LevelFilter == 11 && bz.Item.Item.IsHeroic) || (bz.Item.Item.LevelMinimum < (packet.LevelFilter * 10) + 1 && bz.Item.Item.LevelMinimum >= (packet.LevelFilter * 10) - 9))    //Level filter
                            {
                                if (packet.RareFilter == 0 || packet.RareFilter == bz.Item.Rare + 1)
                                {
                                    if (packet.UpgradeFilter == 0 || packet.UpgradeFilter == bz.Item.Upgrade + 1)
                                    {
                                        bzlist.Add(bz);
                                    }
                                }
                            }
                        }
                    }

                    break;

                case BazaarListType.Equipment:
                    if (bz.Item.Item.Type == InventoryType.Equipment && bz.Item.Item.ItemType == ItemType.Fashion)
                    {
                        if (packet.SubTypeFilter == 0 || (packet.SubTypeFilter == 2 && bz.Item.Item.EquipmentSlot == EquipmentType.Mask) || ((packet.SubTypeFilter == 1 && bz.Item.Item.EquipmentSlot == EquipmentType.Hat) || (packet.SubTypeFilter == 6 && bz.Item.Item.EquipmentSlot == EquipmentType.CostumeHat) || (packet.SubTypeFilter == 5 && bz.Item.Item.EquipmentSlot == EquipmentType.CostumeSuit) || (packet.SubTypeFilter == 3 && bz.Item.Item.EquipmentSlot == EquipmentType.Gloves) || (packet.SubTypeFilter == 4 && bz.Item.Item.EquipmentSlot == EquipmentType.Boots)))
                        {
                            if (packet.LevelFilter == 0 || (packet.LevelFilter == 11 && bz.Item.Item.IsHeroic) || (bz.Item.Item.LevelMinimum < (packet.LevelFilter * 10) + 1 && bz.Item.Item.LevelMinimum >= (packet.LevelFilter * 10) - 9))    //Level filter
                            {
                                bzlist.Add(bz);
                            }
                        }
                    }

                    break;

                case BazaarListType.Jewelery:
                    if (bz.Item.Item.Type == InventoryType.Equipment && bz.Item.Item.ItemType == ItemType.Jewelery)
                    {
                        if (packet.SubTypeFilter == 0 || (packet.SubTypeFilter == 2 && bz.Item.Item.EquipmentSlot == EquipmentType.Ring) || (packet.SubTypeFilter == 1 && bz.Item.Item.EquipmentSlot == EquipmentType.Necklace) || (packet.SubTypeFilter == 5 && bz.Item.Item.EquipmentSlot == EquipmentType.Amulet) || (packet.SubTypeFilter == 3 && bz.Item.Item.EquipmentSlot == EquipmentType.Bracelet) || (packet.SubTypeFilter == 4 && (bz.Item.Item.EquipmentSlot == EquipmentType.Fairy || (bz.Item.Item.ItemType == ItemType.Box && bz.Item.Item.ItemSubType == 5))))
                        {
                            if (packet.LevelFilter == 0 || (packet.LevelFilter == 11 && bz.Item.Item.IsHeroic) || (bz.Item.Item.LevelMinimum < (packet.LevelFilter * 10) + 1 && bz.Item.Item.LevelMinimum >= (packet.LevelFilter * 10) - 9))    //Level filter
                            {
                                bzlist.Add(bz);
                            }
                        }
                    }

                    break;

                case BazaarListType.Specialist:
                    if (bz.Item.Item.Type == InventoryType.Equipment && bz.Item.Item.ItemType == ItemType.Box && bz.Item.Item.ItemSubType == 2)
                    {
                        if (packet.SubTypeFilter == 0)
                        {
                            if (packet.LevelFilter == 0 || (bz.Item.SpLevel < (packet.LevelFilter * 10) + 1 && bz.Item.SpLevel >= (packet.LevelFilter * 10) - 9))
                            {
                                if (packet.UpgradeFilter == 0 || packet.UpgradeFilter == bz.Item.Upgrade + 1)
                                {
                                    if (packet.SubTypeFilter == 0 || (packet.SubTypeFilter == 1 && bz.Item.HoldingVNum == 0) || (packet.SubTypeFilter == 2 && bz.Item.HoldingVNum != 0))
                                    {
                                        bzlist.Add(bz);
                                    }
                                }
                            }
                        }
                        else if (bz.Item.HoldingVNum == 0)
                        {
                            if (packet.SubTypeFilter == 1)
                            {
                                if (packet.LevelFilter == 0 || (bz.Item.SpLevel < (packet.LevelFilter * 10) + 1 && bz.Item.SpLevel >= (packet.LevelFilter * 10) - 9))
                                {
                                    if (packet.UpgradeFilter == 0 || packet.UpgradeFilter == bz.Item.Upgrade + 1)
                                    {
                                        if (packet.SubTypeFilter == 0 || (packet.SubTypeFilter == 1 && bz.Item.HoldingVNum == 0) || (packet.SubTypeFilter == 2 && bz.Item.HoldingVNum != 0))
                                        {
                                            bzlist.Add(bz);
                                        }
                                    }
                                }
                            }
                        }
                        else if ((packet.SubTypeFilter == 2 && ServerManager.Instance.GetItem(bz.Item.HoldingVNum).Morph == 10) ||
                                 (packet.SubTypeFilter == 3 && ServerManager.Instance.GetItem(bz.Item.HoldingVNum).Morph == 11) ||
                                 (packet.SubTypeFilter == 4 && ServerManager.Instance.GetItem(bz.Item.HoldingVNum).Morph == 2) ||
                                 (packet.SubTypeFilter == 5 && ServerManager.Instance.GetItem(bz.Item.HoldingVNum).Morph == 3) ||
                                 (packet.SubTypeFilter == 6 && ServerManager.Instance.GetItem(bz.Item.HoldingVNum).Morph == 13) ||
                                 (packet.SubTypeFilter == 7 && ServerManager.Instance.GetItem(bz.Item.HoldingVNum).Morph == 5) ||
                                 (packet.SubTypeFilter == 8 && ServerManager.Instance.GetItem(bz.Item.HoldingVNum).Morph == 12) ||
                                 (packet.SubTypeFilter == 9 && ServerManager.Instance.GetItem(bz.Item.HoldingVNum).Morph == 4) ||
                                 (packet.SubTypeFilter == 10 && ServerManager.Instance.GetItem(bz.Item.HoldingVNum).Morph == 7) ||
                                 (packet.SubTypeFilter == 11 && ServerManager.Instance.GetItem(bz.Item.HoldingVNum).Morph == 15) ||
                                 (packet.SubTypeFilter == 12 && ServerManager.Instance.GetItem(bz.Item.HoldingVNum).Morph == 6) ||
                                 (packet.SubTypeFilter == 13 && ServerManager.Instance.GetItem(bz.Item.HoldingVNum).Morph == 14) ||
                                 (packet.SubTypeFilter == 14 && ServerManager.Instance.GetItem(bz.Item.HoldingVNum).Morph == 9) ||
                                 (packet.SubTypeFilter == 15 && ServerManager.Instance.GetItem(bz.Item.HoldingVNum).Morph == 8) ||
                                 (packet.SubTypeFilter == 16 && ServerManager.Instance.GetItem(bz.Item.HoldingVNum).Morph == 1) ||
                                 (packet.SubTypeFilter == 17 && ServerManager.Instance.GetItem(bz.Item.HoldingVNum).Morph == 16) ||
                                 (packet.SubTypeFilter == 18 && ServerManager.Instance.GetItem(bz.Item.HoldingVNum).Morph == 17) ||
                                 ((packet.SubTypeFilter == 19 && ServerManager.Instance.GetItem(bz.Item.HoldingVNum).Morph == 18) ||
                                  (packet.SubTypeFilter == 20 && ServerManager.Instance.GetItem(bz.Item.HoldingVNum).Morph == 19) ||
                                  (packet.SubTypeFilter == 21 && ServerManager.Instance.GetItem(bz.Item.HoldingVNum).Morph == 20) ||
                                  (packet.SubTypeFilter == 22 && ServerManager.Instance.GetItem(bz.Item.HoldingVNum).Morph == 21) ||
                                  (packet.SubTypeFilter == 23 && ServerManager.Instance.GetItem(bz.Item.HoldingVNum).Morph == 22) ||
                                  (packet.SubTypeFilter == 24 && ServerManager.Instance.GetItem(bz.Item.HoldingVNum).Morph == 23) ||
                                  (packet.SubTypeFilter == 25 && ServerManager.Instance.GetItem(bz.Item.HoldingVNum).Morph == 24) ||
                                  (packet.SubTypeFilter == 26 && ServerManager.Instance.GetItem(bz.Item.HoldingVNum).Morph == 25) ||
                                  (packet.SubTypeFilter == 27 && ServerManager.Instance.GetItem(bz.Item.HoldingVNum).Morph == 26) ||
                                  (packet.SubTypeFilter == 28 && ServerManager.Instance.GetItem(bz.Item.HoldingVNum).Morph == 27) ||
                                  (packet.SubTypeFilter == 29 && ServerManager.Instance.GetItem(bz.Item.HoldingVNum).Morph == 28)))
                        {
                            if (packet.LevelFilter == 0 || (bz.Item.SpLevel < (packet.LevelFilter * 10) + 1 && bz.Item.SpLevel >= (packet.LevelFilter * 10) - 9))
                            {
                                if (packet.UpgradeFilter == 0 || packet.UpgradeFilter == bz.Item.Upgrade + 1)
                                {
                                    if (packet.SubTypeFilter == 0 || (packet.SubTypeFilter == 1 && bz.Item.HoldingVNum == 0) || (packet.SubTypeFilter >= 2 && bz.Item.HoldingVNum != 0))
                                    {
                                        bzlist.Add(bz);
                                    }
                                }
                            }
                        }
                    }
                    break;

                case BazaarListType.Pet:
                    if (bz.Item.Item.Type == InventoryType.Equipment && bz.Item.Item.ItemType == ItemType.Box && bz.Item.Item.ItemSubType == 0 && (packet.LevelFilter == 0 || (bz.Item.SpLevel < (packet.LevelFilter * 10) + 1 && bz.Item.SpLevel >= (packet.LevelFilter * 10) - 9)))
                    {
                        if (packet.SubTypeFilter == 0 || (packet.SubTypeFilter == 1 && bz.Item.HoldingVNum == 0) || (packet.SubTypeFilter == 2 && bz.Item.HoldingVNum != 0))
                        {
                            bzlist.Add(bz);
                        }
                    }
                    break;

                case BazaarListType.Npc:
                    if (bz.Item.Item.Type == InventoryType.Equipment && bz.Item.Item.ItemType == ItemType.Box && bz.Item.Item.ItemSubType == 1 && (packet.LevelFilter == 0 || (bz.Item.SpLevel < (packet.LevelFilter * 10) + 1 && bz.Item.SpLevel >= (packet.LevelFilter * 10) - 9)))
                    {
                        if (packet.SubTypeFilter == 0 || (packet.SubTypeFilter == 1 && bz.Item.HoldingVNum == 0) || (packet.SubTypeFilter == 2 && bz.Item.HoldingVNum != 0))
                        {
                            bzlist.Add(bz);
                        }
                    }
                    break;

                case BazaarListType.Shell:
                    if (bz.Item.Item.Type == InventoryType.Equipment && bz.Item.Item.ItemType == ItemType.Shell)
                    {
                        if (packet.SubTypeFilter == 0 || bz.Item.Item.ItemSubType == bz.Item.Item.ItemSubType + 1)
                        {
                            if (packet.RareFilter == 0 || packet.RareFilter == bz.Item.Rare + 1)
                            {
                                if ((packet.LevelFilter == 0 || (bz.Item.SpLevel < (packet.LevelFilter * 10) + 1 && bz.Item.SpLevel >= (packet.LevelFilter * 10) - 9)))
                                {
                                    bzlist.Add(bz);
                                }
                            }
                        }
                    }

                    break;

                case BazaarListType.Main:
                    if (bz.Item.Item.Type == InventoryType.Main)
                    {
                        if (packet.SubTypeFilter == 0 || (packet.SubTypeFilter == 1 && bz.Item.Item.ItemType == ItemType.Main) || (packet.SubTypeFilter == 2 && bz.Item.Item.ItemType == ItemType.Upgrade) || (packet.SubTypeFilter == 3 && bz.Item.Item.ItemType == ItemType.Production) || (packet.SubTypeFilter == 4 && bz.Item.Item.ItemType == ItemType.Special) || (packet.SubTypeFilter == 5 && bz.Item.Item.ItemType == ItemType.Potion) || (packet.SubTypeFilter == 6 && bz.Item.Item.ItemType == ItemType.Event))
                        {
                            bzlist.Add(bz);
                        }
                    }

                    break;

                case BazaarListType.Usable:
                    if (bz.Item.Item.Type == InventoryType.Etc)
                    {
                        if (packet.SubTypeFilter == 0 || (packet.SubTypeFilter == 1 && bz.Item.Item.ItemType == ItemType.Food) || ((packet.SubTypeFilter == 2 && bz.Item.Item.ItemType == ItemType.Snack) || (packet.SubTypeFilter == 3 && bz.Item.Item.ItemType == ItemType.Magical) || (packet.SubTypeFilter == 4 && bz.Item.Item.ItemType == ItemType.Part) || (packet.SubTypeFilter == 5 && bz.Item.Item.ItemType == ItemType.Teacher) || (packet.SubTypeFilter == 6 && bz.Item.Item.ItemType == ItemType.Sell)))
                        {
                            bzlist.Add(bz);
                        }
                    }

                    break;

                case BazaarListType.Other:
                    if (bz.Item.Item.Type == InventoryType.Equipment && bz.Item.Item.ItemType == ItemType.Box && !bz.Item.Item.IsHolder)
                    {
                        bzlist.Add(bz);
                    }

                    break;

                case BazaarListType.Vehicle:
                    if (bz.Item.Item.ItemType == ItemType.Box && bz.Item.Item.ItemSubType == 4 && (packet.SubTypeFilter == 0 || (packet.SubTypeFilter == 1 && bz.Item.HoldingVNum == 0) || (packet.SubTypeFilter == 2 && bz.Item.HoldingVNum != 0)))
                    {
                        bzlist.Add(bz);
                    }

                    break;

                default:
                    bzlist.Add(bz);
                    break;
                }
            }
            List <BazaarItemLink> bzlistsearched = bzlist.Where(s => itemssearch.Contains(s.Item.ItemVNum.ToString())).ToList();

            //price up price down quantity up quantity down
            List <BazaarItemLink> definitivelist = itemssearch.Count > 0 ? bzlistsearched : bzlist;

            switch (packet.OrderFilter)
            {
            case 0:
                definitivelist = definitivelist.OrderBy(s => s.Item.Item.Name).ThenBy(s => s.BazaarItem.Price).ToList();
                break;

            case 1:
                definitivelist = definitivelist.OrderBy(s => s.Item.Item.Name).ThenByDescending(s => s.BazaarItem.Price).ToList();
                break;

            case 2:
                definitivelist = definitivelist.OrderBy(s => s.Item.Item.Name).ThenBy(s => s.BazaarItem.Amount).ToList();
                break;

            case 3:
                definitivelist = definitivelist.OrderBy(s => s.Item.Item.Name).ThenByDescending(s => s.BazaarItem.Amount).ToList();
                break;

            default:
                definitivelist = definitivelist.OrderBy(s => s.Item.Item.Name).ToList();
                break;
            }
            foreach (BazaarItemLink bzlink in definitivelist.Where(s => (s.BazaarItem.DateStart.AddHours(s.BazaarItem.Duration) - DateTime.Now).TotalMinutes > 0 && s.Item.Amount > 0).Skip(packet.Index * 50).Take(50))
            {
                long   time = (long)(bzlink.BazaarItem.DateStart.AddHours(bzlink.BazaarItem.Duration) - DateTime.Now).TotalMinutes;
                string info = string.Empty;
                if (bzlink.Item.Item.Type == InventoryType.Equipment)
                {
                    info = (bzlink.Item.Item.EquipmentSlot != EquipmentType.Sp ?
                            bzlink.Item?.GenerateEInfo() : bzlink.Item.Item.SpType == 0 && bzlink.Item.Item.ItemSubType == 4 ?
                            bzlink.Item?.GeneratePslInfo() : bzlink.Item?.GenerateSlInfo()).Replace(' ', '^').Replace("slinfo^", "").Replace("e_info^", "");
                }
                itembazar += $"{bzlink.BazaarItem.BazaarItemId}|{bzlink.BazaarItem.SellerId}|{bzlink.Owner}|{bzlink.Item.Item.VNum}|{bzlink.Item.Amount}|{(bzlink.BazaarItem.IsPackage ? 1 : 0)}|{bzlink.BazaarItem.Price}|{time}|2|0|{bzlink.Item.Rare}|{bzlink.Item.Upgrade}|{info} ";
            }

            return($"rc_blist {packet.Index} {itembazar} ");
        }
Exemplo n.º 7
0
        /// <summary>
        /// c_buy packet
        /// </summary>
        /// <param name="cBuyPacket"></param>
        public void BuyBazaar(CBuyPacket cBuyPacket)
        {
            if (ServerManager.Instance.InShutdown || Session.Character == null || Session.Character.InExchangeOrTrade)
            {
                return;
            }
            BazaarItemDTO bz = DAOFactory.BazaarItemDAO.FirstOrDefault(s => s.BazaarItemId == cBuyPacket.BazaarId);

            if (bz != null && cBuyPacket.Amount > 0)
            {
                long price = cBuyPacket.Amount * bz.Price;

                if (Session.Character.Gold >= price)
                {
                    BazaarItemLink bzcree = new BazaarItemLink {
                        BazaarItem = bz
                    };
                    if (DAOFactory.CharacterDAO.FirstOrDefault(s => s.CharacterId == bz.SellerId && s.State == (byte)CharacterState.Active) != null)
                    {
                        bzcree.Owner = DAOFactory.CharacterDAO.FirstOrDefault(s => s.CharacterId.Equals(bz.SellerId) && s.State == (byte)CharacterState.Active)?.Name;
                        bzcree.Item  = (ItemInstance)DAOFactory.IteminstanceDAO.FirstOrDefault(s => s.Id == bz.ItemInstanceId);
                    }
                    if (cBuyPacket.Amount <= bzcree.Item.Amount)
                    {
                        if (!Session.Character.Inventory.CanAddItem(bzcree.Item.ItemVNum))
                        {
                            Session.SendPacket(UserInterfaceHelper.Instance.GenerateMsg(Language.Instance.GetMessageFromKey("NOT_ENOUGH_PLACE"), 0));
                            return;
                        }

                        if (bzcree.Item == null)
                        {
                            return;
                        }
                        if (bz.IsPackage && cBuyPacket.Amount != bz.Amount)
                        {
                            return;
                        }
                        ItemInstanceDTO bzitemdto = DAOFactory.IteminstanceDAO.FirstOrDefault(s => s.Id == bzcree.BazaarItem.ItemInstanceId);
                        if (bzitemdto.Amount < cBuyPacket.Amount)
                        {
                            return;
                        }
                        bzitemdto.Amount       -= cBuyPacket.Amount;
                        Session.Character.Gold -= price;
                        Session.SendPacket(Session.Character.GenerateGold());
                        DAOFactory.IteminstanceDAO.InsertOrUpdate(ref bzitemdto);
                        ServerManager.Instance.BazaarRefresh(bzcree.BazaarItem.BazaarItemId);
                        Session.SendPacket($"rc_buy 1 {bzcree.Item.Item.VNum} {bzcree.Owner} {cBuyPacket.Amount} {cBuyPacket.Price} 0 0 0");
                        ItemInstance newBz = bzcree.Item.DeepCopy();
                        newBz.Id     = Guid.NewGuid();
                        newBz.Amount = cBuyPacket.Amount;
                        newBz.Type   = newBz.Item.Type;
                        if (newBz is WearableInstance wear)
                        {
                            wear.EquipmentOptions.ForEach(s => s.WearableInstanceId = newBz.Id);
                        }


                        List <ItemInstance> newInv = Session.Character.Inventory.AddToInventory(newBz);
                        if (newInv.Any())
                        {
                            Session.SendPacket(Session.Character.GenerateSay($"{Language.Instance.GetMessageFromKey("ITEM_ACQUIRED")}: { bzcree.Item.Item.Name} x {cBuyPacket.Amount}", 10));
                        }
                    }
                    else
                    {
                        Session.SendPacket(UserInterfaceHelper.Instance.GenerateModal(Language.Instance.GetMessageFromKey("STATE_CHANGED"), 1));
                    }
                }
                else
                {
                    Session.SendPacket(Session.Character.GenerateSay(Language.Instance.GetMessageFromKey("NOT_ENOUGH_MONEY"), 10));
                    Session.SendPacket(UserInterfaceHelper.Instance.GenerateModal(Language.Instance.GetMessageFromKey("NOT_ENOUGH_MONEY"), 1));
                }
            }
            else
            {
                Session.SendPacket(UserInterfaceHelper.Instance.GenerateModal(Language.Instance.GetMessageFromKey("STATE_CHANGED"), 1));
            }
        }
Exemplo n.º 8
0
        private void ExecuteHandler(ClientSession session)
        {
            SpinWait.SpinUntil(() => !ServerManager.Instance.InBazaarRefreshMode);
            string                itembazar   = string.Empty;
            List <string>         itemssearch = ItemVNumFilter == "0" ? new List <string>() : ItemVNumFilter.Split(' ').ToList();
            List <BazaarItemLink> bzlist      = new List <BazaarItemLink>();

            BazaarItemLink[] billist = new BazaarItemLink[ServerManager.Instance.BazaarList.Count + 20];
            ServerManager.Instance.BazaarList.CopyTo(billist);
            try
            {
                foreach (BazaarItemLink bz in billist)
                {
                    if (bz?.Item == null)
                    {
                        continue;
                    }

                    switch (TypeFilter)
                    {
                    case BazaarListType.Weapon:
                        if (bz.Item.Item.Type == InventoryType.Equipment && bz.Item.Item.ItemType == ItemType.Weapon && (SubTypeFilter == 0 || ((bz.Item.Item.Class + 1 >> SubTypeFilter) & 1) == 1) && ((LevelFilter == 0 || (LevelFilter == 11 && bz.Item.Item.IsHeroic) || (bz.Item.Item.LevelMinimum < (LevelFilter * 10) + 1 && bz.Item.Item.LevelMinimum >= (LevelFilter * 10) - 9)) && ((RareFilter == 0 || RareFilter == bz.Item.Rare + 1) && (UpgradeFilter == 0 || UpgradeFilter == bz.Item.Upgrade + 1))))
                        {
                            bzlist.Add(bz);
                        }
                        break;

                    case BazaarListType.Armor:
                        if (bz.Item.Item.Type == InventoryType.Equipment && bz.Item.Item.ItemType == ItemType.Armor && (SubTypeFilter == 0 || ((bz.Item.Item.Class + 1 >> SubTypeFilter) & 1) == 1) && ((LevelFilter == 0 || (LevelFilter == 11 && bz.Item.Item.IsHeroic) || (bz.Item.Item.LevelMinimum < (LevelFilter * 10) + 1 && bz.Item.Item.LevelMinimum >= (LevelFilter * 10) - 9)) && ((RareFilter == 0 || RareFilter == bz.Item.Rare + 1) && (UpgradeFilter == 0 || UpgradeFilter == bz.Item.Upgrade + 1))))
                        {
                            bzlist.Add(bz);
                        }
                        break;

                    case BazaarListType.Equipment:
                        if (bz.Item.Item.Type == InventoryType.Equipment && bz.Item.Item.ItemType == ItemType.Fashion && ((SubTypeFilter == 0 || (SubTypeFilter == 2 && bz.Item.Item.EquipmentSlot == EquipmentType.Mask) || ((SubTypeFilter == 1 && bz.Item.Item.EquipmentSlot == EquipmentType.Hat) || (SubTypeFilter == 6 && bz.Item.Item.EquipmentSlot == EquipmentType.CostumeHat) || (SubTypeFilter == 5 && bz.Item.Item.EquipmentSlot == EquipmentType.CostumeSuit) || (SubTypeFilter == 3 && bz.Item.Item.EquipmentSlot == EquipmentType.Gloves) || (SubTypeFilter == 4 && bz.Item.Item.EquipmentSlot == EquipmentType.Boots))) && (LevelFilter == 0 || (LevelFilter == 11 && bz.Item.Item.IsHeroic) || (bz.Item.Item.LevelMinimum < (LevelFilter * 10) + 1 && bz.Item.Item.LevelMinimum >= (LevelFilter * 10) - 9))))
                        {
                            bzlist.Add(bz);
                        }
                        break;

                    case BazaarListType.Jewelery:
                        if (bz.Item.Item.Type == InventoryType.Equipment && bz.Item.Item.ItemType == ItemType.Jewelery && ((SubTypeFilter == 0 || (SubTypeFilter == 2 && bz.Item.Item.EquipmentSlot == EquipmentType.Ring) || (SubTypeFilter == 1 && bz.Item.Item.EquipmentSlot == EquipmentType.Necklace) || (SubTypeFilter == 5 && bz.Item.Item.EquipmentSlot == EquipmentType.Amulet) || (SubTypeFilter == 3 && bz.Item.Item.EquipmentSlot == EquipmentType.Bracelet) || (SubTypeFilter == 4 && (bz.Item.Item.EquipmentSlot == EquipmentType.Fairy || (bz.Item.Item.ItemType == ItemType.Box && bz.Item.Item.ItemSubType == 5)))) && (LevelFilter == 0 || (LevelFilter == 11 && bz.Item.Item.IsHeroic) || (bz.Item.Item.LevelMinimum < (LevelFilter * 10) + 1 && bz.Item.Item.LevelMinimum >= (LevelFilter * 10) - 9))))
                        {
                            bzlist.Add(bz);
                        }
                        break;

                    case BazaarListType.Specialist:
                        if (bz.Item.Item.Type == InventoryType.Equipment && bz.Item.Item.ItemType == ItemType.Box && bz.Item.Item.ItemSubType == 2)
                        {
                            if (SubTypeFilter == 0 && ((LevelFilter == 0 || (bz.Item.SpLevel < (LevelFilter * 10) + 1 && bz.Item.SpLevel >= (LevelFilter * 10) - 9)) && ((UpgradeFilter == 0 || UpgradeFilter == bz.Item.Upgrade + 1) && (SubTypeFilter == 0 || (SubTypeFilter == 1 && bz.Item.HoldingVNum == 0) || (SubTypeFilter == 2 && bz.Item.HoldingVNum != 0)))))
                            {
                                bzlist.Add(bz);
                            }
                            else if (bz.Item.HoldingVNum == 0 && (SubTypeFilter == 1 && ((LevelFilter == 0 || (bz.Item.SpLevel < (LevelFilter * 10) + 1 && bz.Item.SpLevel >= (LevelFilter * 10) - 9)) && ((UpgradeFilter == 0 || UpgradeFilter == bz.Item.Upgrade + 1) && (SubTypeFilter == 0 || (SubTypeFilter == 1 && bz.Item.HoldingVNum == 0) || (SubTypeFilter == 2 && bz.Item.HoldingVNum != 0))))))
                            {
                                bzlist.Add(bz);
                            }
                            else
                            {
                                Item bazaarItem = ServerManager.GetItem(bz.Item.HoldingVNum);
                                if (bazaarItem != null &&
                                    ((SubTypeFilter == 2 && bazaarItem.Morph == 10) ||
                                     (SubTypeFilter == 3 && bazaarItem.Morph == 11) ||
                                     (SubTypeFilter == 4 && bazaarItem.Morph == 2) ||
                                     (SubTypeFilter == 5 && bazaarItem.Morph == 3) ||
                                     (SubTypeFilter == 6 && bazaarItem.Morph == 13) ||
                                     (SubTypeFilter == 7 && bazaarItem.Morph == 5) ||
                                     (SubTypeFilter == 8 && bazaarItem.Morph == 12) ||
                                     (SubTypeFilter == 9 && bazaarItem.Morph == 4) ||
                                     (SubTypeFilter == 10 && bazaarItem.Morph == 7) ||
                                     (SubTypeFilter == 11 && bazaarItem.Morph == 15) ||
                                     (SubTypeFilter == 12 && bazaarItem.Morph == 6) ||
                                     (SubTypeFilter == 13 && bazaarItem.Morph == 14) ||
                                     (SubTypeFilter == 14 && bazaarItem.Morph == 9) ||
                                     (SubTypeFilter == 15 && bazaarItem.Morph == 8) ||
                                     (SubTypeFilter == 16 && bazaarItem.Morph == 1) ||
                                     (SubTypeFilter == 17 && bazaarItem.Morph == 16) ||
                                     (SubTypeFilter == 18 && bazaarItem.Morph == 17) ||
                                     ((SubTypeFilter == 19 && bazaarItem.Morph == 18) ||
                                      (SubTypeFilter == 20 && bazaarItem.Morph == 19) ||
                                      (SubTypeFilter == 21 && bazaarItem.Morph == 20) ||
                                      (SubTypeFilter == 22 && bazaarItem.Morph == 21) ||
                                      (SubTypeFilter == 23 && bazaarItem.Morph == 22) ||
                                      (SubTypeFilter == 24 && bazaarItem.Morph == 23) ||
                                      (SubTypeFilter == 25 && bazaarItem.Morph == 24) ||
                                      (SubTypeFilter == 26 && bazaarItem.Morph == 25) ||
                                      (SubTypeFilter == 27 && bazaarItem.Morph == 26) ||
                                      (SubTypeFilter == 28 && bazaarItem.Morph == 27) ||
                                      (SubTypeFilter == 29 && bazaarItem.Morph == 28))) &&
                                    (LevelFilter == 0 || (bz.Item.SpLevel < (LevelFilter * 10) + 1 && bz.Item.SpLevel >= (LevelFilter * 10) - 9)) &&
                                    ((UpgradeFilter == 0 || UpgradeFilter == bz.Item.Upgrade + 1) &&
                                     (SubTypeFilter == 0 || (SubTypeFilter == 1 && bz.Item.HoldingVNum == 0) ||
                                      (SubTypeFilter >= 2 && bz.Item.HoldingVNum != 0))))
                                {
                                    bzlist.Add(bz);
                                }
                            }
                        }
                        break;

                    case BazaarListType.Pet:
                        if (bz.Item.Item.Type == InventoryType.Equipment && bz.Item.Item.ItemType == ItemType.Box && bz.Item.Item.ItemSubType == 0 && (LevelFilter == 0 || (bz.Item.SpLevel < (LevelFilter * 10) + 1 && bz.Item.SpLevel >= (LevelFilter * 10) - 9)) && (SubTypeFilter == 0 || (SubTypeFilter == 1 && bz.Item.HoldingVNum == 0) || (SubTypeFilter == 2 && bz.Item.HoldingVNum != 0)))
                        {
                            bzlist.Add(bz);
                        }
                        break;

                    case BazaarListType.Npc:
                        if (bz.Item.Item.Type == InventoryType.Equipment && bz.Item.Item.ItemType == ItemType.Box && bz.Item.Item.ItemSubType == 1 && (LevelFilter == 0 || (bz.Item.SpLevel < (LevelFilter * 10) + 1 && bz.Item.SpLevel >= (LevelFilter * 10) - 9)) && (SubTypeFilter == 0 || (SubTypeFilter == 1 && bz.Item.HoldingVNum == 0) || (SubTypeFilter == 2 && bz.Item.HoldingVNum != 0)))
                        {
                            bzlist.Add(bz);
                        }
                        break;

                    case BazaarListType.Shell:
                        if (bz.Item.Item.Type == InventoryType.Equipment && bz.Item.Item.ItemType == ItemType.Shell && (SubTypeFilter == 0 || SubTypeFilter == bz.Item.Item.ItemSubType + 1) && ((RareFilter == 0 || RareFilter == bz.Item.Rare + 1) && (LevelFilter == 0 || (bz.Item.Upgrade < (LevelFilter * 10) + 1 && bz.Item.Upgrade >= (LevelFilter * 10) - 9))))
                        {
                            bzlist.Add(bz);
                        }
                        break;

                    case BazaarListType.Main:
                        if (bz.Item.Item.Type == InventoryType.Main && (SubTypeFilter == 0 || (SubTypeFilter == 1 && bz.Item.Item.ItemType == ItemType.Main) || (SubTypeFilter == 2 && bz.Item.Item.ItemType == ItemType.Upgrade) || (SubTypeFilter == 3 && bz.Item.Item.ItemType == ItemType.Production) || (SubTypeFilter == 4 && bz.Item.Item.ItemType == ItemType.Special) || (SubTypeFilter == 5 && bz.Item.Item.ItemType == ItemType.Potion) || (SubTypeFilter == 6 && bz.Item.Item.ItemType == ItemType.Event)))
                        {
                            bzlist.Add(bz);
                        }
                        break;

                    case BazaarListType.Usable:
                        if (bz.Item.Item.Type == InventoryType.Etc && (SubTypeFilter == 0 || (SubTypeFilter == 1 && bz.Item.Item.ItemType == ItemType.Food) || ((SubTypeFilter == 2 && bz.Item.Item.ItemType == ItemType.Snack) || (SubTypeFilter == 3 && bz.Item.Item.ItemType == ItemType.Magical) || (SubTypeFilter == 4 && bz.Item.Item.ItemType == ItemType.Part) || (SubTypeFilter == 5 && bz.Item.Item.ItemType == ItemType.Teacher) || (SubTypeFilter == 6 && bz.Item.Item.ItemType == ItemType.Sell))))
                        {
                            bzlist.Add(bz);
                        }
                        break;

                    case BazaarListType.Other:
                        if (bz.Item.Item.Type == InventoryType.Equipment && bz.Item.Item.ItemType == ItemType.Box && !bz.Item.Item.IsHolder)
                        {
                            bzlist.Add(bz);
                        }
                        break;

                    case BazaarListType.Vehicle:
                        if (bz.Item.Item.ItemType == ItemType.Box && bz.Item.Item.ItemSubType == 4 && (SubTypeFilter == 0 || (SubTypeFilter == 1 && bz.Item.HoldingVNum == 0) || (SubTypeFilter == 2 && bz.Item.HoldingVNum != 0)))
                        {
                            bzlist.Add(bz);
                        }
                        break;

                    default:
                        bzlist.Add(bz);
                        break;
                    }
                }

                List <BazaarItemLink> bzlistsearched;

                if (TypeFilter == BazaarListType.Specialist)
                {
                    bzlistsearched = bzlist.Where(s => itemssearch.Contains(s.Item.HoldingVNum.ToString())).ToList();
                }
                else
                {
                    bzlistsearched = bzlist.Where(s => itemssearch.Contains(s.Item.ItemVNum.ToString())).ToList();
                }

                //price up price down quantity up quantity down
                List <BazaarItemLink> definitivelist = itemssearch.Count > 0 ? bzlistsearched : bzlist;
                switch (OrderFilter)
                {
                case 0:
                    definitivelist = definitivelist.OrderBy(s => s.Item.Item.Name).ThenBy(s => s.BazaarItem.Price).ThenBy(s => s.BazaarItem.BazaarItemId).ToList();
                    break;

                case 1:
                    definitivelist = definitivelist.OrderBy(s => s.Item.Item.Name).ThenByDescending(s => s.BazaarItem.Price).ThenBy(s => s.BazaarItem.BazaarItemId).ToList();
                    break;

                case 2:
                    definitivelist = definitivelist.OrderBy(s => s.Item.Item.Name).ThenBy(s => s.BazaarItem.Amount).ThenBy(s => s.BazaarItem.BazaarItemId).ToList();
                    break;

                case 3:
                    definitivelist = definitivelist.OrderBy(s => s.Item.Item.Name).ThenByDescending(s => s.BazaarItem.Amount).ThenBy(s => s.BazaarItem.BazaarItemId).ToList();
                    break;

                default:
                    definitivelist = definitivelist.OrderBy(s => s.Item.Item.Name).ToList();
                    break;
                }
                foreach (BazaarItemLink bzlink in definitivelist.Where(s => (s.BazaarItem.DateStart.AddHours(s.BazaarItem.Duration) - DateTime.UtcNow).TotalMinutes > 0 && s.Item.Amount > 0).Skip(Index * 50).Take(50))
                {
                    long   time = (long)(bzlink.BazaarItem.DateStart.AddHours(bzlink.BazaarItem.Duration) - DateTime.UtcNow).TotalMinutes;
                    string info = string.Empty;
                    if (bzlink.Item.Item.Type == InventoryType.Equipment)
                    {
                        info = (bzlink.Item.Item.EquipmentSlot != EquipmentType.Sp ?
                                bzlink.Item?.GenerateEInfo() : bzlink.Item.Item.SpType == 0 && bzlink.Item.Item.ItemSubType == 4 ?
                                bzlink.Item?.GeneratePslInfo() : bzlink.Item?.GenerateSlInfo(callFormBazaar: true)).Replace(' ', '^').Replace("slinfo^", "").Replace("e_info^", "");
                    }
                    itembazar += $"{bzlink.BazaarItem.BazaarItemId}|{bzlink.BazaarItem.SellerId}|{bzlink.OwnerName}|{bzlink.Item.Item.VNum}|{bzlink.Item.Amount}|{(bzlink.BazaarItem.IsPackage ? 1 : 0)}|{bzlink.BazaarItem.Price}|{time}|2|0|{bzlink.Item.Rare}|{bzlink.Item.Upgrade}|{info} ";
                }

                session.SendPacket($"rc_blist {Index} {itembazar}");
            }
            catch (Exception ex)
            {
                Logger.Error(ex);
            }
        }
Exemplo n.º 9
0
        public static string GenerateRCBList(CBListPacket packet)
        {
            if (packet == null || packet.ItemVNumFilter == null)
            {
                return(string.Empty);
            }
            string itembazar = string.Empty;

            List <string>         itemssearch = packet.ItemVNumFilter == "0" ? new List <string>() : packet.ItemVNumFilter.Split(' ').ToList();
            List <BazaarItemLink> bzlist      = new List <BazaarItemLink>();

            BazaarItemLink[] billist = new BazaarItemLink[ServerManager.Instance.BazaarList.Count + 20];
            ServerManager.Instance.BazaarList.CopyTo(billist);
            try
            {
                List <BazaarItemLink> temps = new List <BazaarItemLink>();
                foreach (BazaarItemLink temp in billist)
                {
                    if (temp == null)
                    {
                        temps.Add(temp);
                        continue;
                    }
                    if (temp.Item == null)
                    {
                        temps.Add(temp);
                        continue;
                    }
                    if (temp.Item.Item == null)
                    {
                        temps.Add(temp);
                        continue;
                    }
                    if (temp.BazaarItem == null)
                    {
                        temps.Add(temp);
                        continue;
                    }
                }
                List <BazaarItemLink> test = billist.ToList();
                foreach (BazaarItemLink temp2 in temps)
                {
                    test.Remove(temp2);
                }
                billist = test.ToArray();
                foreach (BazaarItemLink bz in billist)
                {
                    if (bz?.Item == null || bz?.Item.Item == null || bz?.BazaarItem == null)
                    {
                        continue;
                    }

                    switch (packet.TypeFilter)
                    {
                    case BazaarListType.Weapon:
                        if (bz.Item.Item.Type == InventoryType.Equipment && bz.Item.Item.ItemType == ItemType.Weapon && (packet.SubTypeFilter == 0 || ((bz.Item.Item.Class + 1 >> packet.SubTypeFilter) & 1) == 1) && ((packet.LevelFilter == 0 || (packet.LevelFilter == 11 && bz.Item.Item.IsHeroic) || (bz.Item.Item.LevelMinimum < (packet.LevelFilter * 10) + 1 && bz.Item.Item.LevelMinimum >= (packet.LevelFilter * 10) - 9)) && ((packet.RareFilter == 0 || packet.RareFilter == bz.Item.Rare + 1) && (packet.UpgradeFilter == 0 || packet.UpgradeFilter == bz.Item.Upgrade + 1))))
                        {
                            bzlist.Add(bz);
                        }
                        break;

                    case BazaarListType.Armor:
                        if (bz.Item.Item.Type == InventoryType.Equipment && bz.Item.Item.ItemType == ItemType.Armor && (packet.SubTypeFilter == 0 || ((bz.Item.Item.Class + 1 >> packet.SubTypeFilter) & 1) == 1) && ((packet.LevelFilter == 0 || (packet.LevelFilter == 11 && bz.Item.Item.IsHeroic) || (bz.Item.Item.LevelMinimum < (packet.LevelFilter * 10) + 1 && bz.Item.Item.LevelMinimum >= (packet.LevelFilter * 10) - 9)) && ((packet.RareFilter == 0 || packet.RareFilter == bz.Item.Rare + 1) && (packet.UpgradeFilter == 0 || packet.UpgradeFilter == bz.Item.Upgrade + 1))))
                        {
                            bzlist.Add(bz);
                        }
                        break;

                    case BazaarListType.Equipment:
                        if (bz.Item.Item.Type == InventoryType.Equipment && bz.Item.Item.ItemType == ItemType.Fashion && ((packet.SubTypeFilter == 0 || (packet.SubTypeFilter == 2 && bz.Item.Item.EquipmentSlot == EquipmentType.Mask) || ((packet.SubTypeFilter == 1 && bz.Item.Item.EquipmentSlot == EquipmentType.Hat) || (packet.SubTypeFilter == 6 && bz.Item.Item.EquipmentSlot == EquipmentType.CostumeHat) || (packet.SubTypeFilter == 5 && bz.Item.Item.EquipmentSlot == EquipmentType.CostumeSuit) || (packet.SubTypeFilter == 3 && bz.Item.Item.EquipmentSlot == EquipmentType.Gloves) || (packet.SubTypeFilter == 4 && bz.Item.Item.EquipmentSlot == EquipmentType.Boots))) && (packet.LevelFilter == 0 || (packet.LevelFilter == 11 && bz.Item.Item.IsHeroic) || (bz.Item.Item.LevelMinimum < (packet.LevelFilter * 10) + 1 && bz.Item.Item.LevelMinimum >= (packet.LevelFilter * 10) - 9))))
                        {
                            bzlist.Add(bz);
                        }
                        break;

                    case BazaarListType.Jewelery:
                        if (bz.Item.Item.Type == InventoryType.Equipment && bz.Item.Item.ItemType == ItemType.Jewelery && ((packet.SubTypeFilter == 0 || (packet.SubTypeFilter == 2 && bz.Item.Item.EquipmentSlot == EquipmentType.Ring) || (packet.SubTypeFilter == 1 && bz.Item.Item.EquipmentSlot == EquipmentType.Necklace) || (packet.SubTypeFilter == 5 && bz.Item.Item.EquipmentSlot == EquipmentType.Amulet) || (packet.SubTypeFilter == 3 && bz.Item.Item.EquipmentSlot == EquipmentType.Bracelet) || (packet.SubTypeFilter == 4 && (bz.Item.Item.EquipmentSlot == EquipmentType.Fairy || (bz.Item.Item.ItemType == ItemType.Box && bz.Item.Item.ItemSubType == 5)))) && (packet.LevelFilter == 0 || (packet.LevelFilter == 11 && bz.Item.Item.IsHeroic) || (bz.Item.Item.LevelMinimum < (packet.LevelFilter * 10) + 1 && bz.Item.Item.LevelMinimum >= (packet.LevelFilter * 10) - 9))))
                        {
                            bzlist.Add(bz);
                        }
                        break;

                    case BazaarListType.Specialist:
                        if (bz.Item.Item.Type == InventoryType.Equipment && bz.Item.Item.ItemType == ItemType.Box && bz.Item.Item.ItemSubType == 2)
                        {
                            if (packet.SubTypeFilter == 0 && ((packet.LevelFilter == 0 || (bz.Item.SpLevel < (packet.LevelFilter * 10) + 1 && bz.Item.SpLevel >= (packet.LevelFilter * 10) - 9)) && ((packet.UpgradeFilter == 0 || packet.UpgradeFilter == bz.Item.Upgrade + 1) && (packet.SubTypeFilter == 0 || (packet.SubTypeFilter == 1 && bz.Item.HoldingVNum == 0) || (packet.SubTypeFilter == 2 && bz.Item.HoldingVNum != 0)))))
                            {
                                bzlist.Add(bz);
                            }
                            else if (bz.Item?.HoldingVNum == 0 && (packet.SubTypeFilter == 1 && ((packet.LevelFilter == 0 || (bz.Item.SpLevel < (packet.LevelFilter * 10) + 1 && bz.Item.SpLevel >= (packet.LevelFilter * 10) - 9)) && ((packet.UpgradeFilter == 0 || packet.UpgradeFilter == bz.Item.Upgrade + 1) && (packet.SubTypeFilter == 0 || (packet.SubTypeFilter == 1 && bz.Item.HoldingVNum == 0) || (packet.SubTypeFilter == 2 && bz.Item.HoldingVNum != 0))))))
                            {
                                bzlist.Add(bz);
                            }
                            else if (Rcbfix(packet.SubTypeFilter, bz?.Item?.HoldingVNum))
                            {
                                if ((packet.LevelFilter == 0 || (bz.Item.SpLevel < (packet.LevelFilter * 10) + 1 && bz.Item.SpLevel >= (packet.LevelFilter * 10) - 9)) && ((packet.UpgradeFilter == 0 || packet.UpgradeFilter == bz.Item.Upgrade + 1) && (packet.SubTypeFilter == 0 || (packet.SubTypeFilter == 1 && bz.Item.HoldingVNum == 0) || (packet.SubTypeFilter >= 2 && bz.Item.HoldingVNum != 0))))
                                {
                                    bzlist.Add(bz);
                                }
                            }
                        }
                        break;

                    case BazaarListType.Pet:
                        if (bz.Item.Item.Type == InventoryType.Equipment && bz.Item.Item.ItemType == ItemType.Box && bz.Item.Item.ItemSubType == 0 && (packet.LevelFilter == 0 || (bz.Item.SpLevel < (packet.LevelFilter * 10) + 1 && bz.Item.SpLevel >= (packet.LevelFilter * 10) - 9)) && (packet.SubTypeFilter == 0 || (packet.SubTypeFilter == 1 && bz.Item.HoldingVNum == 0) || (packet.SubTypeFilter == 2 && bz.Item.HoldingVNum != 0)))
                        {
                            bzlist.Add(bz);
                        }
                        break;

                    case BazaarListType.Npc:
                        if (bz.Item.Item.Type == InventoryType.Equipment && bz.Item.Item.ItemType == ItemType.Box && bz.Item.Item.ItemSubType == 1 && (packet.LevelFilter == 0 || (bz.Item.SpLevel < (packet.LevelFilter * 10) + 1 && bz.Item.SpLevel >= (packet.LevelFilter * 10) - 9)) && (packet.SubTypeFilter == 0 || (packet.SubTypeFilter == 1 && bz.Item.HoldingVNum == 0) || (packet.SubTypeFilter == 2 && bz.Item.HoldingVNum != 0)))
                        {
                            bzlist.Add(bz);
                        }
                        break;

                    case BazaarListType.Shell:
                        if (bz.Item.Item.Type == InventoryType.Equipment && bz.Item.Item.ItemType == ItemType.Shell && (packet.SubTypeFilter == 0 || bz.Item.Item.ItemSubType == bz.Item.Item.ItemSubType + 1) && ((packet.RareFilter == 0 || packet.RareFilter == bz.Item.Rare + 1) && (packet.LevelFilter == 0 || (bz.Item.SpLevel < (packet.LevelFilter * 10) + 1 && bz.Item.SpLevel >= (packet.LevelFilter * 10) - 9))))
                        {
                            bzlist.Add(bz);
                        }
                        break;

                    case BazaarListType.Main:
                        if (bz.Item.Item.Type == InventoryType.Main && (packet.SubTypeFilter == 0 || (packet.SubTypeFilter == 1 && bz.Item.Item.ItemType == ItemType.Main) || (packet.SubTypeFilter == 2 && bz.Item.Item.ItemType == ItemType.Upgrade) || (packet.SubTypeFilter == 3 && bz.Item.Item.ItemType == ItemType.Production) || (packet.SubTypeFilter == 4 && bz.Item.Item.ItemType == ItemType.Special) || (packet.SubTypeFilter == 5 && bz.Item.Item.ItemType == ItemType.Potion) || (packet.SubTypeFilter == 6 && bz.Item.Item.ItemType == ItemType.Event)))
                        {
                            bzlist.Add(bz);
                        }
                        break;

                    case BazaarListType.Usable:
                        if (bz.Item.Item.Type == InventoryType.Etc && (packet.SubTypeFilter == 0 || (packet.SubTypeFilter == 1 && bz.Item.Item.ItemType == ItemType.Food) || ((packet.SubTypeFilter == 2 && bz.Item.Item.ItemType == ItemType.Snack) || (packet.SubTypeFilter == 3 && bz.Item.Item.ItemType == ItemType.Magical) || (packet.SubTypeFilter == 4 && bz.Item.Item.ItemType == ItemType.Part) || (packet.SubTypeFilter == 5 && bz.Item.Item.ItemType == ItemType.Teacher) || (packet.SubTypeFilter == 6 && bz.Item.Item.ItemType == ItemType.Sell))))
                        {
                            bzlist.Add(bz);
                        }
                        break;

                    case BazaarListType.Other:
                        if (bz.Item.Item.Type == InventoryType.Equipment && bz.Item.Item.ItemType == ItemType.Box && !bz.Item.Item.IsHolder)
                        {
                            bzlist.Add(bz);
                        }
                        break;

                    case BazaarListType.Vehicle:
                        if (bz.Item.Item.ItemType == ItemType.Box && bz.Item.Item.ItemSubType == 4 && (packet.SubTypeFilter == 0 || (packet.SubTypeFilter == 1 && bz.Item.HoldingVNum == 0) || (packet.SubTypeFilter == 2 && bz.Item.HoldingVNum != 0)))
                        {
                            bzlist.Add(bz);
                        }
                        break;

                    default:
                        bzlist.Add(bz);
                        break;
                    }
                }
                List <BazaarItemLink> bzlistsearched = bzlist.Where(s => itemssearch.Contains(s?.Item.ItemVNum.ToString())).ToList();

                //price up price down quantity up quantity down
                List <BazaarItemLink> definitivelist = itemssearch.Count > 0 ? bzlistsearched : bzlist;
                if (definitivelist != null)
                {
                    List <BazaarItemLink> remove = new List <BazaarItemLink>();
                    foreach (BazaarItemLink temp in definitivelist)
                    {
                        if (temp == null)
                        {
                            remove.Add(temp);
                            continue;
                        }
                        if (temp.Item == null)
                        {
                            remove.Add(temp);
                            continue;
                        }
                        if (temp.Item.Item == null)
                        {
                            remove.Add(temp);
                            continue;
                        }
                        if (temp.BazaarItem == null)
                        {
                            remove.Add(temp);
                            continue;
                        }
                    }
                    foreach (BazaarItemLink temp2 in remove)
                    {
                        definitivelist.Remove(temp2);
                    }
                }
                if (definitivelist != null)
                {
                    switch (packet.OrderFilter)
                    {
                    case 0:
                        definitivelist = definitivelist.OrderBy(s => s?.Item.Item.Name).
                                         ThenBy(s => s?.BazaarItem.Price).ToList();
                        break;

                    case 1:
                        definitivelist = definitivelist.OrderBy(s => s?.Item.Item.Name).ThenByDescending(s => s?.BazaarItem.Price).ToList();
                        break;

                    case 2:
                        definitivelist = definitivelist.OrderBy(s => s?.Item.Item.Name).ThenBy(s => s?.BazaarItem.Amount).ToList();
                        break;

                    case 3:
                        definitivelist = definitivelist.OrderBy(s => s?.Item.Item.Name).ThenByDescending(s => s?.BazaarItem.Amount).ToList();
                        break;

                    default:
                        definitivelist = definitivelist.OrderBy(s => s?.Item.Item.Name).ToList();
                        break;
                    }
                }
                foreach (BazaarItemLink bzlink in definitivelist.Where(s => (s.BazaarItem.DateStart.AddHours(s.BazaarItem.Duration) - DateTime.Now).TotalMinutes > 0 && s?.Item.Amount > 0).Skip(packet.Index * 50).Take(50))
                {
                    long   time = (long)(bzlink.BazaarItem.DateStart.AddHours(bzlink.BazaarItem.Duration) - DateTime.Now).TotalMinutes;
                    string info = string.Empty;
                    if (bzlink.Item.Item.Type == InventoryType.Equipment)
                    {
                        info = (bzlink.Item.Item.EquipmentSlot != EquipmentType.Sp ?
                                bzlink.Item?.GenerateEInfo() : bzlink.Item.Item.SpType == 0 && bzlink.Item.Item.ItemSubType == 4 ?
                                bzlink.Item?.GeneratePslInfo() : bzlink.Item?.GenerateSlInfo()).Replace(' ', '^').Replace("slinfo^", "").Replace("e_info^", "");
                    }
                    itembazar += $"{bzlink.BazaarItem.BazaarItemId}|{bzlink.BazaarItem?.SellerId}|{bzlink.Owner}|{bzlink.Item.Item.VNum}|{bzlink.Item.Amount}|{(bzlink.BazaarItem.IsPackage ? 1 : 0)}|{bzlink.BazaarItem.Price}|{time}|2|0|{bzlink.Item.Rare}|{bzlink.Item.Upgrade}|{info} ";
                }

                return($"rc_blist {packet.Index} {itembazar} ");
            }
            catch (Exception ex)
            {
                Core.Logger.Error(ex);
                return(string.Empty);
            }
        }
Exemplo n.º 10
0
        private void ExecuteHandler(ClientSession session)
        {
            BazaarItemDTO bzItem = DAOFactory.BazaarItemDAO.LoadById(BazaarId);

            if (bzItem != null && Amount > 0)
            {
                long price = Amount * bzItem.Price;

                if (session.Character.Gold >= price)
                {
                    BazaarItemLink bzItemLink = new BazaarItemLink {
                        BazaarItem = bzItem
                    };
                    if (DAOFactory.CharacterDAO.LoadById(bzItem.SellerId) != null)
                    {
                        bzItemLink.OwnerName = DAOFactory.CharacterDAO.LoadById(bzItem.SellerId)?.Name;
                        bzItemLink.Item      = new ItemInstance(DAOFactory.ItemInstanceDAO.LoadById(bzItem.ItemInstanceId));
                    }
                    else
                    {
                        return;
                    }

                    if (Amount <= bzItemLink.Item.Amount)
                    {
                        if (!session.Character.Inventory.CanAddItem(bzItemLink.Item.ItemVNum))
                        {
                            session.SendPacket(
                                UserInterfaceHelper.GenerateMsg(Language.Instance.GetMessageFromKey("NOT_ENOUGH_PLACE"),
                                                                0));
                            return;
                        }
                        if (bzItemLink.Item == null || (bzItem.IsPackage && Amount != bzItem.Amount))
                        {
                            return;
                        }

                        ItemInstance itemInstance =
                            new ItemInstance(DAOFactory.ItemInstanceDAO.LoadById(bzItemLink.BazaarItem.ItemInstanceId));
                        if (Amount > itemInstance.Amount)
                        {
                            return;
                        }

                        itemInstance.Amount    -= Amount;
                        session.Character.Gold -= price;
                        session.SendPacket(session.Character.GenerateGold());
                        DAOFactory.ItemInstanceDAO.InsertOrUpdate(itemInstance);
                        ServerManager.Instance.BazaarRefresh(bzItemLink.BazaarItem.BazaarItemId);
                        session.SendPacket(
                            $"rc_buy 1 {itemInstance.ItemVNum} {bzItemLink.OwnerName} {Amount} {Price} 0 0 0");

                        ItemInstance newBz = bzItemLink.Item.DeepCopy();
                        newBz.Id     = Guid.NewGuid();
                        newBz.Amount = Amount;
                        newBz.Type   = newBz.Item.Type;
                        List <ItemInstance> newInv = session.Character.Inventory.AddToInventory(newBz);

                        if (newInv.Count > 0)
                        {
                            session.SendPacket(session.Character.GenerateSay(
                                                   $"{Language.Instance.GetMessageFromKey("ITEM_ACQUIRED")}: {itemInstance.Item.Name} x {Amount}",
                                                   10));
                        }

                        GameLogger.Instance.LogBazaarBuy(ServerManager.Instance.ChannelId, session.Character.Name,
                                                         session.Character.CharacterId, bzItem, itemInstance.ItemVNum, Amount, price);
                    }
                    else
                    {
                        session.SendPacket(
                            UserInterfaceHelper.GenerateModal(Language.Instance.GetMessageFromKey("STATE_CHANGED"), 1));
                    }
                }
                else
                {
                    session.SendPacket(
                        session.Character.GenerateSay(Language.Instance.GetMessageFromKey("NOT_ENOUGH_MONEY"), 10));
                    session.SendPacket(
                        UserInterfaceHelper.GenerateModal(Language.Instance.GetMessageFromKey("NOT_ENOUGH_MONEY"), 1));
                }
            }
            else
            {
                session.SendPacket(
                    UserInterfaceHelper.GenerateModal(Language.Instance.GetMessageFromKey("STATE_CHANGED"), 1));
            }
        }