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);
        }
Esempio n. 2
0
        protected override BTreeRunningStatus _DoExecute(BTreeTemplateData input, ref BTreeTemplateData output)
        {
            BTreeInputData  _input  = input as BTreeInputData;
            BTreeOutputData _output = output as BTreeOutputData;

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

            return(BTreeRunningStatus.Executing);
        }
        private void MoveToTarget(BTreeInputData _input, ref BTreeOutputData _output)
        {
            var troop    = _input.troop;
            var outTroop = _output.troop;
            var target   = _input.battleData.mAllTroopDic[troop.targetKey];
            var x        = troop.x;
            var y        = troop.y;
            var tar_x    = target.x;
            var tar_y    = target.y;

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

            if (x > tar_x)
            {
                outTroop.x = x - 1;
                if (outTroop.x < tar_x)
                {
                    outTroop.x = tar_x;
                }
            }
            else if (x < tar_x)
            {
                outTroop.x = x + 1;
                if (outTroop.x > tar_x)
                {
                    outTroop.x = tar_x;
                }
            }
            if (y > tar_y)
            {
                outTroop.y = y - 1;
                if (outTroop.y < tar_y)
                {
                    outTroop.y = tar_y;
                }
            }
            else if (y < tar_y)
            {
                outTroop.y = y + 1;
                if (outTroop.y > tar_y)
                {
                    outTroop.y = tar_y;
                }
            }
        }
        protected override BTreeRunningStatus _DoExecute(BTreeTemplateData input, ref BTreeTemplateData output)
        {
            BTreeInputData  _input  = input as BTreeInputData;
            BTreeOutputData _output = output as BTreeOutputData;

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

            if (_input.troop.targetKey != 0)
            {
                _output.troop.state = (int)TroopAnimState.Move;
                MoveToTarget(_input, ref _output);
            }
            return(BTreeRunningStatus.Finish);
        }
Esempio n. 5
0
        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;

            List <TroopData> enemys;

            if (troop.isAtkTroop)
            {
                enemys = _input.battleData.mDefTroopList;
            }
            else
            {
                enemys = _input.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;
                }
            }
            outTroop.targetKey = targetKey;
            return(BTreeRunningStatus.Finish);
        }
Esempio n. 6
0
        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;

            if (troop.count == 0)
            {
                outTroop.state = (int)TroopAnimState.Die;
                return(BTreeRunningStatus.Executing);
            }
            if (troop.inPrepose)
            {
                if (troop.preTime > 0)
                {
                    outTroop.preTime = troop.preTime - 1;
                }
                else
                {
                    outTroop.inPrepose = false;
                }
                outTroop.state = (int)TroopAnimState.Idle;
                return(BTreeRunningStatus.Executing);
            }
            if (troop.norAtkCD > 0)
            {
                outTroop.norAtkCD = troop.norAtkCD - 1;
                outTroop.state    = (int)TroopAnimState.Idle;
                return(BTreeRunningStatus.Executing);
            }
            outTroop.state = (int)TroopAnimState.Idle;
            return(BTreeRunningStatus.Finish);
        }