public void UCE_IncreaseCraftCounterFor(UCE_Tmpl_Recipe recipe) { for (int i = 0; i < UCE_quests.Count; ++i) { if ((!UCE_quests[i].completed || !UCE_quests[i].completedAgain) && UCE_quests[i].craftTarget.Length > 0 && UCE_quests[i].craftTarget.Any(x => x.target == recipe) ) { UCE_Quest quest = UCE_quests[i]; bool bChanged = false; for (int j = 0; j < quest.craftTarget.Length; ++j) { if (quest.craftTarget[j].target == recipe && quest.craftedTarget[j] < quest.craftTarget[j].amount) { int idx = j; quest.craftedTarget[idx]++; bChanged = true; break; } } UCE_quests[i] = quest; if (bChanged) { UCE_checkQuestCompletion(i); } } } }
// ============================== DURATION/PROBABILITY =============================== // ----------------------------------------------------------------------------------- // UCE_Crafting_CanBoost // ----------------------------------------------------------------------------------- public bool UCE_Crafting_CanBoost(UCE_Tmpl_Recipe recipe, int amount) { if (recipe.optionalTools.Length <= 0) { return(false); } bool bValid = false; foreach (UCE_CraftingRecipeTool tool in recipe.optionalTools) { if ( (!tool.equippedItem && InventoryCount(new Item(tool.requiredItem)) >= amount) || (tool.equippedItem && tool.requiredItem.maxStack == 1 && UCE_checkHasEquipment(tool.requiredItem)) || (tool.equippedItem && tool.requiredItem.maxStack > 1 && UCE_checkDepletableEquipment(tool.requiredItem)) ) { bValid = true; } else { bValid = false; } } return(bValid); }
// ----------------------------------------------------------------------------------- // ToolTip // ----------------------------------------------------------------------------------- public string ToolTip(UCE_Tmpl_Recipe tpl) { StringBuilder tip = new StringBuilder(); tip.Append(tpl.name + "\n"); tip.Append(tpl.toolTip + "\n"); return(tip.ToString()); }
// ----------------------------------------------------------------------------------- // Show // ----------------------------------------------------------------------------------- public void Show(UCE_Tmpl_Recipe r, bool canBoost) { recipe = r; descriptionText.text = recipe.name; icon.sprite = recipe.image; UIShowToolTip tooltip = GetComponent <UIShowToolTip>(); tooltip.text = ToolTip(); boostToggle.gameObject.SetActive(canBoost); }
// ----------------------------------------------------------------------------------- // UCE_Crafting_LearnRecipe // ----------------------------------------------------------------------------------- public bool UCE_Crafting_LearnRecipe(UCE_Tmpl_Recipe recipe) { if (!UCE_recipes.Any(s => s == recipe.name)) { UCE_recipes.Add(recipe.name); UCE_ShowPopup(craftingPopupMessages.learnedMessage + recipe.name, craftingPopupMessages.learnedIconId, craftingPopupMessages.learnedSoundId); return(true); } return(false); }
// ----------------------------------------------------------------------------------- // UCE_CraftingDuration // ----------------------------------------------------------------------------------- public float UCE_CraftingDuration(UCE_Tmpl_Recipe recipe, bool boost) { float duration = 0f; int level = 0; if (recipe != null) { duration = recipe.duration; // -- Modificator: Skill if (recipe.requiredCraft) { level = UCE_getCraftingProfessionLevel(recipe.requiredCraft); } duration += level * recipe.durationPerSkillLevel; // -- Modificator: Required Tools foreach (UCE_CraftingRecipeTool tool in recipe.tools) { if ((!tool.equippedItem && InventoryCount(new Item(tool.requiredItem)) >= 1) || (tool.equippedItem && UCE_checkHasEquipment(tool.requiredItem))) { duration += tool.modifyDuration; if (!recipe.requiresAllTools) { break; } } } // -- Modificator: Optional Tools if (boost) { foreach (UCE_CraftingRecipeTool tool in recipe.optionalTools) { if ((!tool.equippedItem && InventoryCount(new Item(tool.requiredItem)) >= 1) || (tool.equippedItem && UCE_checkHasEquipment(tool.requiredItem))) { duration += tool.modifyDuration; break; } } } } return(duration); }
// ----------------------------------------------------------------------------------- // UCE_CraftingCriticalProbability // ----------------------------------------------------------------------------------- public float UCE_CraftingCriticalProbability(UCE_Tmpl_Recipe recipe, bool boost) { float proba = 0f; int level = 0; if (recipe != null) { proba = recipe.criticalProbability; // -- Modificator: Skill if (recipe.requiredCraft) { level = UCE_getCraftingProfessionLevel(recipe.requiredCraft); } proba += level * recipe.probabilityPerSkillLevel; // -- Modificator: Required Tools foreach (UCE_CraftingRecipeTool tool in recipe.tools) { if ((!tool.equippedItem && InventoryCount(new Item(tool.requiredItem)) >= 1) || (tool.equippedItem && UCE_checkHasEquipment(tool.requiredItem))) { proba += tool.modifyCriticalProbability; if (!recipe.requiresAllTools) { break; } } } // -- Modificator: Optional Tools if (boost) { foreach (UCE_CraftingRecipeTool tool in recipe.optionalTools) { if ((!tool.equippedItem && InventoryCount(new Item(tool.requiredItem)) >= 1) || (tool.equippedItem && UCE_checkHasEquipment(tool.requiredItem))) { proba += tool.modifyCriticalProbability; break; } } } } return(proba); }
// ----------------------------------------------------------------------------------- // UCE_Crafting_startCrafting // ----------------------------------------------------------------------------------- public void UCE_Crafting_startCrafting(UCE_Tmpl_Recipe recipe, int amount, bool boost) { UCE_myRecipe = recipe; craftAmount = amount; if (UCE_WorkbenchValidation() && UCE_Crafting_CraftValidation(UCE_myRecipe, amount, boost)) { UCE_addTask(); float duration = UCE_CraftingDuration(UCE_myRecipe, boost) * amount; UCE_setTimer(duration); UCE_CastbarShow(UCE_myRecipe.name, duration); StartAnimation(UCE_CraftingAnimation().playerAnimation, UCE_CraftingAnimation().startPlayerSound); } }
// ----------------------------------------------------------------------------------- // UCE_finishCraftingClient // ----------------------------------------------------------------------------------- public void UCE_cancelCrafting() { if (UCE_selectedWorkbench != null || UCE_myRecipe != null) { UCE_stopTimer(); UCE_removeTask(); UCE_CastbarHide(); if (UCE_myRecipe != null && UCE_CraftingAnimation() != null) { StopAnimation(UCE_CraftingAnimation().playerAnimation, UCE_CraftingAnimation().stopPlayerSound); } craftBooster = false; craftAmount = 1; UCE_myRecipe = null; UCE_selectedWorkbench = null; } }
// ----------------------------------------------------------------------------------- // UCE_CraftingExperience // ----------------------------------------------------------------------------------- public int UCE_CraftingExperience(UCE_Tmpl_Recipe recipe, int amount, bool boost) { int experience = 0; if (recipe != null) { experience = UnityEngine.Random.Range(recipe.ProfessionExperienceRewardMin, recipe.ProfessionExperienceRewardMax) * amount; // -- Modificator: Required Tools foreach (UCE_CraftingRecipeTool tool in recipe.tools) { if ((!tool.equippedItem && InventoryCount(new Item(tool.requiredItem)) >= 1) || (tool.equippedItem && UCE_checkHasEquipment(tool.requiredItem))) { experience += UnityEngine.Random.Range(tool.modifyExperienceMin, tool.modifyExperienceMax); if (!recipe.requiresAllTools) { break; } } } // -- Modificator: Optional Tools if (boost) { foreach (UCE_CraftingRecipeTool tool in recipe.optionalTools) { if ((!tool.equippedItem && InventoryCount(new Item(tool.requiredItem)) >= 1) || (tool.equippedItem && UCE_checkHasEquipment(tool.requiredItem))) { experience += UnityEngine.Random.Range(tool.modifyExperienceMin, tool.modifyExperienceMax); break; } } } } return(experience); }
// ----------------------------------------------------------------------------------- // UCE_Crafting_CraftValidation // ----------------------------------------------------------------------------------- public bool UCE_Crafting_CraftValidation(UCE_Tmpl_Recipe recipe, int amount, bool boost, bool craftable = true) { bool valid = true; // ----- set crafting booster craftBooster = boost; // ----- check profession level if (!UCE_HasCraftingProfessionLevel(recipe.requiredCraft, recipe.minSkillLevel)) { valid = false; } if (!craftable) { return(valid); } // ----- check ingredients foreach (UCE_CraftingRecipeIngredient ingredient in recipe.ingredients) { if (InventoryCount(new Item(ingredient.item)) < (ingredient.amount * amount)) { valid = false; } } // ----- check mana if (mana < recipe.manaCost) { valid = false; } // ----- check tools int check = 0; foreach (UCE_CraftingRecipeTool tool in recipe.tools) { if ((!tool.equippedItem && InventoryCount(new Item(tool.requiredItem)) >= 1) || (tool.equippedItem && UCE_checkHasEquipment(tool.requiredItem))) { check++; } } if (recipe.requiresAllTools) { if (check < recipe.tools.Length) { valid = false; } } else { if (check <= 0 && recipe.tools.Length > 0) { valid = false; } } return(valid); }
// ----------------------------------------------------------------------------------- // Show // ----------------------------------------------------------------------------------- public void Show(UCE_Tmpl_Recipe newRecipe) { recipe = newRecipe; text.text = unlearnText + recipe.name; panel.SetActive(true); }
// ----------------------------------------------------------------------------------- // Refresh // ----------------------------------------------------------------------------------- public void Refresh() { Player player = Player.localPlayer; if (!player) { return; } if (panel.activeSelf && instance != null && UCE_Tools.UCE_CheckSelectionHandling(instance) ) { int rcount = getRecipeCount(); int t_index = -1; int r_index = 0; UIUtils.BalancePrefabs(slotPrefab.gameObject, rcount, content); for (int i = 0; i < recipes.Count; ++i) { if (canCraft(i)) { r_index = i; t_index++; UCE_Tmpl_Recipe recipe = recipes[r_index]; UCE_Slot_Crafting slot = content.GetChild(t_index).GetComponent <UCE_Slot_Crafting>(); slot.Show(recipe, player.UCE_Crafting_CanBoost(recipe, slot.amount)); if (player.UCE_Crafting_CraftValidation(recipe, slot.amount, slot.boost) && !player.UCE_Crafting_isBusy()) { slot.actionButton.interactable = true; } else { slot.actionButton.interactable = false; } slot.unlearnButton.interactable = true; slot.unlearnButton.onClick.SetListener(() => { unlearnPanel.Show(recipe); }); slot.actionButton.onClick.SetListener(() => { player.UCE_Crafting_startCrafting(recipe, slot.amount, slot.boost); panel.SetActive(false); }); } } } else { currentCategory = ""; panel.SetActive(false); // hide } }