Beispiel #1
0
    private void BuildTree()
    {
        root = new Selector();
        Sequencer  seq1  = new Sequencer();
        Randomizer rand1 = new Randomizer();

        root.AddChild(rand1);
        root.AddChild(seq1);

        Condition con1 = new Condition(nearDogs);
        BAction   pact = new BAction(Play);
        BAction   wact = new BAction(Wander);
        BAction   ract = new BAction(Run);
        BAction   sact = new BAction(Sleep);

        seq1.AddChild(con1);
        seq1.AddChild(pact);

        rand1.AddChild(wact);
        rand1.AddChild(ract);
        // rand1.AddChild(sact);


        root.AddChild(new BAction(Wander));
    }
 //BActionがtureを返す限りparYield経つごとに繰り返しBActionを実行。
 //参照されているGameObjectが消えても参照している側が生きている限り呼ばれ続けます。
 public static IEnumerator UpdateWhileMethodBool(this MonoBehaviour mono, BAction action, YieldInstruction parYield = null)
 {
     while (action())
     {
         yield return(parYield);
     }
 }
    //Run this on awake, enable, or start
    public void DefineBehavior()
    {
        //Conditions
        ConditionalLambda canSeeTarget     = new ConditionalLambda(() => Vector3.Distance(transform.position, Target.transform.position) <= SightDistance);
        ConditionalLambda tooCloseToTarget = new ConditionalLambda(() => Vector3.Distance(transform.position, Target.transform.position) <= FollowDistance);

        //Actions
        BAction followTarget    = new BAction(FollowTarget);
        BAction getPatrolPoint  = new BAction(GetRandomPatrolPoint);
        BAction goToPatrolPoint = new BAction(GoToPatrolPoint);
        BAction circleTarget    = new BAction(CircleTarget);

        SequenceContinued checkIfShouldCircle = new SequenceContinued(tooCloseToTarget, circleTarget);
        //If too circle target, if not follow Target
        SelectorContinued following        = new SelectorContinued(checkIfShouldCircle, followTarget);
        SequenceContinued checkIfCanFollow = new SequenceContinued(canSeeTarget, following);
        SequenceContinued patrol           = new SequenceContinued(getPatrolPoint, goToPatrolPoint);

        SelectorContinued lookForTarget = new SelectorContinued(checkIfCanFollow, patrol);

        //NOTE: RootSelector allows for StateMachine type usage in behavior tree
        //setup root node, choose initialization phase or pathing/movement phase
        SelectorBranch root = new SelectorBranch(switchBehaviors, lookForTarget);

        //set a reference to the root
        behavior = ScriptableObject.CreateInstance <BehaviorTree>();
        behavior.Init(root);
        CanBehave = true;
    }
Beispiel #4
0
        public Object GetByUser(int userid, int pageid)
        {
            Payload payload = BAccount.ConfirmToken(this.Request);

            if (payload == null || (!payload.rol.Contains(3) && !payload.rol.Contains(6)))
            {
                return(new { result = false, info = "Não autorizado." });
            }

            return(BAction.GetActionsbyUser(userid, pageid));
        }
Beispiel #5
0
    //To create action cell u need to create BAction,
    //then assign it to BSObject
    //and then assign BSObject to cell
    //and return list with events u created
    //examples are here
    public List <BattleCell> AddTargets()
    {
        //Creating BAction
        BAction easyTarget = actionFactory.CreateAction()
                             .AddSkillTest(
            skill: new Skills(str: 5),
            pass: "******",
            fail: "Soldier was too weak to save man");

        BAction hardTarget = actionFactory.CreateAction()
                             .AddItemTest(
            item: new Item(name: "Shovel", count: 1),
            pass: "******",
            fail: "Soldier has no shovel to help man")
                             .AddSkillTest(
            skill: new Skills(med: 1, str: 2),
            pass: "******",
            fail: "Soldier left one-leged man to die");

        BAction insaneTarget = actionFactory.CreateAction()
                               .AddItemTest(
            item: new Item("Knife", 1),
            pass: "******",
            fail: "Soldier has no items to help man")
                               .AddSkillTest(
            skill: new Skills(med: 5, str: 0),
            pass: "******",
            fail: "Soldier didn retrieves a bullet and man died with pain")
                               .AddAnotherAction((Character ch) => { Debug.Log("Sad soldier goes home"); });

        //creating BSObjects with events
        EventObject event1 = actionFactory.CreateEvent(easyTarget);
        EventObject event2 = actionFactory.CreateEvent(hardTarget);
        EventObject event3 = actionFactory.CreateEvent(insaneTarget);

        //creating EventCells with BSObjects
        return(new List <BattleCell>()
        {
            cellFactory.CreateCell(s.action, event1),
            cellFactory.CreateCell(s.action, event2),
            cellFactory.CreateCell(s.action, event3)
        });
    }
        /// <summary>
        /// Connect all the Inputs to the Funtions
        /// </summary>
        private void CharacterConnect()
        {
            //TODO: LOOK INTO THIS
            BoolEvent BAttack1, BAttack2, BAction, BJump, BShift, BFly,
                      BDown, BUp, BDodge, BDeath, BStun, BDamaged, BSpeed1, BSpeed2, BSpeed3, BSpeedUp, BSpeedDown;

            if (Inputs.TryGetValue("Attack1", out BAttack1))
            {
                BAttack1.AddListener(value => Attack1 = value);
            }
            if (Inputs.TryGetValue("Attack2", out BAttack2))
            {
                BAttack2.AddListener(value => Attack2 = value);
            }
            if (Inputs.TryGetValue("Action", out BAction))
            {
                BAction.AddListener(value => Action = value);
            }

            if (Inputs.TryGetValue("Jump", out BJump))
            {
                BJump.AddListener(value => Jump = value);
            }
            if (Inputs.TryGetValue("Shift", out BShift))
            {
                BShift.AddListener(value => Shift = value);
            }
            if (Inputs.TryGetValue("Fly", out BFly))
            {
                BFly.AddListener(value => Fly = value);
            }

            if (Inputs.TryGetValue("Down", out BDown))
            {
                BDown.AddListener(value => Down = value);
            }
            if (Inputs.TryGetValue("Up", out BUp))
            {
                BUp.AddListener(value => Up = value);
            }

            if (Inputs.TryGetValue("Dodge", out BDodge))
            {
                BDodge.AddListener(value => Dodge = value);
            }
            if (Inputs.TryGetValue("Death", out BDeath))
            {
                BDeath.AddListener(value => Death = value);
            }
            if (Inputs.TryGetValue("Stun", out BStun))
            {
                BStun.AddListener(value => Stun = value);
            }
            if (Inputs.TryGetValue("Damaged", out BDamaged))
            {
                BDamaged.AddListener(value => Damaged = value);
            }

            if (Inputs.TryGetValue("Speed1", out BSpeed1))
            {
                BSpeed1.AddListener(value => Speed1 = value);
            }
            if (Inputs.TryGetValue("Speed2", out BSpeed2))
            {
                BSpeed2.AddListener(value => Speed2 = value);
            }
            if (Inputs.TryGetValue("Speed3", out BSpeed3))
            {
                BSpeed3.AddListener(value => Speed3 = value);
            }

            if (Inputs.TryGetValue("SpeedUp", out BSpeedUp))
            {
                BSpeedUp.AddListener(value => SpeedUp = value);
            }
            if (Inputs.TryGetValue("SpeedDown", out BSpeedDown))
            {
                BSpeedDown.AddListener(value => SpeedDown = value);
            }
        }
Beispiel #7
0
 public Button(Rectangle rect, BAction action, string texture) : base(rect, texture)
 {
     this.action = action;
     //textureTest = Game1.cManager.Load<Texture2D>(texture);
 }
Beispiel #8
0
 public BDecorator(BAction check)
 {
     Del_Check = check;
 }