Example #1
0
        /// <summary>
        /// Crafts the item and triggers the coroutine method to handle the crafting itself.
        /// </summary>
        public virtual bool AddBlueprintToCraftingQueue(InventoryPlayer player, CraftingCategory category, CraftingBlueprint blueprint, int amount, ItemCollectionBase storeRewardsCollection, ItemCollectionBase removeItemsFromCollection)
        {
            var craftInfo = new CraftInfo(null, validator, audioSource, category, blueprint)
            {
                storeItemsInCollection    = storeRewardsCollection,
                removeItemsFromCollection = removeItemsFromCollection,
                craftAmount = amount
            };

            return(CraftItem(player, craftInfo));
        }
Example #2
0
        public void RepaintLayout(CraftingCategory category)
        {
            if (window.isVisible == false)
            {
                return;
            }

            var blueprint = GetBlueprintFromCurrentLayout(mainItemsCollection, category);

            SetCraftingBlueprint(blueprint);
            RepaintMainItemsCollection();
        }
Example #3
0
        public override void SetCraftingCategory(CraftingCategory category)
        {
            base.SetCraftingCategory(category);

            if (category.cols * category.rows > removeItemsFromCollection.items.Length)
            {
                Debug.Log("Increasing crafting layout UI slot count");
                removeItemsFromCollection.AddSlots((uint)(category.cols * category.rows - removeItemsFromCollection.items.Length));
            }
            else if (category.cols * category.rows < removeItemsFromCollection.items.Length)
            {
                Debug.Log("Decreasing crafting layout UI slot count");
                removeItemsFromCollection.RemoveSlots((uint)(removeItemsFromCollection.items.Length - category.cols * category.rows));
            }

            RepaintLayout(category);
        }
Example #4
0
        public virtual void ValidateReferences(CraftingCategory category)
        {
            if (mainItemsCollection.useReferences == false)
            {
                return;
            }

            foreach (var wrapper in mainItemsCollection.items)
            {
                if (wrapper.item != null)
                {
                    uint count = InventoryManager.GetItemCount(wrapper.item.ID, category.alsoScanBankForRequiredItems);
                    if (count == 0)
                    {
                        wrapper.item = null;
                    }
                }
            }
        }
        public virtual void UseWithTrigger(CraftingCategory category, CraftingProgressContainer progressContainer, ICraftingActionValidator validator, ItemCollectionBase removeItemsFromCollection, ItemCollectionBase storeRewardItemsInCollection)
        {
            Assert.IsNotNull(category);
            Assert.IsNotNull(progressContainer);

            overrideRemoveItemsFromCollection    = removeItemsFromCollection;
            overrideStoreRewardItemsInCollection = storeRewardItemsInCollection;

            if (_forceSingleInstance)
            {
                this.progressContainer = new CraftingProgressContainer(this, GetInstanceID(), GetComponent <AudioSource>());
            }
            else
            {
                this.progressContainer           = progressContainer;
                this.progressContainer.validator = validator;
            }

            SetCraftingCategory(category);
            window.Show();
        }
 public virtual CraftingBlueprint[] GetBlueprints(CraftingCategory category)
 {
     return(currentCategory.blueprints);
 }
 public virtual void SetCraftingCategory(CraftingCategory category)
 {
     Assert.IsNotNull(category, "Given crafting category is null!");
     currentCategory = category;
 }
Example #8
0
        /// <summary>
        /// Tries to find a blueprint based on the current layout / items inside the UI item wrappers (items).
        /// </summary>
        /// <returns>Returns blueprint if found one, null if not.</returns>
        public virtual CraftingBlueprint GetBlueprintFromCurrentLayout(ItemCollectionBase collection, CraftingCategory category)
        {
            if (collection.items.Length != category.cols * category.rows)
            {
                Debug.LogWarning("Updating blueprint but blueprint layout cols/rows don't match the collection");
            }

            int totalItemCountInLayout = 0; // Nr of items inside the UI wrappers.

            foreach (var item in collection.items)
            {
                if (item.item != null)
                {
                    totalItemCountInLayout++;
                }
            }

            foreach (var b in GetBlueprints(category))
            {
                foreach (var a in b.blueprintLayouts)
                {
                    if (a.enabled)
                    {
                        var hasItems = new Dictionary <uint, uint>(); // ItemID, amount
                        //var requiredItems = new Dictionary<uint, uint>(); // ItemID, amount
                        currentBlueprintItemsDict.Clear();

                        int  counter         = 0; // Item index counter
                        int  shouldHaveCount = 0; // Amount we should have..
                        int  hasCount        = 0; // How many slots in our layout
                        bool matchFailed     = false;
                        foreach (var r in a.rows)
                        {
                            if (matchFailed)
                            {
                                break;
                            }

                            foreach (var c in r.columns)
                            {
                                if (c.item != null && c.amount > 0)
                                {
                                    if (currentBlueprintItemsDict.ContainsKey(c.item.ID) == false)
                                    {
                                        currentBlueprintItemsDict.Add(c.item.ID, 0);
                                    }

                                    currentBlueprintItemsDict[c.item.ID] += (uint)c.amount;
                                    shouldHaveCount++;

                                    if (collection.items[counter].item != null)
                                    {
                                        if (collection.items[counter].item.ID != c.item.ID)
                                        {
                                            matchFailed = true;
                                            break; // Item in the wrong place...
                                        }

                                        if (hasItems.ContainsKey(c.item.ID) == false)
                                        {
                                            uint itemCount = 0;
                                            if (collection.useReferences)
                                            {
                                                itemCount = InventoryManager.GetItemCount(c.item.ID, category.alsoScanBankForRequiredItems);
                                            }
                                            else
                                            {
                                                //                                                itemCount = items[counter].item.currentStackSize;
                                                itemCount = collection.GetItemCount(c.item.ID);
                                            }

                                            hasItems.Add(c.item.ID, itemCount);
                                        }

                                        hasCount++;
                                    }
                                    else if (collection.items[counter].item == null && c != null)
                                    {
                                        matchFailed = true;
                                        break;
                                    }
                                }

                                counter++;
                            }
                        }

                        if (matchFailed)
                        {
                            continue;
                        }

                        // Filled slots test
                        if (totalItemCountInLayout != hasCount || shouldHaveCount != hasCount)
                        {
                            continue;
                        }

                        // Check count
                        foreach (var item in currentBlueprintItemsDict)
                        {
                            if (hasItems.ContainsKey(item.Key) == false || hasItems[item.Key] < item.Value)
                            {
                                matchFailed = true;
                            }
                        }

                        if (matchFailed == false)
                        {
                            return(b);
                        }
                    }
                }
            }

            return(null); // Nothing found
        }
Example #9
0
 public CraftInfo(IEnumerator activeCraft, ICraftingActionValidator validator, AudioSource audioSource, CraftingCategory category, CraftingBlueprint blueprint)
 {
     this.activeCraft = activeCraft;
     this.validator   = validator;
     this.audioSource = audioSource;
     this.category    = category;
     this.blueprint   = blueprint;
     this.craftAmount = 1;
 }
        public override void SetCraftingCategory(CraftingCategory category)
        {
//            if (currentCategory == category)
//            {
//                return;
//            }

            base.SetCraftingCategory(category);

            categoryPool.DestroyAll();
            blueprintPool.DestroyAll();
            if (blueprintCraftAmountInput != null)
            {
                blueprintCraftAmountInput.text = "1"; // Reset
            }
            if (currentCategoryTitle != null)
            {
                currentCategoryTitle.text = category.name;
            }

            if (currentCategoryDescription != null)
            {
                currentCategoryDescription.text = category.description;
            }

            if (noBlueprintSelectedPage != null)
            {
                noBlueprintSelectedPage.Show();
            }

//            var blueprints = GetBlueprints(category);
//            if (blueprintCraftPage != null && blueprints.Length > 0)
//            {
//                SetBlueprint(blueprints[0]); // Select first blueprint
//                blueprintCraftPage.Show();
//            }

            ItemCategory lastItemCategory = null;
            Button       firstButton      = null;

            foreach (var b in GetBlueprints(category))
            {
                if (b.playerLearnedBlueprint == false)
                {
                    continue;
                }

                var blueprintObj = blueprintPool.Get();
                blueprintObj.transform.SetParent(blueprintsContainer);
                InventoryUtility.ResetTransform(blueprintObj.transform);
                blueprintObj.Repaint(b);

                if (blueprintCategoryPrefab != null)
                {
                    Assert.IsTrue(b.resultItems.Length > 0, "No reward items set");
                    var item = b.resultItems.First().item;
                    Assert.IsNotNull(item, "Empty reward row on blueprint!");

                    if (lastItemCategory != item.category)
                    {
                        lastItemCategory = item.category;

                        var uiCategory = categoryPool.Get();
                        uiCategory.Repaint(category, item.category);

                        uiCategory.transform.SetParent(blueprintsContainer);
                        blueprintObj.transform.SetParent(uiCategory.container);

                        InventoryUtility.ResetTransform(uiCategory.transform);
                        InventoryUtility.ResetTransform(blueprintObj.transform);
                    }
                }

                if (firstButton == null)
                {
                    firstButton = blueprintObj.button;
                }

                var bTemp = b; // Store capture list, etc.
                blueprintObj.button.onClick.AddListener(() =>
                {
                    currentBlueprint = bTemp;
                    SetCraftingBlueprint(currentBlueprint);

                    if (blueprintCraftPage != null && blueprintCraftPage.isVisible == false)
                    {
                        blueprintCraftPage.Show();
                    }
                });
            }

            if (firstButton != null)
            {
                firstButton.Select();
            }
        }
 public override CraftingBlueprint[] GetBlueprints(CraftingCategory category)
 {
     return(currentCategory.blueprints.Where(o => o.playerLearnedBlueprint).ToArray());
 }