public void Set(InventoryCraftingBlueprint blueprint) { if(blueprintName != null) blueprintName.text = blueprint.name; if (blueprintDescription != null) blueprintDescription.text = blueprint.description; }
//public AnimationClip successAnimation; //public AnimationClip failedAnimation; //public AnimationClip canceledAnimation; #region Notifies public virtual void NotifyCraftSuccess(InventoryCraftingCategory category, InventoryCraftingBlueprint blueprint, InventoryItemBase result) { InventoryManager.instance.lang.craftedItem.Show(blueprint.itemResult.name, blueprint.itemResult.description); if (successCraftItem != null) InventoryUtility.AudioPlayOneShot(successCraftItem); if (OnCraftSuccess != null) OnCraftSuccess(category, blueprint, result); }
public void OnCraftFailed(InventoryCraftingCategory category, InventoryCraftingBlueprint blueprint) { if (onCraftingFailed.Count > 0) { RunEvents(onCraftingFailed, new plyEventArg("itemID", (int)blueprint.itemResult.ID), new plyEventArg("category", category), new plyEventArg("categoryID", (int)category.ID), new plyEventArg("blueprint", blueprint), new plyEventArg("blueprintID", (int)blueprint.ID)); } }
public void OnCraftProgress(InventoryCraftingCategory category, InventoryCraftingBlueprint blueprint, float progress) { if (onCraftingProgress.Count > 0) { RunEvents(onCraftingProgress, new plyEventArg("itemID", (int)blueprint.itemResult.ID), new plyEventArg("category", category), new plyEventArg("categoryID", (int)category.ID), new plyEventArg("blueprint", blueprint), new plyEventArg("blueprintID", (int)blueprint.ID), new plyEventArg("progress", progress)); } }
public void OnCraftSuccess(InventoryCraftingCategory category, InventoryCraftingBlueprint blueprint, InventoryItemBase result) { if (onCraftingSuccess.Count > 0) { RunEvents(onCraftingSuccess, new plyEventArg("item", result), new plyEventArg("itemID", (int)result.ID), new plyEventArg("category", category), new plyEventArg("categoryID", (int)category.ID), new plyEventArg("blueprint", blueprint), new plyEventArg("blueprintID", (int)blueprint.ID)); } }
/// <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) { if (InventoryManager.CanRemoveCurrency(blueprint.craftingCost, true, alsoScanBank) == false) { InventoryManager.instance.lang.userNotEnoughGold.Show(blueprint.itemResult.name, blueprint.itemResult.description, craftCount, blueprint.craftingCost.GetFormattedString(craftCount)); 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) { InventoryManager.instance.lang.collectionFull.Show(blueprint.itemResult.name, blueprint.itemResult.description, currentCategory.forceSaveInCollection.collectionName); return false; } } else { bool added = InventoryManager.CanAddItem(blueprint.itemResult); if (added == false) { InventoryManager.instance.lang.collectionFull.Show(blueprint.itemResult.name, blueprint.itemResult.description, "Inventory"); return false; } } return true; }
public virtual void NotifyCraftCanceled(InventoryCraftingCategory category, InventoryCraftingBlueprint blueprint, float progress) { InventoryManager.instance.lang.craftingCanceled.Show(currentBlueprint.itemResult.name, currentBlueprint.itemResult.description); activeCraft = null; if (canceledCraftItem != null) InventoryUtility.AudioPlayOneShot(canceledCraftItem); if (OnCraftCanceled != null) OnCraftCanceled(currentCategory, currentBlueprint, currentCraftProgress); }
public void OnCraftFailed(InventoryCraftingCategory category, InventoryCraftingBlueprint blueprint) { if (eventHandler != null) eventHandler.OnCraftFailed(category, blueprint); }
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(); } } }
/// <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); }
public override bool CanCraftBlueprint(InventoryCraftingBlueprint blueprint, bool alsoScanBank, int craftCount) { bool can = base.CanCraftBlueprint(blueprint, alsoScanBank, craftCount); if (can == false) return false; 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; } } return true; }
protected virtual bool GiveCraftReward(InventoryCraftingCategory category, InventoryCraftingBlueprint blueprint) { if (blueprint.successChanceFactor >= UnityEngine.Random.value) { // Store crafted item var c = GameObject.Instantiate<InventoryItemBase>(blueprint.itemResult); c.currentStackSize = (uint)(blueprint.itemResultCount); // * GetCraftInputFieldAmount() if (category.forceSaveInCollection != null) { bool added = category.forceSaveInCollection.AddItem(c); if (added == false) return false; } else { bool added = InventoryManager.AddItem(c); if(added == false) return false; } NotifyCraftSuccess(category, blueprint, c); return true; } NotifyCraftFailed(category, blueprint); return false; }
protected override 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; } RemoveRequiredCraftItems(category, blueprint); GiveCraftReward(category, blueprint); amount--; currentBlueprintItemsDict.Clear(); ValidateReferences(); 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; } }
protected override void RemoveRequiredCraftItems(InventoryCraftingCategory category, InventoryCraftingBlueprint blueprint) { // 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() } // Remove gold InventoryManager.RemoveCurrency(blueprint.craftingCost); }
/// <summary> /// Called when an item is being crafted. /// </summary> /// <param name="progress"></param> public override void NotifyCraftProgress(InventoryCraftingCategory category, InventoryCraftingBlueprint blueprint, float progress) { base.NotifyCraftProgress(category, blueprint, progress); if (blueprintCraftProgressSlider != null) blueprintCraftProgressSlider.value = progress; }
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 (blueprintCraftCost != null) { blueprintCraftCost.Repaint(blueprint.craftingCost); } }
protected virtual IEnumerator _CraftItem(InventoryCraftingCategory category, InventoryCraftingBlueprint blueprint, int amount, float currentCraftTime) { // Override me! return null; }
public virtual void NotifyCraftFailed(InventoryCraftingCategory category, InventoryCraftingBlueprint blueprint) { InventoryManager.instance.lang.craftingFailed.Show(blueprint.itemResult.name, blueprint.itemResult.description); if (failedCraftItem != null) InventoryUtility.AudioPlayOneShot(failedCraftItem); if (OnCraftFailed != null) OnCraftFailed(category, blueprint); }
protected virtual void RemoveRequiredCraftItems(InventoryCraftingCategory category, InventoryCraftingBlueprint blueprint) { // Remove items from inventory foreach (var item in blueprint.requiredItems) InventoryManager.RemoveItem(item.item.ID, (uint)item.amount, category.alsoScanBankForRequiredItems); // * GetCraftInputFieldAmount() // Remove gold InventoryManager.RemoveCurrency(blueprint.craftingCost); }
/// <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; }
/// <summary> /// Does the inventory contain the required items? /// </summary> /// <param name="blueprint"></param> /// <param name="alsoScanBank"></param> /// <param name="craftCount"></param> /// <returns></returns> public override bool CanCraftBlueprint(InventoryCraftingBlueprint blueprint, bool alsoScanBank, int craftCount) { bool can = base.CanCraftBlueprint(blueprint, alsoScanBank, craftCount); if (can == false) return false; // No blueprint found if (GetBlueprintFromCurrentLayout(currentCategory) == null) return false; return true; }
public void OnCraftCanceled(InventoryCraftingCategory category, InventoryCraftingBlueprint blueprint, float progress) { if (eventHandler != null) eventHandler.OnCraftCanceled(category, blueprint, progress); }
/// <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; }
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 } }
/// <summary> /// Crafts the item and triggers the coroutine method to handle the crafting itself. /// </summary> /// <param name="category"></param> /// <param name="blueprint"></param> /// <param name="amount"></param> /// <returns></returns> 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; }
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; } }
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); } }
public virtual void NotifyCraftProgress(InventoryCraftingCategory category, InventoryCraftingBlueprint blueprint, float progress) { currentCraftProgress = progress; if (OnCraftProgress != null) OnCraftProgress(category, blueprint, progress); }
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; } }
public void OnCraftSuccess(InventoryCraftingCategory category, InventoryCraftingBlueprint blueprint, InventoryItemBase result) { if (eventHandler != null) eventHandler.OnCraftSuccess(category, blueprint, result); }