Beispiel #1
0
        public BTParallel Parallel(params BTNode[] cs)
        {
            BTParallel node = new BTParallel(cs);

            node.bt = this;
            return(node);
        }
Beispiel #2
0
    protected override void Init()
    {
        base.Init();
        m_DirectID = database.GetDataId("direct");
        database.SetData <Vector2>(m_DirectID, new Vector2(1, 0));

        m_timeWaitId = database.GetDataId("timeWait");
        database.SetData <float>(m_timeWaitId, 0);

        CheckPlayer      _checkPlayer      = new CheckPlayer(m_Find);
        CheckAllowAttack _checkAllowAttack = new CheckAllowAttack(m_timeWaitId, timeAttack);

        BTPrecondition2 con = new BTPrecondition2(_checkPlayer, _checkAllowAttack, BTPrecondition2.BTPrecondition2Param.And);

        _root = new BTPrioritySelector();
        BTParallel moveAttack = new BTParallel(BT.BTParallel.ParallelFunction.Or, con);
        float      maxX, maxY;

        maxX = distance.position.x - transform.position.x;
        maxY = 0;
        moveAttack.AddChild(new Move(speed, new Vector2(1, 0), transform.position, maxX, maxY, m_DirectID, null, true));
        moveAttack.AddChild(new Shoot(bulletObject, shooter, new Vector2(0, -1), m_timeWaitId));

        _root.AddChild(moveAttack);
        _root.AddChild(new Move(speed, new Vector2(1, 0), transform.position, maxX, maxY, m_DirectID, null, true));
    }
Beispiel #3
0
        public override void Init()
        {
            Debug.Log("S");
            _rootNode = new BTPrioritySelector(null);


            ValueCondition            vc    = new ValueCondition(10, true);
            ValueCondition            vd    = new ValueCondition(10, false);
            DieCondition              die   = new DieCondition();
            EnemyInSight              sight = new EnemyInSight();
            CheckSelfToTargetDistance CTD   = new CheckSelfToTargetDistance(vo.AttackDistance, false);
            CheckSelfToTargetDistance CTD2  = new CheckSelfToTargetDistance(vo.AttackDistance, true);

            AiTestAction1 first  = new AiTestAction1(vc);
            AiTestAction2 second = new AiTestAction2(vd);

            BTDieAction    dieAction    = new BTDieAction(3);
            BTPortalAction portalAction = new BTPortalAction();
            BTAttackAction attackAction = new BTAttackAction(vo.AttackCD);
            BTChaseAction  ChaseAction  = new BTChaseAction();



            BTParallel p = new BTParallel(die);

            _rootNode.AddChild(p);
            p.AddChild(dieAction);
            p.AddChild(new PlayAnimatorAction("Die"));

            BTPrioritySelector Select  = new BTPrioritySelector(null);
            BTPrioritySelector Select2 = new BTPrioritySelector(null);
            BTParallel         p2      = new BTParallel(ParallelFunction.And, sight);

            _rootNode.AddChild(Select);
            Select.AddChild(p2);
            p2.AddChild(portalAction);
            p2.AddChild(new PlayAnimatorAction("Run"));

            Select.AddChild(Select2);
            BTParallel p3 = new BTParallel(ParallelFunction.And, CTD);

            p3.AddChild(attackAction);
            p3.AddChild(new PlayAnimatorAction("attack1"));

            BTParallel p4 = new BTParallel(ParallelFunction.Or, null);

            p4.AddChild(ChaseAction);
            p4.AddChild(new PlayAnimatorAction("Run"));

            Select2.AddChild(p3);
            Select2.AddChild(p4);
        }
Beispiel #4
0
    protected override void Init()
    {
        base.Init();
        m_DirectID = database.GetDataId("direct");
        database.SetData<Vector2>(m_DirectID, new Vector2(0, 0));
        CheckPlayer _checkPlayer = new CheckPlayer(m_Find);
        _root = new BTPrioritySelector();

        BTParallel run = new BTParallel(BTParallel.ParallelFunction.Or,_checkPlayer);
        run.AddChild(new Move(m_Speed, new Vector2(0, 0), transform.position, 999, 999, m_DirectID));
        run.AddChild(new PlayAnimation("run"));
        _root.AddChild(run);
        _root.AddChild(new PlayAnimation("stand"));

    }
Beispiel #5
0
    protected override void Init()
    {
        base.Init();
        float   time       = 0;
        float   timeAttack = m_MaxTimeAttack + 1;
        Vector2 direct     = new Vector2(0, 1);

        m_DirectID = database.GetDataId("direct");
        database.SetData <Vector2>(m_DirectID, direct);

        m_timeWaitId = database.GetDataId("timeWait");
        database.SetData <float>(m_timeWaitId, time);

        m_timeAttackId = database.GetDataId("timeAttack");
        database.SetData <float>(m_timeAttackId, timeAttack);

        _root = new BTPrioritySelector();
        CheckPlayer      _checkPlayer      = new CheckPlayer(m_Find);
        CheckAllowAttack _checkAllowAttack = new CheckAllowAttack(m_timeWaitId, m_TimeAttackCooldown);
        CheckAttacking   _checkAttacking   = new CheckAttacking(m_timeAttackId, m_MaxTimeAttack);

        BTPrecondition2 con1 = new BTPrecondition2(_checkAllowAttack, _checkAttacking, BTPrecondition2.BTPrecondition2Param.Or);
        BTPrecondition2 con2 = new BTPrecondition2(_checkPlayer, con1, BTPrecondition2.BTPrecondition2Param.And);

        BTParallel moveAttack = new BTParallel(BT.BTParallel.ParallelFunction.Or);

        moveAttack.AddChild(new Move(m_Speed, direct, transform.position, 1000f, 0.2f, m_DirectID));

        BTPrioritySelector fight = new BTPrioritySelector();

        fight.AddChild(new PlayAnimation("attack", con2));
        fight.AddChild(new PlayAnimation("fly"));

        moveAttack.AddChild(fight);
        _root.AddChild(moveAttack);
    }
Beispiel #6
0
    protected override void Init()
    {
        base.Init();
        root = new BTPrioritySelector();   // 根节点首先是一个选择器

        // 转移条件
        MonsterCheckPlayerInRange playerInRange    = new MonsterCheckPlayerInRange(checkPlayerRange, PLAYER_NAME);
        MonsterCheckPlayerInRange playerNotInRange = new MonsterCheckPlayerInRange(checkPlayerRange, PLAYER_NAME, true);

        // 行为节点
        move = new MonsterMove(DESTINATION, moveSpeed);
        MonsterFindToTargetDestination findToTargetDestination = new MonsterFindToTargetDestination(PLAYER_NAME, PLAYERLOCATION, DESTINATION, ATKdistance);
        MonsterWait monsterWait = new MonsterWait();

        // 怪兽攻击
        MonsterAttack monsterAttack;

        if (myMonsterType == MonsterType.LongDistanceAttack)
        {
            monsterAttack = new MonsterLongDistanceAttacks(longDistanceATK);
        }
        else if (myMonsterType == MonsterType.MeleeAttack)
        {
            monsterAttack = new MonsterMeleeAttack(meleeATK);
        }
        else
        {
            monsterAttack = new MonsterAttack(meleeATK);     // 先暂时为近战的攻击力
        }
        MonsterRandomMoveDistance randomMoveDistance = new MonsterRandomMoveDistance(DESTINATION, moveX, moveZ);
        MonsterRotateToTarget     monsterMoveRotate  = new MonsterRotateToTarget(DESTINATION);
        MonsterRotateToTarget     attackRotate       = new MonsterRotateToTarget(PLAYERLOCATION);

        // 攻击
        BTSequence attack = new BTSequence(playerInRange);

        {
            BTParallel parallel = new BTParallel(BTParallel.ParallelFunction.Or);
            {
                parallel.AddChild(findToTargetDestination);    // 先找到走到攻击目标的目的地
                BTSequence rotateAndMove = new BTSequence();
                {
                    rotateAndMove.AddChild(monsterMoveRotate);
                    rotateAndMove.AddChild(move);
                }
                parallel.AddChild(rotateAndMove);             // 怪物朝着目的地移动
            }
            attack.AddChild(parallel);
            attack.AddChild(attackRotate);                // 怪物朝向玩家
            attack.AddChild(monsterAttack);               // 进行攻击
        }
        root.AddChild(attack);

        // 随机巡逻
        BTSequence randomMove = new BTSequence(playerNotInRange);

        {
            randomMove.AddChild(monsterWait);                  // 怪物静止几秒

            BTParallel parallel = new BTParallel(BTParallel.ParallelFunction.And);
            {
                parallel.AddChild(randomMoveDistance);         // 随机找一个移动地点
                BTSequence rotateAndMove = new BTSequence();
                {
                    rotateAndMove.AddChild(monsterMoveRotate);
                    rotateAndMove.AddChild(move);
                }
                parallel.AddChild(rotateAndMove);             // 怪物朝着目的地移动
            }
            randomMove.AddChild(parallel);
        }
        root.AddChild(randomMove);
    }
Beispiel #7
0
    protected override void Init()
    {
        // -------Prepare--------
        // 1. Initialize parent
        base.Init();

        // 2. Enable BT framework's log for debug, optional
        // BTConfiguration.ENABLE_LOG = true;

        // 3. Create root, usually it's a priority selector
        _root = new BTPrioritySelector();

        // 4. Create the nodes for reuse later

        // Preconditions
        CheckInSight checkOrcInSight            = new CheckInSight(sightForOrc, ORC_NAME);
        CheckInSight checkGoblinInFightDistance = new CheckInSight(fightDistance, GOBLIN_NAME);
        CheckInSight checkGoblinInSight         = new CheckInSight(sightForGoblin, GOBLIN_NAME);

        // Actions
        BTParallel run = new BTParallel(BTParallel.ParallelFunction.Or);
        {
            run.AddChild(new DoRun(DESTINATION, speed));
            run.AddChild(new PlayAnimation(RUN_ANIMATION));
        }

        FindEscapeDestination   findDestination         = new FindEscapeDestination(ORC_NAME, DESTINATION, sightForOrc);
        FindToTargetDestination findToTargetDestination = new FindToTargetDestination(GOBLIN_NAME, DESTINATION, fightDistance * 0.9f);



        // -------Construct-------

        // 3.1 Escape node
        // "Escape" serves as a parallel node
        // "Or" means the parallel node ends when any of its children ends.
        BTParallel escape = new BTParallel(BTParallel.ParallelFunction.Or, checkOrcInSight);

        {
            escape.AddChild(findDestination);

            escape.AddChild(run);
        }
        _root.AddChild(escape);                 // Add node into root


        // 3.2 Fight node

        BTSequence fight = new BTSequence(checkGoblinInSight);

        {
            BTParallel parallel = new BTParallel(BTParallel.ParallelFunction.Or);
            {
                parallel.AddChild(findToTargetDestination);

                parallel.AddChild(run);                         // Reuse Run
            }
            fight.AddChild(parallel);

            fight.AddChild(new PlayAnimation(FIGHT_ANIMATION, checkGoblinInFightDistance));
        }
        _root.AddChild(fight);


        // 3.3 Idle node
        _root.AddChild(new PlayAnimation(IDLE_ANIMATION));
    }
Beispiel #8
0
    protected override void Init()
    {
        base.Init();
        root = new BTPrioritySelector();   // 根节点首先是一个选择器

        // 转移条件
        // 远程攻击条件
        MonsterCheckPlayerInRangeAndRandomAttack longAttack = new MonsterCheckPlayerInRangeAndRandomAttack(checkPlayerRange, PLAYER_NAME, true);
        // 进程攻击条件
        MonsterCheckPlayerInRangeAndRandomAttack meleeAttack = new MonsterCheckPlayerInRangeAndRandomAttack(checkPlayerRange, PLAYER_NAME, false);
        // 静止条件
        MonsterCheckPlayerInRange playerNotInRange = new MonsterCheckPlayerInRange(checkPlayerRange, PLAYER_NAME, true);

        // 行为节点
        move = new MonsterMove(DESTINATION, moveSpeed);
        MonsterFindToTargetDestination findMeleeToTargetDestination = new MonsterFindToTargetDestination(PLAYER_NAME, PLAYERLOCATION, DESTINATION, ATKMeleeDistance);
        MonsterFindToTargetDestination findLongToTargetDestination  = new MonsterFindToTargetDestination(PLAYER_NAME, PLAYERLOCATION, DESTINATION, ATKLongDistance);
        MonsterWait monsterWait = new MonsterWait();

        MonsterLongDistanceAttacks monsterLongDistanceAttacks = new MonsterLongDistanceAttacks(longDistanceATK);
        MonsterMeleeAttack         monsterMeleeAttack         = new MonsterMeleeAttack(meleeATK);

        MonsterRotateToTarget monsterMoveRotate = new MonsterRotateToTarget(DESTINATION);
        MonsterRotateToTarget attackRotate      = new MonsterRotateToTarget(PLAYERLOCATION);

        MonsterRandomMoveDistance randomMoveDistance = new MonsterRandomMoveDistance(DESTINATION, moveX, moveZ);

        // 随机巡逻(玩家不在攻击范围)
        BTSequence randomMove = new BTSequence(playerNotInRange);

        {
            BTParallel parallel = new BTParallel(BTParallel.ParallelFunction.And);
            {
                parallel.AddChild(randomMoveDistance);         // 随机找一个移动地点
                BTSequence rotateAndMove = new BTSequence();
                {
                    rotateAndMove.AddChild(monsterMoveRotate);
                    rotateAndMove.AddChild(move);
                }
                parallel.AddChild(rotateAndMove);             // 怪物朝着目的地移动
            }
            randomMove.AddChild(parallel);
        }
        root.AddChild(randomMove);

        // 进程攻击(一个随机数并且玩家在攻击范围内)
        BTSequence meleeattack = new BTSequence(meleeAttack);

        {
            BTParallel parallel = new BTParallel(BTParallel.ParallelFunction.Or);
            {
                parallel.AddChild(findMeleeToTargetDestination);    // 先找到走到攻击目标的目的地
                BTSequence rotateAndMove = new BTSequence();
                {
                    rotateAndMove.AddChild(monsterMoveRotate);
                    rotateAndMove.AddChild(move);
                }
                parallel.AddChild(rotateAndMove);                   // 怪物朝着目的地移动
            }
            meleeattack.AddChild(parallel);
            meleeattack.AddChild(attackRotate);                     // 怪物朝向玩家
            meleeattack.AddChild(monsterMeleeAttack);               // 进行攻击
        }
        root.AddChild(meleeattack);

        // 远程攻击(一个随机数并且玩家在攻击范围内)
        BTSequence longattack = new BTSequence(longAttack);

        {
            BTParallel parallel = new BTParallel(BTParallel.ParallelFunction.Or);
            {
                parallel.AddChild(findLongToTargetDestination);    // 先找到走到攻击目标的目的地
                BTSequence rotateAndMove = new BTSequence();
                {
                    rotateAndMove.AddChild(monsterMoveRotate);
                    rotateAndMove.AddChild(move);
                }
                parallel.AddChild(rotateAndMove);                   // 怪物朝着目的地移动
            }
            longattack.AddChild(parallel);
            longattack.AddChild(attackRotate);                          // 怪物朝向玩家
            longattack.AddChild(monsterLongDistanceAttacks);            // 进行攻击
        }
        root.AddChild(longattack);
    }