Esempio n. 1
0
        /// <summary>
        /// Adds an item to the backpack, used for moving from to inv. (for Pickup use AddItem)
        /// </summary>
        protected Boolean addItemAtPosition(InventoryItem item, InventorySlot _slot)
        {
            int row    = _slot.R;
            int column = _slot.C;

            InventorySize size = item.InventorySize;

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

            if (!Items.ContainsKey(item.DynamicID)) //hmm OJO AL DUPE...
            {
                Items.Add(item.DynamicID, item);
            }

            for (int h = 0; h < size.Height; h++)
            {
                for (int w = 0; w < size.Width; w++)
                {
                    //System.Diagnostics.Debug.Assert(_backpack[r, c] == 0, "You need to remove an item from the backpack before placing another item there");
                    backpack[row + h, column + w] = item.DynamicID; // para cada slot ocupado, relleno con id
                }
            }
            item.InventorySlot.R = row;
            item.InventorySlot.C = column;
            item.EquipmentSlot   = EquipmentSlotId.Inventory;

            return(true);
        }
Esempio n. 2
0
        protected bool canPutitemThere_checking_self_item(InventoryItem item, int row, int colum)
        {
            InventorySize itemsize = item.InventorySize;

            for (int r = 0; r < itemsize.Height; r++)
            {
                for (int c = 0; c < itemsize.Width; c++)
                {
                    if (backpack[row + r, colum + c] != 0)
                    {
                        if (backpack[row + r, colum + c] != item.DynamicID)
                        {
                            return(false); //no puede, algun lugar de los q ocupa esta ocupado
                        }
                    }
                }
            }
            return(true);
        }
Esempio n. 3
0
        protected bool canPutitemThere(InventoryItem item, int row, int colum)
        {
            InventorySize itemsize = item.InventorySize;

            for (int r = 0; r < itemsize.Height; r++)
            {
                for (int c = 0; c < itemsize.Width; c++)
                {
                    if ((row + r) >= this.Rows || (colum + c) >= this.Columns)
                    {
                        return(false);
                    }
                    if (backpack[row + r, colum + c] != 0)
                    {
                        return(false); //no puede, algun lugar de los q ocupa esta ocupado
                    }
                }
            }
            return(true);
        }
Esempio n. 4
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>
        protected InventorySlot findSlotForItem(InventoryItem item)
        {
            InventorySize size = item.InventorySize;

            for (int r = 0; r < Rows; r++)
            {
                for (int c = 0; c < Columns; c++)
                {
                    if (canPutitemThere(item, r, c) == true)
                    {
                        return new InventorySlot()
                               {
                                   R = r, C = c
                               }
                    }
                }
            }
            ;
            return(null);
        }