Esempio n. 1
0
 private ObjCharacter GetCanAttack(ObjNPC npc)
 {
     if (mLastEnemy == null || mLastEnemy.IsDead() || !mLastEnemy.Active)
     {
         ObjCharacter temp   = null;
         var          maxDis = 9999999.0f;
         foreach (var pair in npc.Scene.mObjDict)
         {
             var t = pair.Value as ObjCharacter;
             if (t == null)
             {
                 continue;
             }
             if (t.IsDead() || !t.Active)
             {
                 continue;
             }
             if (!mAddList.Contains(t.TypeId))
             {
                 continue;
             }
             var dis = (npc.GetPosition() - t.GetPosition()).LengthSquared();
             if (dis < maxDis)
             {
                 temp   = t;
                 maxDis = dis;
             }
         }
         return(temp);
     }
     return(mLastEnemy);
 }
Esempio n. 2
0
        private void ResetTowerHp()
        {
            mIsFubenInfoDirty = true;
            var unit = mFubenInfoMsg.Units[1];

            if (leftTower.IsDead() || !leftTower.Active)
            {
                unit.Params[0] = 0;
            }
            else
            {
                unit.Params[0] = leftTower.GetAttribute(eAttributeType.HpNow) * 100 /
                                 leftTower.GetAttribute(eAttributeType.HpMax);
            }

            if (middleTower.IsDead() || !middleTower.Active)
            {
                unit.Params[1] = 0;
            }
            else
            {
                unit.Params[1] = middleTower.GetAttribute(eAttributeType.HpNow) * 100 /
                                 middleTower.GetAttribute(eAttributeType.HpMax);
            }

            if (rightTower.IsDead() || !rightTower.Active)
            {
                unit.Params[2] = 0;
            }
            else
            {
                unit.Params[2] = rightTower.GetAttribute(eAttributeType.HpNow) * 100 /
                                 rightTower.GetAttribute(eAttributeType.HpMax);
            }

            var unit2 = mFubenInfoMsg.Units[2];

            if (mainTower.IsDead() || !mainTower.Active)
            {
                unit2.Params[0] = 0;
            }
            else
            {
                unit2.Params[0] = mainTower.GetAttribute(eAttributeType.HpNow) * 100 /
                                  mainTower.GetAttribute(eAttributeType.HpMax);
            }
        }
Esempio n. 3
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;
                    }
                }
            }
        }
Esempio n. 4
0
        private ObjCharacter GetCanAttack(ObjNPC npc)
        {
            if (mLastEnemy != null && mLastEnemy.Active && !mLastEnemy.IsDead() && npc.Zone.ObjDict.ContainsKey(mLastEnemy.ObjId))
            {
                return(mLastEnemy);
            }

            if (MyTargetObjList.Count == 0)
            {
                foreach (var pair in npc.Scene.mObjDict)
                {
                    if (!pair.Value.IsCharacter())
                    {
                        continue;
                    }
                    var t = pair.Value as ObjCharacter;

                    if (t.IsDead() || !t.Active)
                    {
                        continue;
                    }
                    if (!mAddList.Contains(t.TypeId))
                    {
                        continue;
                    }
                    MyTargetObjList.Add(t.ObjId);
                }
            }


            var e = npc.Zone.EnumAllVisiblePlayer();

            foreach (var objPlayer in e)
            {
                if (!MyTargetObjList.Contains(objPlayer.ObjId))
                {
                    MyTargetObjList.Add(objPlayer.ObjId);
                }
            }

            ObjCharacter temp   = null;
            var          maxDis = 9999999.0f;

            for (int i = 0; i < MyTargetObjList.Count;)
            {
                var objId  = MyTargetObjList[i];
                var target = npc.Scene.FindObj(objId);
                if (null == target)
                {
                    MyTargetObjList.RemoveAt(i);
                    continue;
                }
                var enemy = target as ObjCharacter;
                if (enemy.IsDead() || !enemy.Active)
                {
                    MyTargetObjList.RemoveAt(i);
                    continue;
                }
                var dis = (npc.GetPosition() - enemy.GetPosition()).LengthSquared();
                if (dis < maxDis)
                {
                    temp   = enemy;
                    maxDis = dis;
                }

                i++;
            }

            mLastEnemy = temp;

            return(temp ?? mLastEnemy);
        }