/// <summary>
        /// 小怪巡逻
        /// </summary>
        /// <param name="self"></param>
        public static void UpdatePatrol(this PatrolComponent self)
        {
            if (self.isIdle)
            {
                //开始休息 4秒
                if (!self.startNull)
                {
                    self.startTime = TimeHelper.ClientNowSeconds();
                    self.startNull = true;
                }
                long timeNow = TimeHelper.ClientNowSeconds();
                if ((timeNow - self.startTime) > self.idleResTime)
                {
                    self.startNull   = false;
                    self.isStartWalk = true;
                    self.isIdle      = false;
                }
            }
            else
            {
                //发送坐标,开始行走,开始发送巡逻目标点坐标
                if (self.isStartWalk)
                {
                    self.SendPatrolPosition();
                    self.isStartWalk = false;
                }

                //如果到达目标点,开始休息,并计时4秒后 重置巡逻目标点
                float sqr = SqrDistanceComponentHelper.Distance(self.GetParent <Unit>().Position, self.goalPoint);
                if (sqr < 0.1f)
                {
                    self.isStartWalk = true;
                    self.isIdle      = true;
                    self.patolNull   = false;
                }

                //如果卡住在地图到达不了目标点 此计时40秒后 重置巡逻目标点
                if (!self.patolNull)
                {
                    self.patolTimer = TimeHelper.ClientNowSeconds();
                    self.patolNull  = true;
                }
                long timeNow = TimeHelper.ClientNowSeconds();
                if ((timeNow - self.patolTimer) > self.lifeCdTime)
                {
                    self.patolNull   = false;
                    self.isStartWalk = true;
                }
            }
        }
示例#2
0
        /// 检查有无追击目标-Monster
        public static bool CheckSeekTarget(this SeekComponent self)
        {
            self.GetParent <Unit>().GetComponent <SqrDistanceComponent>().SqrDistance();

            if (self.target == null)
            {
                if (self.GetParent <Unit>().GetComponent <SqrDistanceComponent>().neastDistance < self.enterSeeDis)
                {
                    self.target = self.GetParent <Unit>().GetComponent <SqrDistanceComponent>().neastUnit;

                    self.GetParent <Unit>().GetComponent <AttackComponent>().isBattling = true;

                    return(true);
                }
            }
            else
            {
                self.targetDistance = SqrDistanceComponentHelper.Distance(self.GetParent <Unit>().Position, self.target.Position);

                if (self.targetDistance > self.enterSeeDis)
                {
                    if (self.GetParent <Unit>().GetComponent <SqrDistanceComponent>().neastDistance < self.enterSeeDis)
                    {
                        self.target = self.GetParent <Unit>().GetComponent <SqrDistanceComponent>().neastUnit;

                        self.GetParent <Unit>().GetComponent <AttackComponent>().isBattling = true;

                        return(true);
                    }
                }
                else
                {
                    self.GetParent <Unit>().GetComponent <AttackComponent>().isBattling = true;

                    return(true);
                }
            }
            self.target = null;

            self.GetParent <Unit>().GetComponent <AttackComponent>().isBattling = false;

            return(false);
        }
        /// <summary>
        /// 单目标 得到敌人
        /// </summary>
        /// <param name="unit"></param>
        public static bool MonsterCheckAttackTarget(this AttackComponent self)
        {
            Unit unit = self.GetParent <Unit>();

            if (unit.GetComponent <SeekComponent>() != null && unit.GetComponent <SeekComponent>().target != null)
            {
                self.targetDistance = SqrDistanceComponentHelper.Distance(unit.Position, unit.GetComponent <SeekComponent>().target.Position);

                if (self.targetDistance < self.attackDis)
                {
                    self.target = unit.GetComponent <SeekComponent>().target;

                    return(true);
                }
            }


            self.target = null;

            return(false);
        }