Пример #1
0
 public NodeSearchResult(CompositeBehaviorNode parentNode, List <BehaviorNode> nodeSiblings, int nodeIndex, BehaviorNode node)
 {
     this.ParentNode   = parentNode;
     this.NodeSiblings = nodeSiblings;
     this.NodeIndex    = nodeIndex;
     this.Node         = node;
 }
        public void Inject(CompositeBehaviorNode parentNode, int targetIndex, BehaviorNode branchRoot)
        {
            List <BehaviorNode> siblings = parentNode.Children;
            int injectionIndex           = targetIndex;

            if (InjectionOrder == BehaviourInjectionOrder.BEFORE_SIBLING)
            {
                injectionIndex = targetIndex - 1;
                if (injectionIndex < 0)
                {
                    injectionIndex = 0;
                }
            }
            else if (InjectionOrder == BehaviourInjectionOrder.AFTER_SIBLING)
            {
                injectionIndex = targetIndex + 1;
                if (injectionIndex >= siblings.Count)
                {
                    siblings.Add(branchRoot);
                    return;
                }
            }

            siblings.Insert(injectionIndex, branchRoot);
        }
Пример #3
0
        private NodeSearchResult FindNode(BehaviorNode parent, string nodeName)
        {
            if (parent is CompositeBehaviorNode)
            {
                CompositeBehaviorNode compositeParent = (CompositeBehaviorNode)parent;
                int index = compositeParent.Children.FindIndex(child => {
                    string childName = (string)AccessTools.Field(typeof(BehaviorNode), "name").GetValue(child);
                    if (childName == nodeName)
                    {
                        return(true);
                    }
                    return(false);
                });

                if (index != -1)
                {
                    return(new NodeSearchResult(compositeParent, compositeParent.Children, index, compositeParent.Children[index]));
                }
                return(null);
            }

            string name = (string)AccessTools.Field(typeof(BehaviorNode), "name").GetValue(parent);

            Main.Logger.LogError($"[FindNode] BehaviourNode parent '{name}' is not a composite node. Paths for custom behaviour branches can only contain composite nodes.");
            return(null);
        }
        public override void Build(BehaviorTree behaviourTree, CompositeBehaviorNode parentNode, int targetIndex, BehaviorNode target, AbstractActor unit)
        {
            this.tree = behaviourTree;
            this.unit = unit;

            string targetName = (string)AccessTools.Field(typeof(BehaviorNode), "name").GetValue(target);

            Main.LogDebug($"[{this.GetType().Name}] Injecting custom behaviour branch {InjectionOrder} '{targetName}'");

            SequenceNode testBranchNodeRoot = new SequenceNode("follow_lance_if_following", behaviourTree, unit);

            BuildFirstLevel(testBranchNodeRoot);

            Inject(parentNode, targetIndex, testBranchNodeRoot);
        }
 public abstract void Build(BehaviorTree behaviourTree, CompositeBehaviorNode parentNode, int targetIndex, BehaviorNode target, AbstractActor unit);