Beispiel #1
0
 private static CraftingIngredient MinecraftIdConversion(CraftingIngredient ingredient)
 {
     if (_conversionDictionary.ContainsKey(ingredient.IngredientMinecraftId))
     {
         ingredient.IngredientMinecraftId = _conversionDictionary[ingredient.IngredientMinecraftId];
         ingredient.Id = _minecraftItemRepository.GetIdByMinecraftId(ingredient.IngredientMinecraftId);
     }
     return(ingredient);
 }
        public void AddIngredient(Item i, int number)
        {
            CraftingIngredient[] copy = new CraftingIngredient[ingredients.Length + 1];
            ingredients.CopyTo(copy, 0);

            copy[ingredients.Length + 1] = new CraftingIngredient(i, number);

            ingredients = copy;
        }
 public CustomCrafting()
 {
     ingredients = new CraftingIngredient[9];
     for (int i = 0; i < 9; i++)
     {
         ingredients[i] = (new CraftingIngredient());
     }
     changedItem = new CraftingIngredient();
 }
Beispiel #4
0
 public CustomCrafting()
 {
     craftingModes = new ICraftingMode[] { new Rerolling(), new Reforging(), new Polishing(), new Empowering(), new IndividualRerolling() };
     ingredients   = new CraftingIngredient[9];
     for (int i = 0; i < 9; i++)
     {
         ingredients[i] = (new CraftingIngredient());
     }
     changedItem = new CraftingIngredient();
 }
Beispiel #5
0
        /// <summary>
        ///     Checks and fixes cross links of the ingredient-object and all its heirs recursively.
        /// </summary>
        /// <param name="checkingRecipe">What recipe we need to check and fix?</param>
        /// <param name="indexInRecipe">What index should be present in the ingredient?</param>
        /// <param name="requiredIngredient">What ingredient and its heirs we need to check and fix?</param>
        /// <param name="parentsAndChilds">Dictionary of game objects and its heirs(variants).</param>
        private static void CheckAndFixCraftingCrossLinks(
            CraftingRecipe checkingRecipe,
            int indexInRecipe,
            GameObject requiredIngredient,
            Dictionary <GameObject, HashSet <GameObject> > parentsAndChilds
            )
        {
            CraftingIngredient craftingIngredient = requiredIngredient.GetComponent <CraftingIngredient>();
            // has the ingredient a link to the recipe?
            bool foundRecipe = false;

            foreach (RelatedRecipe relatedRecipe in craftingIngredient.RelatedRecipes)
            {
                if (relatedRecipe.Recipe != checkingRecipe)
                {
                    continue;
                }

                foundRecipe = true;
                if (relatedRecipe.IngredientIndex != indexInRecipe)
                {
                    Logger.Log(
                        $"A crafting ingredient ({requiredIngredient}) had a wrong related recipe index, " +
                        "but was fixed automatically. " +
                        $"Expected {indexInRecipe}, but found: {relatedRecipe.IngredientIndex}."
                        );
                    relatedRecipe.IngredientIndex = indexInRecipe;
                    PrefabUtility.SavePrefabAsset(requiredIngredient);
                }
                break;
            }

            if (foundRecipe == false)
            {
                Logger.Log(
                    $"A crafting ingredient ({requiredIngredient}) didn't have a link to a recipe " +
                    $"({checkingRecipe}) in its RelatedRecipes list, since the recipe requires this " +
                    "ingredient (prefab), any of it's heirs (prefab variants) " +
                    "or even some parents (prefab sources aka bases)."
                    );
                craftingIngredient.RelatedRecipes.Add(new RelatedRecipe(checkingRecipe, indexInRecipe));
                PrefabUtility.SavePrefabAsset(requiredIngredient);
            }

            if (parentsAndChilds.ContainsKey(requiredIngredient) == false)
            {
                return;
            }

            foreach (GameObject child in parentsAndChilds[requiredIngredient])
            {
                CheckAndFixCraftingCrossLinks(checkingRecipe, indexInRecipe, child, parentsAndChilds);
            }
        }
Beispiel #6
0
    //Check input items for recipe matches
    public void CheckInput(bool pKeepIndex = false)
    {
        List <RecipeContainer> recipeList = new List <RecipeContainer>();

        //Build a list of ingredients from the input's items
        List <CraftingIngredient> ingredientList = new List <CraftingIngredient>();

        foreach (StationItem stack in ChosenItems)
        {
            CraftingIngredient ingredient = new CraftingIngredient();
            ingredient.ContainedItem = stack.ContainedItem.Clone(stack.ContainedItem);
            ingredient.Amount        = stack.Amount;
            if (ingredient.ContainedItem.ID != 0)
            {
                ingredientList.Add(ingredient);
            }
        }

        //Check recipes against this station's contained recipes to find matches
        recipeList = CraftingManager.Instance.CheckRecipeMatches(ingredientList, StationRecipes);


        if (recipeList.Count < 1)
        {
            // print("nothing");
            RecipeIndex = 0;
            SetRecipe();
        }

        RecipesInInput = recipeList;
        if (RecipeIndex > RecipesInInput.Count - 1)
        {
            RecipeIndex = 0;
        }
        SetRecipe();
    }