Exemple #1
0
        /// <summary>
        /// Collects (counts) the items overlapping with the item about to be dropped.
        /// If there are none, drop item
        /// If there is exacly one, swap it with item (TODO)
        /// If there are more, item cannot be dropped
        /// </summary>
        private int CollectOverlappingItems(Item item, int row, int column)
        {
            InventorySize dropSize    = GetItemInventorySize(item);
            var           overlapping = new List <uint>();

            // For every slot...
            for (int r = row; r < _backpack.GetLength(0) && r < row + dropSize.Height; r++)
            {
                for (int c = column; c < _backpack.GetLength(1) && c < column + dropSize.Width; c++)
                {
                    // that contains an item other than the one we want to drop
                    if (_backpack[r, c] != 0 && _backpack[r, c] != item.DynamicID) //TODO this would break for an item with id 0

                    // add it to the list if if dropping the item in <row, column> would need the same slot
                    //if (r >= row && r <= row + dropSize.Height)
                    //    if (c >= column && c <= column + dropSize.Width)
                    {
                        if (!overlapping.Contains(_backpack[r, c]))
                        {
                            overlapping.Add(_backpack[r, c]);
                        }
                    }
                }
            }

            return(overlapping.Count);
        }
Exemple #2
0
        public void AddSelledItem(Item item, int row, int column)
        {
            InventorySize size = GetItemInventorySize(item);

            //check backpack boundaries
            if (row + size.Width > Rows || column + size.Width > Columns)
            {
                return;
            }

            Items.Add(item.DynamicID, item);

            for (int r = row; r < Math.Min(row + size.Height, Rows); r++)
            {
                for (int c = column; c < Math.Min(column + size.Width, Columns); c++)
                {
                    if (_backpack[r, c] != 0)
                    {
                        _backpack[r, c] = 0;
                    }
                    System.Diagnostics.Debug.Assert(_backpack[r, c] == 0, "You need to remove an item from the backpack before placing another item there");

                    _backpack[r, c] = item.DynamicID;
                }
            }

            item.Owner = _owner;
            item.Attributes[Net.GS.Message.GameAttribute.Special_Inventory_Has_Sold] = true;
            item.SetInventoryLocation(EquipmentSlot, column, row);
        }
Exemple #3
0
 public ItemData(String FileName)
 {
     this.Header            = new Header();
     this.ClothingInfo      = new ClothingInfo();
     this.InventorySize     = new InventorySize();
     this.ExtraMeshFileName = new List <String>();
 }
Exemple #4
0
        public bool FreeSpace(Item item, int row, int column)
        {
            bool          result = true;
            InventorySize size   = GetItemInventorySize(item);

            for (int r = row; r < Math.Min(row + size.Height, Rows); r++)
            {
                for (int c = column; c < Math.Min(column + size.Width, Columns); c++)
                {
                    if ((_backpack[r, c] != 0) && (_backpack[r, c] != item.DynamicID))
                    {
                        result = false;
                    }
                }
            }
            return(result);
        }
Exemple #5
0
        /// <summary>
        /// Find an inventory slot with enough space for an item
        /// </summary>
        /// <returns>Slot or null if there is no space in the backpack</returns>
        private InventorySlot?FindSlotForItem(Item item)
        {
            InventorySize size = GetItemInventorySize(item);

            for (int r = 0; r <= Rows - size.Height; r++)
            {
                for (int c = 0; c <= Columns - size.Width; c++)
                {
                    if (CollectOverlappingItems(item, r, c) == 0)
                    {
                        return new InventorySlot()
                               {
                                   Row = r, Column = c
                               }
                    }
                }
            }
            ;
            return(null);
        }
Exemple #6
0
        /// <summary>
        /// Find an inventory slot with enough space for an item
        /// </summary>
        /// <returns>Slot or null if there is no space in the backpack</returns>
        private InventorySlot?FindSlotForItem(int minRow, int maxRow, Item item)
        {
            InventorySize size = GetItemInventorySize(item);
            // If we target a specific tab in stash, we need to specify min and max row to fill
            int nStartRow = minRow == -1 ? 0 : Math.Min(minRow, Rows); // maybe not needed, because Rows always > minRow
            int nEndRow   = minRow == -1 ? Rows : Math.Min(maxRow, Rows);

            for (int r = nStartRow; r <= nEndRow - size.Height; r++)
            {
                for (int c = 0; c <= Columns - size.Width; c++)
                {
                    if (CollectOverlappingItems(item, r, c) == 0)
                    {
                        return new InventorySlot()
                               {
                                   Row = r, Column = c
                               }
                    }
                }
            }
            ;
            return(null);
        }