Beispiel #1
0
        public BehaviorNode ToNode(BehaviorTree tree, AbstractActor unit)
        {
            var parameters = GetNodeConstructorParameters(tree, unit, out var parameterTypes);
            var node       = BehaviorNodeFactory.CreateBehaviorNode(TypeName, parameterTypes, parameters);

            if (node == null)
            {
                Main.HBSLog?.LogError($"BehaviorNode name: {Name} type: {TypeName} did not convert properly!");
            }

            switch (node)
            {
            case CompositeBehaviorNode composite:
                foreach (var child in Children)
                {
                    composite.AddChild(child.ToNode(tree, unit));
                }
                break;

            case DecoratorBehaviorNode decorator:
                decorator.ChildNode = Children.Count != 0 ? Children[0].ToNode(tree, unit) : null;
                break;
            }

            return(node);
        }
Beispiel #2
0
        public void BraceNodeTest()
        {
            var typeName  = "BraceNode";
            var name      = "braceNode0000";
            var braceNode = BehaviorNodeFactory.CreateBehaviorNode(typeName, name, null, null);

            Assert.IsNotNull(braceNode);
            Assert.AreEqual(typeName, braceNode.GetType().ToString());
            Assert.AreEqual(name, braceNode.GetName());
        }
Beispiel #3
0
        public void SimpleAddNodeTest()
        {
            var root     = CoreAI_BT.InitRootNode(null, null, null);
            var name     = "braceNodeTest";
            var typeName = "BraceNode";

            var leaf = BehaviorNodeFactory.CreateBehaviorNode(typeName, name, null, null);

            Assert.IsNull(root.FindChildByName(name, out _));

            root.AddNode(leaf, "core_AI_root", "startup_cleanup");
            var foundNode = root.FindChildByName(name, out var foundParent);

            Assert.AreEqual(leaf, foundNode);
            Assert.AreEqual(root, foundParent);
            Assert.IsInstanceOfType(foundNode, AccessTools.TypeByName(typeName));
            Assert.AreEqual(1, (foundParent as CompositeBehaviorNode)?.Children.IndexOf(foundNode));
        }