Exemplo n.º 1
0
    /** 退回 */
    public void reBack()
    {
        clearFightAI();
        _fightState = UnitAIFightStateType.Back;

        if (_isAnchorUseUnit)
        {
            Unit unit = _anchorUnit.getUnit();
            if (unit != null)
            {
                _unit.move.moveToUnit(unit, _anchorRadius);
            }
            else
            {
                setCurrentAnchorPos();
                stopMoveAndReIdle();
            }
        }
        else
        {
            _unit.move.moveTo(_anchorPos, _anchorRadius);
        }
    }
Exemplo n.º 2
0
    /** 更新指令(1秒10次) */
    public void updateCommand(int delay)
    {
        switch (_commandType)
        {
        case UnitAICommandType.Protect:
        {
        }
        break;

        case UnitAICommandType.Escape:
        {
            _aiLogic.updateEscape();
        }
        break;

        case UnitAICommandType.MoveTo:
        case UnitAICommandType.PickUpItem:
        {
            //没有移动中
            if (!_unit.move.isMoving())
            {
                //向目标移动
                _unit.move.moveTo(_commandPos);
            }
            else
            {
                if (_commandType == UnitAICommandType.PickUpItem)
                {
                    if (_unit.pos.calculateDistanceSq(_commandPos) <= Global.pickUpRadiusSq)
                    {
                        pickUpMoveOver();
                    }
                }
            }
        }
        break;

        case UnitAICommandType.MoveDir:
        {
            UnitMoveLogic unitMoveLogic = _unit.move;

            _commandPassTime += delay;

            //没有移动中
            if (unitMoveLogic.canMoveNow() && (!unitMoveLogic.isMoving() || _commandPassTime >= Global.moveDirSendDelay))
            {
                _commandPassTime = 0;
                doMoveDirOnce();
            }
        }
        break;

        case UnitAICommandType.MoveToUnit:
        {
            //没有移动中
            if (!_unit.move.isMoving())
            {
                Unit unit = _commandUnit.getUnit();

                if (unit != null)
                {
                    //向目标移动
                    _unit.move.moveToUnit(unit, _commandDistance);
                }
                else
                {
                    commandFailed();
                }
            }
        }
        break;

        case UnitAICommandType.AttackMoveTo:
        {
            //没有移动中
            if (_unit.ai.isIdle() && !_unit.move.isMoving())
            {
                //向目标移动
                _unit.move.moveTo(_commandPos);
            }
        }
        break;

        case UnitAICommandType.SpecialMoveTo:
        {
        }
        break;

        case UnitAICommandType.Follow:
        case UnitAICommandType.FollowAttack:
        {
            if (_unit.ai.isIdle() && _unit.move.canMoveNow())
            {
                Unit unit = _commandUnit.getUnit();

                if (unit == null)
                {
                    commandOver();
                }
                else
                {
                    if (_unit.pos.calculateDistanceSq(unit.pos.getPos()) > _fightUnitConfig.followRadiusT)
                    {
                        _unit.move.moveToUnit(unit, _fightUnitConfig.followRadius);
                    }
                }
            }
        }
        break;
        }
    }
Exemplo n.º 3
0
    /** 刷战斗状态 */
    protected void updateFightThree()
    {
        Unit target;

        switch (_fightState)
        {
        case UnitAIFightStateType.Idle:
        {
            if (checkNeedBack())
            {
                return;
            }

            if ((target = searchTarget()) != null)
            {
                _isWandering = false;

                startPursue(target, true);
            }
            else
            {
                if (needWander())
                {
                    _isWandering = true;

                    if (_wanderWaitTime == -1)
                    {
                        if (!_unit.move.isMoving())
                        {
                            if (_unit.move.isAllFreeNow())
                            {
                                wanderWaitTime();
                            }
                        }
                    }
                }
            }
        }
        break;

        case UnitAIFightStateType.Pursue:
        {
            if (_commandLogic.isCommandCanFight())
            {
                //无施法数据
                if (_pursueSkillTarget == null)
                {
                    //目标丢失或者影响类型不匹配
                    if ((target = getPursueUnit()) == null || !_fightLogic.checkTargetInfluence(target, _fightUnitConfig.attackInfluenceTypeT))
                    {
                        //又找到目标
                        if ((target = searchTarget()) != null)
                        {
                            setPursueUnit(target);
                            selectPursueSkill();
                            continuePursue();
                        }
                        else
                        {
                            pursueOver();
                        }
                    }
                    else
                    {
                        if (_commandLogic.isCommandCanChangePursueUnit())
                        {
                            //1秒3次
                            if (_fightUnitConfig.needHateSwitchTarget)
                            {
                                //寻找其他目标
                                reSelectPursueTarget();

                                //目标变化
                                if (_pursueUnit.getUnit() != target)
                                {
                                    selectPursueSkill();
                                    continuePursue();
                                    return;
                                }
                            }
                        }

                        if (_commandLogic.isCommandCanChangePursueSkill())
                        {
                            SkillData purseSkill = _pursueSkill;
                            selectPursueSkill();

                            if (_pursueSkill != purseSkill)
                            {
                                continuePursue();
                                return;
                            }
                        }

                        //toPursue(target.pos.getPos());
                    }
                }
            }
            else
            {
                _fightState = UnitAIFightStateType.Idle;
            }
        }
        break;
        }
    }