コード例 #1
0
 public CraftingState(CraftingState oldCraftingState)
 {
     Inventory = oldCraftingState.Inventory.ToDictionary(keyValuePair => keyValuePair.Key,
                                                         keyValuePair => keyValuePair.Value);
     TrueInventory = oldCraftingState.TrueInventory.ToDictionary(keyValuePair => keyValuePair.Key,
                                                                 keyValuePair => keyValuePair.Value);
     RecipeUsed = oldCraftingState.RecipeUsed.ToDictionary(keyValuePair => keyValuePair.Key,
                                                           keyValuePair => keyValuePair.Value);
     Depth = oldCraftingState.Depth + 1;
 }
コード例 #2
0
        public RecipeInfo FindIngredientsForRecipe(Recipe recipe, int timeCraft = 1)
        {
            CraftingState = new CraftingState(Inventory);
            bool craftable = CraftableAmount(recipe, recipe.createItem.stack * timeCraft,
                                             recipe.createItem.stack * timeCraft, new List <int>()).Item1 > 0;

            if (timeCraft == 1)
            {
                PossibleCraftCache[recipe] = craftable;
            }
            return(!craftable ? null : CreateRecipeInfo());
        }
コード例 #3
0
        public (int, int) CraftableAmount(Recipe recipe, int amount, int trueAmount, List <int> forbiddenItems)
        {
            if (!IsAvailable(recipe))
            {
                return(0, 0);
            }
            CraftingState oldState = CraftingState;

            CraftingState = new CraftingState(oldState);

            List <int> newForbiddenItems = forbiddenItems.ToList();

            List <int> recipeAcceptedGroups =
                (List <int>)RecursiveCraft.GetAcceptedGroups.Invoke(null, new object[] { recipe });

            int timeCraft     = (amount + recipe.createItem.stack - 1) / recipe.createItem.stack;
            int trueTimeCraft = (trueAmount + recipe.createItem.stack - 1) / recipe.createItem.stack;

            foreach (Item ingredient in recipe.requiredItem)
            {
                if (ingredient.type == ItemID.None)
                {
                    break;
                }

                int ingredientsNeeded     = timeCraft * ingredient.stack;
                int trueIngredientsNeeded =
                    trueTimeCraft * ingredient.stack - DiscountRecipe(recipe, trueTimeCraft, ingredient);

                List <int> ingredientList = ListAllIngredient(recipeAcceptedGroups, ingredient);

                ingredientList.RemoveAll(forbiddenItems.Contains);

                UseExistingIngredients(ingredientList, ref ingredientsNeeded, ref trueIngredientsNeeded);

                if (ingredientsNeeded > 0 && MaxDepth - CraftingState.Depth != 0)
                {
                    if (!newForbiddenItems.Contains(recipe.createItem.type))
                    {
                        newForbiddenItems.Add(recipe.createItem.type);
                    }
                    foreach (int validItem in ingredientList)
                    {
                        UseIngredientFromRecipe(newForbiddenItems,
                                                validItem, ref ingredientsNeeded, ref trueIngredientsNeeded);

                        if (ingredientsNeeded <= 0)
                        {
                            break;
                        }
                    }
                }

                if (ingredientsNeeded > 0)
                {
                    timeCraft -= (ingredientsNeeded + ingredient.stack - 1) / ingredient.stack;
                    if (trueTimeCraft != 0)
                    {
                        trueTimeCraft -= (ingredientsNeeded + ingredient.stack - 1) / ingredient.stack;
                    }
                    break;
                }
            }

            if (timeCraft <= 0)
            {
                CraftingState = oldState;
                return(0, 0);
            }
            else if (amount > timeCraft * recipe.createItem.stack)
            {
                CraftingState = oldState;
                return(CraftableAmount(recipe, timeCraft * recipe.createItem.stack,
                                       trueTimeCraft * recipe.createItem.stack, forbiddenItems));
            }
            else
            {
                UseItems(recipe, amount, trueAmount, timeCraft, trueTimeCraft);
                return(amount, trueAmount);
            }
        }