UnequipItem() public method

Removes an item from the equipment slot it uses returns the used equipmentSlot
public UnequipItem ( Item item ) : int
item Mooege.Core.Common.Items.Item
return int
Exemplo n.º 1
0
 public void SellItem(Item item)
 {
     if (_equipment.IsItemEquipped(item))
     {
         _equipment.UnequipItem(item);
         SendVisualInventory(_owner);
     }
     else
     {
         _inventoryGrid.RemoveItem(item);
     }
     item.Destroy();
 }
Exemplo n.º 2
0
        /// <summary>
        /// Handles a request to move an item within the inventory.
        /// This covers moving items within the backpack, from equipment
        /// slot to backpack and from backpack to equipment slot
        /// </summary>
        public void HandleInventoryRequestMoveMessage(InventoryRequestMoveMessage request)
        {
            // TODO Normal inventory movement does not require setting of inv loc msg! Just Tick. /fasbat
            Item item = GetItem(request.ItemID);

            if (item == null)
            {
                return;
            }
            // Request to equip item from backpack
            if (request.Location.EquipmentSlot != 0 && request.Location.EquipmentSlot != (int)EquipmentSlotId.Stash)
            {
                var sourceGrid = (item.InvLoc.EquipmentSlot == 0 ? _inventoryGrid :
                                  item.InvLoc.EquipmentSlot == (int)EquipmentSlotId.Stash ? _stashGrid : null);

                System.Diagnostics.Debug.Assert((sourceGrid != null && sourceGrid.Contains(request.ItemID)) || _equipment.IsItemEquipped(request.ItemID), "Request to equip unknown item");

                int targetEquipSlot = request.Location.EquipmentSlot;

                if (IsValidEquipmentRequest(item, targetEquipSlot))
                {
                    Item oldEquipItem = _equipment.GetEquipment(targetEquipSlot);

                    // check if equipment slot is empty
                    if (oldEquipItem == null)
                    {
                        // determine if item is in backpack or switching item from position with target originally empty
                        if (sourceGrid != null)
                        {
                            sourceGrid.RemoveItem(item);
                        }
                        else
                        {
                            _equipment.UnequipItem(item);
                        }

                        _equipment.EquipItem(item, targetEquipSlot);
                        AcceptMoveRequest(item);
                    }
                    else
                    {
                        // check if item is already equipped at another equipmentslot
                        if (_equipment.IsItemEquipped(item))
                        {
                            // switch both items
                            if (!IsValidEquipmentRequest(oldEquipItem, item.EquipmentSlot))
                            {
                                return;
                            }

                            int oldEquipmentSlot = _equipment.UnequipItem(item);
                            _equipment.EquipItem(item, targetEquipSlot);
                            _equipment.EquipItem(oldEquipItem, oldEquipmentSlot);
                        }
                        else
                        {
                            // Get original location
                            int x = item.InventoryLocation.X;
                            int y = item.InventoryLocation.Y;
                            // equip item and place other item in the backpack
                            sourceGrid.RemoveItem(item);
                            _equipment.UnequipItem(oldEquipItem);
                            sourceGrid.AddItem(oldEquipItem, y, x);
                            _equipment.EquipItem(item, targetEquipSlot);
                        }
                        AcceptMoveRequest(item);
                        AcceptMoveRequest(oldEquipItem);
                    }

                    SendVisualInventory(this._owner);
                }
            }
            // Request to move an item (from backpack or equipmentslot)
            else
            {
                if (request.Location.EquipmentSlot == 0)
                {
                    // check if not unsocketting rune
                    for (int i = 0; i < _skillSocketRunes.Length; i++)
                    {
                        if (_skillSocketRunes[i] == request.ItemID)
                        {
                            if (_inventoryGrid.FreeSpace(item, request.Location.Row, request.Location.Column))
                            {
                                RemoveRune(i);
                                _inventoryGrid.AddItem(item, request.Location.Row, request.Location.Column);
                                if (item.InvLoc.EquipmentSlot != request.Location.EquipmentSlot)
                                {
                                    AcceptMoveRequest(item);
                                }
                            }
                            return;
                        }
                    }
                }

                var destGrid = (request.Location.EquipmentSlot == 0 ? _inventoryGrid : _stashGrid);

                if (destGrid.FreeSpace(item, request.Location.Row, request.Location.Column))
                {
                    if (_equipment.IsItemEquipped(item))
                    {
                        _equipment.UnequipItem(item); // Unequip the item
                        SendVisualInventory(this._owner);
                    }
                    else
                    {
                        var sourceGrid = (item.InvLoc.EquipmentSlot == 0 ? _inventoryGrid : _stashGrid);
                        sourceGrid.RemoveItem(item);
                    }
                    destGrid.AddItem(item, request.Location.Row, request.Location.Column);
                    if (item.InvLoc.EquipmentSlot != request.Location.EquipmentSlot)
                    {
                        AcceptMoveRequest(item);
                    }
                }
            }
        }