Пример #1
0
        /// <summary>
        /// Move an item to the merchant
        /// </summary>
        /// <param name="playerInventory"></param>
        /// <param name="fromSlot"></param>
        /// <param name="toSlot"></param>
        /// <returns></returns>
        protected IDictionary<int, InventoryItem> MoveItemToMerchant(GamePlayer player, IGameInventory playerInventory,
                                                                     eInventorySlot fromSlot, eInventorySlot toSlot)
        {
            // We will only allow moving from the backpack.            
            if (fromSlot < eInventorySlot.FirstBackpack || fromSlot > eInventorySlot.LastBackpack)
                return null;

            InventoryItem fromItem = playerInventory.GetItem(fromSlot);

            if (fromItem == null)
                return null;

            if (fromItem is InventoryArtifact)
                return null;

            IDictionary<int, InventoryItem> inventory = ConInventory;
            IDictionary<int, InventoryItem> updateItems = new Dictionary<int, InventoryItem>(1);

            playerInventory.RemoveItem(fromItem);
            InventoryLogging.LogInventoryAction(player, this, eInventoryActionType.Merchant, fromItem.Template, fromItem.Count);

            if (inventory.ContainsKey((int)toSlot))
            {
                InventoryItem toItem = inventory[(int)toSlot];
                GameServer.Database.DeleteObject(toItem);

                if (playerInventory.AddItem(fromSlot, toItem))
                    InventoryLogging.LogInventoryAction(this, player, eInventoryActionType.Other, toItem.Template, toItem.Count);
            }

            House house = HouseMgr.GetHouse(HouseNumber);

            fromItem.SlotPosition = (int)(toSlot);

            var price = player.TempProperties.getProperty<int>(PlayerSetMarketPriceHandler.NEW_PRICE);
            player.TempProperties.removeProperty(PlayerSetMarketPriceHandler.NEW_PRICE);

            if (fromItem.OwnerID != house.OwnerID)
            {
                fromItem.OwnerID = house.OwnerID;
            }

            fromItem.SellPrice = price;
            fromItem.OwnerLot = (ushort)HouseNumber; // used to mark the lot for market explorer
            GameServer.Database.AddObject(fromItem);

            if ((int)toSlot >= (int)eInventorySlot.Consignment_First)
            {
                toSlot = (eInventorySlot)(RecalculateSlot((int)toSlot));
            }

            updateItems.Add((int)toSlot, fromItem);

            return updateItems;
        }
Пример #2
0
        /// <summary>
        /// Move an Item from the merchant 
        /// </summary>
        /// <param name="playerInventory"></param>
        /// <param name="fromSlot"></param>
        /// <param name="toSlot"></param>
        /// <returns></returns>
        protected IDictionary<int, InventoryItem> MoveItemFromMerchant(GamePlayer player, IGameInventory playerInventory,
                                                                       eInventorySlot fromSlot, eInventorySlot toSlot)
        {
            // We will only allow moving to the backpack.            
            if (toSlot < eInventorySlot.FirstBackpack || toSlot > eInventorySlot.LastBackpack)
                return null;

            IDictionary<int, InventoryItem> inventory = ConInventory;

            if ((int)fromSlot >= (int)eInventorySlot.Consignment_First)
            {
                fromSlot = (eInventorySlot)(RecalculateSlot((int)fromSlot));
            }

            if (!inventory.ContainsKey((int)fromSlot))
                return null;

            IDictionary<int, InventoryItem> updateItems = new Dictionary<int, InventoryItem>(1);
            InventoryItem fromItem = inventory[(int)fromSlot];
            InventoryItem toItem = playerInventory.GetItem(toSlot);
            if (toItem != null)
            {
                playerInventory.RemoveItem(toItem);
                InventoryLogging.LogInventoryAction(player, this, eInventoryActionType.Merchant, toItem.Template, toItem.Count);
                toItem.SlotPosition = fromItem.SlotPosition;
                GameServer.Database.AddObject(toItem);
            }

            GameServer.Database.DeleteObject(fromItem);

            if (fromItem.OwnerID != player.DBCharacter.ObjectId)
            {
                fromItem.OwnerID = player.DBCharacter.ObjectId;
            }

            if (fromItem.SellPrice != 0)
            {
                fromItem.SellPrice = 0;
            }

            fromItem.OwnerLot = 0;
            if (playerInventory.AddItem(toSlot, fromItem))
                InventoryLogging.LogInventoryAction(this, player, eInventoryActionType.Merchant, fromItem.Template, fromItem.Count);
            updateItems.Add((int)fromSlot, toItem);

            return updateItems;
        }