示例#1
0
        private ChemicalReaction GetReactionToMake(Chemical c)
        {
            var reaction = this.Reactions.SingleOrDefault(react => react.Produces(c));

            if (reaction != null)
            {
                return(reaction);
            }
            else
            {
                throw new Exception($"Boi, you done found a chemical that ain't got a reaction: {c}");
            }
        }
示例#2
0
 private void AddToSurplus(long amountMade, Chemical requested)
 {
     if (amountMade > requested.Amount)
     {
         var surp = amountMade - requested.Amount;
         if (Surplus.ContainsKey(requested.Name))
         {
             Surplus[requested.Name] += surp;
         }
         else
         {
             Surplus.Add(requested.Name, surp);
         }
     }
 }
示例#3
0
        public void ProduceChemical(Chemical c)
        {
            if (c.Name == OreName)
            {
                this.OreRequired += c.Amount;
                return;
            }

            //< See if there's anything laying about in the Surplus we can use
            if (Surplus.ContainsKey(c.Name))
            {
                //< If the surplus has enough to satisfy this request, use it and return
                if (Surplus[c.Name] >= c.Amount)
                {
                    Surplus[c.Name] -= c.Amount;
                    return;
                }
                else
                {
                    //< Not enough, so use what we have and make the rest
                    c.Amount       -= Surplus[c.Name];
                    Surplus[c.Name] = 0;
                }
            }

            //< Get the ChemicalReaction that produces this shit
            var reaction = GetReactionToMake(c);
            //< Get the number of times to do this reaction
            int mult = (int)Math.Ceiling((double)c.Amount / (double)reaction.Output.Amount);

            //< Create each required input (scaled by the multiplier)
            foreach (var input in reaction.Inputs)
            {
                ProduceChemical(new Chemical(input.Name, input.Amount * mult));
            }

            //< Check if we can add anything to the surplus
            AddToSurplus(reaction.Output.Amount * mult, c);
        }
示例#4
0
 public bool Produces(Chemical chem)
 {
     return(this.Output.Name == chem.Name);
 }