Ejemplo n.º 1
0
        public void BuildListAuctionItems(AuctionListItemsResult packet, Player player, string searchedname, uint listfrom, byte levelmin, byte levelmax, bool usable, Optional <AuctionSearchFilters> filters, uint quality)
        {
            long curTime = GameTime.GetGameTime();

            foreach (var Aentry in AuctionsMap.Values)
            {
                // Skip expired auctions
                if (Aentry.expire_time < curTime)
                {
                    continue;
                }

                Item item = Global.AuctionMgr.GetAItem(Aentry.itemGUIDLow);
                if (!item)
                {
                    continue;
                }

                ItemTemplate proto = item.GetTemplate();
                if (filters.HasValue)
                {
                    // if we dont want any class filters, Optional is not initialized
                    // if we dont want this class included, SubclassMask is set to FILTER_SKIP_CLASS
                    // if we want this class and did not specify and subclasses, its set to FILTER_SKIP_SUBCLASS
                    // otherwise full restrictions apply
                    if (filters.Value.Classes[(int)proto.GetClass()].SubclassMask == AuctionSearchFilters.FilterType.SkipClass)
                    {
                        continue;
                    }

                    if (filters.Value.Classes[(int)proto.GetClass()].SubclassMask != AuctionSearchFilters.FilterType.SkipSubclass)
                    {
                        if (!Convert.ToBoolean((int)filters.Value.Classes[(int)proto.GetClass()].SubclassMask & (1u << (int)proto.GetSubClass())))
                        {
                            continue;
                        }

                        if (!Convert.ToBoolean(filters.Value.Classes[(int)proto.GetClass()].InvTypes[(int)proto.GetSubClass()] & (1u << (int)proto.GetInventoryType())))
                        {
                            continue;
                        }
                    }
                }

                if (quality != 0xffffffff && (uint)proto.GetQuality() != quality)
                {
                    continue;
                }

                if (levelmin != 0 && (item.GetRequiredLevel() < levelmin || (levelmax != 0 && item.GetRequiredLevel() > levelmax)))
                {
                    continue;
                }

                if (usable && player.CanUseItem(item) != InventoryResult.Ok)
                {
                    continue;
                }

                // Allow search by suffix (ie: of the Monkey) or partial name (ie: Monkey)
                // No need to do any of this if no search term was entered
                if (!string.IsNullOrEmpty(searchedname))
                {
                    string name = proto.GetName(player.GetSession().GetSessionDbcLocale());
                    if (string.IsNullOrEmpty(name))
                    {
                        continue;
                    }
                }

                // Add the item if no search term or if entered search term was found
                if (packet.Items.Count < 50 && packet.TotalCount >= listfrom)
                {
                    Aentry.BuildAuctionInfo(packet.Items, true);
                }

                ++packet.TotalCount;
            }
        }
Ejemplo n.º 2
0
        void HandleUseItem(UseItem packet)
        {
            Player user = GetPlayer();

            // ignore for remote control state
            if (user.m_unitMovedByMe != user)
            {
                return;
            }

            Item item = user.GetUseableItemByPos(packet.PackSlot, packet.Slot);

            if (item == null)
            {
                user.SendEquipError(InventoryResult.ItemNotFound);
                return;
            }

            if (item.GetGUID() != packet.CastItem)
            {
                user.SendEquipError(InventoryResult.ItemNotFound);
                return;
            }

            ItemTemplate proto = item.GetTemplate();

            if (proto == null)
            {
                user.SendEquipError(InventoryResult.ItemNotFound, item);
                return;
            }

            // some item classes can be used only in equipped state
            if (proto.GetInventoryType() != InventoryType.NonEquip && !item.IsEquipped())
            {
                user.SendEquipError(InventoryResult.ItemNotFound, item);
                return;
            }

            InventoryResult msg = user.CanUseItem(item);

            if (msg != InventoryResult.Ok)
            {
                user.SendEquipError(msg, item);
                return;
            }

            // only allow conjured consumable, bandage, poisons (all should have the 2^21 item flag set in DB)
            if (proto.GetClass() == ItemClass.Consumable && !proto.GetFlags().HasAnyFlag(ItemFlags.IgnoreDefaultArenaRestrictions) && user.InArena())
            {
                user.SendEquipError(InventoryResult.NotDuringArenaMatch, item);
                return;
            }

            // don't allow items banned in arena
            if (proto.GetFlags().HasAnyFlag(ItemFlags.NotUseableInArena) && user.InArena())
            {
                user.SendEquipError(InventoryResult.NotDuringArenaMatch, item);
                return;
            }

            if (user.IsInCombat())
            {
                for (int i = 0; i < proto.Effects.Count; ++i)
                {
                    SpellInfo spellInfo = Global.SpellMgr.GetSpellInfo((uint)proto.Effects[i].SpellID);
                    if (spellInfo != null)
                    {
                        if (!spellInfo.CanBeUsedInCombat())
                        {
                            user.SendEquipError(InventoryResult.NotInCombat, item);
                            return;
                        }
                    }
                }
            }

            // check also  BIND_WHEN_PICKED_UP and BIND_QUEST_ITEM for .additem or .additemset case by GM (not binded at adding to inventory)
            if (item.GetBonding() == ItemBondingType.OnUse || item.GetBonding() == ItemBondingType.OnAcquire || item.GetBonding() == ItemBondingType.Quest)
            {
                if (!item.IsSoulBound())
                {
                    item.SetState(ItemUpdateState.Changed, user);
                    item.SetBinding(true);
                    GetCollectionMgr().AddItemAppearance(item);
                }
            }

            SpellCastTargets targets = new SpellCastTargets(user, packet.Cast);

            // Note: If script stop casting it must send appropriate data to client to prevent stuck item in gray state.
            if (!Global.ScriptMgr.OnItemUse(user, item, targets, packet.Cast.CastID))
            {
                // no script or script not process request by self
                user.CastItemUseSpell(item, targets, packet.Cast.CastID, packet.Cast.Misc);
            }
        }
Ejemplo n.º 3
0
        public void BuildListAuctionItems(AuctionListItemsResult packet, Player player, string searchedname, uint listfrom, byte levelmin, byte levelmax, bool usable, Optional <AuctionSearchFilters> filters, uint quality)
        {
            long curTime = Global.WorldMgr.GetGameTime();

            foreach (var Aentry in AuctionsMap.Values)
            {
                // Skip expired auctions
                if (Aentry.expire_time < curTime)
                {
                    continue;
                }

                Item item = Global.AuctionMgr.GetAItem(Aentry.itemGUIDLow);
                if (!item)
                {
                    continue;
                }

                ItemTemplate proto = item.GetTemplate();
                if (filters.HasValue)
                {
                    // if we dont want any class filters, Optional is not initialized
                    // if we dont want this class included, SubclassMask is set to FILTER_SKIP_CLASS
                    // if we want this class and did not specify and subclasses, its set to FILTER_SKIP_SUBCLASS
                    // otherwise full restrictions apply
                    if (filters.Value.Classes[(int)proto.GetClass()].SubclassMask == AuctionSearchFilters.FilterType.SkipClass)
                    {
                        continue;
                    }

                    if (filters.Value.Classes[(int)proto.GetClass()].SubclassMask != AuctionSearchFilters.FilterType.SkipSubclass)
                    {
                        if (!Convert.ToBoolean((int)filters.Value.Classes[(int)proto.GetClass()].SubclassMask & (1u << (int)proto.GetSubClass())))
                        {
                            continue;
                        }

                        if (!Convert.ToBoolean(filters.Value.Classes[(int)proto.GetClass()].InvTypes[(int)proto.GetSubClass()] & (1u << (int)proto.GetInventoryType())))
                        {
                            continue;
                        }
                    }
                }

                if (quality != 0xffffffff && (uint)proto.GetQuality() != quality)
                {
                    continue;
                }

                if (levelmin != 0 && (proto.GetBaseRequiredLevel() < levelmin || (levelmax != 0x00 && proto.GetBaseRequiredLevel() > levelmax)))
                {
                    continue;
                }

                if (usable && player.CanUseItem(item) != InventoryResult.Ok)
                {
                    continue;
                }

                // Allow search by suffix (ie: of the Monkey) or partial name (ie: Monkey)
                // No need to do any of this if no search term was entered
                if (!string.IsNullOrEmpty(searchedname))
                {
                    string name = proto.GetName(player.GetSession().GetSessionDbcLocale());
                    if (string.IsNullOrEmpty(name))
                    {
                        continue;
                    }

                    // DO NOT use GetItemEnchantMod(proto.RandomProperty) as it may return a result
                    //  that matches the search but it may not equal item.GetItemRandomPropertyId()
                    //  used in BuildAuctionInfo() which then causes wrong items to be listed
                    int propRefID = item.GetItemRandomPropertyId();
                    if (propRefID != 0)
                    {
                        string suffix = null;
                        // Append the suffix to the name (ie: of the Monkey) if one exists
                        // These are found in ItemRandomProperties.dbc, not ItemRandomSuffix.dbc
                        //  even though the DBC names seem misleading
                        if (propRefID < 0)
                        {
                            ItemRandomSuffixRecord itemRandSuffix = CliDB.ItemRandomSuffixStorage.LookupByKey(-propRefID);
                            if (itemRandSuffix != null)
                            {
                                suffix = itemRandSuffix.Name[player.GetSession().GetSessionDbcLocale()];
                            }
                        }
                        else
                        {
                            ItemRandomPropertiesRecord itemRandProp = CliDB.ItemRandomPropertiesStorage.LookupByKey(propRefID);
                            if (itemRandProp != null)
                            {
                                suffix = itemRandProp.Name[player.GetSession().GetSessionDbcLocale()];
                            }
                        }

                        // dbc local name
                        if (!string.IsNullOrEmpty(suffix))
                        {
                            // Append the suffix (ie: of the Monkey) to the name using localization
                            // or default enUS if localization is invalid
                            name += ' ' + suffix;
                        }
                    }
                }

                // Add the item if no search term or if entered search term was found
                if (packet.Items.Count < 50 && packet.TotalCount >= listfrom)
                {
                    Aentry.BuildAuctionInfo(packet.Items, true);
                }

                ++packet.TotalCount;
            }
        }