Exemplo n.º 1
0
 public SerializedInstanceItem(InstanceItem instanceItem)
 {
     Item              = instanceItem.Item;
     StackSize         = instanceItem.StackSize;
     CurrentDurability = instanceItem.CurrentDurability;
     IntStore          = instanceItem.IntStore;
 }
Exemplo n.º 2
0
        /// <summary>
        /// Adds the InventoryItem to the Inventory
        /// </summary>
        /// <param name="instanceItem"></param>
        /// <returns>Returns false if the inventory could not fit the entire inventoryItem</returns>
        public bool AddItemToInventory(InstanceItem instanceItem)
        {
            // Add items to existing slots of same item
            for (int i = 0; i < ItemList.Length; i++)
            {
                if (ItemList[i]?.Item != null && ItemList[i].Item == instanceItem.Item)
                {
                    if (ItemList[i].Combine(instanceItem))
                    {
                        InventorySlotUpdated.Invoke(i);
                        return(true);
                    }

                    InventorySlotUpdated.Invoke(i);
                }
            }

            // Add to next available slot
            for (int i = 0; i < ItemList.Length; i++)
            {
                if (ItemList[i] == null || ItemList[i].Item == null)
                {
                    ItemList[i] = instanceItem;
                    InventorySlotUpdated.Invoke(i);
                    return(true);
                }
            }

            return(false);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Combines 2 InventoryItem stacks. Returns true if inventoryItem.StackSize is 0.
        /// </summary>
        /// <param name="instanceItem"></param>
        /// <returns></returns>
        public bool Combine(InstanceItem instanceItem)
        {
            instanceItem.StackSize = Add(instanceItem.StackSize);
            if (instanceItem.StackSize <= 0)
            {
                return(true);
            }

            return(false);
        }
Exemplo n.º 4
0
        public static WorldItem CreateWorldItem(InstanceItem item, Vector3 position)
        {
            GameObject go = Instantiate(Resources.Load(PrefabName)) as GameObject;

            go.name = item.Item.name;
            go.transform.position = position + new Vector3(0.5f, 0.5f, 0); // Offset to center of tile
            WorldItem worldItem = go.GetComponent <WorldItem>();

            worldItem._item = item;
            return(worldItem);
        }
Exemplo n.º 5
0
        public void OnAfterDeserialize()
        {
            ItemList = new InstanceItem[SerializedItemList.Length];

            for (int i = 0; i < SerializedItemList.Length; i++)
            {
                if (SerializedItemList[i].Item != null)
                {
                    ItemList[i] = new InstanceItem(SerializedItemList[i]);
                }
            }
        }
Exemplo n.º 6
0
        private void Start()
        {
            if (_item == null)
            {
                _item = new InstanceItem(SerializedInstanceItem);
            }

            _col           = GetComponent <BoxCollider2D>();
            _col.isTrigger = true;

            _renderer        = GetComponent <SpriteRenderer>();
            _renderer.sprite = _item.ItemSprite;

            _item.Initialise();
        }
Exemplo n.º 7
0
 public ItemParams(InstanceItem item)
 {
     CurrentDurability = item.CurrentDurability;
     StackSize         = item.StackSize;
     IntStore          = item.IntStore;
 }