Example #1
0
        public override void OnEnterCombat(ObjNPC npc)
        {
            //保存下进入战斗时的位置,距离这个位置太远了就要回家
            mBackPosition = npc.GetPosition();

            //获得目标
            var enemy = npc.Scene.FindCharacter(npc.LastEnemyId);

            if (null != enemy)
            {
                npc.TurnFaceTo(enemy.GetPosition());
            }

            npc.BroadcastDirection();

            //保存普攻数据
            if (-1 != npc.NormalSkillId)
            {
                mTableNormalSkill = Table.GetSkill(npc.NormalSkillId);

                //计算普攻技能距离
                mSkillDistance =
                    SkillManager.GetSkillDistance((SkillTargetType)mTableNormalSkill.TargetType,
                                                  mTableNormalSkill.TargetParam) - 0.8f;
                mSkillDistance = Math.Max(mSkillDistance, 0);
                //上来先来个cd,要不攻击者一攻击怪一瞬间怪就反击
                //GenNextNormalAttackTime();
            }

            mNoMoveTime = 0;
        }
Example #2
0
        //战斗
        public override void OnEnterCombat(ObjNPC npc)
        {
            ChangeAi(npc, npc.TableNpc.mAI);
            //获得目标
            var enemy = npc.Scene.FindCharacter(npc.LastEnemyId);

            if (null != enemy)
            {
                npc.TurnFaceTo(enemy.GetPosition());
            }

            npc.BroadcastDirection();

            //保存普攻数据
            if (-1 != npc.TableAI.CommonSkill)
            {
                mTableNormalSkill = Table.GetSkill(npc.TableAI.CommonSkill);

                //计算普攻技能距离
                mSkillDistance = SkillManager.GetSkillDistance((SkillTargetType)mTableNormalSkill.TargetType,
                                                               mTableNormalSkill.TargetParam);
            }
            CombatTime = 0;

            for (var i = 0; i != 4; ++i)
            {
                if (npc.TableAI.SpecialSkill[i] == -1)
                {
                    continue;
                }
                PushSkillCd(npc, npc.TableAI.SpecialSkill[i], 0);
            }
            mNextNormalAttackTime = DateTime.Now;
        }
Example #3
0
 //休闲
 public override void OnEnterIdle(ObjNPC npc)
 {
     if (npc.LastState == BehaviorState.GoHome)
     {
         npc.SetDirection(npc.BornDirection);
         npc.BroadcastDirection();
     }
 }
Example #4
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);
                    }
                }
            }
        }