protected override BTreeRunningStatus _DoExecute(BTreeTemplateData input, ref BTreeTemplateData output)
        {
            base._DoExecute(input, ref output);
            BTreeInputData  _input  = input as BTreeInputData;
            BTreeOutputData _output = output as BTreeOutputData;

            if (_input == null || _output == null)
            {
                Debugger.LogError("数据类型错误");
            }

            var troop    = _input.troop;
            var outTroop = _output.troop;
            var target   = _input.battleData.mAllTroopDic[troop.targetKey];
            var tar_x    = target.x;
            var tar_y    = target.y;

            outTroop.dir_x = tar_x;
            outTroop.dir_y = tar_y;

            outTroop.state     = (int)TroopAnimState.Attack;
            outTroop.inPrepose = true;
            outTroop.preTime   = TroopHelper.GetTroopAtkPrepareTime(outTroop.type);
            outTroop.isAtk     = true;
            outTroop.norAtkCD  = TroopHelper.GetTroopAtkCDTime(outTroop.type);
            return(BTreeRunningStatus.Finish);
        }
예제 #2
0
        public override bool ExternalCondition(BTreeTemplateData input)
        {
            var _input     = (BTreeInputData)input;
            var troop      = _input.troop;
            var battleData = _input.battleData;

            if (troop.targetKey != 0)
            {
                TroopData tarTroop = battleData.mAllTroopDic[troop.targetKey];
                if (tarTroop == null)
                {
                    return(false);
                }
                uint atkDis   = TroopHelper.GetTroopAtkDis(troop.type);
                uint myRange  = TroopHelper.GetTroopRange(troop.type);
                uint tarRange = TroopHelper.GetTroopRange(tarTroop.type);
                int  dis      = MathHelper.TroopDistanceV2(troop, tarTroop);
                if (dis > atkDis + myRange + tarRange)
                {
                    return(false);
                }
                else
                {
                    return(true);
                }
            }
            return(false);
        }
예제 #3
0
        public override Enum Enter(ref FSMInputData _input)
        {
            var troop = _input.m_Troop;

            if (troop.targetKey != 0)
            {
                TroopData tarTroop = dataMgr.m_BattleData.mAllTroopDic[troop.targetKey];
                if (tarTroop == null)
                {
                    Debugger.LogError("AttackState 未找到目标");
                }
                uint atkDis   = TroopHelper.GetTroopAtkDis(troop.type);
                uint myRange  = TroopHelper.GetTroopRange(troop.type);
                uint tarRange = TroopHelper.GetTroopRange(tarTroop.type);
                int  dis      = MathHelper.TroopDistanceV2(troop, tarTroop);
                if (dis > atkDis + myRange + tarRange)
                {
                    return(TroopFSMState.Move);
                }
                else
                {
                    return(Excute(ref _input));
                }
            }
            return(TroopFSMState.End);
        }
        public override Enum Excute(ref FSMInputData _input)
        {
            var troop = _input.m_Troop;
            List <TroopData> enemys;

            if (troop.isAtkTroop)
            {
                enemys = dataMgr.m_BattleData.mDefTroopList;
            }
            else
            {
                enemys = dataMgr.m_BattleData.mAtcTroopList;
            }
            //找最近的目标
            int  minDis    = -1;
            uint targetKey = 0;

            for (int i = 0; i < enemys.Count; i++)
            {
                int dis = MathHelper.TroopDistanceV2(troop, enemys[i]);
                if (minDis < 0)
                {
                    minDis    = dis;
                    targetKey = enemys[i].key;
                }
                else if (minDis > dis)
                {
                    minDis    = dis;
                    targetKey = enemys[i].key;
                }
            }
            if (minDis < 0)
            {
                return(TroopFSMState.End);
            }
            else if (troop.inWar || minDis <= TroopHelper.GetTroopSpyDis(troop.type))
            {
                troop.targetKey = targetKey;
                troop.inWar     = true;
                return(TroopFSMState.Attack);
            }
            return(TroopFSMState.Move);
        }
예제 #5
0
        public override Enum Excute(ref FSMInputData _input)
        {
            var       troop    = _input.m_Troop;
            TroopData tarTroop = dataMgr.m_BattleData.mAllTroopDic[troop.targetKey];

            if (tarTroop == null)
            {
                Debugger.LogError("AttackState 未找到目标");
            }
            if (troop.norAtkCD == 0)
            {
                troop.state     = (int)TroopAnimState.Attack;
                troop.dir_x     = tarTroop.x;
                troop.dir_y     = tarTroop.y;
                troop.inPrepose = true;
                troop.preTime   = TroopHelper.GetTroopAtkPrepareTime(troop.type);
                troop.isAtk     = true;
                troop.norAtkCD  = TroopHelper.GetTroopAtkCDTime(troop.type);
            }
            return(TroopFSMState.End);
        }