Esempio n. 1
0
        private void bulidSelfAbortTree()
        {
            var builder = BehaviorTreeBuilder <SlimeBehaviorTree> .begin(this);

            builder.selector(AbortTypes.Self);
            builder.conditionalDecorator(m =>
            {
                return(m.slime.actorProperty.HP <= 0);
            }, false);
            builder.sequence()
            .logAction("-- dead! --")
            .action(m => m.slime.dead())
            .endComposite();

            builder.conditionalDecorator(m =>
            {
                return(m.slime.startLostTarget);
            });
            builder.sequence()
            .logAction("-- lostTarget!--")
            .action(m => m.slime.lostTarget())
            .endComposite();

            builder.conditionalDecorator(
                m => m.slime.isLostTarget, false
                );
            builder.sequence()
            .logAction("--back! --")
            .action(m => m.slime.back())
            .endComposite();

            builder.conditionalDecorator(
                m => m.slime.isFindTarget, false
                );
            builder.sequence()
            .logAction("--chase! --")
            .action(m => m.slime.chase())
            .endComposite();


            builder.sequence()
            .logAction("--idle --")
            //.action(m => m.slime.idle())
            .waitAction(2f)
            .action(m => m.slime.patrol())
            .endComposite()
            ;

            builder.endComposite();

            tree = builder.build(1f / 60);
        }
Esempio n. 2
0
        // the same tree is here, once with LowerPriority aborts and once with Self aborts and ConditionalDecorators
        public void buildLowerPriorityAbortTree()
        {
            var builder = BehaviorTreeBuilder <BehaviorTreeMiner> .begin(this);

            builder.selector();

            // sleep is most important
            builder.sequence(AbortTypes.LowerPriority)
            .conditional(m => m.minerState.fatigue >= MinerState.MAX_FATIGUE)
            .logAction("--- tired! gotta go home")
            .action(m => m.goToLocation(MinerState.Location.Home))
            .logAction("--- prep me my bed!")
            .action(m => m.sleep())
            .endComposite();

            // thirst is next most important
            builder.sequence(AbortTypes.LowerPriority)
            .conditional(m => m.minerState.thirst >= MinerState.MAX_THIRST)
            .logAction("--- thirsty! time for a drink")
            .action(m => m.goToLocation(MinerState.Location.Saloon))
            .logAction("--- get me a drink!")
            .action(m => m.drink())
            .endComposite();

            // dropping off gold is next
            builder.sequence(AbortTypes.LowerPriority)
            .conditional(m => m.minerState.gold >= MinerState.MAX_GOLD)
            .logAction("--- bags are full! gotta drop this off at the bank.")
            .action(m => m.goToLocation(MinerState.Location.Bank))
            .logAction("--- take me gold!")
            .action(m => m.depositGold())
            .endComposite();

            // fetching gold is last
            builder.sequence()
            .action(m => m.goToLocation(MinerState.Location.Mine))
            .logAction("--- time to get me some gold!")
            .action(m => m.digForGold())
            .endComposite();

            builder.endComposite();

            _tree = builder.build();
        }
Esempio n. 3
0
        private void buildBehaviorTree()
        {
            //Initialize pathfinding
            _origin    = (entity.position / Game1.TILE_SIZE).ToPoint();
            _waypoints = _grid.search(new Point(_origin.X, _origin.Y), new Point(_origin.X + 5, _origin.Y));

            BehaviorTreeBuilder <EnemyController> _behaviorTreeBuilder = BehaviorTreeBuilder <EnemyController> .begin(this);

            _behaviorTreeBuilder.untilSuccess();
            //Creates a method with input of EnemyController and output of TaskStatus
            Func <EnemyController, TaskStatus> chasePlayer = delegate(EnemyController context) {
                if (target == null)
                {
                    return(TaskStatus.Failure);
                }

                Point currentNode = (entity.position / Game1.TILE_SIZE).ToPoint();
                Point targetNode  = (target.position / Game1.TILE_SIZE).ToPoint();

                _waypoints            = _grid.search(currentNode, targetNode);
                _currentWaypointIndex = 0;

                //Check to see if path exists
                if (_waypoints == null)
                {
                    return(TaskStatus.Failure);
                }

                return(TaskStatus.Running);
            };


            _behaviorTreeBuilder.action(chasePlayer);

            _behaviorTree = _behaviorTreeBuilder.build();
        }