Beispiel #1
0
        public override void OnTickCombat(ObjNPC npc, float delta)
        {
            ObjCharacter enemy = null;

            //判断敌人是否存在
            if (npc.TableAI == null)
            {
                enemy = npc.GetMaxHatre();
            }
            else
            {
                enemy = GetAttackTarget(npc);
            }

            //判断敌人是否存在

            if (null == enemy)
            {
                npc.EnterState(BehaviorState.GoHome);
                return;
            }

            //判断敌人是否有效
            if (enemy.IsDead() || !enemy.Active)
            {
                npc.EnterState(BehaviorState.GoHome);
                return;
            }

            //判断是否太远了
            var dis = (npc.GetPosition() - mBackPosition).Length();

            if (npc.TableNpc.MaxCombatDistance > 0 && dis >= npc.TableNpc.MaxCombatDistance)
            {
                npc.EnterState(BehaviorState.GoHome);
                return;
            }

            //如果有普通
            if (null != mTableNormalSkill)
            {
                //跟着敌人打
                if ((npc.GetPosition() - enemy.GetPosition()).Length() <= mSkillDistance)
                {
                    npc.TurnFaceTo(enemy.GetPosition());
                    if (npc.IsMoving())
                    {
                        GenNextNormalAttackTime(100);
                        npc.StopMove();
                    }
                    if (DateTime.Now >= mNextNormalAttackTime)
                    {
                        npc.Seperate(enemy, mSkillDistance / 3);
                        var skillId = npc.NormalSkillId;
                        npc.UseSkill(ref skillId, enemy);
                        GenNextNormalAttackTime();
                        mNoMoveTime = 0; //攻击了一次就把自己站在原地的累计时间清空
                    }
                }
                else
                {
                    var targetPos = npc.CalculatePostionToEnemy(enemy, mSkillDistance / 3);
                    if (MoveResult.CannotReach == npc.MoveTo(targetPos))
                    {
//如果长时间无法到达目的地说明卡怪了, 就回去
                        mNoMoveTime += delta;
                        if (mNoMoveTime >= MAX_NO_MOVE_TIME)
                        {
                            npc.EnterState(BehaviorState.GoHome);
                        }
                    }
                    else
                    {
                        mNoMoveTime = 0;
                    }
                }
            }
        }