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;
                    }
                }
            }
        }
Beispiel #2
0
        public virtual ObjCharacter GetAttackTarget(NPCScriptBase _this, ObjNPC npc)
        {
            switch (npc.TableAI.HatreType)
            {
            case 0:     //仇恨的
                if (npc.TableAI.SortType == 0)
                {
                    return(npc.GetMaxHatre());
                }
                if (npc.TableAI.SortType == 1)
                {
                    return(npc.GetMinHatre());
                }
                Logger.Warn("GetAttackTarget AiId={0} Config Error!! HatreType={1} , SortType={2}", npc.TableAI.Id,
                            npc.TableAI.HatreType, npc.TableAI.SortType);
                return(null);

            case 1:     //距离的

                if (npc.TableAI.SortType == 0)
                {
                    return(npc.GetMaxDistanceEnemy());
                }
                if (npc.TableAI.SortType == 1)
                {
                    return(npc.GetMinDistanceEnemy());
                }
                Logger.Warn("GetAttackTarget AiId={0} Config Error!! HatreType={1} , SortType={2}", npc.TableAI.Id,
                            npc.TableAI.HatreType, npc.TableAI.SortType);
                return(null);

            case 2:     //按血量

                if (npc.TableAI.SortType == 0)
                {
                    return(npc.GetMaxHpNow());
                }
                if (npc.TableAI.SortType == 1)
                {
                    return(npc.GetMinHpNow());
                }
                Logger.Warn("GetAttackTarget AiId={0} Config Error!! HatreType={1} , SortType={2}", npc.TableAI.Id,
                            npc.TableAI.HatreType, npc.TableAI.SortType);
                return(null);

            case 3:     //按职业
            {
                switch (npc.TableAI.SortType)
                {
                case 2:         //战法猎
                    return(npc.GetCharacterByRole(NPCScriptBase.tempTypeList2));

                case 3:
                    return(npc.GetCharacterByRole(NPCScriptBase.tempTypeList3));

                case 4:
                    return(npc.GetCharacterByRole(NPCScriptBase.tempTypeList4));

                case 5:
                    return(npc.GetCharacterByRole(NPCScriptBase.tempTypeList5));

                case 6:
                    return(npc.GetCharacterByRole(NPCScriptBase.tempTypeList6));

                case 7:
                    return(npc.GetCharacterByRole(NPCScriptBase.tempTypeList7));
                }
            }
                Logger.Warn("GetAttackTarget AiId={0} Config Error!! HatreType={1} , SortType={2}", npc.TableAI.Id,
                            npc.TableAI.HatreType, npc.TableAI.SortType);
                return(null);
            }
            return(null);
        }