Ejemplo n.º 1
0
        public void EnemyAI()
        {
            var dictionary = new TreeDictionary();
            var builder    = new BlackboardTreeBuilder <Enemy>(new TreeBuilder(), dictionary);

            builder
            .Sequence()
            .Begin()
            .Selector()
            .Begin()
            .IsTrue((e) => e.HasTarget())
            .Selector()
            .Begin()
            .Action((e) => e.SelectTarget())
            .End()
            .End()
            .Selector()
            .Begin()
            .IsTrue((e) => e.WithinDistance())
            .Selector()
            .Begin()
            .Action((e) => e.MoveTowards())
            .End()
            .End()
            .End()
            .Action((e) => e.HitTarget())
            .End()
            .BuildAndRegisterAs <BaseEnemyAI>();

            var topBuilder = new BlackboardTreeBuilder <EnemySituation>(new TreeBuilder(), dictionary);
            var tree       = topBuilder
                             .UseStub <BaseEnemyAI, Enemy>()
                             .Build();

            var walker = new NodeWalker(tree);

            walker.AddBlackboard <EnemySituation>(new Blackboard <EnemySituation> {
                Context = new EnemySituation()
            });
            walker.AddDependentBlackboard <EnemySituation, Enemy>((es) => { return(es.Individual); });
        }