Esempio n. 1
0
        List <MatchedSmeltableStackAlloy> mergeAndCompareStacks(ItemStack[] inputStacks, bool useSmeltedWhereApplicable)
        {
            List <MatchedSmeltableStackAlloy> mergedStacks = new List <MatchedSmeltableStackAlloy>();
            List <MetalAlloyIngredient>       ingredients  = new List <MetalAlloyIngredient>(this.Ingredients);

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

                ItemStack stack     = inputStacks[i];
                float     stackSize = stack.StackSize;

                if (useSmeltedWhereApplicable && stack.Collectible.CombustibleProps?.SmeltedStack != null)
                {
                    stackSize /= stack.Collectible.CombustibleProps.SmeltedRatio;
                    stack      = stack.Collectible.CombustibleProps.SmeltedStack.ResolvedItemstack;
                }

                bool exists = false;
                for (int j = 0; j < mergedStacks.Count; j++)
                {
                    if (stack.Class == mergedStacks[j].stack.Class && stack.Id == mergedStacks[j].stack.Id)
                    {
                        mergedStacks[j].stackSize += stackSize;
                        exists = true;
                        break;
                    }
                }

                if (!exists)
                {
                    MetalAlloyIngredient ingred = getIgrendientFor(stack, ingredients);
                    if (ingred == null)
                    {
                        return(null);
                    }

                    mergedStacks.Add(new MatchedSmeltableStackAlloy()
                    {
                        stack = stack.Clone(), ingred = ingred, stackSize = stackSize
                    });
                }
            }

            if (ingredients.Count > 0)
            {
                return(null);
            }

            return(mergedStacks);
        }
Esempio n. 2
0
        /// <summary>
        /// Deserializes the alloy
        /// </summary>
        /// <param name="reader"></param>
        /// <param name="resolver"></param>
        public void FromBytes(BinaryReader reader, IWorldAccessor resolver)
        {
            Ingredients = new MetalAlloyIngredient[reader.ReadInt32()];

            for (int i = 0; i < Ingredients.Length; i++)
            {
                Ingredients[i] = new MetalAlloyIngredient();
                Ingredients[i].FromBytes(reader, resolver.ClassRegistry);
                Ingredients[i].Resolve(resolver, "[FromBytes]");
            }

            Output = new JsonItemStack();
            Output.FromBytes(reader, resolver.ClassRegistry);
            Output.Resolve(resolver, "[FromBytes]");
        }
Esempio n. 3
0
        /// <summary>
        /// Creates a deep copy of this object
        /// </summary>
        /// <returns></returns>
        public new MetalAlloyIngredient Clone()
        {
            MetalAlloyIngredient stack = new MetalAlloyIngredient()
            {
                Code      = Code,
                StackSize = StackSize,
                Type      = Type,
                MinRatio  = MinRatio,
                MaxRatio  = MaxRatio
            };

            if (Attributes != null)
            {
                stack.Attributes = Attributes.Clone();
            }

            return(stack);
        }
Esempio n. 4
0
        MetalAlloyIngredient getIgrendientFor(ItemStack stack, List <MetalAlloyIngredient> ingredients)
        {
            if (stack == null)
            {
                return(null);
            }

            for (int i = 0; i < ingredients.Count; i++)
            {
                ItemStack ingredientstack = ingredients[i].ResolvedItemstack;
                if (ingredientstack.Class == stack.Class && ingredientstack.Id == stack.Id)
                {
                    MetalAlloyIngredient ingred = ingredients[i];
                    ingredients.Remove(ingredients[i]);
                    return(ingred);
                }
            }
            return(null);
        }