public bool AddItemToInventory(CubeProperties.itemIDs itemID , int number , SlotProperties slot)
 {
     if(CubeProperties.cubeProperties.itemDict[itemID].stackable)
     {
         SlotProperties temp = CheckIfIsInInvenory( itemID);
         if( temp != null)
         {
             int remainder = temp.UpdateNumberOfItem(number);
             if(remainder == 0)
             {
                 slot.UpdateSlot(0,0);
                 return true;
             }
             else
             {
                 slot.UpdateSlot(itemID , remainder);
                 return AddItemToInventory(itemID ,remainder ,slot );
             }
         }
     }
     SlotProperties temp1 = GetNextAvailableSlot (itemID);
     if(temp1 != null)
     {
         temp1.UpdateSlot(itemID , number);
         return true;
     }
     return false;
 }
 void Start()
 {
     slot = InventoryManager.inventoryManager.activeInventorySlots [index];
     image = transform.FindChild ("ItemIcon").GetComponent<Image>();
     text = transform.FindChild ("ItemNumber").GetComponent<Text>();
 }
예제 #3
0
 void UpdateActiveSlot()
 {
     indexOfSlot = moveToActive.index;
     activeSlot = InventoryManager.inventoryManager.activeInventorySlots [indexOfSlot];
     activeItemID = activeSlot.itemID;
     if (activeItemID != 0)
         activeItemType = CubeProperties.cubeProperties.itemDict [activeItemID].itemType;
 }
    public void CallCrafting(SlotProperties[] craftingInventorySlots, SlotProperties outputInventorySlots)
    {
        //pass in input
        string inputString = null;
        int output = 0;
        int numberOfOutput = 1;

        for(int i=0; i<craftingInventorySlots.Length; i++)
        {
            inputString += ((int)craftingInventorySlots[i].itemID).ToString() + " ";
            if (craftingInventorySlots.Length == 4)
            {
                if (i == 1)
                    inputString += "0 ";
                if (i == 3)
                    inputString += "0 0 0 0 ";
            }
        }

        if (!masterCrafter)
        {
            output = crafting.GetOutput (inputString);
            numberOfOutput = crafting.GetOutputNumber (inputString);
            outputInventorySlots.UpdateSlot((CubeProperties.itemIDs)output , numberOfOutput);
        //			outputInventorySlots.itemID = (CubeProperties.itemIDs)output;
        //			outputInventorySlots.numberOfItem = (byte)numberOfOutput;
        }
    }
 public void AddOneToCrafting(SlotProperties slot)
 {
     slot.UpdateSlot (firstSwap.itemID, 1);
     firstSwap.UpdateNumberOfItem (-1);
 }
    void SaveXMLButton(SlotProperties[] craftingInventorySlots, SlotProperties outputInventorySlots)
    {
        string craftingIDs = null;
        for(int i=0; i<craftingInventorySlots.Length; i++)
        {
            craftingIDs += ((int)craftingInventorySlots[i].itemID).ToString() + " ";

            if (craftingInventorySlots.Length == 4)
            {
                if (i == 1)
                    craftingIDs += "0 ";
                if (i == 3)
                    craftingIDs += "0 0 0 0 ";
            }
        }
        craftingIDs += "," + ((int)outputInventorySlots.itemID).ToString() + ",";
        craftingIDs += outputInventorySlots.numberOfItem + "," + "\n";

        crafting.SaveXML (craftingIDs);
    }
 IEnumerator ResetFirstSwap()
 {
     yield return new WaitForSeconds (10f);
     firstSwap = null;
 }
    public void SwapWithFirstSlot( SlotProperties slot)
    {
        if(firstSwap != null)
        {
            if(firstSwap.itemID != slot.itemID || !firstSwap.isStackable || !slot.isStackable)
            {
                CubeProperties.itemIDs temp = firstSwap.itemID;
                int tempNum = firstSwap.numberOfItem;
                firstSwap.UpdateSlot(slot.itemID , slot.numberOfItem);
                slot.UpdateSlot(temp , tempNum);
            }
            else
            {
                int numberSlotsLeft = 64 - slot.numberOfItem;
                if(firstSwap.numberOfItem < numberSlotsLeft)
                {
                    slot.UpdateNumberOfItem(firstSwap.numberOfItem);
                    firstSwap.UpdateSlot(0,0);
                }
                else
                {
                    slot.UpdateNumberOfItem(numberSlotsLeft);
                    firstSwap.UpdateNumberOfItem(-numberSlotsLeft);
                }

            }
        }
    }
 public void SetFirstSwap( SlotProperties slot)
 {
     firstSwap = slot;
     if(resetSlot == null)
         resetSlot = StartCoroutine (ResetFirstSwap ());
     else {
         StopCoroutine(resetSlot);
         resetSlot= StartCoroutine (ResetFirstSwap());
     }
 }