コード例 #1
0
    public ActionResult AddItem(BaseCollectibleItem objectToAdd)
    {
        bool needNewItemSlot = true;

        foreach (InventorySlot slot in slotList)
        {
            if (slot.item.type == objectToAdd.type)
            {
                if (!slot.slotFull)
                {
                    needNewItemSlot = false;

                    slot.currentSlotValue += 1;

                    slot.CheckMaxValue();

                    Debug.Log("PICKED UP OBJECT!");

                    return(ActionResult.Success);
                }
            }
        }

        if (needNewItemSlot)
        {
            int slotCounter = 0;

            if (slotList.Count == maxSlotNumber)
            {
                Debug.Log("INVENTORY FULL!");
                return(ActionResult.InventoryFull);
            }

            foreach (InventorySlot slot in slotList)
            {
                if (slot.item.type == objectToAdd.type)
                {
                    slotCounter += 1;
                }
            }

            if (slotCounter < objectToAdd.maxStackNumber)
            {
                if (slotList.Count - 1 < maxSlotNumber)
                {
                    InventorySlot tempSlot = new InventorySlot();

                    tempSlot.currentSlotValue = 1;

                    tempSlot.item = objectToAdd;

                    slotList.Add(tempSlot);

                    Debug.Log("NEW SLOT CREATED!");

                    return(ActionResult.Success);
                }
            }
            else
            {
                Debug.Log("MAX STACK NUMBER REACHED!");

                return(ActionResult.MaxStack);
            }
        }

        return(ActionResult.Fail);
    }
コード例 #2
0
ファイル: BaseEnemy.cs プロジェクト: WoolMagician/8-Cores
 public Drop(BaseCollectibleItem i, int q)
 {
     item     = i;
     quantity = q;
 }