示例#1
0
        public void Make(long amount, string what)
        {
            Recipe directRecipe = recipes.FirstOrDefault(r => r.Product.Id == what);

            if (AvailableElements.Has(what))
            {
                long leftoverUsed = Math.Min(AvailableElements.Count(e => e.Id == what), amount);
                amount -= leftoverUsed;
            }
            if (directRecipe == null)
            {
                AvailableElements.Add(amount, what);
                UsedElements.Add(amount, what);
                return;
            }
            if (amount > 0)
            {
                long times = (long)Math.Ceiling((double)amount / (double)directRecipe.Product.Amount);
                RunRecipe(times, directRecipe);
                UsedElements.Add(directRecipe.Product.Amount * times, what);
                AvailableElements.Add(directRecipe.Product.Amount * times, what);
            }
        }
示例#2
0
 public long GetUsed(string what)
 {
     return(UsedElements.Count(e => e.Id == what));
 }