protected virtual bool CraftItem(InventoryPlayer player, CraftInfo craftInfo) { if (craftQueue.Count >= maxCraftQueueCount) { return(false); // At max amount } if (validator.CanCraftBlueprint(player, craftInfo) == false) { craftInfo.StopAudioSource(); if (craftInfo == activeCraft) { craftQueue.Dequeue(); } return(false); } craftInfo.activeCraft = _CraftItem(player, craftInfo, craftInfo.blueprint.craftingTimeDuration); if (removeItemsOnCraftStart) { for (int i = 0; i < craftInfo.craftAmount; i++) { validator.RemoveRequiredCraftItemsAndCurrency(craftInfo); } craftInfo.removedCraftItems = true; } craftQueue.Enqueue(craftInfo); validator.StartCoroutine(craftInfo.activeCraft); return(true); }
protected virtual IEnumerator _CraftItem(InventoryPlayer player, CraftInfo craftInfo, float currentCraftTime) { NotifyCraftStart(craftInfo); float counter = currentCraftTime; while (true) { yield return(null); counter -= Time.deltaTime; NotifyCraftProgress(craftInfo, 1.0f - Mathf.Clamp01(counter / currentCraftTime)); if (counter <= 0.0f) { break; } } if (craftInfo.removedCraftItems == false && validator.CanCraftBlueprint(player, activeCraft) == false) { craftInfo.StopAudioSource(); yield break; } if (craftInfo.blueprint.successChanceFactor >= UnityEngine.Random.value) { if (activeCraft.removedCraftItems == false) { validator.RemoveRequiredCraftItemsAndCurrency(activeCraft); } validator.GiveCraftReward(activeCraft); NotifyCraftSuccess(craftInfo); } else { NotifyCraftFailed(craftInfo); } craftInfo.craftAmount--; if (craftInfo.craftAmount > 0) { if (removeItemsOnCraftStart == false) { activeCraft.removedCraftItems = false; // For the next cycle. } validator.StartCoroutine(_CraftItem(player, craftInfo, Mathf.Clamp(currentCraftTime / craftInfo.blueprint.craftingTimeSpeedupFactor, 0.0f, craftInfo.blueprint.craftingTimeDuration))); } else { craftQueue.Dequeue(); } }
/// <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)); }
protected virtual void RemovePlayerCollections(InventoryPlayer playerBefore) { foreach (var inv in playerBefore.inventoryCollections) { InventoryManager.RemoveInventoryCollection(inv); } if (playerBefore.characterUI != null) { InventoryManager.RemoveEquipCollection(playerBefore.characterUI); } }
public bool CanDoDecrease(InventoryPlayer player) { var prop = player.stats.Get(stat.category, stat.statName); if (prop != null) { if (prop.currentValue >= floatValue) { return(true); } } return(false); }
/// <summary> /// Does the inventory contain the required items? /// </summary> public override bool CanCraftBlueprint(InventoryPlayer player, CraftingProgressContainer.CraftInfo craftInfo) { bool can = base.CanCraftBlueprint(player, craftInfo); if (can == false) { return(false); } // No blueprint found if (GetBlueprintFromCurrentLayout(craftInfo.removeItemsFromCollection ?? mainItemsCollection, craftInfo.category) == null) { return(false); } return(true); }
public virtual void SetPlayerAsCurrentPlayer(InventoryPlayer player) { if (previousPlayer != null) { RemovePlayerCollections(previousPlayer); } foreach (var inv in player.inventoryCollections) { var i = inv as ICollectionPriority; InventoryManager.AddInventoryCollection(inv, i != null ? i.collectionPriority : 50); } var eq = player.characterUI as ICollectionPriority; InventoryManager.AddEquipCollection(player.characterUI, eq != null ? eq.collectionPriority : 50); previousPlayer = player; }
public virtual bool CanCraftBlueprint(InventoryPlayer player, CraftingProgressContainer.CraftInfo craftInfo) { // Required properties? if (player.characterUI != null) { foreach (var propLookup in craftInfo.blueprint.usageRequirement) { if (propLookup.CanUse(player) == false) { InventoryManager.langDatabase.craftingCannotStatNotValid.Show(craftInfo.blueprint.name, craftInfo.blueprint.description, propLookup.stat.statName); return(false); } } } if (CanRemoveRequiredItems(craftInfo) == false) { InventoryManager.langDatabase.craftingDontHaveRequiredItems.Show(craftInfo.blueprint.requiredItems[0].item.name, craftInfo.blueprint.requiredItems[0].item.description, craftInfo.blueprint.name); return(false); } if (CanAddItemsRewardItems(craftInfo) == false) { InventoryManager.langDatabase.collectionFull.Show(craftInfo.blueprint.name, craftInfo.blueprint.description, "Reward collection"); return(false); } // Enough currency? if (CanRemoveRequiredCurrency(craftInfo) == false) { InventoryManager.langDatabase.userNotEnoughGold.Show(craftInfo.blueprint.name, craftInfo.blueprint.description, craftInfo.craftAmount, craftInfo.blueprint.craftingCost.ToString(craftInfo.craftAmount)); return(false); } return(true); }
public bool CanCraftBlueprint(InventoryPlayer player, CraftingProgressContainer.CraftInfo craftInfo) { return(craftingWindow.CanCraftBlueprint(player, craftInfo)); }