예제 #1
0
 public void AddItem(InventoryItemWrapper A)
 {
     if (A == null)
     {
         return;
     }
     Debug.Assert(canAddWeight(A.Weight), "ADDED MORE WEIGHT THAN COULD CARRY!");
     TotalWeight += A.Weight;
     if (A.GetStackable() && !A.isUniqueInstance())
     {
         foreach (ItemStack B in myInventoryItems)
         {
             if (B.hasItemData(A.GetItemData()))
             {
                 B.AddItem(A);
                 return;
             }
         }
     }
     else
     {
         ItemStack myNewStack = new ItemStack();
         myNewStack.AddItem(A);
         myInventoryItems.Add(myNewStack);
     }
     SortItems();
 }
예제 #2
0
    protected override void PlantHarvested(Job job)
    {
        Debug.Log("Harvested tomato plant");

        // Install a new ungrown tomato plant, a character will have to construct (read plant) it again
        // Don't remove and replace the tile, reset the values to default!
        this.ResetPlantValues();

        // Create an itemStack with the yield of the harvest and put it
        float stackSize = UnityEngine.Random.Range(ItemValues.tomato_min_yield, ItemValues.tomato_max_yield);

        if (stackSize > 0)
        {
            // We have a yield! (probably should always have this though)
            ItemStack tomatoStack = new ItemStack(ItemFactory.GetTomato());
            stackSize--;

            // Now add tomato's so the full yield is on the tile
            while (stackSize > 0)
            {
                tomatoStack.AddItem(ItemFactory.GetTomato());
                stackSize--;
            }

            // now that we have the yield inside of a stack, try add this stack to the tile of the tomato plant.
            this.tile.AddItemStackToTile(tomatoStack);

            // TODO: try add the stack to neighbours? for now if the tile is occupied the excess tomato's are lost
        }
    }
예제 #3
0
    public ItemStack RemoveItem(int quantity)
    {
        ItemStack myRet = new ItemStack();

        for (int i = 0; i < quantity; i++)
        {
            myRet.AddItem(myStack[0]);
            myStack.RemoveAt(0);
        }
        return(myRet);
    }
예제 #4
0
    public void EquipItemFromInventory(ItemStack myWrapper)
    {
        InventoryItemWrapper myStackedItem = myWrapper.RemoveItemFromStack();

        if (myWrapper.IsEmpty())
        {
            if (!myEquipmentHandler.TryToAutoEquipItem(myStackedItem))
            {
                myWrapper.AddItem(myStackedItem);
            }
            else
            {
                RemoveItemStack(myWrapper);
            }
        }
        else
        {
            if (!myEquipmentHandler.TryToAutoEquipItem(myStackedItem))
            {
                myWrapper.AddItem(myStackedItem);
            }
        }
    }