Exemple #1
0
 private static void ReportUnused(PartsList partsList)
 {
     foreach (var item in partsList.Unused)
     {
         Console.WriteLine($"{item.Name,-20} {item.Amount,7:0.00}");
     }
 }
Exemple #2
0
        public PartsList CalculateTemp(string item, decimal quantity = 1)
        {
            var preferred = new PreferredFilter();

            // Iron Gear using Iron Bar
            preferred.Add("Iron Gear", _gameContext.Recipes.GetRecipes(r => r.Products.Any(p => p.Name == "Iron Gear") && r.Ingredients.Any(i => i.Name == "Iron Bar")).Single());

            // Steel using Coal
            preferred.Add("Steel", _gameContext.Recipes.GetRecipes(r => r.Products.Any(p => p.Name == "Steel") && r.Ingredients.Any(i => i.Name == "Coal")).Single());

            // Raw Meat using Bison Carcass
            preferred.Add("Raw Meat", _gameContext.Recipes.GetRecipes(r => r.Products.Any(p => p.Name == "Raw Meat") && r.Ingredients.Any(i => i.Name == "Bison Carcass")).Single());

            // Scrap Meat using Raw Meat
            preferred.Add("Scrap Meat", _gameContext.Recipes.GetRecipes(r => r.Products.All(p => p.Name == "Scrap Meat") && r.Ingredients.Any(i => i.Name == "Raw Meat")).Single());

            // Sugar
            preferred.Add("Sugar", _gameContext.Recipes.GetRecipes(r => r.Products.Any(p => p.Name == "Sugar")).First());

            // Vegetable Medley
            preferred.Add("Vegetable Medley", _gameContext.Recipes.GetRecipes(r => r.Products.Any(p => p.Name == "Vegetable Medley")).First());

            // Fruit Salad
            preferred.Add("Fruit Salad", _gameContext.Recipes.GetRecipes(r => r.Products.Any(p => p.Name == "Fruit Salad")).First());

            // Basic Salad
            preferred.Add("Basic Salad", _gameContext.Recipes.GetRecipes(r => r.Products.Any(p => p.Name == "Basic Salad")).First());

            // Tallow
            preferred.Add("Tallow", _gameContext.Recipes.GetRecipes(r => r.Products.Any(p => p.Name == "Tallow") && r.Ingredients.All(i => i.Name == "Raw Bacon")).Single());

            // Leather Hide
            preferred.Add("Leather Hide", _gameContext.Recipes.GetRecipes(r => r.Products.Any(p => p.Name == "Leather Hide")).First());

            // Fur Pelt
            preferred.Add("Fur Pelt", _gameContext.Recipes.GetRecipes(r => r.Products.Any(p => p.Name == "Fur Pelt")).First());

            // Oil
            preferred.Add("Oil", _gameContext.Recipes.GetRecipes(r => r.Products.Any(p => p.Name == "Oil") && r.Ingredients.Any(i => i.Name == "Tallow")).Single());

            // Cereal Germ
            preferred.Add("Cereal Germ", _gameContext.Recipes.GetRecipes(r => r.Products.Any(p => p.Name == "Cereal Germ")).First());



            var filter = new CompositeFilter
                         (
                new ProductFilter(),
                preferred
                         );


            var partsList = new PartsList();

            Calculate(item, partsList, filter, quantity);

            return(partsList);
        }
Exemple #3
0
        // Improvments can be made. We cant take the .7 iron bars leftover from recipe and use them in another recipie. Thats what this assumes.
        // We should actually be able to calculate waste.
        // Handle the case where both products are used in the main thinkg being built
        private void Calculate(string item, PartsList shoppingList, IRecipeFilter filter, decimal q = 1)
        {
            // Take from our unused first
            q = shoppingList.Consume(item, q);

            if (q == 0)
            {
                return;
            }

            var recipes = _gameContext.Recipes.GetRecipes(item, filter);

            if (!recipes.Any())
            {
                return; // Item cant be crafted with a recipe.. Iron Ore etc..
            }
            if (recipes.Count() > 1)
            {
                throw new Exception($"Multiple recipes were found that produce {item}.");
            }

            var recipe    = recipes.Single();
            var principal = recipe.Products.Single(p => p.Name == item);

            // q = how many we need, count = how many times this recipe must be executed.
            var count = q / principal.Quantity.Compute(_gameContext.Player);


            foreach (var product in recipe.Products)
            {
                // This recipe has additional products, all will be considered unused
                if (product != principal)
                {
                    shoppingList.IncrementUnused(product.Name, product.Quantity.Compute(_gameContext.Player) * count);
                    continue;
                }

                // Portion of principal that will be unused
                var unused = q - (count * principal.Quantity.Compute(_gameContext.Player));

                if (unused > 0)
                {
                    shoppingList.IncrementUnused(product.Name, unused);
                }


                foreach (var ingredient in recipe.Ingredients)
                {
                    var quantity = ingredient.Quantity.Compute(_gameContext.Player) * count;

                    shoppingList.Increment(ingredient.Name, quantity);
                    Calculate(ingredient.Name, shoppingList, filter, quantity);
                }
            }
        }
Exemple #4
0
        public PartsList Calculate(string item, decimal quantity = 1, IRecipeFilter filter = null)
        {
            if (filter != null)
            {
                filter = new CompositeFilter(new ProductFilter(), filter);
            }
            else
            {
                filter = new ProductFilter();
            }

            var partsList = new PartsList();

            Calculate(item, partsList, filter, quantity);

            return(partsList);
        }
Exemple #5
0
        private static void Report(IGameContext context, PartsList partsList)
        {
            var amount = 0M;

            foreach (var item in partsList)
            {
                var cost = context.Costs.SingleOrDefault(c => c.Name == item.Name) ?? new ItemCost {
                    Amount = 0
                };

                var itemTotal = Math.Ceiling(item.Amount) * cost.Amount;
                amount += itemTotal;

                Console.WriteLine($"{item.Name,-20} {item.Amount,7:0.00} {itemTotal,7:0.00}");
            }

            Console.WriteLine("{0,36}", $"Total: {amount,7:0.00}");
        }