public void AddRecipe_AddsChildRecipeToParentRecipe_GivenParentId()
        {
            //Arrange
            var title              = "Almost completely new recipe";
            var description        = "Almost completely new description";
            var parentAncestryPath = "3/11/";
            var expectedNode       = new RecipeNode()
            {
                RecipeID = 12, AncestryPath = "3/11/12/"
            };
            var expectedLogEntry = new RecipeLogEntry()
            {
                VersionID   = 15,
                RecipeID    = 12,
                Title       = title,
                Description = description
            };

            //Act
            var recipeId = _repo.AddRecipe(title, description, parentAncestryPath);

            var actualNode     = _repo.GetRecipeNode(recipeId);
            var actualLogEntry = _repo.GetLatestLogEntryFor(recipeId);

            //Assert
            Assert.True(recipeId > 0);
            Assert.Equal(actualNode, expectedNode, new NodeEqualityComparer());
            Assert.Equal(actualLogEntry, expectedLogEntry, new LogEntryEqualityComparer());
            _fixture.ResetRepository();
        }
        public void AddRecipe_AddsRecipeToRootLevelWithNewId_GivenNoParentAncestryPath()
        {
            //Arrange
            var    title              = "Completely new recipe";
            var    description        = "Completely new description";
            string parentAncestryPath = null;
            var    expectedNode       = new RecipeNode()
            {
                RecipeID = 12, AncestryPath = "12/"
            };
            var expectedLogEntry = new RecipeLogEntry()
            {
                VersionID   = 15,
                RecipeID    = 12,
                Title       = title,
                Description = description
            };

            //Act
            var recipeId = _repo.AddRecipe(title, description, parentAncestryPath);

            var actualNode     = _repo.GetRecipeNode(recipeId);
            var actualLogEntry = _repo.GetLatestLogEntryFor(recipeId);

            //Assert
            Assert.True(recipeId > 0);
            Assert.Equal(actualNode, expectedNode, new NodeEqualityComparer());
            Assert.Equal(actualLogEntry, expectedLogEntry, new LogEntryEqualityComparer());
            _fixture.ResetRepository();
        }
예제 #3
0
        public static RecipeNode Create(Recipe baseRecipe, ProductionGraph graph)
        {
            var node = new RecipeNode(baseRecipe, graph);

            node.Graph.Nodes.Add(node);
            node.Graph.InvalidateCaches();
            return(node);
        }
예제 #4
0
        // Swaps out an unfulfilled Node with a real node?
        internal RecipeNode Push(UnfulfilledNode current, Recipe recipe, int needed)
        {
            this.current = null;
            RecipeNode recipeNode = new RecipeNode(recipe, needed, current.ChildNumber, current.parent, current.craftPath);

            //current.parent.children[current.ChildNumber] = recipeNode;
            // Swap out Edges
            //recipeNode.parent = current.parent;
            //recipeNode.ChildNumber = current.ChildNumber;
            current.parent      = null;
            current.ChildNumber = -1;
            //this.current = null;

            // Consume
            ConsumeResources(recipeNode);             // consumes items from haveItems

            return(recipeNode);
        }
예제 #5
0
            internal override void Build(ProductionGraph graph)
            {
                var duration = 1;

                name ??= "recipe-" + GetSequence();

                var recipe = new Recipe(name, duration, itemizeKeys(inputs), itemizeKeys(outputs));

                Built = RecipeNode.Create(recipe, graph);
                Built.BeaconModules.OverrideProductivityBonus = efficiency;

                if (target > 0)
                {
                    Built.DesiredRate = target;
                    Built.RateType    = RateType.Manual;
                }
                else
                {
                    Built.RateType = RateType.Auto;
                }
            }
예제 #6
0
            internal void CheckParentsForRecipeLoopViaIngredients(List <int> vialbleIngredients)
            {
                var p = parent;

                while (p != null)
                {
                    RecipeNode r = p as RecipeNode;                     // Technically this shouldn't ever fail...
                    if (r != null)
                    {
                        // TODO: 100Wood <- Bundle, Bundle <- Wood+Duplicator problem. Stack size matters? issue.
                        if (vialbleIngredients.Contains(r.recipe.createItem.type))
                        {
                            //Console.WriteLine();
                        }

                        if (r.recipe.createItem.type == 9 && (r.craftPath.root as RecipeNode).recipe.createItem.type == 9)
                        {
                            Console.WriteLine();                             // 2629 living wood plat
                        }

                        vialbleIngredients.Remove(r.recipe.createItem.type);
                        p = p.parent;
                    }
                    else if (p is HaveItemNode)                     //
                    {
                        //Console.WriteLine();
                        p = p.parent;
                    }
                    else if (p is HaveItemsNode)
                    {
                        //Console.WriteLine();
                        p = p.parent;
                    }
                    else
                    {
                        throw new Exception("How is a parent not a recipe?");
                    }
                }
            }
예제 #7
0
            internal override void Build(ProductionGraph graph)
            {
                var duration = 1;

                if (name == null)
                {
                    name = "recipe-" + GetSequence();
                }

                Recipe recipe = new Recipe(name, duration, itemizeKeys(inputs), itemizeKeys(outputs));

                Built = RecipeNode.Create(recipe, graph);
                this.Built.ProductivityBonus = efficiency;

                if (target > 0)
                {
                    this.Built.desiredRate = target;
                    this.Built.rateType    = RateType.Manual;
                }
                else
                {
                    this.Built.rateType = RateType.Auto;
                }
            }
예제 #8
0
            internal bool CheckParentsForRecipeLoop(Recipe recipe)
            {
                // Yeah, wait until later is a better idea.
                var p = parent;

                while (p != null)
                {
                    RecipeNode r = p as RecipeNode;                     // Technically this shouldn't ever fail...
                    if (r != null)
                    {
                        if (r.recipe.createItem.type == recipe.createItem.type && r.recipe.createItem.stack != recipe.createItem.stack)
                        {
                            throw new Exception("Found a stack size problem craft path!");
                        }
                        // If any create item matches an above create item
                        if (r.recipe.createItem.type == recipe.createItem.type)                         // is there a Recipe Group problem here? below?
                        {
                            return(true);
                        }
                        p = p.parent;
                    }
                    else if (p is HaveItemNode || p is HaveItemsNode)                     // is this OK?
                    {
                        p = p.parent;
                    }
                    else
                    {
                        throw new Exception("How is a parent not a recipe?");
                    }
                }
                return(false);

                // TODO: Ignore recipe group items

                // I removed RecipeGroup items. Remember to check this later when actualizing it.
                // I could just check Result->Result and bypass any recipe group problem
                // 100Wood <- Bundle, Bundle <- Wood+Duplicator problem. Stack size matters?
                //HashSet<int> items = new HashSet<int>(recipe.requiredItem.Where(x => !x.IsAir).Select(x => x.type));
                //List<int> groups = RecipePath.GetAcceptedGroups(recipe);
                //foreach (var groupid in groups)
                //{
                //	items.Remove(RecipeGroup.recipeGroups[groupid].ValidItems[RecipeGroup.recipeGroups[groupid].IconicItemIndex]);
                //}

                //var p = parent;
                //while (p != null)
                //{
                //	RecipeNode r = p as RecipeNode;
                //	if (r != null)
                //	{
                //		// If any create item matches an above create item
                //		if (p.recipe.createItem.type == recipe.createItem.type) // is there a Recipe Group problem here? below?
                //			return true;
                //		// Vs
                //		if (RecipePath.shortCircitIngredients && recipe.requiredItem.Any(x => x.type == p.recipe.createItem.type)) // TODO: Don't short circuit if parent is creating wood but recipe requires any wood...?
                //			return true;
                //		// If any ingredient matches a parent create item
                //		// OLD
                //		//if (p.recipe == recipe)
                //		//	return true;
                //	}
                //	p = p.parent;
                //}
                //return false;
            }
예제 #9
0
 public void SetData(RecipeNode node)
 {
     Data = node.Data;
 }