예제 #1
0
 public bool addItem(itemStack input)
 {
     foreach (itemStack stack in inventoryContents)
     {
         if (stack.isEmpty())
         {
             stack.setStack(input);
             return(true);
         }
         else
         {
             if (itemStack.areItemsEqual(input, stack))
             {
                 if (stack.canAddTo(input.getCount()))
                 {
                     stack.increaseAmount(input.getCount());
                     return(true);
                 }
                 else
                 {
                     int difference = (stack.getCount() + input.getCount()) - stack.getItem().maxStack;
                     stack.setCount(stack.getItem().maxStack);
                     input.setCount(difference);
                 }
             }
         }
     }
     return(false);
 }
예제 #2
0
 public void setSlot(inventory attachedInventory, int SlotID, container attachedContainer)
 {
     this.SlotID            = SlotID;
     this.attachedContainer = attachedContainer;
     myStack          = attachedInventory.getStackInSlot(SlotID);
     inventoryManager = inventoryManager.INSTANCE;
     updateSlot();
 }
예제 #3
0
    // splits stack
    public itemStack splitStack(int amount)
    {
        int       i           = Mathf.Min(amount, count);
        itemStack copiedStack = this.copy();

        copiedStack.setCount(i);
        this.decreaseAmount(i);
        Debug.Log("Split");
        return(copiedStack);
    }
예제 #4
0
    public void OnPointerDown(PointerEventData eventData)
    {
        itemStack currentDraggedStack = inventoryManager.getDraggedItem();
        itemStack stackCopy           = myStack.copy();

        if (eventData.pointerId == -1)
        {
            onLeftClick(currentDraggedStack, stackCopy);
        }
        //throw new System.NotImplementedException();
    }
예제 #5
0
    private void onLeftClick(itemStack currentDraggedItem, itemStack itemCopy)
    {
        if (!myStack.isEmpty() && currentDraggedItem.isEmpty())
        {
            inventoryManager.setDragged(itemCopy);
            this.setSlotContents(itemStack.Empty);
        }

        if (myStack.isEmpty() && !currentDraggedItem.isEmpty())
        {
            this.setSlotContents(currentDraggedItem);
            inventoryManager.setDragged(itemStack.Empty);
        }
        if (!myStack.isEmpty() && !currentDraggedItem.isEmpty())
        {
            if (itemStack.areItemsEqual(itemCopy, currentDraggedItem))
            {
                if (itemCopy.canAddTo(currentDraggedItem.getCount()))
                {
                    itemCopy.increaseAmount(currentDraggedItem.getCount());
                    this.setSlotContents(itemCopy);
                    inventoryManager.setDragged(itemStack.Empty);
                }
                else
                {
                    int difference = (itemCopy.getCount() + currentDraggedItem.getCount()) - itemCopy.getItem().maxStack;
                    itemCopy.setCount(myStack.getItem().maxStack);
                    itemStack dragCopy = currentDraggedItem.copy();
                    dragCopy.setCount(difference);
                    this.setSlotContents(itemCopy);
                    inventoryManager.setDragged(dragCopy);
                }
            }
            else
            {
                itemStack currentDragCopy = currentDraggedItem.copy();
                this.setSlotContents(currentDraggedItem);
                inventoryManager.setDragged(itemCopy);
            }
        }
    }
예제 #6
0
 private void setSlotContents(itemStack stackIn)
 {
     myStack.setStack(stackIn);
     updateSlot();
 }
예제 #7
0
 public void setDragged(itemStack itemIn)
 {
     dragItem.setDraggedItem(currentDraggedItem = itemIn);
 }
예제 #8
0
 public void setDraggedItem(itemStack stackIn)
 {
     myStack = stackIn;
 }
예제 #9
0
 // makes a stack
 public void setStack(itemStack itemIn)
 {
     this.item  = itemIn.getItem();
     this.count = itemIn.getCount();
 }
예제 #10
0
 // check item stacks are equal or not, if both a and b are not empty return false
 public static bool areItemsEqual(itemStack stackA, itemStack stackB)
 {
     return(stackA == stackB ? true : (!stackA.isEmpty() && !stackB.isEmpty() ? stackA.isItemEqual(stackB) : false));
 }
예제 #11
0
 //checks if items can stack or not
 public bool isItemEqual(itemStack stackIn)
 {
     //Debug.Log("Stacking");
     return(!stackIn.isEmpty() && this.item == stackIn.getItem());
 }