protected Node BuildTreeRoot()
    {
        Func <bool> PolicemanNotSeeTheFighter = () => (!checkSee(fighter1, policeman));

        Func <bool> SeeTheFighter = () => (checkSee(fighter1, policeman) && checkSee(fighter1, heroAgent));

        Func <bool> HeroAgentNotSeeTheFighter = () => (!checkSee(fighter1, heroAgent));

        Node doChase = new Sequence(new DecoratorInvert(new DecoratorLoop(new LeafAssert(PolicemanNotSeeTheFighter))), new LeafWait(1000), ST_Chase(fighter1, policeman, escapeDestination)
                                    );

        Node fight = new Sequence(ST_Fight(fighter1), ST_Fight(fighter2),
                                  ST_RPunch(fighter2), ST_FaceHitted(fighter1), ST_PickupRightWeapon(fighter1));

        Node fight_with_weapon = new DecoratorInvert(
            new DecoratorLoop(
                new Sequence(
                    new DecoratorInvert(new LeafAssert(SeeTheFighter)), ST_UseWeapon(fighter1), new DecoratorInvert(new LeafAssert(SeeTheFighter)), ST_HeavyHitted(fighter2)
                    )));

        Node doFight = new Sequence(fight, fight_with_weapon);

        Node doEscape = new Sequence(new DecoratorInvert(new DecoratorLoop(new LeafAssert(HeroAgentNotSeeTheFighter))),
                                     fighter1.GetComponent <BehaviorMecanim> ().Node_GoTo(escapeDestination.position, 18f));

        Node root = new SequenceParallel(doFight, doChase, doEscape);

        return(root);
    }
Example #2
0
    protected Node ST_MainStoryArc()
    {
        //Node actor1 = new DecoratorLoop(new SequenceShuffle(this.ST_GoToUpToRadius(wanderpoint1,0.5f, 3f), this.ST_GoToUpToRadius(wanderpoint2,0.5f, 5.0f), this.ST_GoToUpToRadius(wanderpoint3, 1f, 6f)));
        Node actor1       = this.ST_PlayGesture("COWBOY", 3000L, adam1);
        Node actor2       = this.ST_PlayGesture("POINTING", 3000L, adam2);
        Node mainStoryArc = new SequenceParallel(actor1, actor2);

        return(mainStoryArc);
    }
Example #3
0
    protected Node ST_freeAdam1()
    {
        Node freeAdam1 = new SequenceParallel
                         (
            this.ST_PlayGesture("POINTING", 3000L, adam2)

                         );

        return(freeAdam1);
    }
Example #4
0
    protected Node BuildTreeRoot()
    {
        Node ibt = new SequenceParallel(
            StoryTree(),
            UserInput(),
            Move(),
            SideCharactersAffordances()
            );

        return(ibt);
    }
Example #5
0
    /// <summary>
    /// This is what you create, using control nodes(sequence, selector, etc.) and leaf nodes
    /// and pass it to the Behavior Agent. Each time the root ticks, it will tick its children,
    /// if any, and the ticks continue down the tree until reaching a leaf to execute. This process
    /// is implemented using Closures and Enumerators in C#.
    /// </summary>
    /// <returns></returns>
    protected Node BuildTreeRoot()
    {
        //Node actor1 = new DecoratorLoop(new SequenceShuffle(this.ST_GoToUpToRadius(wanderpoint1,0.5f, 3f), this.ST_GoToUpToRadius(wanderpoint2,0.5f, 5.0f), this.ST_GoToUpToRadius(wanderpoint3, 1f, 6f)));
        Node actor1 = new DecoratorLoop(
            new Sequence(
                this.ST_Routes(wanderpoint1, wanderpoint2, 3f, 2f, 6f, 3f, wanderpoint3),
                this.ST_Grab(item)
                )
            );
        Node actor2       = new Sequence();
        Node mainStoryArc = new SequenceParallel(actor1, actor2);

        return(mainStoryArc);
    }
Example #6
0
    protected Node SeqP_AntagonistsRoot()
    {
        Node antagonistsIBT = new SequenceParallel(
            // Patrol until the time limit is reached to succeed.
            new DecoratorLoopSuccess(
                this.Patrol()
                ),
            // Continually evaluate your surroundings, returning success.
            new DecoratorLoop(
                this.SelP_AntagonistEvaluate()
                ));

        return(antagonistsIBT);
    }
Example #7
0
    protected Node BuildTreeRoot()
    {
        //Node node1 = new Sequence (new LeafWait (1000), this.Conversation (Daniel, Tom, gatherPoint), new LeafWait(1000));
        //Node node2 = new Sequence (new LeafWait(1000), this.ExchangeItem(Daniel, Tom, gatherPoint, ball));
        //Node node3 = new Sequence (new LeafWait(1000), this.Follow(Daniel, Tom, Richard));
        //Node node4 = new Sequence (new LeafWait(1000), this.Haggling(Daniel, Tom)); // TODO: when does this event happen? price = 7? or what?

        Node nodeDanielOut = new Sequence(Daniel.GetComponent <BehaviorMecanim> ().ST_PlayHandGesture("THINK", 1000),
                                          this.ST_turnonlight(Daniel),
                                          this.ST_GetOutHouse(Daniel),
                                          this.ST_SetDanielOut(),
                                          this.ST_WalkTo(Daniel, fishingPoint),
                                          this.ST_LookAT(Daniel, poolCenter));
        Node nodeLuren = new SequenceParallel(
            //this.ST_ThinkUntilClicked (Luren1),
            this.Conversation(Luren1, Luren2, LurenMeetingPoint12),
            this.Conversation(Luren3, Luren4, LurenMeetingPoint34),
            this.Conversation(Luren5, Luren6, LurenMeetingPoint56),
            this.Conversation(Luren7, Luren8, LurenMeetingPoint78));
        //Node nodePolice = new Sequence (
        //	                  this.ST_ThinkUntilClicked (police),
        //	                  this.ChaseBoss ());
        Node nodeFish = new DecoratorInvert(
            new DecoratorLoop(
                new Sequence(
                    Daniel.GetComponent <BehaviorMecanim> ().ST_PlayHandGesture("Fishing", 1000),
                    new DecoratorInvert(this.ST_Call(Daniel)))));
        Node nodeConverse = this.ConversationNtimes(Daniel, Tom, gatherPoint, 2);
        Node nodeSteal    = new Sequence(this.WaitUntilDanielLeave(Richard),
                                         this.ST_GetInHouse(Richard),
                                         this.ST_SetRichardIn(),
                                         Richard.GetComponent <BehaviorMecanim> ().ST_PlayFaceGesture("ROAR", 1000),
                                         this.ST_GrabObj(Richard, ball),
                                         this.ST_GetOutHouse(Richard));
        Node nodeChase   = this.Chase(Richard, Daniel, Tom, chasePoint1);
        Node nodeTomCall = new Sequence(this.WaitUntilRichardIn(Tom),
                                        this.ST_TomCallDaniel(),
                                        new SequenceParallel(
                                            Daniel.GetComponent <BehaviorMecanim> ().ST_PlayBodyGesture("Talking On Phone", 1000),
                                            Tom.GetComponent <BehaviorMecanim> ().ST_PlayBodyGesture("Talking On Phone", 1000)));
        Node nodeExchange = new Sequence(new LeafWait(1000), this.ExchangeItem(Richard, PassengerB, dealPoint, ball), this.ST_DropObj(PassengerB, ball));
        //Node nodeEnd = new Sequence (this.ST_BallUp (), this.ST_SetGameOver (), this.ST_CheerN (PassengerB, 5));
        //Node nodeEnd = new Sequence (this.ST_CheerN (PassengerB, 5), new DecoratorForceStatus(RunStatus.Failure, new LeafWait(1000)));
        Node doorNode      = this.AssertAndWaitForClap();
        Node passengerNode = new Sequence(
            new DecoratorLoop(
                this.ST_Repeat(Passenger)));

        Node nodeMonitorUI    = this.MonitorUI();
        Node nodeMonitorState = this.MonitorState();
        Node nodeStory1       = this.NewConverse();
        Node nodeStory2       = this.NewPolice();

        /*Node root1 = new SequenceParallel (
         *      new Sequence (
         *              new SequenceParallel (
         *                      new Sequence (nodeDanielOut, nodeFish),
         *                      nodeSteal,
         *                      nodeTomCall),
         *              nodeConverse,
         *              nodeChase,
         *              nodeExchange,
         *              this.ST_CheerN(PassengerB, 5)),
         *      doorNode, passengerNode);
         *
         * Node nodestory = new DecoratorLoop (
         *                       new DecoratorForceStatus (RunStatus.Success,
         *                               new Sequence (nodeStory1, nodeStory2)));
         *
         * Node root = new SequenceParallel (root1,
         *                  nodeMonitorUI,
         *                  nodeMonitorState,
         *                  nodestory);*/
        /*
         * Node root = new SequenceParallel (
         *      new Sequence (
         *              new SequenceParallel (
         *                      new Sequence (nodeDanielOut, nodeFish),
         *                      nodeSteal,
         *                      nodeTomCall),
         *              nodeConverse,
         *              nodeChase,
         *              nodeExchange,
         *              this.ST_CheerN(PassengerB, 5)),
         *      doorNode, passengerNode, nodeLuren, nodePolice);
         */
        Node nodePolice1 = new DecoratorLoop(
            new DecoratorForceStatus(RunStatus.Success,
                                     // new SequenceParallel (
                                     new Sequence(this.ST_Repeatpolice(police1, wanderp11, wanderp12))));
        Node nodePolice2 = new DecoratorLoop(
            new DecoratorForceStatus(RunStatus.Success,
                                     // new SequenceParallel (
                                     new Sequence(this.ST_Repeatpolice(police2, wanderp21, wanderp22))));

        /*Node nodePolice3 = new DecoratorLoop (
         *      new DecoratorForceStatus (RunStatus.Success,
         *              // new SequenceParallel (
         *              new Sequence (this.ST_Repeatpolice (police3, wanderp31, wanderp32))));*/
        Node nodePolice4 = new DecoratorLoop(
            new DecoratorForceStatus(RunStatus.Success,
                                     // new SequenceParallel (
                                     new Sequence(this.ST_Repeatpolice(police4, wanderp41, wanderp42))));
        Node nodePolice5 = new DecoratorLoop(
            new DecoratorForceStatus(RunStatus.Success,
                                     // new SequenceParallel (
                                     new Sequence(this.ST_Repeatpolice(police5, wanderp51, wanderp52))));
        //new Sequence (this.ST_Repeatpolice (police2, wanderp21, wanderp22)),
        //new Sequence (this.ST_Repeatpolice (police3, wanderp31, wanderp32)),
        //new Sequence (this.ST_Repeatpolice (police4, wanderp41, wanderp42)),
        //new Sequence (this.ST_Repeatpolice (police5, wanderp51, wanderp52)))));

        Node Danielcontrol = new DecoratorLoop(
            new DecoratorForceStatus(RunStatus.Success,
                                     new Sequence(
                                         this.ST_ThinkUntilClickedLight(Daniel),
                                         this.clickLight(Daniel))));

        Node root = new SequenceParallel(
            this.gameOverNew(), Danielcontrol, doorNode, passengerNode, nodeLuren, nodePolice1, nodePolice2, nodePolice4, nodePolice5);

        return(root);
    }
Example #8
0
    public static Node Get2(GameObject hero, List <GameObject> sideCharacters)
    {
        SequenceParallel sp = new SequenceParallel();

        foreach (var character in sideCharacters)
        {
            Val <Vector3> position    = Val.V(() => hero.transform.position);
            Node          interaction =
                new Selector(
                    new Sequence(new LeafAssert(() => character.CompareTag("Group") == true),
                                 new Selector(

                                     // The Sequence when hero is nearby : Currently just look at the hero
                                     new Sequence(new LeafAssert(() => StoryIBT
                                                                 .blackboardTrigger[
                                                                     character.transform.GetChild(0).gameObject] ==
                                                                 true),
                                                  character.transform.GetChild(0).gameObject.GetComponent <BehaviorMecanim>()
                                                  .ST_TurnToFace(Val.V(() => (hero.transform.position))),
                                                  character.transform.GetChild(1).gameObject.GetComponent <BehaviorMecanim>()
                                                  .ST_TurnToFace(Val.V(() => (hero.transform.position))),
                                                  hero.GetComponent <BehaviorMecanim>().ST_TurnToFace(Val.V(() =>
                                                                                                            character.transform.GetChild(0).transform.position))
                                                  ),

                                     // The sequence when hero not nearby : Currently do Animations one after another
                                     new Sequence(
                                         new SequenceParallel(
                                             character.transform.GetChild(0).gameObject.GetComponent <BehaviorMecanim>()
                                             .ST_TurnToFace(Val.V(() =>
                                                                  (character.transform.GetChild(1).gameObject.transform.position))),
                                             character.transform.GetChild(1).gameObject.GetComponent <BehaviorMecanim>()
                                             .ST_TurnToFace(Val.V(() =>
                                                                  (character.transform.GetChild(0).gameObject.transform.position)))),

                                         new SequenceParallel(
                                             new Sequence(character.transform.GetChild(0).gameObject
                                                          .GetComponent <BehaviorMecanim>()
                                                          .ST_PlayHandGesture("cheer", 2500),
                                                          character.transform.GetChild(0).gameObject.GetComponent <BehaviorMecanim>()
                                                          .ST_PlayHandGesture("Wonderful", 2500)),
                                             new Sequence(character.transform.GetChild(1).gameObject
                                                          .GetComponent <BehaviorMecanim>()
                                                          .ST_PlayHandGesture("Wonderful", 2500),
                                                          character.transform.GetChild(1).gameObject.GetComponent <BehaviorMecanim>()
                                                          .ST_PlayHandGesture("cheer", 2500))
                                             )
                                         )
                                     )
                                 )

                    // Single Person Events - currently not working

                    // new Sequence(new LeafAssert(()=>character.CompareTag("Untagged")),
                    //         new Selector(new Sequence(
                    //     new LeafAssert(()=>StoryIBT.blackboardTrigger[character] == true),
                    // character.GetComponent<BehaviorMecanim>()
                    //     .ST_TurnToFace(Val.V(() => (hero.transform.position)))
                    // ),
                    // new Sequence(character.GetComponent<BehaviorMecanim>()
                    //     .ST_PlayHandGesture(Val.V(() => affordances[random.Next(5)]), 5000))
                    // )
                    // )
                    );


            // Code converted above

            // Node interaction;
            // if (character.CompareTag("Group"))
            // {
            //     var child1 = character.transform.GetChild(0).gameObject;
            //     var child2 = character.transform.GetChild(1).gameObject;
            //     Val<Vector3> child1Position = Val.V(() => (child1.transform.position));
            //     Val<Vector3> child2Position = Val.V(() => (child2.transform.position));
            //
            //     if (StoryIBT.blackboardTrigger[child1] || StoryIBT.blackboardTrigger[child2] )
            //     {
            //         interaction = new SequenceParallel(child1.GetComponent<BehaviorMecanim>()
            //             .Node_GoTo(Val
            //                 .V(() => (hero.transform.position - new Vector3(1.0f,0,1.5f)))),
            //             child2.GetComponent<BehaviorMecanim>()
            //                 .Node_GoTo(Val
            //                     .V(() => (hero.transform.position - new Vector3(2f,0,1.5f))))
            //             );
            //     }
            //     else
            //     {
            //         interaction = new Sequence(
            //             new SequenceParallel(
            //                 child1.GetComponent<BehaviorMecanim>().ST_TurnToFace(child2Position),
            //                 child2.GetComponent<BehaviorMecanim>().ST_TurnToFace(child1Position)),
            //             new SequenceParallel(
            //                 new Sequence(child1.GetComponent<BehaviorMecanim>()
            //                         .ST_PlayHandGesture("cheer", 2500),
            //                     child1.GetComponent<BehaviorMecanim>().ST_PlayHandGesture("Wonderful", 2500)),
            //                 new Sequence(child2.GetComponent<BehaviorMecanim>()
            //                         .ST_PlayHandGesture("Wonderful", 2500),
            //                     child2.GetComponent<BehaviorMecanim>().ST_PlayHandGesture("cheer", 2500))
            //             )
            //         );
            //     }
            //
            // }
            // else
            // {
            //     if (StoryIBT.blackboardTrigger[character])
            //     {
            //         interaction = character.GetComponent<BehaviorMecanim>()
            //             .Node_GoTo(Val.V(() => (hero.transform.position - new Vector3(1.5f,0,1.5f))));
            //     }
            //     else
            //     {
            //         var next = Val.V(() => affordances[random.Next(5)]);
            //         interaction = character.GetComponent<BehaviorMecanim>()
            //             .ST_PlayHandGesture(next, 5000);
            //     }
            // }
            // Node interaction = new LeafInvoke(()=>print("test"));
            sp.Children.Add(interaction);
        }
        return(sp);
    }
Example #9
0
    public static Node Get(GameObject hero, List <GameObject> sideCharacters)
    {
        SequenceParallel sp = new SequenceParallel();

        foreach (var character in sideCharacters)
        {
            Val <Vector3> position = Val.V(() => hero.transform.position);

            Node interaction;
            if (character.CompareTag("Group"))
            {
                var           child1         = character.transform.GetChild(0).gameObject;
                var           child2         = character.transform.GetChild(1).gameObject;
                Val <Vector3> child1Position = Val.V(() => (child1.transform.position));
                Val <Vector3> child2Position = Val.V(() => (child2.transform.position));

                if (StoryIBT.blackboardTrigger[child1] || StoryIBT.blackboardTrigger[child2])
                {
                    interaction = new SequenceParallel(child1.GetComponent <BehaviorMecanim>()
                                                       .Node_GoTo(Val
                                                                  .V(() => (hero.transform.position - new Vector3(1.0f, 0, 1.5f)))),
                                                       child2.GetComponent <BehaviorMecanim>()
                                                       .Node_GoTo(Val
                                                                  .V(() => (hero.transform.position - new Vector3(2f, 0, 1.5f))))
                                                       );
                }
                else
                {
                    interaction = new Sequence(
                        new SequenceParallel(
                            child1.GetComponent <BehaviorMecanim>().ST_TurnToFace(child2Position),
                            child2.GetComponent <BehaviorMecanim>().ST_TurnToFace(child1Position)),
                        new SequenceParallel(
                            new Sequence(child1.GetComponent <BehaviorMecanim>()
                                         .ST_TurnToFace(Val.V(() => (hero.transform.position))),
                                         child1.GetComponent <BehaviorMecanim>().ST_PlayHandGesture("Wonderful", 2500)),
                            new Sequence(child2.GetComponent <BehaviorMecanim>()
                                         .ST_TurnToFace(Val.V(() => (hero.transform.position))),
                                         child2.GetComponent <BehaviorMecanim>().ST_PlayHandGesture("cheer", 2500))
                            )
                        );
                }
            }
            else
            {
                if (StoryIBT.blackboardTrigger[character])
                {
                    interaction = character.GetComponent <BehaviorMecanim>()
                                  .Node_GoTo(Val.V(() => (hero.transform.position - new Vector3(1.5f, 0, 1.5f))));
                }
                else
                {
                    var next = Val.V(() => affordances[random.Next(5)]);
                    interaction = character.GetComponent <BehaviorMecanim>()
                                  .ST_PlayHandGesture(next, 5000);
                }
            }
            // Node interaction = new LeafInvoke(()=>print("test"));
            sp.Children.Add(interaction);
        }
        return(sp);
    }
Example #10
0
    protected Node[] BuildTreeRoot()
    {
        ForEach <GameObject> returnValue = new ForEach <GameObject>((participant) =>
        {
            Func <bool> act  = () => ((Math.Abs(police.transform.position.z - participant.transform.position.z) < 5) && (Math.Abs(police.transform.position.x - participant.transform.position.x) < 5));
            Func <bool> act2 = () => ((Math.Abs(door.transform.position.z - participant.transform.position.z) < 5) && (Math.Abs(door.transform.position.x - participant.transform.position.x) < 5));
            Func <bool> act4 = () => ((Math.Abs(police.transform.position.z - participant.transform.position.z) >= 5) && (Math.Abs(police.transform.position.x - participant.transform.position.x) >= 5));
            Node trigger     = new DecoratorLoop(new LeafAssert(act));
            Node trigger4    = new DecoratorLoop(new LeafAssert(act4));
            Node roaming     =
                new SequenceParallel(
                    new DecoratorForceStatus(RunStatus.Success, ST_RunAndWait(police.transform, participant.transform)), new LeafInvoke(() => { participant.GetComponent <CanvasController>().enableSpeech(); participant.GetComponent <CanvasController>().setText("AHH, RUN!"); }))
            ;
            Node clearText = new LeafInvoke(() => { participant.GetComponent <CanvasController>().disableSpeech(); });
            Node trigger2  = new DecoratorLoop(new LeafAssert(act2));

            Node open = new DecoratorLoop(
                new Sequence(CompleteOpenDoor(specialDaniel.transform)));
            Node root = new DecoratorLoop(new Sequence(new SequenceParallel(new DecoratorForceStatus(RunStatus.Success, new SequenceParallel(trigger, roaming)),
                                                                            new DecoratorForceStatus(RunStatus.Success, new SequenceParallel(trigger4, clearText))),
                                                       new DecoratorForceStatus(RunStatus.Success, new SequenceParallel(trigger2, open))));
            return(root);
        }, participants);

        Func <bool> act3     = () => (1 < 0);
        Node        trigger3 = new LeafInvoke(() => RunStatus.Failure);
        Node        temp     = new Sequence(new LeafInvoke(() => {
            if (index < 2)
            {
                index++;
            }
            else
            {
                index = 0;
            }
            Debug.Log("leafinvoke index: " + index);
        }), new LeafWait(5000));
        //Vector3 policeVector = new Vector3(0,0,0);

        Node chasing = new DecoratorLoop(
            new Sequence(
                ChaseDaniels(police.transform, participants[index].transform)));
        Func <bool> danny0     = () => (index == 0);
        Func <bool> danny1     = () => (index == 1);
        Func <bool> danny2     = () => (index == 2);
        Node        dannyTest0 = new LeafAssert(danny0);
        Node        dannyTest1 = new LeafAssert(danny1);
        Node        dannyTest2 = new LeafAssert(danny2);

        Node check = new LeafInvoke(() => {
            foreach (GameObject participant in participants)
            {
                Func <bool> measure = () => ((Math.Abs(police.transform.position.z - participant.transform.position.z) < 1) && (Math.Abs(police.transform.position.x - participant.transform.position.x) < 1));
                Node trigger        = new DecoratorLoop(new LeafAssert(measure));
                Node root           = new Sequence(new DecoratorForceStatus(RunStatus.Success, new SequenceParallel(trigger, ChaseDaniels(police.transform, participant.transform))));
            }
        });
        Node change = new Sequence(new Race(new LeafWait(10000), ChaseDaniels(police.transform, participants[0].transform)), new Race(new LeafWait(10000), ChaseDaniels(police.transform, participants[1].transform)), new Race(new LeafWait(10000), ChaseDaniels(police.transform, participants[2].transform)));

        //Node trigger = new DecoratorLoop(new LeafAssert(measure));
        //Node change2 =
        Node returnValue2 = new DecoratorLoop(change);

        // Node returnValue3 = new DecoratorLoop(new DecoratorForceStatus(RunStatus.Success, new LeafInvoke(() => { CompleteOpenDoor(specialDaniel.transform); })));

        Node[] rv = new Node[2];
        rv[0] = returnValue;
        rv[1] = returnValue2;
        // rv[2] = returnValue3;
        return(rv);

        //Vector3 min = (participants[0].transform.position - police.transform.position);
        //int index = 0;


        /*
         * Node chase =
         *      new Sequence(new LeafInvoke(() => {
         *          //min = (participants[0].transform.position - police.transform.position);
         *          //for (int i = 1; i < participants.Length; i++)
         *          //{
         *          //    if ((Math.Pow((police.transform.position.x - participants[i].transform.position.x), 2) + Math.Pow((police.transform.position.z - participants[i].transform.position.z), 2) < min.sqrMagnitude))
         *          //    {
         *          //        min = participants[i].transform.position - police.transform.position;
         *          //        index = i;
         *          //    }
         *          //
         *          if (index < 2)
         *              index++;
         *          else
         *              index = 0;
         *      }),ST_ApproachAndWait(participants[index].transform, police.transform));
         *     // new Sequence(ChaseDaniels(police.transform, participants)));
         */
        //return new Sequence(new DecoratorLoop(new DecoratorForceStatus(RunStatus.Success, new SequenceParallel(trigger3, chasing))), returnValue);
        //return new Sequence(new DecoratorLoop(new SequenceParallel(new Sequence(chasing, new LeafWait(1000)),returnValue)));
        //return returnValue;
    }
Example #11
0
 protected override void init_BT()
 {
     root = new SequenceParallel(
         new LeafInvoke(test_increment)
         );
 }