コード例 #1
0
        /// <summary>
        /// Does the inventory contain the required items?
        /// </summary>
        /// <param name="blueprint"></param>
        /// <param name="alsoScanBank"></param>
        /// <param name="craftCount"></param>
        /// <returns></returns>
        public virtual bool CanCraftBlueprint(InventoryCraftingBlueprint blueprint, bool alsoScanBank, int craftCount)
        {
            // Layout can only be triggered if one is visible -> selected. So no need to check it here.


            if (InventoryManager.instance.inventory.gold < blueprint.craftCostPrice * craftCount)
            {
                InventoryManager.instance.lang.userNotEnoughGold.Show(blueprint.itemResult.name, blueprint.itemResult.description, craftCount, blueprint.craftCostPrice * craftCount, InventoryManager.instance.inventory.gold);
                return(false);
            }

            // Can the items be stored in the inventory / designated spot?
            if (currentCategory.forceSaveInCollection != null)
            {
                bool added = currentCategory.forceSaveInCollection.CanAddItem(blueprint.itemResult);
                if (added == false)
                {
                    return(false);
                }
            }
            else
            {
                bool added = InventoryManager.CanAddItem(blueprint.itemResult);
                if (added == false)
                {
                    return(false);
                }
            }

            return(true);
        }
コード例 #2
0
        protected virtual void SetBlueprint(InventoryCraftingBlueprint blueprint)
        {
            currentBlueprint = blueprint;

            // Set all the details for the blueprint.
            if (blueprintTitle != null)
            {
                blueprintTitle.text = blueprint.name;
            }

            if (blueprintDescription != null)
            {
                blueprintDescription.text = blueprint.description;
            }

            SetBlueprintResult(blueprint);

            if (blueprintCraftCostText != null)
            {
                if (InventoryManager.instance.inventory.gold < blueprint.craftCostPrice)
                {
                    blueprintCraftCostText.color = notEnoughGoldColor;
                }
                else
                {
                    blueprintCraftCostText.color = enoughGoldColor;
                }

                blueprintCraftCostText.text = InventorySettingsManager.instance.currencyFormatter.Format(blueprint.craftCostPrice);
            }
        }
        protected virtual bool CraftItem(InventoryCraftingCategory category, InventoryCraftingBlueprint blueprint, int amount)
        {
            if (activeCraft != null)
            {
                return(false); // Already crafting
            }
            activeCraft = _CraftItem(category, blueprint, amount, blueprint.craftingTimeDuration);
            StartCoroutine(activeCraft);

            return(true);
        }
        public void Set(InventoryCraftingBlueprint blueprint)
        {
            if (blueprintName != null)
            {
                blueprintName.text = blueprint.name;
            }

            if (blueprintDescription != null)
            {
                blueprintDescription.text = blueprint.description;
            }
        }
        /// <summary>
        /// Does the inventory contain the required items?
        /// </summary>
        /// <param name="blueprint"></param>
        /// <param name="alsoScanBank"></param>
        /// <param name="craftCount"></param>
        /// <returns></returns>
        public virtual bool CanCraftBlueprint(InventoryCraftingBlueprint blueprint, bool alsoScanBank, int craftCount)
        {
            foreach (var item in blueprint.requiredItems)
            {
                uint count = InventoryManager.GetItemCount(item.item.ID, alsoScanBank);
                if (count < item.amount * craftCount)
                {
                    InventoryManager.instance.lang.craftingDontHaveRequiredItems.Show(item.item.name, item.item.description, blueprint.name);
                    return(false);
                }
            }

            if (InventoryManager.instance.inventory.gold < blueprint.craftCostPrice * craftCount)
            {
                InventoryManager.instance.lang.userNotEnoughGold.Show(blueprint.itemResult.name, blueprint.itemResult.description, craftCount, blueprint.craftCostPrice * craftCount, InventoryManager.instance.inventory.gold);
                return(false);
            }

            // Can the items be stored in the inventory / designated spot?
            if (currentCategory.forceSaveInCollection != null)
            {
                bool added = currentCategory.forceSaveInCollection.CanAddItem(blueprint.itemResult);
                if (added == false)
                {
                    return(false);
                }
            }
            else
            {
                bool added = InventoryManager.CanAddItem(blueprint.itemResult);
                if (added == false)
                {
                    return(false);
                }
            }

            return(true);
        }
コード例 #6
0
        protected virtual void SetBlueprintResult(InventoryCraftingBlueprint blueprint)
        {
            if (blueprintItemResult != null)
            {
                if (blueprint != null)
                {
                    blueprintItemResult.item = blueprint.itemResult;
                    blueprintItemResult.item.currentStackSize = (uint)blueprint.itemResultCount;
                    blueprintItemResult.Repaint();
                    blueprintItemResult.item.currentStackSize = 1; // Reset
                }
                else
                {
                    bool nullBefore = blueprintItemResult.item == null;
                    blueprintItemResult.item = null;

                    if (nullBefore == false)
                    {
                        blueprintItemResult.Repaint();
                    }
                }
            }
        }
        private IEnumerator _CraftItem(InventoryCraftingCategory category, InventoryCraftingBlueprint blueprint, int amount, float currentCraftTime)
        {
            bool canCraft = CanCraftBlueprint(blueprint, category.alsoScanBankForRequiredItems, amount);

            if (canCraft)
            {
                float counter = currentCraftTime;
                while (true)
                {
                    yield return(new WaitForSeconds(Time.deltaTime)); // Update loop

                    counter -= Time.deltaTime;
                    NotifyCraftProgress(category, blueprint, 1.0f - Mathf.Clamp01(counter / currentCraftTime));

                    if (counter <= 0.0f)
                    {
                        break;
                    }
                }


                // Remove items from inventory
                foreach (var item in blueprint.requiredItems)
                {
                    InventoryManager.RemoveItem(item.item.ID, (uint)item.amount, category.alsoScanBankForRequiredItems); //  * GetCraftInputFieldAmount()
                }

                // Remove gold
                InventoryManager.instance.inventory.gold -= blueprint.craftCostPrice;

                if (blueprint.successChanceFactor >= Random.value)
                {
                    // Store crafted item
                    var c = GameObject.Instantiate <InventoryItemBase>(blueprint.itemResult);
                    c.currentStackSize = (uint)(blueprint.itemResultCount); //  * GetCraftInputFieldAmount()
                    if (category.forceSaveInCollection != null)
                    {
                        category.forceSaveInCollection.AddItem(c);
                    }
                    else
                    {
                        InventoryManager.AddItem(c);
                    }

                    InventoryManager.instance.lang.craftedItem.Show(blueprint.itemResult.name, blueprint.itemResult.description);

                    if (OnCraftSuccess != null)
                    {
                        OnCraftSuccess(category, blueprint, c);
                    }
                }
                else
                {
                    InventoryManager.instance.lang.craftingFailed.Show(blueprint.itemResult.name, blueprint.itemResult.description);

                    if (OnCraftFailed != null)
                    {
                        OnCraftFailed(category, blueprint);
                    }
                }

                amount--;

                if (amount > 0)
                {
                    if (blueprintCraftAmountInput != null)
                    {
                        blueprintCraftAmountInput.text = amount.ToString();
                    }

                    activeCraft = _CraftItem(category, blueprint, amount, Mathf.Clamp(currentCraftTime / blueprint.craftingTimeSpeedupFactor, 0.0f, blueprint.craftingTimeDuration));
                    StartCoroutine(activeCraft);
                }
                else
                {
                    activeCraft = null; // All done
                }
            }
            else
            {
                //StopCoroutine(activeCraft);
                activeCraft = null;
            }
        }
        /// <summary>
        /// Called when an item is being crafted.
        /// </summary>
        /// <param name="progress"></param>
        protected virtual void NotifyCraftProgress(InventoryCraftingCategory category, InventoryCraftingBlueprint blueprint, float progress)
        {
            currentCraftProgress = progress;
            if (blueprintCraftProgressSlider != null)
            {
                blueprintCraftProgressSlider.value = currentCraftProgress;
            }

            if (OnCraftProgress != null)
            {
                OnCraftProgress(category, blueprint, progress);
            }
        }
        protected virtual void SetBlueprint(InventoryCraftingBlueprint blueprint)
        {
            if (window.isVisible == false)
            {
                return;
            }

            // Set all the details for the blueprint.
            if (blueprintTitle != null)
            {
                blueprintTitle.text = blueprint.name;
            }

            if (blueprintDescription != null)
            {
                blueprintDescription.text = blueprint.description;
            }

            if (blueprintIcon != null)
            {
                blueprintIcon.item = blueprint.itemResult;
                blueprintIcon.item.currentStackSize = (uint)blueprint.itemResultCount;
                blueprintIcon.Repaint();
                blueprintIcon.item.currentStackSize = 1; // Reset
            }

            if (blueprintCraftProgressSlider)
            {
                blueprintCraftProgressSlider.value = 0.0f; // Reset
            }
            if (blueprintCraftCostText != null)
            {
                if (InventoryManager.instance.inventory.gold < blueprint.craftCostPrice)
                {
                    blueprintCraftCostText.color = itemsNotAvailableColor;
                }
                else
                {
                    blueprintCraftCostText.color = itemsAvailableColor;
                }

                blueprintCraftCostText.text = InventorySettingsManager.instance.currencyFormatter.Format(blueprint.craftCostPrice);
            }

            blueprintRequiredItemsPool.DestroyAll();
            foreach (var item in blueprint.requiredItems)
            {
                var ui = blueprintRequiredItemsPool.Get();
                item.item.currentStackSize = (uint)item.amount;
                ui.transform.SetParent(blueprintRequiredItemsContainer);
                ui.item = item.item;
                if (InventoryManager.GetItemCount(item.item.ID, currentCategory.alsoScanBankForRequiredItems) >= item.amount)
                {
                    ui.icon.color = itemsAvailableColor;
                }
                else
                {
                    ui.icon.color = itemsNotAvailableColor;
                }

                ui.Repaint();
                item.item.currentStackSize = 1; // Reset
            }
        }
コード例 #10
0
        private IEnumerator _CraftItem(InventoryCraftingCategory category, InventoryCraftingBlueprint blueprint, int amount, float currentCraftTime)
        {
            bool canCraft = CanCraftBlueprint(blueprint, category.alsoScanBankForRequiredItems, amount);

            if (canCraft)
            {
                float counter = currentCraftTime;
                while (true)
                {
                    yield return(new WaitForSeconds(Time.deltaTime)); // Update loop

                    counter -= Time.deltaTime;
                    NotifyCraftProgress(category, blueprint, 1.0f - Mathf.Clamp01(counter / currentCraftTime));

                    if (counter <= 0.0f)
                    {
                        break;
                    }
                }


                // Remove items from inventory
                uint[] keys = currentBlueprintItemsDict.Keys.ToArray();
                uint[] vals = currentBlueprintItemsDict.Values.ToArray();
                for (int i = 0; i < keys.Length; i++)
                {
                    InventoryManager.RemoveItem(keys[i], vals[i], category.alsoScanBankForRequiredItems); //  * GetCraftInputFieldAmount()
                }

                for (int i = 0; i < keys.Length; i++)
                {
                    uint c = InventoryManager.GetItemCount(keys.ElementAt(i), category.alsoScanBankForRequiredItems);
                    foreach (var item in items)
                    {
                        if (item.item != null && c == 0)
                        {
                            item.item = null;
                            item.Repaint();
                        }
                    }
                }


                // Remove gold
                InventoryManager.instance.inventory.gold -= blueprint.craftCostPrice;

                if (blueprint.successChanceFactor >= Random.value)
                {
                    // Store crafted item
                    var c = GameObject.Instantiate <InventoryItemBase>(blueprint.itemResult);
                    c.currentStackSize = (uint)(blueprint.itemResultCount); //  * GetCraftInputFieldAmount()
                    if (category.forceSaveInCollection != null)
                    {
                        category.forceSaveInCollection.AddItem(c);
                    }
                    else
                    {
                        InventoryManager.AddItem(c);
                    }

                    InventoryManager.instance.lang.craftedItem.Show(blueprint.itemResult.name, blueprint.itemResult.description);

                    if (OnCraftSuccess != null)
                    {
                        OnCraftSuccess(category, blueprint, c);
                    }
                }
                else
                {
                    InventoryManager.instance.lang.craftingFailed.Show(blueprint.itemResult.name, blueprint.itemResult.description);

                    if (OnCraftFailed != null)
                    {
                        OnCraftFailed(category, blueprint);
                    }
                }

                amount--;
                currentBlueprintItemsDict.Clear();

                if (amount > 0)
                {
                    activeCraft = _CraftItem(category, blueprint, amount, Mathf.Clamp(currentCraftTime / blueprint.craftingTimeSpeedupFactor, 0.0f, blueprint.craftingTimeDuration));
                    StartCoroutine(activeCraft);
                }
                else
                {
                    activeCraft = null; // All done
                }
            }
            else
            {
                //StopCoroutine(activeCraft);
                activeCraft = null;
            }
        }