// Use this for initialization void Awake() { attackType = (int)specialAttackType; chase = new NodeChase(this); attack = new NodeAttack(this); stunned = new NodeStunned(this); melee = new NodeAttackMelee(this); if (attackType == (int)SpecialAttackType.Lunge) { special = new NodeSpecialAttackLunge(this); } if (attackType == (int)SpecialAttackType.Ranged) { special = new NodeSpecialAttackRanged(this); } if (attackType == (int)SpecialAttackType.DoubleShot) { special = new NodeSpecialAttackRangedDouble(this); } npcNav = GetComponent <NPCNavigation>(); if (npcNav == null) { npcNav = transform.parent.GetComponent <NPCNavigation>(); } navMeshAgent = GetComponent <NavMeshAgent>(); if (navMeshAgent == null) { navMeshAgent = transform.parent.GetComponent <NavMeshAgent>(); } targets = new Transform[2]; }
/// <summary> /// Add a created Action Node to the Tree /// </summary> public BehaviourTreeBuilder Do(IBehaviourTreeNode node) { AssertCanAddLeaf(); _parentNodeStack.Peek().AddChild(node); return(this); }
// A Selector may be contaminated with other nodes (Condition) or IParentBeahviourTreeNodes over which // it's behaviour as a selector is applied. The assumption here is that any item in it's child list // should have selector behaviour applied unless the first one is a condition Action. public BehaviourTreeStatus Tick(TimeData time) { int skipOne = 0; // check if this is a conditional action IBehaviourTreeNode firstNode = children[0]; if (firstNode is ConditionNode) { ConditionNode firstChild = (ConditionNode)firstNode; var status = firstChild.Tick(time); if (status != BehaviourTreeStatus.Success) { return(BehaviourTreeStatus.Success); } ++skipOne; } List <IBehaviourTreeNode> remainingChildren = children.Skip(skipOne).ToList <IBehaviourTreeNode>(); if (isRandom) { remainingChildren = Randomize(remainingChildren); } foreach (var child in remainingChildren) { var childStatus = child.Tick(time); if (childStatus != BehaviourTreeStatus.Failure) { return(childStatus); } } return(BehaviourTreeStatus.Failure); }
public BehaviourTree( IBehaviourTreeNode startNode, IBehaviourTreeNode[] nodes) { StartNode = startNode; Nodes = nodes; }
public string RegisterBehaviour(IBehaviourTreeNode node) { TimeData time = new TimeData(_objProc.ProcessingTickInterval); string behaviourID = _objProc.RegisterProcessingEvent(() => node.Tick(time)); return(behaviourID); }
/// <summary> /// Splice a sub tree into the parent tree. /// </summary> public BehaviourTreeBuilder Splice(IBehaviourTreeNode subTree) { AssertCanSplice(subTree); _parentNodeStack.Peek().AddChild(subTree); return(this); }
private void SetRootInternal(IBehaviourTreeNode <TTickData, TState> root) { if (_root != null) { throw new BehaviourTreeBuilderException("root already specified"); } _root = root; }
public void AddChild(IBehaviourTreeNode child) { if (Children.Count > 0) { throw new ApplicationException($"Can't add more than a single child to {GetType().Name}!"); } Children.Add(child); }
public void Decorate(IBehaviourTreeNode <TTick, TState> node) { if (node == null) { throw new ArgumentNullException(nameof(node)); } _parentNode.Decorate(node); }
/// <summary> /// Add a child to the parent node. /// </summary> public void AddChild(IBehaviourTreeNode child) { if (this.childNode != null) { throw new ApplicationException("Can't add more than a single child to InverterNode!"); } this.childNode = child; }
void Start() { behaviorController = GetComponent <BehaviorController>(); var builder = new BehaviourTreeBuilder(); tree = builder.Sequence("gatherResources").Splice(CreateGatherTreeSequence()) .End() .Build(); }
public void AddNode(IBehaviourTreeNode <TTickData, TState> node) { if (node == null) { throw new ArgumentNullException(nameof(node)); } _nodes.Add(node); }
public void AddNode(IBehaviourTreeNode <TTickData, TState> node, uint probality) { if (node == null) { throw new ArgumentNullException(nameof(node)); } _nodes.Add(new RandomEntry <IBehaviourTreeNode <TTickData, TState> >(probality, node)); }
public void Decorate(IBehaviourTreeNode <TTickData, TState> node) { if (DecoratedNode != null) { throw new BehaviourTreeException(ExceptionMessages.СantDecorateMoreThanOneNode); } DecoratedNode = node ?? throw new ArgumentNullException(nameof(node)); }
public void Run(object[] args) { TimeData time = new TimeData(_ops.ProcessingTickInterval); IBehaviourTreeNode node = (IBehaviourTreeNode)args[0]; NWCreature creature = (NWCreature)args[1]; if (creature.IsValid && !creature.IsDead && !creature.IsPossessedFamiliar && !creature.IsDMPossessed) { node.Tick(time); } }
public BehaviourTreeNodeSequenceBuilder <TTickData, TState> Add(IBehaviourTreeNode <TTickData, TState> node) { if (node == null) { throw new ArgumentNullException(nameof(node)); } _parentNode.AddNode(node); return(this); }
/// <summary> /// Add a child to the sequence. /// </summary> public void AddChild(IBehaviourTreeNode child) { NodeStatusPair nspair = new NodeStatusPair { Action = child, Status = BehaviourTreeStatus.Success }; children.AddLast(nspair); current = children.First; }
public void ExecutionResult(IBehaviourTreeNode <int, int> node, BehaviourTreeState expectedState) { var invert = new SucceederNode <int, int>(); invert.Decorate(node); var func = invert.Compile(); var state = func(0, 0); Assert.Equal(expectedState, state); }
public BehaviourTreeNodeRandomBuilder <TTick, TState> Add(uint probability, IBehaviourTreeNode <TTick, TState> node) { if (node == null) { throw new ArgumentNullException(nameof(node)); } _parentNode.AddNode(node, probability); return(this); }
void initTree1() { Log("Initializing Behavior Tree 1"); btree1 = treeBuilder .Sequence("Sequence1") .Do(seq1Action1, t => { return(actionSuccess(t, seq1Action1)); }) .Do(seq1Action2, t => { return(actionSuccess(t, seq1Action2)); }) .End() .Selector("Selector-With-Condition") .Condition(sel1Condition, t => { return(evalActionTrue(t, sel1Condition)); }) .Do(sel1Action1, t => { return(actionFail(t, sel1Action1)); }) .Do(sel1Action2, t => { return(actionFail(t, sel1Action2)); }) .Do(sel1Action3, t => { return(actionFail(t, sel1Action3)); }) .Parallel("Parallel1", 1, 1). Do(par1Action1, t => { return(actionFail(t, par1Action1)); }) .Do(par1Action2, t => { return(actionFail(t, par1Action2)); }) .Do(par1Action3, t => { return(actionSuccess(t, par1Action3)); }) .End() .End() .Sequence("Sequence2") .Do(seq2Action1, t => { return(actionSuccess(t, seq2Action1)); }) .Do(seq2Action2, t => { return(actionSuccess(t, seq2Action2)); }) .Do(seq2Action3, t => { return(actionSuccess(t, seq2Action3)); }) .End() .Build(); Log("Finished Buidling Behavior Tree 1 !"); }
private void pruneStack() { if (parentNodeStack.Count > 1) { curNode = parentNodeStack.Pop(); } else if (parentNodeStack.Count == 1) { curNode = parentNodeStack.Peek(); } }
public void RegisterBehaviour(IBehaviourTreeNode node, NWCreature creature) { TimeData time = new TimeData(_objProc.ProcessingTickInterval); string behaviourID = _objProc.RegisterProcessingEvent(() => { if (creature.IsValid) { node.Tick(time); } }); _state.NPCBehaviours.Add(behaviourID, creature); }
private void AssertCanSplice(IBehaviourTreeNode subTree) { AssertCanModify(); if (subTree == null) { throw new ArgumentNullException("subTree"); } if (_parentNodeStack.Count <= 0) { throw new ApplicationException("Can't splice an unnested sub-tree, there must be a parent-tree."); } }
void initTree1() { Console.WriteLine("Initializing Behavior Tree 1"); btree1 = treeBuilder2 .Sequence("Sequence1") .Do(seq1Action1, t => { return(actionSuccess(t, seq1Action1)); }) .Do(seq1Action2, t => { return(actionSuccess(t, seq1Action2)); }) .End() .RandomSelector("Random-Selector1-With-Condition") .Condition(sel1Condition, t => { return(evalActionTrue(t, sel1Condition)); }) .Do(sel1Action1, t => { return(actionSuccess(t, sel1Action1)); }) .Do(sel1Action2, t => { return(actionSuccess(t, sel1Action2)); }) .Do(sel1Action3, t => { return(actionSuccess(t, sel1Action3)); }) .Do(sel1Action4, t => { return(actionSuccess(t, sel1Action4)); }) .Do(sel1Action5, t => { return(actionSuccess(t, sel1Action5)); }) .Do(sel1Action6, t => { return(actionSuccess(t, sel1Action6)); }) .Do(sel1Action7, t => { return(actionSuccess(t, sel1Action7)); }) .Do(sel1Action8, t => { return(actionSuccess(t, sel1Action8)); }) .Do(sel1Action9, t => { return(actionSuccess(t, sel1Action9)); }) .Do(sel1Action10, t => { return(actionSuccess(t, sel1Action10)); }) .Do(sel1Action11, t => { return(actionSuccess(t, sel1Action11)); }) .Do(sel1Action12, t => { return(actionSuccess(t, sel1Action12)); }) .End() .Selector("Normal-Selector2-With-Condition") .Condition(sel2Condition, t => { return(evalActionTrue(t, sel2Condition)); }) .Do(sel2Action1, t => { return(actionFail(t, sel2Action1)); }) .Do(sel2Action2, t => { return(actionFail(t, sel2Action2)); }) .Do(sel2Action3, t => { return(actionFail(t, sel2Action3)); }) .Do(sel2Action4, t => { return(actionFail(t, sel2Action4)); }) .Do(sel2Action5, t => { return(actionSuccess(t, sel2Action5)); }) .Do(sel2Action6, t => { return(actionSuccess(t, sel2Action6)); }) .Do(sel2Action7, t => { return(actionSuccess(t, sel2Action7)); }) .Do(sel2Action8, t => { return(actionSuccess(t, sel2Action8)); }) .Do(sel2Action9, t => { return(actionSuccess(t, sel2Action9)); }) .Do(sel2Action10, t => { return(actionSuccess(t, sel2Action10)); }) .Do(sel2Action11, t => { return(actionSuccess(t, sel2Action11)); }) .Do(sel2Action12, t => { return(actionSuccess(t, sel2Action12)); }) .End() .Build(); Console.WriteLine("Finished Buidling Behavior Tree 1 !"); }
public BehaviourTreeConstructor Splice(IBehaviourTreeNode subTree) { if (subTree == null) { throw new Exception("Subtree is null"); } if (Nodes.Count <= 0) { throw new ApplicationException("Can't splice an unnested sub-tree, there must be a parent-tree."); } Nodes.Peek().AddChild((BehaviorTreeNode)subTree); return(this); }
/// <summary> /// Splice a sub tree into the parent tree. /// </summary> public BehaviourTreeBuilder Splice(IBehaviourTreeNode subTree) { if (subTree == null) { throw new ArgumentNullException("subTree"); } if (parentNodeStack.Count <= 0) { throw new ApplicationException("Can't splice an unnested sub-tree, there must be a parent-tree."); } parentNodeStack.Peek().AddChild(subTree); return(this); }
void Start() { Debug.Log("ZombieBT start"); var builder = new BehaviourTreeBuilder(); // var targetPosition = GameObject.Find("Player").transform.position; targetPosition = GameObject.Find("Player").transform.position; this.tree = builder .Selector("ChooseAction") .Sequence("tryToGoToPlayer") // If player is alive and close then go to it .Condition("isPlayerClose", t => (BlackboardZombie.Instance.getIsPlayerAlive() == true && Vector3.Distance(transform.position, targetPosition) < 8 && Vector3.Distance(transform.position, targetPosition) > 2)) .Do("GoToPlayer", t => { GetComponent <Animator>().SetBool("bool_walk", true); GetComponent <Animator>().SetBool("bool_attack", false); Debug.Log("~~~ GoToPlayer"); BehaviourTreeStatus bts; bts = GoToTarget("target1", targetPosition); BlackboardZombie.Instance.setTarget1(bts == BehaviourTreeStatus.Success); return(bts); }) .End() .Sequence("tryToAttackPlayer") // If player is alive and in range then attack him .Condition("isPlayerInRange", t => (BlackboardZombie.Instance.getIsPlayerAlive() == true && Vector3.Distance(transform.position, targetPosition) <= 2)) .Do("AttackPlayer", t => { GetComponent <Animator>().SetBool("bool_walk", false); GetComponent <Animator>().SetBool("bool_attack", true); Debug.Log("~~~ AttackPlayer"); return(AttackPlayer()); }) .End() .Do("Wander", t => { GetComponent <Animator>().SetBool("bool_walk", true); GetComponent <Animator>().SetBool("bool_attack", false); GetComponent <SteerForWander>().enabled = true; Debug.Log("~~~ Wander"); return(Wander()); }) .End() .Build(); }
public CrocoBehaviour(CrocoLoco _crocoLoco) { crocoLoco = _crocoLoco; var builder = new BehaviourTreeBuilder(); tree = builder .Selector("Watch players") .Condition("Is any player visible", IsAnyPlayerVisible) .End() .Build(); timeData = new TimeData(); properties = new CrocoProperties(); properties.watchLength = 300; }
public BehaviourTreeBuilder AddChild(IBehaviourTreeNode child) { if (child == null) { throw new ArgumentNullException(nameof(child)); } if (this.parentStack.Count <= 0) { throw new ApplicationException("There is no parent node in tree."); } this.parentStack.Peek().AddChild(child); return(this); }
protected override void Start() { BehaviourTreeBuilder treeBuilder = new BehaviourTreeBuilder(); this.rootNode = treeBuilder.Selector("SomeSelector", true) .Do("some-action-1", t => { return(BehaviourTreeStatus.Success); }) .Do("some-action-2", t => { return(BehaviourTreeStatus.Success); }) .End() .Build(); this.rootNode = this.BuildSimpleAI(); base.Start(); }
/// <summary> /// Ends a sequence of children. /// </summary> public BehaviourTreeBuilder End() { curNode = parentNodeStack.Pop(); return this; }
public void AddChild(IBehaviourTreeNode child) { children.Add(child); }
/// <summary> /// Splice a sub tree into the parent tree. /// </summary> public BehaviourTreeBuilder Splice(IBehaviourTreeNode subTree) { if (subTree == null) { throw new ArgumentNullException("subTree"); } if (parentNodeStack.Count <= 0) { throw new ApplicationException("Can't splice an unnested sub-tree, there must be a parent-tree."); } parentNodeStack.Peek().AddChild(subTree); return this; }