Beispiel #1
0
    // -----------------------------------------------------------------------------------
    // 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;
        }
    }
Beispiel #2
0
    public void UCE_OnSelect_InteractableWorkbench(UCE_InteractableWorkbench _UCE_selectedWorkbench)
    {
        UCE_selectedWorkbench = _UCE_selectedWorkbench;

        UCE_CraftingProfessionRequirement requiredProfession = getRequiredCraftingProfession();

        if (requiredProfession != null)
        {
            List <UCE_Tmpl_Recipe> recipes = new List <UCE_Tmpl_Recipe>();

            // -- filter recipes that match the workbench's profession
            // -- filter recipes that match the players recipe list
            recipes.AddRange(
                UCE_Tmpl_Recipe.dict.Values.ToList().Where(
                    x => x.requiredCraft == requiredProfession.template &&
                    UCE_recipes.Any(r => r == x.name)
                    )
                );

            if (recipes.Count > 0)
            {
                if (!_UCE_UI_Crafting)
                {
                    _UCE_UI_Crafting = FindObjectOfType <UCE_UI_Crafting>();
                }

                _UCE_UI_Crafting.Show(UCE_selectedWorkbench.gameObject, requiredProfession.template, recipes);
            }
            else
            {
                UCE_PopupShow(UCE_selectedWorkbench.nothingMessage);
            }
        }
        else
        {
            UCE_PopupShow(UCE_selectedWorkbench.nothingMessage);
        }
    }
Beispiel #3
0
    public void Cmd_UCE_Crafting_finishCrafting(GameObject _UCE_selectedWorkbench, string recipeName, int amount, bool boost)
    {
        UCE_selectedWorkbench = _UCE_selectedWorkbench.GetComponent <UCE_InteractableWorkbench>();

        UCE_CraftingResult craftingResult = UCE_CraftingResult.None;

        // -- validation (in case something changed during the craft duration)

        if (UCE_selectedWorkbench && UCE_Tmpl_Recipe.dict.TryGetValue(recipeName.GetStableHashCode(), out UCE_myRecipe))
        {
            if (UCE_Crafting_CraftValidation(UCE_myRecipe, amount, boost))
            {
                UCE_removeTask();

                // --------------------------------------------------------------------------- Experience

                var prof     = UCE_getCraftingProfession(UCE_myRecipe.requiredCraft);
                int oldLevel = prof.level;
                int exp      = UCE_CraftingExperience(UCE_myRecipe, amount, boost);
                prof.experience += exp;
                UCE_setCraftingProfession(prof);

#if _iMMOTOOLS
                if (oldLevel < prof.level)
                {
                    UCE_ShowPopup(UCE_selectedWorkbench.levelUpMessage + prof.templateName + " [L" + prof.level + "]");
                }
#endif

                // --------------------------------------------------------------------------- Skill Check

                float successProbability  = UCE_CraftingProbability(UCE_myRecipe, boost);
                float criticalProbability = UCE_CraftingCriticalProbability(UCE_myRecipe, boost);

                for (int i = 1; i <= amount; i++)
                {
                    if (UnityEngine.Random.value <= successProbability)
                    {
                        // ---- Success

                        craftingResult = UCE_CraftingResult.Success;

                        experience      += UCE_myRecipe.experience;
                        skillExperience += UCE_myRecipe.skillExp;

                        float critProba = UCE_myRecipe.criticalProbability += UCE_myRecipe.criticalResultPerSkillLevel * oldLevel;

                        // ---- gain default or critical item

                        if (UnityEngine.Random.value <= criticalProbability)
                        {
                            craftingResult = UCE_CraftingResult.CriticalSuccess;

                            if (UCE_myRecipe.criticalResult.Length > 0)
                            {
                                foreach (UCE_CraftingRecipeIngredient result in UCE_myRecipe.criticalResult)
                                {
                                    InventoryAdd(new Item(result.item), result.amount);
                                }
                            }
                            else
                            {
                                foreach (UCE_CraftingRecipeIngredient result in UCE_myRecipe.defaultResult)
                                {
                                    InventoryAdd(new Item(result.item), result.amount);
                                }
                            }
                        }
                        else
                        {
                            foreach (UCE_CraftingRecipeIngredient result in UCE_myRecipe.defaultResult)
                            {
                                InventoryAdd(new Item(result.item), result.amount);
                            }
                        }

#if _iMMOCRAFTING && _iMMOQUESTS
                        UCE_IncreaseCraftCounterFor(UCE_myRecipe);
#endif
                    }
                    else
                    {
                        // --------------------------------------------------------------------------- Failure

                        craftingResult = UCE_CraftingResult.Failure;

                        // --------------------------------------------------------------------------- [Optional] Gain failure item

                        float failProba = UCE_myRecipe.failureProbability += UCE_myRecipe.failureResultPerSkillLevel * oldLevel;

                        if (UnityEngine.Random.value <= failProba)
                        {
                            foreach (UCE_CraftingRecipeIngredient result in UCE_myRecipe.failureResult)
                            {
                                InventoryAdd(new Item(result.item), result.amount);
                            }
                        }
                    }
                }

                // --------------------------------------------------------------------------- Deplete Ingredients

                foreach (UCE_CraftingRecipeIngredient ingredient in UCE_myRecipe.ingredients)
                {
                    if (craftingResult == UCE_CraftingResult.Failure && ingredient.DontDestroyOnFailure)
                    {
                        continue;
                    }
                    if (craftingResult == UCE_CraftingResult.CriticalSuccess && ingredient.DontDestroyOnCriticalSuccess)
                    {
                        continue;
                    }
                    InventoryRemove(new Item(ingredient.item), (ingredient.amount * amount));
                }

                // --------------------------------------------------------------------------- Deplete other Costs (mana etc.)

                mana -= UCE_myRecipe.manaCost;

                // --------------------------------------------------------------------------- Check Tool breakage

                foreach (UCE_CraftingRecipeTool tool in UCE_myRecipe.tools)
                {
                    if ((!tool.equippedItem && InventoryCount(new Item(tool.requiredItem)) >= 1) || (tool.equippedItem && UCE_checkHasEquipment(tool.requiredItem)))
                    {
                        if (UnityEngine.Random.value <= tool.toolDestroyChance)
                        {
                            if (tool.equippedItem)
                            {
                                UCE_removeEquipment(tool.requiredItem);
                            }
                            else
                            {
                                InventoryRemove(new Item(tool.requiredItem), 1);
                            }
                            UCE_TargetAddMessage(craftingPopupMessages.breakMessage);
                        }
                    }
                }

                if (boost)
                {
                    foreach (UCE_CraftingRecipeTool tool in UCE_myRecipe.optionalTools)
                    {
                        if ((!tool.equippedItem && InventoryCount(new Item(tool.requiredItem)) >= amount) || (tool.equippedItem && UCE_checkHasEquipment(tool.requiredItem)))
                        {
                            if (UnityEngine.Random.value <= tool.toolDestroyChance)
                            {
                                if (tool.equippedItem)
                                {
                                    UCE_removeEquipment(tool.requiredItem);
                                }
                                else
                                {
                                    InventoryRemove(new Item(tool.requiredItem), amount);
                                }
                                UCE_TargetAddMessage(craftingPopupMessages.boosterMessage);
                            }
                        }
                    }
                }

                // --------------------------------------------------------------------------- Popup Message

                if (craftingResult == UCE_CraftingResult.Failure)
                {
                    UCE_ShowPopup(craftingPopupMessages.failMessage, (byte)craftingPopupMessages.failIconId, (byte)craftingPopupMessages.failSoundId);
                }
                else if (craftingResult == UCE_CraftingResult.Success)
                {
                    UCE_ShowPopup(craftingPopupMessages.successMessage, (byte)craftingPopupMessages.successIconId, (byte)craftingPopupMessages.successSoundId);
                }
                else if (craftingResult == UCE_CraftingResult.CriticalSuccess)
                {
                    UCE_ShowPopup(craftingPopupMessages.critMessage, (byte)craftingPopupMessages.critIconId, (byte)craftingPopupMessages.critSoundId);
                }

                // --------------------------------------------------------------------------- Cleanup

                UCE_selectedWorkbench.OnCrafted();

                Target_UCE_Crafting_cancelCraftingClient(connectionToClient);
            }
        }
    }