Example #1
0
        /// <summary>
        ///     进入某个AI状态
        /// </summary>
        /// <param name="_this"></param>
        /// <param name="state"></param>
        public void EnterState(ObjNPC _this, BehaviorState state)
        {
            if (state == _this.CurrentState)
            {
                return;
            }

            try
            {
                switch (_this.CurrentState)
                {
                case BehaviorState.Idle:
                    _this.Script.OnExitIdle(_this);
                    break;

                case BehaviorState.Combat:
                    _this.Script.OnExitCombat(_this);
                    break;

                case BehaviorState.GoHome:
                    _this.Script.OnExitGoHome(_this);
                    break;

                case BehaviorState.Die:
                    _this.Script.OnExitDie(_this);
                    break;

                default:
                    //Logger.Warn("Unknow ai type");
                    break;
                }
            }
            catch (Exception e)
            {
                Logger.Error(e);
            }

            _this.LastState    = _this.CurrentState;
            _this.CurrentState = state;
            try
            {
                switch (_this.CurrentState)
                {
                case BehaviorState.Idle:
                    _this.Script.OnEnterIdle(_this);
                    break;

                case BehaviorState.Combat:
                    _this.Script.OnEnterCombat(_this);
                    break;

                case BehaviorState.GoHome:
                    _this.Script.OnEnterGoHome(_this);
                    _this.RemoveMeFromOtherEnemyList();
                    _this.ClearEnemy();
                    _this.Skill.LastSkillMainTarget.SetTarget(null);
                    break;

                case BehaviorState.Die:
                    _this.Script.OnEnterDie(_this);
                    break;

                default:
                    Logger.Warn("Unknow ai type");
                    break;
                }
            }
            catch (Exception e)
            {
                Logger.Error(e);
            }

            // 爬塔怪物行为状态监听
            if (null != _this.OnBehaviourChangeCallback)
            {
                _this.OnBehaviourChangeCallback.Invoke(_this, _this.CurrentState, _this.LastState);
            }
        }
Example #2
0
 public override void OnExitCombat(ObjNPC npc)
 {
     npc.RemoveMeFromOtherEnemyList();
     npc.ClearEnemy();
     npc.CleanHatre();
 }
Example #3
0
        public override void OnTickCombat(ObjNPC npc, float delta)
        {
            CombatTime += 500;
            if (!npc.CanSkill())
            {
                return;
            }
            //判断是否需要状态转换
            var nextAi = CheckStateChange(npc);

            ChangeAi(npc, nextAi);
            //判断敌人是否存在
            var enemy = GetAttackTarget(npc);

            if (null == enemy || enemy.IsDead() || !enemy.Active)
            {
                npc.EnterState(BehaviorState.Idle);
                npc.SetDirection(npc.BornDirection);
                npc.BroadcastDirection();
                npc.RemoveMeFromOtherEnemyList();
                npc.ClearEnemy();
                return;
            }


            var WillskillId     = GetCanDoSkill(npc); //npc.NormalSkillId;
            var mTableWillskill = Table.GetSkill(WillskillId);

            if (mTableWillskill == null)
            {
                return;
            }
            switch ((SkillTargetType)mTableWillskill.TargetType)
            {
            case SkillTargetType.SELF:
            {
                if (DateTime.Now >= mNextNormalAttackTime)
                {
                    var reCodes = npc.MustSkill(ref WillskillId, npc);     //npc.UseSkill(ref skillId, enemy);
                    if (reCodes == ErrorCodes.OK)
                    {
                        PushSkillCd(npc, WillskillId);
                    }
                    return;
                }
                mTableWillskill = Table.GetSkill(npc.TableAI.CommonSkill);
                if (mTableWillskill == null)
                {
                    return;
                }
            }
            break;

            case SkillTargetType.SINGLE:
                break;

            case SkillTargetType.CIRCLE:
                break;

            case SkillTargetType.SECTOR:
                break;

            case SkillTargetType.RECT:
                break;

            case SkillTargetType.TARGET_CIRCLE:
                break;

            case SkillTargetType.TARGET_RECT:
                break;

            case SkillTargetType.TARGET_SECTOR:
                break;

            default:
                break;
            }
            mSkillDistance = SkillManager.GetSkillDistance((SkillTargetType)mTableWillskill.TargetType,
                                                           mTableWillskill.TargetParam);
            //跟着敌人打
            if ((npc.GetPosition() - enemy.GetPosition()).Length() > mSkillDistance)
            {
                npc.SetDirection(npc.BornDirection);
                npc.BroadcastDirection();
            }
            else
            {
                npc.TurnFaceTo(enemy.GetPosition());

                if (DateTime.Now >= mNextNormalAttackTime)
                {
                    var reCodes = npc.MustSkill(ref WillskillId, enemy); //npc.UseSkill(ref skillId, enemy);
                    if (reCodes == ErrorCodes.OK)
                    {
                        PushSkillCd(npc, WillskillId);
                    }
                }
            }
        }