示例#1
0
 protected Inventory(InventoryResult apiInventory)
 {
     NumSlots = apiInventory.num_backpack_slots;
     Items = apiInventory.items;
     IsPrivate = (apiInventory.status == "15");
     IsGood = (apiInventory.status == "1");
 }
示例#2
0
        protected Inventory(InventoryResult apiInventory)
        {
            NumSlots = apiInventory.num_backpack_slots;
            Items = apiInventory.items;

            if (Items != null)
            {
                foreach (Inventory.Item item in Items)
                {
                    if (item.Attributes != null)
                    {
                        foreach (ItemAttribute attr in item.Attributes)
                        {
                            if (attr.Defindex == 187)
                            {
                                item.IsCrate = true;
                                item.CrateSeriesNumber = Convert.ToInt32(attr.FloatValue);
                                break;
                            }
                        }
                    }
                }
            }

            IsPrivate = (apiInventory.status == "15");
            IsGood = (apiInventory.status == "1");
        }
示例#3
0
        internal InventoryResult GetInventory()
        {
            var result = new InventoryResult(new List <InventoryContainer>(), GetPlayerStat().CharacterId);

            _szItemInfo          = Signature.PointerLib[PointerType.Inventory].DtStep;
            _inventoryPointerMap = _gs.GetPointer(PointerType.Inventory);

            const int offset = (int)InventoryContainerOffset.LAST_AVAILABLE * 24;
            var       arr    = _gs.Reader.Read(_inventoryPointerMap, offset + 10);

            result.InventoryContainers.Add(GetInventoryItems(arr, InventoryContainerOffset.INVENTORY_1));
            result.InventoryContainers.Add(GetInventoryItems(arr, InventoryContainerOffset.INVENTORY_2));
            result.InventoryContainers.Add(GetInventoryItems(arr, InventoryContainerOffset.INVENTORY_3));
            result.InventoryContainers.Add(GetInventoryItems(arr, InventoryContainerOffset.INVENTORY_4));
            result.InventoryContainers.Add(GetInventoryItems(arr, InventoryContainerOffset.EQUIPPING));
            result.InventoryContainers.Add(GetInventoryItems(arr, InventoryContainerOffset.CURRENCIES));
            result.InventoryContainers.Add(GetInventoryItems(arr, InventoryContainerOffset.CRYSTALS));

            result.InventoryContainers.Add(GetInventoryItems(arr, InventoryContainerOffset.HIRE_1));
            result.InventoryContainers.Add(GetInventoryItems(arr, InventoryContainerOffset.HIRE_2));
            result.InventoryContainers.Add(GetInventoryItems(arr, InventoryContainerOffset.HIRE_3));
            result.InventoryContainers.Add(GetInventoryItems(arr, InventoryContainerOffset.HIRE_4));
            result.InventoryContainers.Add(GetInventoryItems(arr, InventoryContainerOffset.HIRE_5));
            result.InventoryContainers.Add(GetInventoryItems(arr, InventoryContainerOffset.HIRE_6));
            result.InventoryContainers.Add(GetInventoryItems(arr, InventoryContainerOffset.HIRE_EQUIP));
            result.InventoryContainers.Add(GetInventoryItems(arr, InventoryContainerOffset.HIRE_CURRENCIES));
            result.InventoryContainers.Add(GetInventoryItems(arr, InventoryContainerOffset.HIRE_CRTSTALS));
            result.InventoryContainers.Add(GetInventoryItems(arr, InventoryContainerOffset.HIRE_LISTING));

            result.InventoryContainers.Add(GetInventoryItems(arr, InventoryContainerOffset.AC_MH));
            result.InventoryContainers.Add(GetInventoryItems(arr, InventoryContainerOffset.AC_OH));
            result.InventoryContainers.Add(GetInventoryItems(arr, InventoryContainerOffset.AC_HEAD));
            result.InventoryContainers.Add(GetInventoryItems(arr, InventoryContainerOffset.AC_BODY));
            result.InventoryContainers.Add(GetInventoryItems(arr, InventoryContainerOffset.AC_HANDS));
            result.InventoryContainers.Add(GetInventoryItems(arr, InventoryContainerOffset.AC_BELT));
            result.InventoryContainers.Add(GetInventoryItems(arr, InventoryContainerOffset.AC_LEGS));
            result.InventoryContainers.Add(GetInventoryItems(arr, InventoryContainerOffset.AC_FEET));
            result.InventoryContainers.Add(GetInventoryItems(arr, InventoryContainerOffset.AC_EARRINGS));
            result.InventoryContainers.Add(GetInventoryItems(arr, InventoryContainerOffset.AC_NECK));
            result.InventoryContainers.Add(GetInventoryItems(arr, InventoryContainerOffset.AC_WRISTS));
            result.InventoryContainers.Add(GetInventoryItems(arr, InventoryContainerOffset.AC_RINGS));
            result.InventoryContainers.Add(GetInventoryItems(arr, InventoryContainerOffset.AC_SOULS));

            result.InventoryContainers.Add(GetInventoryItems(arr, InventoryContainerOffset.COMPANY_1));
            result.InventoryContainers.Add(GetInventoryItems(arr, InventoryContainerOffset.COMPANY_2));
            result.InventoryContainers.Add(GetInventoryItems(arr, InventoryContainerOffset.COMPANY_3));
            result.InventoryContainers.Add(GetInventoryItems(arr, InventoryContainerOffset.COMPANY_CURRENCIES));
            result.InventoryContainers.Add(GetInventoryItems(arr, InventoryContainerOffset.COMPANY_CRYSTALS));

            result.InventoryContainers.Add(GetInventoryItems(arr, InventoryContainerOffset.CHOCOBO_BAG_1));
            result.InventoryContainers.Add(GetInventoryItems(arr, InventoryContainerOffset.CHOCOBO_BAG_2));

            return(result);
        }
示例#4
0
        public override bool OnExpire(Player player, ItemTemplate pItemProto)
        {
            List <ItemPosCount> dest = new List <ItemPosCount>();
            InventoryResult     msg  = player.CanStoreNewItem(ItemConst.NullBag, ItemConst.NullSlot, dest, 39883, 1); // Cracked Egg

            if (msg == InventoryResult.Ok)
            {
                player.StoreNewItem(dest, 39883, true, ItemEnchantment.GenerateItemRandomPropertyId(39883));
            }

            return(true);
        }
示例#5
0
        public override bool OnExpire(Player player, ItemTemplate pItemProto)
        {
            List <ItemPosCount> dest = new List <ItemPosCount>();
            InventoryResult     msg  = player.CanStoreNewItem(ItemConst.NullBag, ItemConst.NullSlot, dest, 44718, 1); // Ripe Disgusting Jar

            if (msg == InventoryResult.Ok)
            {
                player.StoreNewItem(dest, 44718, true, ItemEnchantment.GenerateItemRandomPropertyId(44718));
            }

            return(true);
        }
示例#6
0
        private void MenuItem_inventory_Click(object sender, EventArgs e)
        {
            InventoryResult result = _driver.Inventory(GetCurrentReaderName(), "only_new");

            MessageBox.Show(this, result.ToString());
            if (result.Results != null && result.Results.Count > 0)
            {
                _inventory_info = result.Results[0];
            }
            else
            {
                _inventory_info = null;
            }
        }
示例#7
0
        public static InventoryResult GetInventory()
        {
            var result = new InventoryResult();

            if (!CanGetInventory() || !MemoryHandler.Instance.IsAttached)
            {
                return(result);
            }

            try {
                result.InventoryContainers.Add(GetInventoryItems(Inventory.Container.INVENTORY_1));
                result.InventoryContainers.Add(GetInventoryItems(Inventory.Container.INVENTORY_2));
                result.InventoryContainers.Add(GetInventoryItems(Inventory.Container.INVENTORY_3));
                result.InventoryContainers.Add(GetInventoryItems(Inventory.Container.INVENTORY_4));
                result.InventoryContainers.Add(GetInventoryItems(Inventory.Container.CURRENT_EQ));
                result.InventoryContainers.Add(GetInventoryItems(Inventory.Container.EXTRA_EQ));
                result.InventoryContainers.Add(GetInventoryItems(Inventory.Container.CRYSTALS));
                result.InventoryContainers.Add(GetInventoryItems(Inventory.Container.QUESTS_KI));
                result.InventoryContainers.Add(GetInventoryItems(Inventory.Container.HIRE_1));
                result.InventoryContainers.Add(GetInventoryItems(Inventory.Container.HIRE_2));
                result.InventoryContainers.Add(GetInventoryItems(Inventory.Container.HIRE_3));
                result.InventoryContainers.Add(GetInventoryItems(Inventory.Container.HIRE_4));
                result.InventoryContainers.Add(GetInventoryItems(Inventory.Container.HIRE_5));
                result.InventoryContainers.Add(GetInventoryItems(Inventory.Container.HIRE_6));
                result.InventoryContainers.Add(GetInventoryItems(Inventory.Container.HIRE_7));
                result.InventoryContainers.Add(GetInventoryItems(Inventory.Container.COMPANY_1));
                result.InventoryContainers.Add(GetInventoryItems(Inventory.Container.COMPANY_2));
                result.InventoryContainers.Add(GetInventoryItems(Inventory.Container.COMPANY_3));
                result.InventoryContainers.Add(GetInventoryItems(Inventory.Container.COMPANY_CRYSTALS));
                result.InventoryContainers.Add(GetInventoryItems(Inventory.Container.AC_MH));
                result.InventoryContainers.Add(GetInventoryItems(Inventory.Container.AC_OH));
                result.InventoryContainers.Add(GetInventoryItems(Inventory.Container.AC_HEAD));
                result.InventoryContainers.Add(GetInventoryItems(Inventory.Container.AC_BODY));
                result.InventoryContainers.Add(GetInventoryItems(Inventory.Container.AC_HANDS));
                result.InventoryContainers.Add(GetInventoryItems(Inventory.Container.AC_BELT));
                result.InventoryContainers.Add(GetInventoryItems(Inventory.Container.AC_LEGS));
                result.InventoryContainers.Add(GetInventoryItems(Inventory.Container.AC_FEET));
                result.InventoryContainers.Add(GetInventoryItems(Inventory.Container.AC_EARRINGS));
                result.InventoryContainers.Add(GetInventoryItems(Inventory.Container.AC_NECK));
                result.InventoryContainers.Add(GetInventoryItems(Inventory.Container.AC_WRISTS));
                result.InventoryContainers.Add(GetInventoryItems(Inventory.Container.AC_RINGS));
                result.InventoryContainers.Add(GetInventoryItems(Inventory.Container.AC_SOULS));
            }
            catch (Exception ex) {
                MemoryHandler.Instance.RaiseException(Logger, ex, true);
            }

            return(result);
        }
示例#8
0
        public ActionResult Confirm(int Id)
        {
            InventoryResult inventoryResult = db.InventoryResults.Find(Id);

            inventoryResult.Status = true;
            db.SaveChanges();
            var           goodsMovements = db.GoodsMovements.ToList();
            GoodsMovement goodsMovement  = goodsMovements.FirstOrDefault(gm => gm.Date.Date == DateTime.Now.Date && gm.GoodsId == inventoryResult.GoodsId && gm.WarehouseId == inventoryResult.WarehouseId);

            goodsMovement.GoodsBalance   += inventoryResult.ActualGoodsBalance - inventoryResult.RegisteredGoodsBalance;
            db.Entry(goodsMovement).State = EntityState.Modified;
            db.SaveChanges();

            return(RedirectToAction("InventoryResultStatus", inventoryResult));
        }
示例#9
0
        internal InventoryResult GetInventory(InventoryContainerId containerType)
        {
            var type   = InventoryContainerTypeConverter.ToOffset((int)containerType);
            var result = new InventoryResult(new List <InventoryContainer>(), -1);

            _szItemInfo          = Signature.PointerLib[PointerType.Inventory].DtStep;
            _inventoryPointerMap = _gs.GetPointer(PointerType.Inventory);

            const int offset = (int)InventoryContainerOffset.LAST_AVAILABLE * 24;
            var       arr    = _gs.Reader.Read(_inventoryPointerMap, offset + 10);

            result.InventoryContainers.Add(GetInventoryItems(arr, type));

            return(result);
        }
示例#10
0
        void HandleBuybackItem(BuyBackItem packet)
        {
            Creature creature = _player.GetNPCIfCanInteractWith(packet.VendorGUID, NPCFlags.Vendor, NPCFlags2.None);

            if (creature == null)
            {
                Log.outDebug(LogFilter.Network, "WORLD: HandleBuybackItem - {0} not found or you can not interact with him.", packet.VendorGUID.ToString());
                _player.SendSellError(SellResult.CantFindVendor, null, ObjectGuid.Empty);
                return;
            }

            // remove fake death
            if (_player.HasUnitState(UnitState.Died))
            {
                _player.RemoveAurasByType(AuraType.FeignDeath);
            }

            Item pItem = _player.GetItemFromBuyBackSlot(packet.Slot);

            if (pItem != null)
            {
                uint price = _player.m_activePlayerData.BuybackPrice[(int)(packet.Slot - InventorySlots.BuyBackStart)];
                if (!_player.HasEnoughMoney(price))
                {
                    _player.SendBuyError(BuyResult.NotEnoughtMoney, creature, pItem.GetEntry());
                    return;
                }

                List <ItemPosCount> dest = new();
                InventoryResult     msg  = _player.CanStoreItem(ItemConst.NullBag, ItemConst.NullSlot, dest, pItem, false);
                if (msg == InventoryResult.Ok)
                {
                    _player.ModifyMoney(-price);
                    _player.RemoveItemFromBuyBackSlot(packet.Slot, false);
                    _player.ItemAddedQuestCheck(pItem.GetEntry(), pItem.GetCount());
                    _player.StoreItem(dest, pItem, true);
                }
                else
                {
                    _player.SendEquipError(msg, pItem);
                }
                return;
            }
            else
            {
                _player.SendBuyError(BuyResult.CantFindItem, creature, 0);
            }
        }
示例#11
0
        public List <ProductResult> getAll()
        {
            var productsResult = new List <ProductResult>();

            foreach (var product in products)
            {
                var inventoryResult = new InventoryResult();
                foreach (var warewouse in product.inventory.warehouses)
                {
                    inventoryResult.warehouses.Add(getWarehouseResult(warewouse));
                }
                inventoryResult.quantity = product.inventory.quantity;
                productsResult.Add(getProductResult(product, inventoryResult));
            }
            return(productsResult);
        }
示例#12
0
        private void ScanTimerElapsed(object sender, ElapsedEventArgs e)
        {
            if (this._isScanning)
            {
                return;
            }

            // this._scanTimer.Interval = Settings.Default.InventoryWorkerTiming;

            this._isScanning = true;

            InventoryResult result = this._memoryHandler.Reader.GetInventory();

            EventHost.Instance.RaiseNewInventoryContainersEvent(this._memoryHandler, result.InventoryContainers);

            this._isScanning = false;
        }
示例#13
0
        void HandleAutoStoreBankItem(AutoStoreBankItem packet)
        {
            if (!CanUseBank())
            {
                Log.outDebug(LogFilter.Network, "WORLD: HandleAutoBankItemOpcode - {0} not found or you can't interact with him.", m_currentBankerGUID.ToString());
                return;
            }

            Item item = GetPlayer().GetItemByPos(packet.Bag, packet.Slot);

            if (!item)
            {
                return;
            }

            if (Player.IsBankPos(packet.Bag, packet.Slot))                 // moving from bank to inventory
            {
                List <ItemPosCount> dest = new();
                InventoryResult     msg  = GetPlayer().CanStoreItem(ItemConst.NullBag, ItemConst.NullSlot, dest, item, false);
                if (msg != InventoryResult.Ok)
                {
                    GetPlayer().SendEquipError(msg, item);
                    return;
                }

                GetPlayer().RemoveItem(packet.Bag, packet.Slot, true);
                Item storedItem = GetPlayer().StoreItem(dest, item, true);
                if (storedItem)
                {
                    GetPlayer().ItemAddedQuestCheck(storedItem.GetEntry(), storedItem.GetCount());
                }
            }
            else                                                    // moving from inventory to bank
            {
                List <ItemPosCount> dest = new();
                InventoryResult     msg  = GetPlayer().CanBankItem(ItemConst.NullBag, ItemConst.NullSlot, dest, item, false);
                if (msg != InventoryResult.Ok)
                {
                    GetPlayer().SendEquipError(msg, item);
                    return;
                }

                GetPlayer().RemoveItem(packet.Bag, packet.Slot, true);
                GetPlayer().BankItem(dest, item, true);
            }
        }
示例#14
0
        public ActionResult InventorizationSend(InventorizationViewModel model, int goodsQuantity)
        {
            Goods goods = db.Goods.Find(model.Id);
            ApplicationUserManager UserManager = HttpContext.GetOwinContext().GetUserManager <ApplicationUserManager>();
            ApplicationUser        user        = UserManager.FindByName(User.Identity.Name);
            var             WarehouseId        = user.Claims.SingleOrDefault(c => c.ClaimType == "WarehouseId").ClaimValue;
            GoodsMovement   goodsMovement      = goods.GoodsMovements.FirstOrDefault(gm => gm.WarehouseId.ToString() == WarehouseId && gm.Date.Date == DateTime.Now.Date);
            int             goodsBalance       = goodsMovement.GoodsBalance;
            InventoryResult inventoryResult    = new InventoryResult {
                GoodsId = model.Id, ActualGoodsBalance = goodsQuantity, RegisteredGoodsBalance = goodsBalance, InventoryDate = DateTime.Now, WarehouseId = Int32.Parse(WarehouseId)
            };

            db.InventoryResults.Add(inventoryResult);
            db.SaveChanges();
            ((List <InventorizationViewModel>)HttpContext.Session["Inv"]).Find(x => x.Id == model.Id).Status = true;
            model.Status = ((List <InventorizationViewModel>)HttpContext.Session["Inv"]).Find(x => x.Id == model.Id).Status;
            return(PartialView("InventorizationPartial", model));
        }
示例#15
0
        public ProductResult getProduct(int sku)
        {
            var product         = products.FirstOrDefault(p => p.sku == sku);
            var inventoryResult = new InventoryResult();

            if (product != null)
            {
                foreach (var warewouse in product.inventory.warehouses)
                {
                    inventoryResult.warehouses.Add(getWarehouseResult(warewouse));
                }
                inventoryResult.quantity = product.inventory.quantity;
                return(getProductResult(product, inventoryResult));
            }
            else
            {
                return(null);
            }
        }
        public async Task <InventoryItem[]> GetProductInventory(string country, string orderType = null)
        {
            OrderType type = string.IsNullOrWhiteSpace(orderType) ? OrderType.Rso
                : EnumHelper.GetValueFromDescription <OrderType>(orderType);

            object response = await _proxy.GetProductInventory.POSTAsync(new
            {
                CountryCode = country,
                OrderType   = EnumHelper.GetDescription(type)
            });

            InventoryResult result = JsonConvert.DeserializeObject <InventoryResult>(JsonConvert.SerializeObject(response));

            if (!result.Inventory.IsSussess)
            {
                throw new HrblRestApiException($"An error occured while requesting product inventory in {country}");
            }

            return(result.Inventory.Inventories.ItemsRoot.Items);
        }
示例#17
0
        public InventoryResult SubmitCashPayment(decimal payment, decimal price)
        {
            var result = new InventoryResult
            {
                Result    = true,
                Message   = "APPROVED",
                PayMethod = "cash",
            };


            if (payment < price)
            {
                result.Result  = false;
                result.Message = "NSF";
                return(result);
            }

            result.Change = payment - price;

            return(result);
        }
示例#18
0
            public override bool GossipSelect(Player player, uint menuId, uint gossipListId)
            {
                uint action = player.PlayerTalkClass.GetGossipOptionAction(gossipListId);

                player.PlayerTalkClass.ClearMenus();
                switch (action)
                {
                case eTradeskill.GossipActionInfoDef:
                    player.ADD_GOSSIP_ITEM(GossipOptionIcon.Chat, GOSSIP_ITEM_KUR2, eTradeskill.GossipSenderMain, eTradeskill.GossipActionInfoDef + 1);
                    player.SEND_GOSSIP_MENU(9227, me.GetGUID());
                    break;

                case eTradeskill.GossipActionInfoDef + 1:
                    player.ADD_GOSSIP_ITEM(GossipOptionIcon.Chat, GOSSIP_ITEM_KUR3, eTradeskill.GossipSenderMain, eTradeskill.GossipActionInfoDef + 2);
                    player.SEND_GOSSIP_MENU(9229, me.GetGUID());
                    break;

                case eTradeskill.GossipActionInfoDef + 2:
                {
                    if (!player.HasItemCount(24573))
                    {
                        List <ItemPosCount> dest = new List <ItemPosCount>();
                        uint            itemId   = 24573;
                        uint            temp;
                        InventoryResult msg = player.CanStoreNewItem(ItemConst.NullBag, ItemConst.NullSlot, dest, itemId, 1, out temp);
                        if (msg == InventoryResult.Ok)
                        {
                            player.StoreNewItem(dest, itemId, true);
                        }
                        else
                        {
                            player.SendEquipError(msg, null, null, itemId);
                        }
                    }
                    player.SEND_GOSSIP_MENU(9231, me.GetGUID());
                    break;
                }
                }
                return(true);
            }
示例#19
0
        void DoInventory()
        {
            _cancelInventory = new CancellationTokenSource();
            bool bFirst = true;

            try
            {
                while (_cancelInventory.IsCancellationRequested == false)
                {
                    Task.Delay(500, _cancelInventory.Token).Wait();

                    InventoryResult result = null;

                    result = _driver.Inventory(GetCurrentReaderName(), bFirst ? "" : "only_new");
                    bFirst = false;
                    if (result.Value == -1)
                    {
                        // 显示报错信息
                        this.ShowMessage($"{result.ErrorInfo},error_code={result.ErrorCode}", "red", true);
                        // 让按钮释放
                        this.Invoke((Action)(() =>
                        {
                            this.toolStripButton_autoInventory.Checked = false;
                        }));
                        break;
                    }

                    this.Invoke((Action)(() =>
                    {
                        FillIventoryInfo(result.Results);
                    }));
                }
            }
            catch (TaskCanceledException)
            {
            }
            catch (ObjectDisposedException)
            {
            }
        }
示例#20
0
        public void BuyProduct_UseCredit()
        {
            var prodId = 6;
            var cash   = 0M;
            var credit = new CreditCard
            {
                CreditType = "VISA",
                ExpDate    = new DateTime(2019, 10, 12),
                CardNumber = "4111111111111111",
                NameOnCard = "Joe P Tester"
            };
            var expectedResult = new InventoryResult {
                Result = true, Message = "APPROVED"
            };

            var result = classUnderTest.BuyProduct(prodId, cash, credit);

            Assert.IsNotNull(result);
            Assert.IsTrue(result.Result);
            Assert.AreEqual(expectedResult.PayMethod, result.PayMethod);
            Assert.AreEqual(expectedResult.Message, result.Message);
        }
示例#21
0
        void HandleDestroyItem(DestroyItem destroyItem)
        {
            ushort pos = (ushort)((destroyItem.ContainerId << 8) | destroyItem.SlotNum);

            // prevent drop unequipable items (in combat, for example) and non-empty bags
            if (Player.IsEquipmentPos(pos) || Player.IsBagPos(pos))
            {
                InventoryResult msg = _player.CanUnequipItem(pos, false);
                if (msg != InventoryResult.Ok)
                {
                    _player.SendEquipError(msg, _player.GetItemByPos(pos));
                    return;
                }
            }

            Item pItem = _player.GetItemByPos(destroyItem.ContainerId, destroyItem.SlotNum);

            if (pItem == null)
            {
                _player.SendEquipError(InventoryResult.ItemNotFound);
                return;
            }

            if (pItem.GetTemplate().HasFlag(ItemFlags.NoUserDestroy))
            {
                _player.SendEquipError(InventoryResult.DropBoundItem);
                return;
            }

            if (destroyItem.Count != 0)
            {
                uint i_count = destroyItem.Count;
                _player.DestroyItemCount(pItem, ref i_count, true);
            }
            else
            {
                _player.DestroyItem(destroyItem.ContainerId, destroyItem.SlotNum, true);
            }
        }
    /// <summary>
    /// Try and store the specified number of the item into the inventories.
    /// Starts with the main inventory, then tries to store in all other inventories.
    /// </summary>
    public InventoryResult Store(InventoryItem item, uint count = 0)
    {
        if (count != 0)
        {
            Debug.Assert(item.count == 0, "[InventoryComponent] Overwriting count of InventoryItem with count > 0 on Store!");
            item.count = count;
        }

        InventoryResult result = InventoryResult.ItemNotAllowed;

        foreach (InventorySpace space in stores)
        {
            if (space.CanStore(item.Item))
            {
                if ((result = space.Store(item)) != InventoryResult.NotEnoughSpace)
                {
                    break;
                }
            }
        }

        return(result);
    }
示例#23
0
        void HandleSocketGems(SocketGems socketGems)
        {
            if (socketGems.ItemGuid.IsEmpty())
            {
                return;
            }

            //cheat . tried to socket same gem multiple times
            if ((!socketGems.GemItem[0].IsEmpty() && (socketGems.GemItem[0] == socketGems.GemItem[1] || socketGems.GemItem[0] == socketGems.GemItem[2])) ||
                (!socketGems.GemItem[1].IsEmpty() && (socketGems.GemItem[1] == socketGems.GemItem[2])))
            {
                return;
            }

            Item itemTarget = GetPlayer().GetItemByGuid(socketGems.ItemGuid);

            if (!itemTarget)                                         //missing item to socket
            {
                return;
            }

            ItemTemplate itemProto = itemTarget.GetTemplate();

            if (itemProto == null)
            {
                return;
            }

            //this slot is excepted when applying / removing meta gem bonus
            byte slot = itemTarget.IsEquipped() ? itemTarget.GetSlot() : ItemConst.NullSlot;

            Item[] gems = new Item[ItemConst.MaxGemSockets];
            ItemDynamicFieldGems[] gemData       = new ItemDynamicFieldGems[ItemConst.MaxGemSockets];
            GemPropertiesRecord[]  gemProperties = new GemPropertiesRecord[ItemConst.MaxGemSockets];
            SocketedGem[]          oldGemData    = new SocketedGem[ItemConst.MaxGemSockets];


            for (int i = 0; i < ItemConst.MaxGemSockets; ++i)
            {
                Item gem = _player.GetItemByGuid(socketGems.GemItem[i]);
                if (gem)
                {
                    gems[i]            = gem;
                    gemData[i].ItemId  = gem.GetEntry();
                    gemData[i].Context = (byte)gem.m_itemData.Context;
                    for (int b = 0; b < ((List <uint>)gem.m_itemData.BonusListIDs).Count && b < 16; ++b)
                    {
                        gemData[i].BonusListIDs[b] = (ushort)((List <uint>)gem.m_itemData.BonusListIDs)[b];
                    }

                    gemProperties[i] = CliDB.GemPropertiesStorage.LookupByKey(gem.GetTemplate().GetGemProperties());
                }

                oldGemData[i] = itemTarget.GetGem((ushort)i);
            }

            // Find first prismatic socket
            uint firstPrismatic = 0;

            while (firstPrismatic < ItemConst.MaxGemSockets && itemTarget.GetSocketColor(firstPrismatic) != 0)
            {
                ++firstPrismatic;
            }

            for (uint i = 0; i < ItemConst.MaxGemSockets; ++i)                //check for hack maybe
            {
                if (gemProperties[i] == null)
                {
                    continue;
                }

                // tried to put gem in socket where no socket exists (take care about prismatic sockets)
                if (itemTarget.GetSocketColor(i) == 0)
                {
                    // no prismatic socket
                    if (itemTarget.GetEnchantmentId(EnchantmentSlot.Prismatic) == 0)
                    {
                        return;
                    }

                    if (i != firstPrismatic)
                    {
                        return;
                    }
                }

                // Gem must match socket color
                if (ItemConst.SocketColorToGemTypeMask[(int)itemTarget.GetSocketColor(i)] != gemProperties[i].Type)
                {
                    // unless its red, blue, yellow or prismatic
                    if (!ItemConst.SocketColorToGemTypeMask[(int)itemTarget.GetSocketColor(i)].HasAnyFlag(SocketColor.Prismatic) || !gemProperties[i].Type.HasAnyFlag(SocketColor.Prismatic))
                    {
                        return;
                    }
                }
            }

            // check unique-equipped conditions
            for (int i = 0; i < ItemConst.MaxGemSockets; ++i)
            {
                if (!gems[i])
                {
                    continue;
                }

                // continue check for case when attempt add 2 similar unique equipped gems in one item.
                ItemTemplate iGemProto = gems[i].GetTemplate();

                // unique item (for new and already placed bit removed enchantments
                if (iGemProto.HasFlag(ItemFlags.UniqueEquippable))
                {
                    for (int j = 0; j < ItemConst.MaxGemSockets; ++j)
                    {
                        if (i == j)                                    // skip self
                        {
                            continue;
                        }

                        if (gems[j])
                        {
                            if (iGemProto.GetId() == gems[j].GetEntry())
                            {
                                GetPlayer().SendEquipError(InventoryResult.ItemUniqueEquippableSocketed, itemTarget);
                                return;
                            }
                        }
                        else if (oldGemData[j] != null)
                        {
                            if (iGemProto.GetId() == oldGemData[j].ItemId)
                            {
                                GetPlayer().SendEquipError(InventoryResult.ItemUniqueEquippableSocketed, itemTarget);
                                return;
                            }
                        }
                    }
                }

                // unique limit type item
                int limit_newcount = 0;
                if (iGemProto.GetItemLimitCategory() != 0)
                {
                    ItemLimitCategoryRecord limitEntry = CliDB.ItemLimitCategoryStorage.LookupByKey(iGemProto.GetItemLimitCategory());
                    if (limitEntry != null)
                    {
                        // NOTE: limitEntry.mode is not checked because if item has limit then it is applied in equip case
                        for (int j = 0; j < ItemConst.MaxGemSockets; ++j)
                        {
                            if (gems[j])
                            {
                                // new gem
                                if (iGemProto.GetItemLimitCategory() == gems[j].GetTemplate().GetItemLimitCategory())
                                {
                                    ++limit_newcount;
                                }
                            }
                            else if (oldGemData[j] != null)
                            {
                                // existing gem
                                ItemTemplate jProto = Global.ObjectMgr.GetItemTemplate(oldGemData[j].ItemId);
                                if (jProto != null)
                                {
                                    if (iGemProto.GetItemLimitCategory() == jProto.GetItemLimitCategory())
                                    {
                                        ++limit_newcount;
                                    }
                                }
                            }
                        }

                        if (limit_newcount > 0 && limit_newcount > _player.GetItemLimitCategoryQuantity(limitEntry))
                        {
                            GetPlayer().SendEquipError(InventoryResult.ItemUniqueEquippableSocketed, itemTarget);
                            return;
                        }
                    }
                }

                // for equipped item check all equipment for duplicate equipped gems
                if (itemTarget.IsEquipped())
                {
                    InventoryResult res = GetPlayer().CanEquipUniqueItem(gems[i], slot, (uint)Math.Max(limit_newcount, 0));
                    if (res != 0)
                    {
                        GetPlayer().SendEquipError(res, itemTarget);
                        return;
                    }
                }
            }

            bool SocketBonusActivated = itemTarget.GemsFitSockets();   //save state of socketbonus

            GetPlayer().ToggleMetaGemsActive(slot, false);             //turn off all metagems (except for the target item)

            //if a meta gem is being equipped, all information has to be written to the item before testing if the conditions for the gem are met

            //remove ALL mods - gem can change item level
            if (itemTarget.IsEquipped())
            {
                _player._ApplyItemMods(itemTarget, itemTarget.GetSlot(), false);
            }

            for (ushort i = 0; i < ItemConst.MaxGemSockets; ++i)
            {
                if (gems[i])
                {
                    uint gemScalingLevel = _player.GetLevel();
                    uint fixedLevel      = gems[i].GetModifier(ItemModifier.TimewalkerLevel);
                    if (fixedLevel != 0)
                    {
                        gemScalingLevel = fixedLevel;
                    }

                    itemTarget.SetGem(i, gemData[i], gemScalingLevel);

                    if (gemProperties[i] != null && gemProperties[i].EnchantId != 0)
                    {
                        itemTarget.SetEnchantment(EnchantmentSlot.Sock1 + i, gemProperties[i].EnchantId, 0, 0, GetPlayer().GetGUID());
                    }

                    uint gemCount = 1;
                    GetPlayer().DestroyItemCount(gems[i], ref gemCount, true);
                }
            }

            if (itemTarget.IsEquipped())
            {
                _player._ApplyItemMods(itemTarget, itemTarget.GetSlot(), true);
            }

            Item childItem = _player.GetChildItemByGuid(itemTarget.GetChildItem());

            if (childItem)
            {
                if (childItem.IsEquipped())
                {
                    _player._ApplyItemMods(childItem, childItem.GetSlot(), false);
                }
                childItem.CopyArtifactDataFromParent(itemTarget);
                if (childItem.IsEquipped())
                {
                    _player._ApplyItemMods(childItem, childItem.GetSlot(), true);
                }
            }

            bool SocketBonusToBeActivated = itemTarget.GemsFitSockets(); //current socketbonus state

            if (SocketBonusActivated ^ SocketBonusToBeActivated)         //if there was a change...
            {
                GetPlayer().ApplyEnchantment(itemTarget, EnchantmentSlot.Bonus, false);
                itemTarget.SetEnchantment(EnchantmentSlot.Bonus, SocketBonusToBeActivated ? itemTarget.GetTemplate().GetSocketBonus() : 0, 0, 0, GetPlayer().GetGUID());
                GetPlayer().ApplyEnchantment(itemTarget, EnchantmentSlot.Bonus, true);
                //it is not displayed, client has an inbuilt system to determine if the bonus is activated
            }

            GetPlayer().ToggleMetaGemsActive(slot, true);              //turn on all metagems (except for target item)

            GetPlayer().RemoveTradeableItem(itemTarget);
            itemTarget.ClearSoulboundTradeable(GetPlayer());           // clear tradeable flag

            itemTarget.SendUpdateSockets();
        }
 protected TF2Inventory(InventoryResult apiInventory)
     : base(apiInventory)
 {
 }
示例#25
0
        void HandleAutoEquipItem(AutoEquipItem autoEquipItem)
        {
            if (autoEquipItem.Inv.Items.Count != 1)
            {
                Log.outError(LogFilter.Network, "WORLD: HandleAutoEquipItem - Invalid itemCount ({0})", autoEquipItem.Inv.Items.Count);
                return;
            }

            var  pl      = GetPlayer();
            Item srcItem = pl.GetItemByPos(autoEquipItem.PackSlot, autoEquipItem.Slot);

            if (srcItem == null)
            {
                return;                                             // only at cheat
            }
            ushort          dest;
            InventoryResult msg = pl.CanEquipItem(ItemConst.NullSlot, out dest, srcItem, !srcItem.IsBag());

            if (msg != InventoryResult.Ok)
            {
                pl.SendEquipError(msg, srcItem);
                return;
            }

            ushort src = srcItem.GetPos();

            if (dest == src)                                           // prevent equip in same slot, only at cheat
            {
                return;
            }

            Item dstItem = pl.GetItemByPos(dest);

            if (dstItem == null)                                         // empty slot, simple case
            {
                if (!srcItem.GetChildItem().IsEmpty())
                {
                    InventoryResult childEquipResult = _player.CanEquipChildItem(srcItem);
                    if (childEquipResult != InventoryResult.Ok)
                    {
                        _player.SendEquipError(msg, srcItem);
                        return;
                    }
                }

                pl.RemoveItem(autoEquipItem.PackSlot, autoEquipItem.Slot, true);
                pl.EquipItem(dest, srcItem, true);
                if (!srcItem.GetChildItem().IsEmpty())
                {
                    _player.EquipChildItem(autoEquipItem.PackSlot, autoEquipItem.Slot, srcItem);
                }

                pl.AutoUnequipOffhandIfNeed();
            }
            else                                                    // have currently equipped item, not simple case
            {
                byte dstbag  = dstItem.GetBagSlot();
                byte dstslot = dstItem.GetSlot();

                msg = pl.CanUnequipItem(dest, !srcItem.IsBag());
                if (msg != InventoryResult.Ok)
                {
                    pl.SendEquipError(msg, dstItem);
                    return;
                }

                if (!dstItem.HasItemFlag(ItemFieldFlags.Child))
                {
                    // check dest.src move possibility
                    List <ItemPosCount> sSrc = new();
                    ushort eSrc = 0;
                    if (pl.IsInventoryPos(src))
                    {
                        msg = pl.CanStoreItem(autoEquipItem.PackSlot, autoEquipItem.Slot, sSrc, dstItem, true);
                        if (msg != InventoryResult.Ok)
                        {
                            msg = pl.CanStoreItem(autoEquipItem.PackSlot, ItemConst.NullSlot, sSrc, dstItem, true);
                        }
                        if (msg != InventoryResult.Ok)
                        {
                            msg = pl.CanStoreItem(ItemConst.NullBag, ItemConst.NullSlot, sSrc, dstItem, true);
                        }
                    }
                    else if (Player.IsBankPos(src))
                    {
                        msg = pl.CanBankItem(autoEquipItem.PackSlot, autoEquipItem.Slot, sSrc, dstItem, true);
                        if (msg != InventoryResult.Ok)
                        {
                            msg = pl.CanBankItem(autoEquipItem.PackSlot, ItemConst.NullSlot, sSrc, dstItem, true);
                        }
                        if (msg != InventoryResult.Ok)
                        {
                            msg = pl.CanBankItem(ItemConst.NullBag, ItemConst.NullSlot, sSrc, dstItem, true);
                        }
                    }
                    else if (Player.IsEquipmentPos(src))
                    {
                        msg = pl.CanEquipItem(autoEquipItem.Slot, out eSrc, dstItem, true);
                        if (msg == InventoryResult.Ok)
                        {
                            msg = pl.CanUnequipItem(eSrc, true);
                        }
                    }

                    if (msg == InventoryResult.Ok && Player.IsEquipmentPos(dest) && !srcItem.GetChildItem().IsEmpty())
                    {
                        msg = _player.CanEquipChildItem(srcItem);
                    }

                    if (msg != InventoryResult.Ok)
                    {
                        pl.SendEquipError(msg, dstItem, srcItem);
                        return;
                    }

                    // now do moves, remove...
                    pl.RemoveItem(dstbag, dstslot, false);
                    pl.RemoveItem(autoEquipItem.PackSlot, autoEquipItem.Slot, false);

                    // add to dest
                    pl.EquipItem(dest, srcItem, true);

                    // add to src
                    if (pl.IsInventoryPos(src))
                    {
                        pl.StoreItem(sSrc, dstItem, true);
                    }
                    else if (Player.IsBankPos(src))
                    {
                        pl.BankItem(sSrc, dstItem, true);
                    }
                    else if (Player.IsEquipmentPos(src))
                    {
                        pl.EquipItem(eSrc, dstItem, true);
                    }

                    if (Player.IsEquipmentPos(dest) && !srcItem.GetChildItem().IsEmpty())
                    {
                        _player.EquipChildItem(autoEquipItem.PackSlot, autoEquipItem.Slot, srcItem);
                    }
                }
                else
                {
                    Item parentItem = _player.GetItemByGuid(dstItem.GetCreator());
                    if (parentItem)
                    {
                        if (Player.IsEquipmentPos(dest))
                        {
                            _player.AutoUnequipChildItem(parentItem);
                            // dest is now empty
                            _player.SwapItem(src, dest);
                            // src is now empty
                            _player.SwapItem(parentItem.GetPos(), src);
                        }
                    }
                }

                pl.AutoUnequipOffhandIfNeed();

                // if inventory item was moved, check if we can remove dependent auras, because they were not removed in Player::RemoveItem (update was set to false)
                // do this after swaps are done, we pass nullptr because both weapons could be swapped and none of them should be ignored
                if ((autoEquipItem.PackSlot == InventorySlots.Bag0 && autoEquipItem.Slot < InventorySlots.BagEnd) || (dstbag == InventorySlots.Bag0 && dstslot < InventorySlots.BagEnd))
                {
                    pl.ApplyItemDependentAuras(null, false);
                }
            }
        }
示例#26
0
        //[WorldPacketHandler(ClientOpcodes.MasterLootItem)]
        void HandleLootMasterGive(WorldPacket packet)
        {
            ObjectGuid lootguid          = packet.ReadPackedGuid();
            byte       slotid            = packet.ReadUInt8();
            ObjectGuid target_playerguid = packet.ReadPackedGuid();

            if (GetPlayer().GetGroup() == null || GetPlayer().GetGroup().GetLooterGuid() != GetPlayer().GetGUID() || GetPlayer().GetGroup().GetLootMethod() != LootMethod.MasterLoot)
            {
                GetPlayer().SendLootError(lootguid, ObjectGuid.Empty, LootError.DidntKill);
                return;
            }

            // player on other map
            Player target = Global.ObjAccessor.GetPlayer(_player, target_playerguid);

            if (!target)
            {
                GetPlayer().SendLootError(lootguid, ObjectGuid.Empty, LootError.PlayerNotFound);
                return;
            }

            Log.outDebug(LogFilter.Network, "HandleLootMasterGive (CMSG_LOOT_MASTER_GIVE, 0x02A3) Target = [{0}].", target.GetName());

            if (GetPlayer().GetLootGUID() != lootguid)
            {
                GetPlayer().SendLootError(lootguid, ObjectGuid.Empty, LootError.DidntKill);
                return;
            }

            if (!GetPlayer().IsInRaidWith(target) || !GetPlayer().IsInMap(target))
            {
                GetPlayer().SendLootError(lootguid, ObjectGuid.Empty, LootError.MasterOther);
                Log.outInfo(LogFilter.Loot, "MasterLootItem: Player {0} tried to give an item to ineligible player {1}!", GetPlayer().GetName(), target.GetName());
                return;
            }

            Loot loot = null;

            if (GetPlayer().GetLootGUID().IsCreatureOrVehicle())
            {
                Creature creature = GetPlayer().GetMap().GetCreature(lootguid);
                if (creature == null)
                {
                    return;
                }

                loot = creature.loot;
            }
            else if (GetPlayer().GetLootGUID().IsGameObject())
            {
                GameObject pGO = GetPlayer().GetMap().GetGameObject(lootguid);
                if (pGO == null)
                {
                    return;
                }

                loot = pGO.loot;
            }

            if (loot == null)
            {
                return;
            }

            if (slotid >= loot.items.Count + loot.quest_items.Count)
            {
                Log.outDebug(LogFilter.Loot, "MasterLootItem: Player {0} might be using a hack! (slot {1}, size {2})",
                             GetPlayer().GetName(), slotid, loot.items.Count);
                return;
            }

            LootItem item = slotid >= loot.items.Count ? loot.quest_items[slotid - loot.items.Count] : loot.items[slotid];

            List <ItemPosCount> dest = new List <ItemPosCount>();
            InventoryResult     msg  = target.CanStoreNewItem(ItemConst.NullBag, ItemConst.NullSlot, dest, item.itemid, item.count);

            if (item.follow_loot_rules && !item.AllowedForPlayer(target))
            {
                msg = InventoryResult.CantEquipEver;
            }
            if (msg != InventoryResult.Ok)
            {
                if (msg == InventoryResult.ItemMaxCount)
                {
                    GetPlayer().SendLootError(lootguid, ObjectGuid.Empty, LootError.MasterUniqueItem);
                }
                else if (msg == InventoryResult.InvFull)
                {
                    GetPlayer().SendLootError(lootguid, ObjectGuid.Empty, LootError.MasterInvFull);
                }
                else
                {
                    GetPlayer().SendLootError(lootguid, ObjectGuid.Empty, LootError.MasterOther);
                }

                target.SendEquipError(msg, null, null, item.itemid);
                return;
            }

            // not move item from loot to target inventory
            Item newitem = target.StoreNewItem(dest, item.itemid, true, item.randomBonusListId, item.GetAllowedLooters(), item.context, item.BonusListIDs);

            target.SendNewItem(newitem, item.count, false, false, true);
            target.UpdateCriteria(CriteriaTypes.LootItem, item.itemid, item.count);
            target.UpdateCriteria(CriteriaTypes.LootType, item.itemid, item.count, (ulong)loot.loot_type);
            target.UpdateCriteria(CriteriaTypes.LootEpicItem, item.itemid, item.count);

            // mark as looted
            item.count     = 0;
            item.is_looted = true;

            loot.NotifyItemRemoved(slotid);
            --loot.unlootedCount;
        }
示例#27
0
        // parameters:
        //      style   如果为 "getTagInfo",表示要在结果中返回 TagInfo
        public ListTagsResult ListTags(string reader_name, string style)
        {
            InventoryResult result = new InventoryResult();

            if (Program.MainForm.ErrorState != "normal")
            {
                return new ListTagsResult
                       {
                           Value     = -1,
                           ErrorInfo = $"{Program.MainForm.ErrorStateInfo}",
                           ErrorCode = $"state:{Program.MainForm.ErrorState}"
                       }
            }
            ;

            List <OneTag> tags = new List <OneTag>();

            // uid --> OneTag
            Hashtable uid_table = new Hashtable();

            foreach (Reader reader in Program.Rfid.Readers)
            {
#if NO
                if (reader_name == "*" || reader.Name == reader_name)
                {
                }
                else
                {
                    continue;
                }
#endif

                if (Reader.MatchReaderName(reader_name, reader.Name) == false)
                {
                    continue;
                }

                InventoryResult inventory_result = Program.Rfid.Inventory(reader.Name, "");

                if (inventory_result.Value == -1)
                {
                    return(new ListTagsResult {
                        Value = -1, ErrorInfo = inventory_result.ErrorInfo, ErrorCode = inventory_result.ErrorCode
                    });
                }

                foreach (InventoryInfo info in inventory_result.Results)
                {
                    OneTag tag = null;
                    if (uid_table.ContainsKey(info.UID))
                    {
                        // 重复出现的,追加 读卡器名字
                        tag             = (OneTag)uid_table[info.UID];
                        tag.ReaderName += "," + reader.Name;
                    }
                    else
                    {
                        // 首次出现
                        tag = new OneTag
                        {
                            Protocol   = info.Protocol,
                            ReaderName = reader.Name,
                            UID        = info.UID,
                            DSFID      = info.DsfID
                        };

                        uid_table[info.UID] = tag;
                        tags.Add(tag);
                    }

                    if (StringUtil.IsInList("getTagInfo", style) &&
                        tag.TagInfo == null)
                    {
                        // TODO: 这里要利用 Hashtable 缓存
                        GetTagInfoResult result0 = Program.Rfid.GetTagInfo(reader.Name, info);
                        if (result0.Value == -1)
                        {
                            tag.TagInfo = null;
                            // TODO: 如何报错?写入操作历史?
                            // $"读取标签{info.UID}信息时出错:{result0.ToString()}"
                        }
                        else
                        {
                            tag.TagInfo = result0.TagInfo;
                        }
                    }
#if NO
                    GetTagInfoResult result0 = Program.Rfid.GetTagInfo(reader.Name, info);
                    if (result0.Value == -1)
                    {
                        // TODO: 如何报错?写入操作历史?
                        Program.MainForm.OutputText($"读取标签{info.UID}信息时出错:{result0.ToString()}", 2);
                        continue;
                    }

                    LogicChip chip = LogicChip.From(result0.TagInfo.Bytes,
                                                    (int)result0.TagInfo.BlockSize,
                                                    "" // result0.TagInfo.LockStatus
                                                    );
                    Element pii = chip.FindElement(ElementOID.PII);
                    if (pii == null)
                    {
                        Program.MainForm.Invoke((Action)(() =>
                        {
                            // 发送 UID
                            SendKeys.SendWait($"uid:{info.UID}\r");
                        }));
                    }
                    else
                    {
                        Program.MainForm.Invoke((Action)(() =>
                        {
                            // 发送 PII
                            SendKeys.SendWait($"pii:{pii.Text}\r");
                        }));
                    }
#endif
                }
            }

            return(new ListTagsResult {
                Results = tags
            });

#if NO
            InventoryResult result = new InventoryResult();
            List <OneTag>   tags   = new List <OneTag>();
            _lockTagList.EnterReadLock();
            try
            {
                foreach (OneTag tag in _tagList)
                {
                    if (reader_name == "*" || tag.ReaderName == reader_name)
                    {
                        tags.Add(tag);
                    }
                }
                return(new ListTagsResult {
                    Results = tags
                });
            }
            finally
            {
                _lockTagList.ExitReadLock();
            }
#endif
        }
示例#28
0
 protected Inventory(InventoryResult apiInventory)
 {
     Items = apiInventory.items;
     IsPrivate = (apiInventory.status == "15");
     IsGood = (apiInventory.status == "1");
 }
示例#29
0
 protected Inventory(InventoryResult apiInventory)
 {
     NumSlots = apiInventory.num_backpack_slots;
     Items = apiInventory.items;
 }
 protected Dota2Inventory(InventoryResult apiInventory)
     : base(apiInventory)
 {
     NumSlots = apiInventory.num_backpack_slots;
 }
示例#31
0
        public static void HandleEquipError(ref WorldClass session, InventoryResult msg)
        {
            PacketWriter inventoryFail = new PacketWriter(JAMCMessage.InventoryChangeFailure);

            inventoryFail.WriteUInt8((byte)msg);

            if (msg != InventoryResult.EQUIP_ERR_OK)
            {
                inventoryFail.WriteUInt64(0);       // used for item1 guid
                inventoryFail.WriteUInt64(0);       // used for item2 guid
                inventoryFail.WriteUInt8(0);        // bag type subclass, used with EQUIP_ERR_EVENT_AUTOEQUIP_BIND_CONFIRM and EQUIP_ERR_ITEM_DOESNT_GO_INTO_BAG2
            }

            session.Send(ref inventoryFail);
        }
示例#32
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);
            }
        }
示例#33
0
        static bool Complete(StringArguments args, CommandHandler handler)
        {
            Player player = handler.GetSelectedPlayer();

            if (!player)
            {
                handler.SendSysMessage(CypherStrings.NoCharSelected);
                return(false);
            }

            // .quest complete #entry
            // number or [name] Shift-click form |color|Hquest:quest_id:quest_level:min_level:max_level:scaling_faction|h[name]|h|r
            string cId = handler.ExtractKeyFromLink(args, "Hquest");

            if (!uint.TryParse(cId, out uint entry))
            {
                return(false);
            }

            Quest quest = Global.ObjectMgr.GetQuestTemplate(entry);

            // If player doesn't have the quest
            if (quest == null || player.GetQuestStatus(entry) == QuestStatus.None || Global.DisableMgr.IsDisabledFor(DisableType.Quest, entry, null))
            {
                handler.SendSysMessage(CypherStrings.CommandQuestNotfound, entry);
                return(false);
            }

            for (int i = 0; i < quest.Objectives.Count; ++i)
            {
                QuestObjective obj = quest.Objectives[i];

                switch (obj.Type)
                {
                case QuestObjectiveType.Item:
                {
                    uint curItemCount        = player.GetItemCount((uint)obj.ObjectID, true);
                    List <ItemPosCount> dest = new();
                    InventoryResult     msg  = player.CanStoreNewItem(ItemConst.NullBag, ItemConst.NullSlot, dest, (uint)obj.ObjectID, (uint)(obj.Amount - curItemCount));
                    if (msg == InventoryResult.Ok)
                    {
                        Item item = player.StoreNewItem(dest, (uint)obj.ObjectID, true);
                        player.SendNewItem(item, (uint)(obj.Amount - curItemCount), true, false);
                    }
                    break;
                }

                case QuestObjectiveType.Monster:
                {
                    CreatureTemplate creatureInfo = Global.ObjectMgr.GetCreatureTemplate((uint)obj.ObjectID);
                    if (creatureInfo != null)
                    {
                        for (int z = 0; z < obj.Amount; ++z)
                        {
                            player.KilledMonster(creatureInfo, ObjectGuid.Empty);
                        }
                    }
                    break;
                }

                case QuestObjectiveType.GameObject:
                {
                    for (int z = 0; z < obj.Amount; ++z)
                    {
                        player.KillCreditGO((uint)obj.ObjectID);
                    }
                    break;
                }

                case QuestObjectiveType.MinReputation:
                {
                    int curRep = player.GetReputationMgr().GetReputation((uint)obj.ObjectID);
                    if (curRep < obj.Amount)
                    {
                        FactionRecord factionEntry = CliDB.FactionStorage.LookupByKey(obj.ObjectID);
                        if (factionEntry != null)
                        {
                            player.GetReputationMgr().SetReputation(factionEntry, obj.Amount);
                        }
                    }
                    break;
                }

                case QuestObjectiveType.MaxReputation:
                {
                    int curRep = player.GetReputationMgr().GetReputation((uint)obj.ObjectID);
                    if (curRep > obj.Amount)
                    {
                        FactionRecord factionEntry = CliDB.FactionStorage.LookupByKey(obj.ObjectID);
                        if (factionEntry != null)
                        {
                            player.GetReputationMgr().SetReputation(factionEntry, obj.Amount);
                        }
                    }
                    break;
                }

                case QuestObjectiveType.Money:
                {
                    player.ModifyMoney(obj.Amount);
                    break;
                }

                case QuestObjectiveType.PlayerKills:
                {
                    for (var z = 0; z < obj.Amount; ++z)
                    {
                        player.KilledPlayerCredit(ObjectGuid.Empty);
                    }
                    break;
                }
                }
            }

            player.CompleteQuest(entry);
            return(true);
        }
 protected CSGOInventory(InventoryResult apiInventory)
     : base(apiInventory)
 {
 }
        void HandleVoidStorageTransfer(VoidStorageTransfer voidStorageTransfer)
        {
            Player player = GetPlayer();

            Creature unit = player.GetNPCIfCanInteractWith(voidStorageTransfer.Npc, NPCFlags.VaultKeeper, NPCFlags2.None);

            if (!unit)
            {
                Log.outDebug(LogFilter.Network, "WORLD: HandleVoidStorageTransfer - {0} not found or player can't interact with it.", voidStorageTransfer.Npc.ToString());
                return;
            }

            if (!player.IsVoidStorageUnlocked())
            {
                Log.outDebug(LogFilter.Network, "WORLD: HandleVoidStorageTransfer - Player ({0}, name: {1}) queried void storage without unlocking it.", player.GetGUID().ToString(), player.GetName());
                return;
            }

            if (voidStorageTransfer.Deposits.Length > player.GetNumOfVoidStorageFreeSlots())
            {
                SendVoidStorageTransferResult(VoidTransferError.Full);
                return;
            }

            uint freeBagSlots = 0;

            if (!voidStorageTransfer.Withdrawals.Empty())
            {
                // make this a Player function
                for (byte i = InventorySlots.BagStart; i < InventorySlots.BagEnd; i++)
                {
                    Bag bag = player.GetBagByPos(i);
                    if (bag)
                    {
                        freeBagSlots += bag.GetFreeSlots();
                    }
                }
                int inventoryEnd = InventorySlots.ItemStart + _player.GetInventorySlotCount();
                for (byte i = InventorySlots.ItemStart; i < inventoryEnd; i++)
                {
                    if (!player.GetItemByPos(InventorySlots.Bag0, i))
                    {
                        ++freeBagSlots;
                    }
                }
            }

            if (voidStorageTransfer.Withdrawals.Length > freeBagSlots)
            {
                SendVoidStorageTransferResult(VoidTransferError.InventoryFull);
                return;
            }

            if (!player.HasEnoughMoney((voidStorageTransfer.Deposits.Length * SharedConst.VoidStorageStoreItemCost)))
            {
                SendVoidStorageTransferResult(VoidTransferError.NotEnoughMoney);
                return;
            }

            VoidStorageTransferChanges voidStorageTransferChanges = new VoidStorageTransferChanges();

            byte depositCount = 0;

            for (int i = 0; i < voidStorageTransfer.Deposits.Length; ++i)
            {
                Item item = player.GetItemByGuid(voidStorageTransfer.Deposits[i]);
                if (!item)
                {
                    Log.outDebug(LogFilter.Network, "WORLD: HandleVoidStorageTransfer - {0} {1} wants to deposit an invalid item ({2}).", player.GetGUID().ToString(), player.GetName(), voidStorageTransfer.Deposits[i].ToString());
                    continue;
                }

                VoidStorageItem itemVS = new VoidStorageItem(Global.ObjectMgr.GenerateVoidStorageItemId(), item.GetEntry(), item.GetCreator(),
                                                             item.GetItemRandomBonusListId(), item.GetModifier(ItemModifier.TimewalkerLevel), item.GetModifier(ItemModifier.ArtifactKnowledgeLevel),
                                                             item.GetContext(), item.m_itemData.BonusListIDs);

                VoidItem voidItem;
                voidItem.Guid    = ObjectGuid.Create(HighGuid.Item, itemVS.ItemId);
                voidItem.Creator = item.GetCreator();
                voidItem.Item    = new ItemInstance(itemVS);
                voidItem.Slot    = _player.AddVoidStorageItem(itemVS);

                voidStorageTransferChanges.AddedItems.Add(voidItem);

                player.DestroyItem(item.GetBagSlot(), item.GetSlot(), true);
                ++depositCount;
            }

            long cost = depositCount * SharedConst.VoidStorageStoreItemCost;

            player.ModifyMoney(-cost);

            for (int i = 0; i < voidStorageTransfer.Withdrawals.Length; ++i)
            {
                byte            slot;
                VoidStorageItem itemVS = player.GetVoidStorageItem(voidStorageTransfer.Withdrawals[i].GetCounter(), out slot);
                if (itemVS == null)
                {
                    Log.outDebug(LogFilter.Network, "WORLD: HandleVoidStorageTransfer - {0} {1} tried to withdraw an invalid item ({2})", player.GetGUID().ToString(), player.GetName(), voidStorageTransfer.Withdrawals[i].ToString());
                    continue;
                }

                List <ItemPosCount> dest = new List <ItemPosCount>();
                InventoryResult     msg  = player.CanStoreNewItem(ItemConst.NullBag, ItemConst.NullSlot, dest, itemVS.ItemEntry, 1);
                if (msg != InventoryResult.Ok)
                {
                    SendVoidStorageTransferResult(VoidTransferError.InventoryFull);
                    Log.outDebug(LogFilter.Network, "WORLD: HandleVoidStorageTransfer - {0} {1} couldn't withdraw {2} because inventory was full.", player.GetGUID().ToString(), player.GetName(), voidStorageTransfer.Withdrawals[i].ToString());
                    return;
                }

                Item item = player.StoreNewItem(dest, itemVS.ItemEntry, true, itemVS.RandomBonusListId, null, itemVS.Context, itemVS.BonusListIDs);
                item.SetCreator(itemVS.CreatorGuid);
                item.SetBinding(true);
                GetCollectionMgr().AddItemAppearance(item);

                voidStorageTransferChanges.RemovedItems.Add(ObjectGuid.Create(HighGuid.Item, itemVS.ItemId));

                player.DeleteVoidStorageItem(slot);
            }

            SendPacket(voidStorageTransferChanges);
            SendVoidStorageTransferResult(VoidTransferError.Ok);
        }
示例#36
0
        async Task DoInventory()
        {
            Program.MainForm.OutputHistory("开始捕获", 0);

            if (Program.Rfid.Readers.Count == 0)
            {
                Program.MainForm.OutputHistory("当前没有可用的读卡器", 2);
            }
            else
            {
                List <string> names = new List <string>();
                Program.Rfid.Readers.ForEach((o) => names.Add(o.Name));
                Program.MainForm.OutputHistory($"当前读卡器数量 {Program.Rfid.Readers.Count}。包括: \r\n{StringUtil.MakePathList(names,"\r\n")}", 0);
            }

            _cancelInventory = new CancellationTokenSource();
            bool bFirst = true;

            try
            {
                // uid --> Driver Name
                // Hashtable uid_table = new Hashtable();
                while (_cancelInventory.IsCancellationRequested == false)
                {
                    await Task.Delay(200, _cancelInventory.Token).ConfigureAwait(false);

                    ClearIdleTag(TimeSpan.FromSeconds(1));  // 1 秒的防误触发时间

                    FlushCompactLog();

                    //if (_captureEnabled.Value == false)
                    //    continue;

                    // uid_table.Clear();
                    foreach (Reader reader in Program.Rfid.Readers)
                    {
                        if (reader == null)
                        {
                            continue;
                        }

                        if (string.IsNullOrEmpty(Program.Rfid.State) == false)
                        {
                            break;
                        }

                        InventoryResult inventory_result = Program.Rfid.Inventory(
                            reader.Name, bFirst ? "" : "only_new");
                        // bFirst = false;
                        if (inventory_result.Value == -1)
                        {
                            _compactLog?.Add($"*** 读卡器 {0} 点选标签时出错: {1}",
                                             new object[] { reader.Name, inventory_result.ToString() }
                                             );
                            continue;
                            // ioError 要主动卸载有问题的 reader?
                            // 如何报错?写入操作历史?
                            // Program.MainForm.OutputHistory($"读卡器{reader.Name}点选标签时出错:{inventory_result.ToString()}\r\n已停止捕获过程", 2);
                            // return;
                        }

                        foreach (InventoryInfo info in inventory_result.Results)
                        {
                            //if (uid_table.ContainsKey(info.UID))
                            //    continue;
                            //uid_table[info.UID] = reader.Name;
                            AddToTagList(reader.Name, info.UID, info.DsfID, info.Protocol);
                        }
                    }
                }
            }
            catch (TaskCanceledException)
            {
            }
            finally
            {
                _cancelInventory = null;
                Program.MainForm.OutputHistory("结束捕获", 0);
            }
        }
示例#37
0
        void HandlePetitionBuy(PetitionBuy packet)
        {
            // prevent cheating
            Creature creature = GetPlayer().GetNPCIfCanInteractWith(packet.Unit, NPCFlags.Petitioner, NPCFlags2.None);

            if (!creature)
            {
                Log.outDebug(LogFilter.Network, "WORLD: HandlePetitionBuyOpcode - {0} not found or you can't interact with him.", packet.Unit.ToString());
                return;
            }

            // remove fake death
            if (GetPlayer().HasUnitState(UnitState.Died))
            {
                GetPlayer().RemoveAurasByType(AuraType.FeignDeath);
            }

            uint charterItemID = GuildConst.CharterItemId;
            int  cost          = WorldConfig.GetIntValue(WorldCfg.CharterCostGuild);

            // do not let if already in guild.
            if (GetPlayer().GetGuildId() != 0)
            {
                return;
            }

            if (Global.GuildMgr.GetGuildByName(packet.Title))
            {
                Guild.SendCommandResult(this, GuildCommandType.CreateGuild, GuildCommandError.NameExists_S, packet.Title);
                return;
            }

            if (Global.ObjectMgr.IsReservedName(packet.Title) || !ObjectManager.IsValidCharterName(packet.Title))
            {
                Guild.SendCommandResult(this, GuildCommandType.CreateGuild, GuildCommandError.NameInvalid, packet.Title);
                return;
            }

            ItemTemplate pProto = Global.ObjectMgr.GetItemTemplate(charterItemID);

            if (pProto == null)
            {
                GetPlayer().SendBuyError(BuyResult.CantFindItem, null, charterItemID);
                return;
            }

            if (!GetPlayer().HasEnoughMoney(cost))
            {                                                       //player hasn't got enough money
                GetPlayer().SendBuyError(BuyResult.NotEnoughtMoney, creature, charterItemID);
                return;
            }

            List <ItemPosCount> dest = new List <ItemPosCount>();
            InventoryResult     msg  = GetPlayer().CanStoreNewItem(ItemConst.NullBag, ItemConst.NullSlot, dest, charterItemID, pProto.GetBuyCount());

            if (msg != InventoryResult.Ok)
            {
                GetPlayer().SendEquipError(msg, null, null, charterItemID);
                return;
            }

            GetPlayer().ModifyMoney(-cost);
            Item charter = GetPlayer().StoreNewItem(dest, charterItemID, true);

            if (!charter)
            {
                return;
            }

            charter.SetPetitionId((uint)charter.GetGUID().GetCounter());
            charter.SetState(ItemUpdateState.Changed, GetPlayer());
            GetPlayer().SendNewItem(charter, 1, true, false);

            // a petition is invalid, if both the owner and the type matches
            // we checked above, if this player is in an arenateam, so this must be
            // datacorruption
            Petition petition = Global.PetitionMgr.GetPetitionByOwner(_player.GetGUID());

            if (petition != null)
            {
                // clear from petition store
                Global.PetitionMgr.RemovePetition(petition.PetitionGuid);
                Log.outDebug(LogFilter.Network, $"Invalid petition GUID: {petition.PetitionGuid.GetCounter()}");
            }

            // fill petition store
            Global.PetitionMgr.AddPetition(charter.GetGUID(), _player.GetGUID(), packet.Title, false);
        }
示例#38
0
 protected Inventory(InventoryResult apiInventory)
 {
     Items     = apiInventory.items;
     IsPrivate = (apiInventory.status == "15");
     IsGood    = (apiInventory.status == "1");
 }