Esempio n. 1
0
        public override TaskStatus Run()
        {
            foreach (BTBaseNode node in nodes)
            {
                if (currentnode != null && currentnode != node) //the node is still running
                {
                    continue;
                }
                TaskStatus result = node.Run();

                switch (result)
                {
                case TaskStatus.Failed:
                    currentnode = null; return(TaskStatus.Failed);

                case TaskStatus.Success:
                    currentnode = null; continue;

                case TaskStatus.Running:
                    currentnode = node;
                    return(TaskStatus.Running);
                }
            }
            currentnode = null;
            return(TaskStatus.Success);
        }
Esempio n. 2
0
    private void Start()
    {
        SmokeEnemy =
            new BTSequence(showNode,
                           new BTCheckAttack(underAttack, isAtPlayer, agent),
                           new BTFlyToCover(agent, cover),
                           new BTWait(3f),
                           new BTThrowSmoke(prefabBom, child, underAttack, hasAttacked)
                           );

        RotateAroundPlayer =
            new BTSequence(showNode,
                           new BTTCheckAtPlayer(isAtPlayer),
                           new BTFlyArroundPlayer(isAtPlayer, agent, child, player)
                           );

        GoToPlayer =
            new BTSequence(showNode,
                           new BTCheckAttackDone(hasAttacked, agent),
                           new BTMoveAlly(hasAttacked, isAtPlayer, child, agent, player)
                           );

        rootNode = new BTSelector(new List <BTBaseNode> {
            SmokeEnemy, GoToPlayer, RotateAroundPlayer
        });
        rootNode.Run();
    }
Esempio n. 3
0
    public int loadTree <T>(int index, out BTBaseNode node, T instanceType)
    {
        SerializedNode serializableNode = mSerializedNode[index];

        switch (serializableNode.mNodeType)
        {
        //We have this as placeholder until we have more nodestypes created
        case BtNodeType.Sequencer:
            node = new SequenceNode();
            break;

        case BtNodeType.Selector:
            node = new BTBaseNode();
            break;

        default:
            node = new BTBaseNode();
            break;
        }

        for (int i = 0; i < serializableNode.mChildCount; i++)
        {
            BTBaseNode childNode;
            index = loadTree <T>(++index, out childNode, instanceType);
            node.addChild(childNode);
        }

        return(index);
    }
Esempio n. 4
0
 public BTGetObject(GameObject obj, Animator anim, string animationname)
 {
     owner         = obj;
     animator      = anim;
     AnimationName = animationname;
     Getobjectree  = new BTNodes.BTParallelNode(1, 0, new BTNodes.Pickup(owner, new Vector3(10, 0, 10), owner.transform.position), new BTNodes.PlayAnimation(animator, AnimationName));
 }
Esempio n. 5
0
    private void Start()
    {
        CheckSmoke =
            new BTSequence(showNode,
                           new BTCheckSmoke(isInSmoke, agent)
                           );

        AttackTree =
            new BTSequence(showNode,
                           new CheckPlayerRange(ClosestPlayer, hasWeapon, needsWeapon),
                           new BTMove(agent, ClosestPlayer, showNode, weaponHolder, hasWeapon, cantAttack, lighting, WeaponCol)
                           );

        CheckWeapon =
            new BTSequence(showNode,
                           new FindWeapon(needsWeapon),
                           new BTGoForWeapon(agent, weapon, hasWeapon, needsWeapon, weaponHolder, weapon, lighting, CheckForWeaponCol)
                           );

        PatrollTree =
            new BTSequence(showNode,
                           new BTPatrol(WayPoints, agent, lighting, PatrolCol)
                           );


        rootNode = new BTSelector(new List <BTBaseNode> {
            CheckSmoke, CheckWeapon, AttackTree, PatrollTree
        });
        rootNode.Run();
    }
Esempio n. 6
0
 public BTPatrol(GameObject obj, Vector3[] list, Animator anim, string animationname)
 {
     owner         = obj;
     position      = list;
     animator      = anim;
     AnimationName = animationname;
     patroltree    = new BTNodes.BTParallelNode(1, 0, new BTNodes.MoveToPosition(owner, position), new BTNodes.PlayAnimation(animator, AnimationName)); //patrol
 }
Esempio n. 7
0
    public BTCheckTaskStatus(BTBaseNode activeTask, params BTBaseNode[] replyNode)
    {
        this.activeTask = activeTask;
        this.replyNode  = new List <BTBaseNode>();

        foreach (BTBaseNode node in replyNode)
        {
            this.replyNode.Add(node);
        }
    }
Esempio n. 8
0
    public bool addChild(BTBaseNode node)
    {
        if (canHaveChilds())
        {
            mChilds.Add(node);
            node.setParent(this);
            return(true);
        }

        return(false);
    }
Esempio n. 9
0
    private void Start()
    {
        Vector3[] patrol = new[] { new Vector3(0, 0, 0), new Vector3(6, 0, 6), new Vector3(-6, 0, 6), new Vector3(-6, 0, -6), new Vector3(6, 0, -6), };
        //new BTNodes.BTPatrol(this.gameObject,patrol,animator, "Run Forward");
        tree =
            new BTNodes.BTSelectorNode(new BTNodes.Attack(fov.validTargets, this.gameObject, animator, "Kick", GameObject.Find("Player")), new BTNodes.BTInverterNode(new BTNodes.BTGetObject(this.gameObject, animator, "Run Forward")), new BTNodes.BTPatrol(this.gameObject, patrol, animator, "Run Forward"));



        //  new BTNodes.BTParallelNode(1, 0, new BTNodes.Attack(), new BTNodes.PlayAnimation(animator, "Idle")),
        //   new BTNodes.BTParallelNode(2,0, new BTNodes.BTSequenceNode(),new BTNodes.DetectPosition(agent,new Vector3(0,0,0))));
    }
Esempio n. 10
0
 public Invertor(BTBaseNode _child)
 {
     child = _child;
 }
Esempio n. 11
0
 public BTInverter(BTBaseNode node)
 {
     this.node = node;
 }
Esempio n. 12
0
    private void Start()
    {
        for (int i = 0; i < hideSpots.transform.childCount; i++)
        {
            VariableGameObject spot = Instantiate(hideSpot);
            spot.Value = hideSpots.transform.GetChild(i).gameObject;
            hideSpotCollection.Add(spot);
        }

        myAgent.Value   = this.gameObject;
        myPlayer.Value  = myPlayerObject;
        Target.Value    = myTarget;
        Enemy.Value     = myEnemy;
        moveSpeed.Value = 0;

        BTBaseNode follow =
            new BTPrioritySelector(
                new BTSequence(
                    new BTSetTarget(Target, myPlayer),
                    new BTCheckRange(myAgent, Target, 5),
                    new BTAnimate(animator, "Run"),
                    new BTMove(2.5f, myNavMesh, Target)
                    ),
                new BTSequence(
                    new BTCheckRange(myAgent, Target, 2),
                    new BTAnimate(animator, "Walk Crouch"),
                    new BTMove(2, myNavMesh, Target)
                    ),
                new BTSequence(
                    new BTAnimate(animator, "Crouch Idle"),
                    new BTStop(myNavMesh)
                    )
                );

        follow._name = "Follow";

        BTBaseNode hide =
            new BTPrioritySelector(
                new BTSequence(
                    new BTCheckBool(Player.inCombat, true),
                    new BTCheckBool(hidden, false),

                    new BTGetClosestHideSpot(hideSpotCollection, myAgent, Target, Enemy),
                    new BTCheckRange(myAgent, Target, 0.5f),

                    new BTAnimate(animator, "Run"),
                    new BTMove(2.5f, myNavMesh, Target)

                    ),
                new BTSequence(
                    new BTCheckBool(Player.inCombat, true),
                    new BTCheckBool(hidden, false),
                    new BTStop(myNavMesh),
                    new BTAnimate(animator, "Crouch Idle"),

                    new BTCheckTaskStatus(
                        new BTWait(3),
                        new BTSetBool(hidden, true)
                        )
                    ),
                new BTSequence(
                    new BTCheckBool(Player.inCombat, true),
                    new BTCheckBool(hidden, true),

                    new BTCheckTaskStatus(
                        new BTSpot(Enemy, myAgent, 200, false),
                        new BTSetBool(hidden, false)
                        ),

                    new BTCheckTaskStatus(
                        new BTCheckBool(Enemy.Value.GetComponent <Guard>().isStunned, false),
                        new BTAnimate(animator, "Throw", "Crouch Idle"),
                        new BTCheckTaskStatus(
                            new BTWait(4),
                            new BTSetBool(Enemy.Value.GetComponent <Guard>().isStunned, true),
                            new BTSetBool(hidden, false)
                            )
                        )
                    )
                );

        hide._name = "Hide";

        tree = new BTPrioritySelector(
            hide,
            follow
            );
        tree._name = "Tree";
    }
Esempio n. 13
0
 private void Start()
 {
     tree = new BTNodes.BTSelectorNode(new BTNodes.BTSelectorNode(new BTNodes.Throw(Throwable, GameObject.Find("AI_Guard").transform, this.gameObject.GetComponent <FieldOfView>().validCovers, this.gameObject), new BTNodes.RunForCover(this.gameObject, this.gameObject.GetComponent <FieldOfView>().validCovers, GameObject.Find("AI_Guard").GetComponent <FieldOfView>().validTargets, GameObject.Find("Player"))), new BTNodes.BTSequenceNode(new BTNodes.BTParallelNode(1, 0, new BTNodes.DetectPosition(agent, GameObject.Find("Player"), this.gameObject), new BTNodes.PlayAnimation(animator, "Run Forward"))));
 }
Esempio n. 14
0
    private void Start()
    {
        BTBaseNode engage =
            new BTPrioritySelector(
                new BTSequence(
                    new BTCheckTaskStatus(
                        new BTCheckRange(myAgent, targetPlayer, 15),
                        new BTSetBool(engaged, false),
                        new BTSetBool(Player.inCombat, false)
                        ),

                    new BTCheckBool(isArmed, false),

                    new BTCheckTaskStatus(
                        new BTInverter(new BTCheckRange(myAgent, targetWeapon, 1.5f)),
                        new BTSetBool(isArmed, true)
                        ),

                    new BTAnimate(animator, "Run"),
                    new BTMove(5, agentNavMesh, targetWeapon)
                    ),
                new BTSequence(
                    new BTCheckRange(myAgent, targetPlayer, 1),
                    new BTAnimate(animator, "Run"),
                    new BTMove(3, agentNavMesh, targetPlayer)
                    ),
                new BTSequence(
                    new BTStop(agentNavMesh),
                    new BTAnimate(animator, "Kick", "Idle")
                    )
                );

        engage._name = "Engage";

        BTBaseNode patrol =
            new BTPrioritySelector(
                new BTSequence(
                    new BTCheckBool(engaged, false),

                    new BTCheckTaskStatus(
                        new BTSpot(targetPlayer, myAgent, spotDistance, true),
                        new BTSetBool(Player.inCombat, true),
                        new BTSetBool(engaged, true)
                        ),

                    new BTCheckRange(myAgent, wayPoint, 1),
                    new BTAnimate(animator, "Rifle Walk"),
                    new BTMove(2, agentNavMesh, wayPoint)
                    ),
                new BTSequence(
                    new BTCheckBool(engaged, false),

                    new BTCheckTaskStatus(
                        new BTSpot(targetPlayer, myAgent, spotDistance, true),
                        new BTSetBool(Player.inCombat, true),
                        new BTSetBool(engaged, true)
                        ),

                    new BTAnimate(animator, "Idle"),
                    new BTWait(3),
                    new BTNextWaypoint(wayPoint, waypoints)// Get new Waypoint
                    ));

        patrol._name = "Patrol";

        BTBaseNode stunned =
            new BTPrioritySelector(
                new BTSequence(
                    new BTCheckBool(isStunned, true),
                    new BTAnimate(animator, "Scared"),
                    new BTStop(agentNavMesh),
                    new BTSetBool(Player.inCombat, false),

                    new BTCheckTaskStatus(
                        new BTWait(5),
                        new BTSetBool(engaged, false),
                        new BTSetBool(isStunned, false)

                        )
                    )
                );

        stunned._name = "Stunned";


        tree = new BTPrioritySelector(
            stunned,
            patrol,
            engage
            );
    }
Esempio n. 15
0
 public void setParent(BTBaseNode parent)
 {
     mParent = parent;
 }