示例#1
0
        /// <summary>
        /// Creates a deep copy
        /// </summary>
        /// <returns></returns>
        public GridRecipe Clone()
        {
            GridRecipe recipe = new GridRecipe();

            recipe.RecipeGroup       = RecipeGroup;
            recipe.Width             = Width;
            recipe.Height            = Height;
            recipe.IngredientPattern = IngredientPattern;
            recipe.Ingredients       = new Dictionary <string, CraftingRecipeIngredient>();
            if (Ingredients != null)
            {
                foreach (var val in Ingredients)
                {
                    recipe.Ingredients[val.Key] = val.Value.Clone();
                }
            }
            if (resolvedIngredients != null)
            {
                recipe.resolvedIngredients = new GridRecipeIngredient[resolvedIngredients.Length];
                for (int i = 0; i < resolvedIngredients.Length; i++)
                {
                    recipe.resolvedIngredients[i] = resolvedIngredients[i]?.CloneTo <GridRecipeIngredient>();
                }
            }

            recipe.Shapeless          = Shapeless;
            recipe.Output             = Output.Clone();
            recipe.Name               = Name;
            recipe.Attributes         = Attributes?.Clone();
            recipe.RequiresTrait      = RequiresTrait;
            recipe.AverageDurability  = AverageDurability;
            recipe.CopyAttributesFrom = CopyAttributesFrom;

            return(recipe);
        }
示例#2
0
        private bool ConsumeInputShapeLess(IPlayer byPlayer, ItemSlot[] inputSlots)
        {
            List <CraftingRecipeIngredient> exactMatchIngredients = new List <CraftingRecipeIngredient>();
            List <CraftingRecipeIngredient> wildcardIngredients   = new List <CraftingRecipeIngredient>();

            for (int i = 0; i < resolvedIngredients.Length; i++)
            {
                CraftingRecipeIngredient ingredient = resolvedIngredients[i];
                if (ingredient == null)
                {
                    continue;
                }

                if (ingredient.IsWildCard || ingredient.IsTool)
                {
                    wildcardIngredients.Add(ingredient.Clone());
                    continue;
                }

                ItemStack stack = ingredient.ResolvedItemstack;

                bool found = false;
                for (int j = 0; j < exactMatchIngredients.Count; j++)
                {
                    if (exactMatchIngredients[j].ResolvedItemstack.Satisfies(stack))
                    {
                        exactMatchIngredients[j].ResolvedItemstack.StackSize += stack.StackSize;
                        found = true;
                        break;
                    }
                }
                if (!found)
                {
                    exactMatchIngredients.Add(ingredient.Clone());
                }
            }

            for (int i = 0; i < inputSlots.Length; i++)
            {
                ItemStack inStack = inputSlots[i].Itemstack;
                if (inStack == null)
                {
                    continue;
                }

                for (int j = 0; j < exactMatchIngredients.Count; j++)
                {
                    if (exactMatchIngredients[j].ResolvedItemstack.Satisfies(inStack))
                    {
                        int quantity = Math.Min(exactMatchIngredients[j].ResolvedItemstack.StackSize, inStack.StackSize);

                        inStack.Collectible.OnConsumedByCrafting(inputSlots, inputSlots[i], this, exactMatchIngredients[j], byPlayer, quantity);

                        exactMatchIngredients[j].ResolvedItemstack.StackSize -= quantity;

                        if (exactMatchIngredients[j].ResolvedItemstack.StackSize <= 0)
                        {
                            exactMatchIngredients.RemoveAt(j);
                        }

                        break;
                    }
                }

                for (int j = 0; j < wildcardIngredients.Count; j++)
                {
                    CraftingRecipeIngredient ingredient = wildcardIngredients[j];

                    if (
                        ingredient.Type == inStack.Class &&
                        WildcardUtil.Match(ingredient.Code, inStack.Collectible.Code, ingredient.AllowedVariants) &&
                        inStack.StackSize >= ingredient.Quantity
                        )
                    {
                        int quantity = Math.Min(ingredient.Quantity, inStack.StackSize);

                        inStack.Collectible.OnConsumedByCrafting(inputSlots, inputSlots[i], this, ingredient, byPlayer, quantity);

                        if (ingredient.IsTool)
                        {
                            wildcardIngredients.RemoveAt(j);
                        }
                        else
                        {
                            ingredient.Quantity -= quantity;

                            if (ingredient.Quantity <= 0)
                            {
                                wildcardIngredients.RemoveAt(j);
                            }
                        }

                        break;
                    }
                }
            }

            return(exactMatchIngredients.Count == 0);
        }