Ejemplo n.º 1
0
        public override void ExecuteTactic(ImpAi imp)
        {
            if (_impAi == null)
            {
                _impAi = imp;
            }

            if (_impCombatBehaviour == null)
            {
                _impCombatBehaviour = _impAi.GetComponent <ImpCombatBehaviour>();
            }

            if (_attackInstance == null)
            {
                _attackInstance = data.TacticAttack.GetAttack();
            }

            if (_tacticBehaviourTree == null)
            {
                BtCondition isFacingTarget = new BtCondition(IsFacingTarget);
                BtCondition inAttackRange  = new BtCondition(InAttackRange);

                BtAction attack = new BtAction(Attack);

                BtSequence meleeAttack = new BtSequence(new IBtTask[] { isFacingTarget, inAttackRange, attack });

                _tacticBehaviourTree = new BehaviourTree(meleeAttack);
            }

            _tacticBehaviourTree.Run();
        }
Ejemplo n.º 2
0
        public override void ExecuteTactic(ImpAi imp)
        {
            if (_imp == null)
            {
                _imp = imp;
                //_contextGroupFormation = imp.GetComponent<ContextGroupFormation>();
                _impRecruitBehaviour = imp.GetComponent <ImpRecruitBehaviour>();

                BtAction startRecruit = new BtAction(StartRecruit);
                BtAction stopRecruit  = new BtAction(StopRecruit);
                //BtCondition inPositionCondition = new BtCondition(InPosition);
                BtCondition isRecruiting    = new BtCondition(() => _isRecruiting);
                BtCondition isNotRecruiting = new BtCondition(() => !_isRecruiting);

                BtSelector startRecruitSelector = new BtSelector(new IBtTask[] { isRecruiting, startRecruit });
                BtSelector stopRecruitSelector  = new BtSelector(new IBtTask[] { isNotRecruiting, stopRecruit });

                BtSequence startRecruitSequence =
                    new BtSequence(new IBtTask[] { startRecruitSelector });

                BtSelector recruitTree = new BtSelector(new IBtTask[] { startRecruitSequence, stopRecruitSelector });

                _recruitBehaviourTree = new BehaviourTree(recruitTree);
            }

            _recruitBehaviourTree.Run();
        }
Ejemplo n.º 3
0
        private void Start()
        {
            BtAction executeTactic = new BtAction(ExecuteTactic);
            BtAction ability       = new BtAction(() => _activeAbility != null);
            BtAction allInPosition = new BtAction(() =>
                                                  !_activeAbility.GetData().InPositionBeforeActivation ||
                                                  _groupManager.Imps.All(pair => pair.Key.GetComponent <ContextGroupFormation>().InPosition()));
            BtAction doAbility = new BtAction(ExecuteAbility);

            BtSequence combatSequence =
                new BtSequence(new IBtTask[] { executeTactic, ability, allInPosition, doAbility });

            FSMState outOfCombat = new FSMState();
            FSMState inCombat    = new FSMState();

            FSMTransition battleEnter = new FSMTransition(() => _inBattle);
            FSMTransition battleExit  = new FSMTransition(() => !_inBattle);

            outOfCombat.AddTransition(battleEnter, inCombat);
            inCombat.AddTransition(battleExit, outOfCombat);

            inCombat.enterActions.Add(() => OnTacticChanged?.Invoke(_activeTactic));
            inCombat.stayActions.Add(() => combatSequence.Run());

            outOfCombat.stayActions.Add(SetPlayer);

            FSM groupFsm = new FSM(outOfCombat);

            StartCoroutine(FsmStayAlive(groupFsm));
        }
Ejemplo n.º 4
0
        private void Start()
        {
            foreach(GameObject group in GroupsManager.Instance.Groups.Values)
            {
                _groupAggros.Add(group.GetComponent<GroupAggro>());
            }

            #region Behaviour tree

            #region Target selection

            BtCondition isTargetStillValid = new BtCondition(() => _currentTargetStillValid);

            BtAction tryChooseByAggro = new BtAction(TryChooseByAggro);

            BtSequence byAggroSequence = new BtSequence(new IBtTask[] { tryChooseByAggro });

            BtSelector targetSelection = new BtSelector(new IBtTask[] { isTargetStillValid, byAggroSequence });

            #endregion

            #region Attack

            BtCondition lastAttackDone = new BtCondition(() => _lastAttackDone);
            BtCondition isFacingTarget = new BtCondition(IsFacingTarget);
            BtCondition inAttackRange = new BtCondition(InAttackRange);

            BtAction chooseAttack = new BtAction(ChooseAttack);
            BtAction attack = new BtAction(Attack);

            BtSequence attackSequence = new BtSequence(new IBtTask[]
            {
                lastAttackDone,
                isFacingTarget,
                inAttackRange,
                chooseAttack,
                attack
            });

            #endregion

            BtSequence combatSequence = new BtSequence(new IBtTask[] { targetSelection, attackSequence });

            #endregion

            #region FSM

            FSMState idle = new FSMState();
            FSMState combat = new FSMState();

            combat.enterActions.Add(StartCombat);

            FSMTransition battleEnter = new FSMTransition(() => _inCombat);

            idle.AddTransition(battleEnter, combat);

            #endregion

            _combatBehaviourTree = new BehaviourTree(combatSequence);

            _bossFsm = new FSM(idle);

            _runFsmCoroutine = StartCoroutine(BossFsmUpdate());
        }
Ejemplo n.º 5
0
        public CCreatureAI(CCreature creature, eAILevel level = eAILevel.HARD, bool bPatrol = true)
        {
            //if(creature.IsMaster())
            //{
            //    m_list = GameObject.Find("ai_list").AddComponent<UISuperList>();
            //    m_list.Init(300, 60, 1, 5);
            //}
            m_player = creature;
            m_level  = level;
            InitComboData();

            //m_aiObject = new GameObject("ai_" + creature.GetUid());
            m_tree        = new BtTree();
            m_tree.m_root = new BtPrioritySelector();
            m_tree.Init();
            m_tree.m_dataBase.SetData <CCreature>((int)eAIParam.INT_ROLE_UID, creature);
            AIParam.Init(m_tree.m_dataBase);


            // skill level up
            //Condi_SkillUp c_skillUp = new Condi_SkillUp();
            //Action_SkillUp a_skillUp = new Action_SkillUp();
            //BtSequence skillUp = new BtSequence(c_skillUp);
            //skillUp.AddChild(a_skillUp);
            //skillUp.name = "升级中";

            //Condi_CheckTransmit c_checkTransmit = new Condi_CheckTransmit();
            //Action_Transmit a_trans = new Action_Transmit();
            //BtSequence transmit = new BtSequence(c_checkTransmit);
            //transmit.AddChild(a_trans);
            //transmit.name = "瞬间传送";

            // Elude skill
            Condi_CheckSendSkill_ c_checkSkill = new Condi_CheckSendSkill_();
            Action_EludePos_      a_eludePos   = new Action_EludePos_();
            BtSequence            eludeSkill   = new BtSequence(c_checkSkill);

            eludeSkill.AddChild(a_eludePos);
            eludeSkill.name = "躲技能";


            // find buff
            Condi_FindMapBuff_ c_find   = new Condi_FindMapBuff_();
            Action_MoveToBuff_ a_move   = new Action_MoveToBuff_();
            BtSequence         findBuff = new BtSequence(c_find);

            findBuff.AddChild(a_move);
            findBuff.name = "寻找中";

            // fight
            AICondi[] c_fight = new AICondi[3];
            c_fight[0] = new Condi_FindTarget();        // 先通过仇恨,位置获取目标
            c_fight[1] = new Condi_CheckState();        // 再检查自身施法条件是否满足
            c_fight[2] = new Condi_SelectSkill();
            Condi_List findTarget = new Condi_List(c_fight);
            // fight action
            BtSequence          fight        = new BtSequence(findTarget);
            Action_MoveToTarget a_fight_move = new Action_MoveToTarget();
            Action_SendSkill_   a_fight_send = new Action_SendSkill_();

            fight.AddChild(a_fight_move);
            fight.AddChild(a_fight_send);
            fight.name = "战斗中";
            // chase
            Condi_CheckChase c_chase = new Condi_CheckChase();
            Action_Chase     a_chase = new Action_Chase();
            BtSequence       chase   = new BtSequence(c_chase);

            chase.AddChild(a_chase);
            chase.name = "追逐";


            //Condi_CheckFollow c_checkFollow = new Condi_CheckFollow();
            //Action_Follow a_follow = new Action_Follow();
            //BtSequence follow = new BtSequence(c_checkFollow);
            //follow.AddChild(a_follow);
            //follow.name = "跟随";

            // patrol
            Action_Patrol patrol = new Action_Patrol();

            patrol.name = "巡逻中";


            //if (creature.IsPartner())
            //{
            //    m_tree.m_root.AddChild(transmit);
            //}
            //if (creature.IsMaster())
            //{
            //    m_tree.m_root.AddChild(findBuff);
            //}
            m_tree.m_root.AddChild(fight);
            //m_tree.m_root.AddChild(chase);

            //if (creature.IsPartner())
            //{
            //    m_tree.m_root.AddChild(follow);
            //}


            m_tree.m_root.AddChild(patrol);


            m_tree.OnStart();
        }