コード例 #1
0
 public void AddItem(InventoryItemStack pItem, InventoryUI pFrom)
 {
     if (Station != null)
     {
         Station.AddItem(pItem.ContainedItem);
     }
 }
コード例 #2
0
    public void Interact()
    {
        if (SupplySlots.Count <= 0)
        {
            return;
        }
        InventoryItemStack currentItem = Toolbar.Instance.SelectedSlot.ReferencedItemStack;

        if (currentItem == null)
        {
            return;
        }
        BuildingMaterial currentSlot = new BuildingMaterial();
        bool             foundSlot   = false;
        int i = 0;

        for (i = i; i < SupplySlots.Count - 1; i++)
        {
            if (SupplySlots[i].ContainedItem.ID == currentItem.ContainedItem.ID)
            {
                if (SupplySlots[i].CurrentAmount >= SupplySlots[i].TargetAmount)
                {
                    return;
                }
                break;
            }
        }
        currentSlot = SupplySlots[i];
        currentSlot.CurrentAmount += 1;
        SupplySlots[i]             = currentSlot;
        FindObjectOfType <PlayerInventory>().RemoveFromStack(currentItem);
    }
コード例 #3
0
    public uint RemoveFromStack(InventoryItemStack itemStack, uint amount = 1)
    {
        uint i = 0;

        for (i = 0; i < amount; i++)
        {
            itemStack.Remove(1);
            CurrentWeight -= itemStack.ContainedItem.Weight;
            if (itemStack.Amount <= 0)
            {
                itemStack.Delete();
                ContainedStacks.Remove(itemStack);
                i++;
                break;
            }
        }
        if (OnItemChanged != null)
        {
            OnItemChanged();
        }
        for (i = 0; i < amount; i++)
        {
            PixelCrushers.MessageSystem.SendMessage(gameObject, "LoseItem", itemStack.ContainedItem.Name);
        }
        return(i);
    }
コード例 #4
0
    public void Setup(List <BuildingMaterial> pMaterials, ConstructionSite pSite)
    {
        Site = pSite;
        ConfirmButton.interactable = true;

        SupplySlotUI[] children = ItemsContainer.GetComponentsInChildren <SupplySlotUI>();

        foreach (SupplySlotUI child in children)
        {
            if (child != ItemsContainer.transform)
            {
                Destroy(child.gameObject);
            }
        }

        foreach (BuildingMaterial material in pMaterials)
        {
            InventoryItemStack boxStack = Site.Box.FindItemStack(material.ContainedItem);
            int amount = 0;
            if (boxStack != null)
            {
                amount = boxStack.Amount;
            }
            SupplySlotUI slot = Instantiate(SlotUI, ItemsContainer.transform);
            slot.ItemIcon.sprite = material.ContainedItem.Icon;
            slot.NameText.text   = material.ContainedItem.Name;
            slot.AmountText.text = amount + "/" + material.TargetAmount;
            if (boxStack == null || boxStack.Amount < material.TargetAmount)
            {
                ConfirmButton.interactable = false;
            }
        }

        GetComponent <WindowToggle>().Toggle();
    }
コード例 #5
0
ファイル: StoreUI.cs プロジェクト: MarieNielly/Blossom-Island
 public void RemoveFromBasket(InventoryItemStack pStack)
 {
     StoreInventory.Add(pStack.ContainedItem, 1);
     BasketInventory.RemoveFromStack(pStack, 1);
     DrawStore();
     DrawBasket();
 }
コード例 #6
0
    public void DropItem(InventoryItemStack itemStack, uint amount = 1)
    {
        uint    DropAmount = RemoveFromStack(itemStack, amount);
        Vector3 newPos     = transform.position;

        newPos.y -= 0.16f;
        ItemSpawner.Instance.SpawnItems(itemStack.ContainedItem, newPos, DropAmount);
    }
コード例 #7
0
 private void UseRecipe(ItemRecipe pItem, InventoryItemStack pStack)
 {
     if (CraftingManager.Instance.TeachRecipe(pItem.Recipe.UniqueName))
     {
         if (pItem.Consumable == true)
         {
             PlayerInventory.RemoveFromStack(pStack, 1);
         }
     }
 }
コード例 #8
0
    public void ChangeItem(InventoryItemStack pItemStack)
    {
        if (pItemStack != null)
        {
            return;
        }
        //	print (pItemStack);
        //If an item stack is specified
        if (pItemStack != null && pItemStack.Amount > 0)
        {
            // If the slot already referenced an item stack, unsubscribe from its item change
            if (ReferencedItemStack != null)
            {
                ReferencedItemStack.OnItemChanged -= UpdateItem;
            }
            // Set the reference stack to the specified stack and subscribe to its item change event
            ReferencedItemStack = pItemStack;
            ReferencedItemStack.OnItemChanged += UpdateItem;

            UpdateVisuals();

            // If stack was referenced by another slot, remove the reference
            foreach (ToolbarSlotUI slot in Toolbar.Instance.Slots)
            {
                if (slot != this && slot.ReferencedItemStack == this.ReferencedItemStack)
                {
                    slot.ChangeItem(null);
                }
            }
        }
        else if (pItemStack == null || pItemStack.Amount <= 0)
        {
            // unsubscribe from item change event
            if (ReferencedItemStack != null)
            {
                ReferencedItemStack.OnItemChanged -= UpdateItem;
            }

            //		print(gameObject.name + " set null item stack ref");
            // remove reference and update visuals
            ReferencedItemStack = null;
            UpdateVisuals();
        }

        //		if (ReferencedItemStack != null) {
        //			Tool.GridItem = ItemSystemUtility.GetItemCopy (ReferencedItemStack.Item.itemID, ItemType.GridItem) as ItemGrid;
        //		} else {
        //			Tool.GridItem = null;
        //		}
        // Call item change event
        if (OnSlotItemChanged != null)
        {
            OnSlotItemChanged();
        }
    }
コード例 #9
0
    private void UseFood(ItemFood pItem, InventoryItemStack pStack)
    {
        PixelCrushers.MessageSystem.SendMessage(GameManager.Instance.Player, "EatItem", pStack.ContainedItem.Name);

        PlayerNeedManager.Instance.GetNeed("Energy").Change(pItem.EnergyRegen);

        if (pItem.Consumable == true)
        {
            PlayerInventory.RemoveFromStack(pStack, 1);
        }
    }
コード例 #10
0
    public void AddFuel(InventoryItemStack pItemStack)
    {
        ItemMaterial item = pItemStack.ContainedItem as ItemMaterial;

        MinutesLeft = Mathf.Clamp(MinutesLeft += item.BurnTime, 0, 10000f);
        FindObjectOfType <PlayerInventory>().RemoveFromStack(pItemStack, 1);

        if (WoodSprite != null)
        {
            WoodSprite.SetActive(true);
        }
    }
コード例 #11
0
ファイル: Hut.cs プロジェクト: MarieNielly/Blossom-Island
        public void Interact()
        {
            InventoryItemStack stack = Toolbar.Instance.SelectedSlot.ReferencedItemStack;

            if (stack != null)
            {
                ItemBase item = stack.ContainedItem;
                if (item.Type == ItemSystem.ItemTypes.Food && (item as ItemFood).BlossomFeed == true)
                {
                    FillBowl(item as ItemFood);
                }
            }
        }
コード例 #12
0
 public bool CheckMaterials()
 {
     foreach (BuildingMaterial material in Building.Materials)
     {
         InventoryItemStack boxStack = Box.FindItemStack(material.ContainedItem);
         if (boxStack == null)
         {
             return(false);
         }
         if (boxStack.Amount < material.TargetAmount)
         {
             return(false);
         }
     }
     return(true);
 }
コード例 #13
0
    void DrawItem(InventoryItemStack pStack)
    {
        if (pStack != null)
        {
            ItemUIPrefab.GetComponent <Button>().interactable = true;
            ItemUIPrefab.ItemIcon.color = Color.white;

            ItemUIPrefab.ItemIcon.sprite = pStack.ContainedItem.Icon;
            ItemUIPrefab.ItemAmount.text = pStack.Amount.ToString();
        }
        else
        {
            ItemUIPrefab.GetComponent <Button>().interactable = false;
            ItemUIPrefab.ItemIcon.color  = new Color(0, 0, 0, 0);
            ItemUIPrefab.ItemAmount.text = "";
        }

        ItemStackUI itemUI = Instantiate(ItemUIPrefab, ItemUIContainer);

        itemUI.Button    = itemUI.GetComponent <Button>();
        itemUI.ItemStack = pStack;

        DrawnItems.Add(itemUI);
        itemUI.Button.onClick.AddListener(delegate
        {
            SetSelectedItem(pStack);
        });


        if (TransferUI != null && TransferUI.IsOpen)
        {
            itemUI.Button.onClick.AddListener(delegate
            {
                TransferUI.TransferItem(pStack, this);
            });
        }

        else if (CraftingInputUI != null && CraftingInputUI.IsOpen)
        {
            itemUI.Button.onClick.AddListener(delegate
            {
                CraftingInputUI.AddItem(pStack, this);
            });
        }
    }
コード例 #14
0
    private void UseBottle(ItemBottle pItem, InventoryItemStack pStack)
    {
        if (pItem.HeldLiquid == null)
        {
            return;
        }
        //remove liquid
        pItem.CurrentCharge--;
        //use liquid
        UseFood(pItem.HeldLiquid, pStack);

        if (pItem.CurrentCharge == 0)
        {
            PlayerInventory.RemoveFromStack(Toolbar.Instance.SelectedSlot.ReferencedItemStack, 1);
            ItemBottle newBottle = ItemSystem.Instance.GetItemClone("Empty Bottle") as ItemBottle;
            ItemSpawner.Instance.SpawnItems(newBottle, Player.transform.position, 1);
        }
    }
コード例 #15
0
    public bool CheckIncreaseIngredientAmount(StationItem pItem, int pAmount)
    {
        if (pItem == null)
        {
            return(false);
        }
        InventoryItemStack stack = GameManager.Instance.Player.GetComponent <PlayerInventory>().FindItemStack(pItem.ContainedItem);

        if (stack == null)
        {
            return(false);
        }
        if (stack.Amount >= pItem.Amount + pAmount)
        {
            return(true);
        }
        return(false);
    }
コード例 #16
0
    public void DoTransfer()
    {
        if (From.SelectedItem == null || From.SelectedItem.ID == 0)
        {
            return;
        }
        ItemBase           item          = ItemSystem.Instance.GetItemClone(From.SelectedItem.ID);
        InventoryItemStack selectedStack = From.SelectedStack;


        int amountAdded = To.CurrentStorage.Add(item, (uint)Amount);
        int amountLeft  = (int)Amount - amountAdded;

        if (amountLeft > 0)
        {
            // Debug.LogWarning("Could not add " + amountLeft + " " + item.itemName + " to storage: " + To.CurrentStorage.Name);
        }
    }
コード例 #17
0
 public void UseItem(InventoryItemStack pStack)
 {
     if (pStack.ContainedItem.UsableFromToolbar == false)
     {
         return;
     }
     PixelCrushers.MessageSystem.SendMessage(GameManager.Instance.Player, "UseItem", pStack.ContainedItem.Name);
     if (pStack.ContainedItem is ItemBottle)
     {
         UseBottle(pStack.ContainedItem as ItemBottle, pStack);
     }
     if (pStack.ContainedItem is ItemFood)
     {
         UseFood(pStack.ContainedItem as ItemFood, pStack);
     }
     if (pStack.ContainedItem is ItemRecipe)
     {
         UseRecipe(pStack.ContainedItem as ItemRecipe, pStack);
     }
 }
コード例 #18
0
    public void TransferItem(InventoryItemStack pStack, InventoryUI pFrom)
    {
        InventoryUI from = pFrom;
        InventoryUI to;

        if (StorageUI == from)
        {
            to = PlayerInventoryUI;
        }
        else
        {
            to = StorageUI;
        }
        int amount = 1;

        if (Input.GetButton("Toggle 1"))
        {
            amount = pStack.Amount;
        }

        if (from.SelectedItem == null || from.SelectedItem.ID == 0)
        {
            return;
        }
        ItemBase           item          = ItemSystem.Instance.GetItemClone(pStack.ContainedItem.ID);
        InventoryItemStack selectedStack = pStack;


        int amountAdded = to.CurrentStorage.Add(item, (uint)amount);
        int amountLeft  = amount - amountAdded;

        if (amountLeft > 0)
        {
            //inventory full
        }

        from.CurrentStorage.RemoveFromStack(selectedStack, (uint)amountAdded);
    }
コード例 #19
0
    public void SetSelectedItem(InventoryItemStack pStack)
    {
        if (pStack != null)
        {
            SelectedItem = pStack.ContainedItem;
        }
        else
        {
            SelectedItem = null;
        }

        if (SelectedItem == null)
        {
            SelectedItem  = new ItemBase();
            SelectedStack = null;
        }

        if (SelectedItem.ID != -1)
        {
            foreach (ItemStackUI itemUI in DrawnItems)
            {
                if (itemUI.ItemStack == null || itemUI.ItemStack.ContainedItem.ID != SelectedItem.ID)
                {
                    itemUI.FrameImage.enabled = false;
                }
                else
                {
                    SelectedStack = itemUI.ItemStack;
                    itemUI.GetComponent <Button>().Select();
                    itemUI.FrameImage.enabled = true;
                }
            }
        }


        DrawSelectedItemInfo();
    }
コード例 #20
0
    //Check if inventory items have changed since last open
    public void AdjustAmounts()
    {
        foreach (StationItem item in ChosenItems)
        {
            StorageObject      Inventory = GameManager.Instance.Player.GetComponent <PlayerInventory>();
            InventoryItemStack stack     = Inventory.FindItemStack(item.ContainedItem);
            int itemAmount = Inventory.GetItemAmount(item.ContainedItem);

            if (itemAmount < 1)
            {
                RemoveItem(item.ContainedItem);
                return;
            }
            if (item.Amount > itemAmount)
            {
                int amt = item.Amount - itemAmount;
                amt = Mathf.Abs(amt);
                for (int i = 0; i < amt; i++)
                {
                    DecreaseIngredientAmount(item);
                }
            }
        }
    }
コード例 #21
0
    void CheckItems(StorageObject pInventory)
    {
        if (pInventory == null)
        {
            return;
        }
        if (pInventory.UniqueID == InventoryID)
        {
            foreach (ContainedItem wantedTtem in WantedItems)
            {
                InventoryItemStack stack = pInventory.FindItemStack(wantedTtem.Item);
                if (stack == null)
                {
                    return;
                }
                else if (stack.Amount < wantedTtem.Amount)
                {
                    return;
                }
            }

            Event.Invoke();
        }
    }
コード例 #22
0
    public void DropItems(int pAmount = 1)
    {
        InventoryItemStack stack = SelectedStack;

        CurrentStorage.DropItem(stack, (uint)pAmount);
    }
コード例 #23
0
    public virtual int Add(ItemBase pItem, uint pAmount, bool pDropLeftOvers = false)
    {
        if (IsSellChest == false && pItem.Name == "Coin")
        {
            return(0);
        }
        int amountToAdd = (int)pAmount;

        //don't add more than weight allows

        if (pItem.Weight > 0)
        {
            amountToAdd = Mathf.FloorToInt((MaxWeight - CurrentWeight) / pItem.Weight);
        }

        //don't add more than requested
        amountToAdd = (int)Mathf.Clamp(amountToAdd, 0f, pAmount);


        //        print("Can add amount if stacks allow: " + amountToAdd);
        // If weight cannot be added, return false
        if (amountToAdd < 1)
        {
            DialogueManager.ShowAlert("Inventory can't contain 1.");
            return(0);
        }
        int amountLeft  = amountToAdd;
        int amountAdded = 0;

        //Check for an existing stack
        InventoryItemStack existingStack = FindItemStack(pItem.ID);


        //if there exists a stack, add as much to it as possible
        if (existingStack != null)
        {
            //            print("existing stack");
            int maxAmt = MaxStackAmount - existingStack.Amount;
            amountAdded = Mathf.Clamp(amountToAdd, 0, maxAmt);
            existingStack.Add(amountAdded);
            amountLeft -= amountAdded;
        }

        //if there are still items to add, determine how many stacks are needed, then create as many as possible, while adding as much as possible to them until there are no more items.
        //If the stack space runs out, return the amount added.

        if (amountLeft > 0)
        {
            //            print("amount left: " + amountToAdd);
            int stacksLeft     = MaxStacks - ContainedStacks.Count;
            int requiredStacks = Mathf.CeilToInt((float)amountLeft / (float)MaxStackAmount);
            //   print("required stacks: " + requiredStacks);
            //
            //            print("free stacks: " + stacksLeft);

            if (requiredStacks > stacksLeft)
            {
                requiredStacks = stacksLeft;
            }
            for (int i = 0; i < requiredStacks; i++)
            {
                InventoryItemStack newItemStack = new InventoryItemStack();
                newItemStack.ContainedItem = pItem.Clone(pItem);
                int newAmt = Mathf.Clamp(amountLeft, 0, MaxStackAmount);
                newItemStack.Amount = newAmt;
                amountAdded        += newAmt;
                ContainedStacks.Add(newItemStack);
                amountLeft -= newAmt;
            }
        }
        if (OnItemChanged != null)
        {
            OnItemChanged();
        }

        if (OnAddItem != null)
        {
            OnAddItem(this);
        }
        CurrentWeight += pItem.Weight * amountAdded;

        if (pDropLeftOvers)
        {
            DropLeftOvers(pItem, amountLeft);
        }
        return(amountAdded);
    }