예제 #1
0
        public override bool IsTrue(Tank owner)
        {
            Tank oppTank = Match.instance.GetOppositeTank(owner.Team);

            if (oppTank == null)
            {
                return(false);
            }
            bool       seeOthers = false;
            RaycastHit hitInfo;

            if (Physics.Linecast(owner.FirePos, oppTank.Position, out hitInfo))
            {
                if (PhysicsUtils.IsFireCollider(hitInfo.collider))
                {
                    seeOthers = true;
                }
            }
            return(seeOthers);
        }
예제 #2
0
        /// <summary>
        /// 是否能看见敌方坦克
        /// </summary>
        /// <returns></returns>
        bool CanSee()
        {
            RaycastHit m_hit;

            if (Physics.Linecast(transform.position, m_oppTankPos, out m_hit, PhysicsUtils.LayerMaskCollsion) && PhysicsUtils.IsFireCollider(m_hit.collider))
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
예제 #3
0
        protected override void OnUpdate()
        {
            base.OnUpdate();
            bool hasStar   = false;
            bool seeOthers = false;

            Vector3 nearestOppTankPos = Vector3.zero;
            Vector3 nearestStarPos    = Vector3.zero;
            Tank    oppTank           = Match.instance.GetOppositeTank(Team);

            Fire();
            if (oppTank != null)
            {
                RaycastHit hitInfo;
                if (Physics.Linecast(FirePos, oppTank.Position, out hitInfo, PhysicsUtils.LayerMaskCollsion))
                {
                    if (PhysicsUtils.IsFireCollider(hitInfo.collider))
                    {
                        seeOthers = true;
                    }
                    else
                    {
                        seeOthers = false;
                    }
                }
                if (seeOthers)
                {
                    TurretTurnTo(oppTank.Position);
                    Vector3 toTarget = oppTank.Position + oppTank.Forward * Velocity.magnitude * Time.deltaTime - FirePos;
                    toTarget.y = 0;
                    toTarget.Normalize();
                    if (Vector3.Dot(TurretAiming, toTarget) > 0.98f)
                    {
                        Fire();
                    }
                }
                else
                {
                    nearestOppTankPos = oppTank.Position;
                }
            }
            if (oppTank == null && hasStar == false)
            {
                Move(new Vector3(0, 0, 0));
            }
            else if (oppTank == null && hasStar)
            {
                Move(nearestStarPos);
            }
            else if (oppTank != null && hasStar == false)
            {
                Move(nearestOppTankPos);
            }
            else if (oppTank != null && hasStar)
            {
                if (HP > 50)
                {
                    float disToStar        = Vector3.Distance(transform.position, nearestStarPos);
                    float disOppTankToStar = Vector3.Distance(nearestStarPos, nearestOppTankPos);
                    if (disToStar <= disOppTankToStar)
                    {
                        Move(nearestStarPos);
                    }
                    if (disToStar > disOppTankToStar)
                    {
                        Move(nearestOppTankPos);
                    }
                }
                else if (HP > 25)
                {
                    Move(nearestStarPos);
                }
                else if (HP > 0)
                {
                    float disToStar      = Vector3.Distance(transform.position, nearestStarPos);
                    float rangeToEatStar = Random.Range(5, 8);
                    if (disToStar <= rangeToEatStar)
                    {
                        Move(nearestStarPos);
                    }
                    else
                    {
                        Move(Match.instance.GetRebornPos(Team));
                    }
                }
            }
            if (m_GetSuperStar.IsTrue(this))
            {
                Move(Vector3.zero);
            }
            else if (m_BackToHome.IsTrue(this))
            {
                Move(Match.instance.GetRebornPos(Team));
            }
            else
            {
                if (Time.time > m_LastTime)
                {
                    if (ApproachNextDestination())
                    {
                        m_LastTime = Time.time + Random.Range(3, 8);
                    }
                }
            }
        }
예제 #4
0
        protected override void OnUpdate()
        {
            base.OnUpdate();
            bool  hasStar     = false;
            bool  seeOthers   = false;
            float nearestDist = float.MaxValue;

            Vector3 nearestOppTankPos = Vector3.zero;
            Vector3 nearestStarPos    = Vector3.zero;


            foreach (var pair in Match.instance.GetStars())
            {
                Star s = pair.Value;

                float dist = (s.transform.position - Position).sqrMagnitude;

                if (dist < nearestDist)
                {
                    hasStar        = true;
                    nearestDist    = dist;
                    nearestStarPos = s.transform.position;
                }
            }
            Tank oppTank = Match.instance.GetOppositeTank(Team);

            if (oppTank != null)
            {
                RaycastHit hitInfo;
                if (Physics.Linecast(FirePos, oppTank.Position, out hitInfo, PhysicsUtils.LayerMaskCollsion))
                {
                    if (PhysicsUtils.IsFireCollider(hitInfo.collider))
                    {
                        seeOthers = true;
                    }
                    else
                    {
                        seeOthers = false;
                    }
                }
                if (seeOthers)
                {
                    TurretTurnTo(oppTank.Position);
                    Vector3 toTarget = oppTank.Position + oppTank.Forward * Velocity.magnitude * Time.deltaTime - FirePos;
                    toTarget.y = 0;
                    toTarget.Normalize();
                    if (Vector3.Dot(TurretAiming, toTarget) > 0.7f)
                    {
                        Fire();
                    }
                }
                else
                {
                    nearestOppTankPos = oppTank.Position;
                }
            }
            if (oppTank == null && hasStar == false)
            {
                Move(new Vector3(0, 0, 0));
            }
            else if (oppTank == null && hasStar)
            {
                Move(nearestStarPos);
            }
            else if (oppTank != null && hasStar == false)
            {
                Move(nearestOppTankPos);
            }
            else if (oppTank != null && hasStar)
            {
                if (HP > 40)
                {
                    float disToStar        = Vector3.Distance(transform.position, nearestStarPos);
                    float disOppTankToStar = Vector3.Distance(nearestStarPos, nearestOppTankPos);
                    if (disToStar <= disOppTankToStar)
                    {
                        Move(nearestStarPos);
                    }
                    if (disToStar > disOppTankToStar)
                    {
                        Move(nearestOppTankPos);
                    }
                }
                else if (HP > 25)
                {
                    Move(nearestStarPos);
                }
                else if (HP > 0)
                {
                    float disToStar      = Vector3.Distance(transform.position, nearestStarPos);
                    float rangeToEatStar = Random.Range(6, 8);
                    if (disToStar <= rangeToEatStar)
                    {
                        Move(nearestStarPos);
                    }
                    else
                    {
                        Move(Match.instance.GetRebornPos(Team));
                    }
                }
            }
        }
예제 #5
0
        protected override void OnUpdate()
        {
            base.OnUpdate();


            bool    hasStar        = false;
            float   nearestDist    = float.MaxValue;
            Vector3 nearestStarPos = Vector3.zero;
            Tank    oppTank        = Match.instance.GetOppositeTank(Team);

            foreach (var pair in Match.instance.GetStars())
            {
                Star s = pair.Value;
                if (s.IsSuperStar)
                {
                    hasStar        = true;
                    nearestStarPos = s.Position;
                }
                else
                {
                    float dist = (s.Position - Position).sqrMagnitude;
                    if (dist < nearestDist)
                    {
                        hasStar        = true;
                        nearestDist    = dist;
                        nearestStarPos = s.Position;
                    }
                }
            }
            if (hasStar == true)
            {
                Vector3    target   = Match.instance.GetRebornPos(Team);
                float      distance = (target - Position).magnitude;
                RaycastHit hitInfo;
                if (oppTank == null)
                {
                    if (Physics.Linecast(FirePos, Match.instance.GetRebornPos(oppTank.Team), out hitInfo, PhysicsUtils.LayerMaskCollsion))
                    {
                        if (hitInfo.transform == null && HP >= 50)
                        {
                            TurretTurnTo(Match.instance.GetRebornPos(oppTank.Team));
                            if (Vector3.Dot(TurretAiming, (Match.instance.GetRebornPos(oppTank.Team) - FirePos)) >
                                0.98f)
                            {
                                Fire();
                            }
                        }
                    }
                }
                else
                {
                    if (HP >= 50)
                    {
                        Move(nearestStarPos);
                    }
                    else
                    {
                        if (nearestDist < 28)
                        {
                            Move(nearestStarPos);
                        }
                        else
                        {
                            Move(target);
                        }
                    }
                }
            }
            else
            {
                if (Time.time > m_LastTime)
                {
                    if (ApproachNextDestination())
                    {
                        m_LastTime = Time.time + Random.Range(3, 8);
                    }
                }
            }


            if (oppTank != null)
            {
                bool       seeOthers = false;
                RaycastHit hitInfo;
                if (Physics.Linecast(FirePos, oppTank.Position, out hitInfo, PhysicsUtils.LayerMaskCollsion))
                {
                    if (PhysicsUtils.IsFireCollider(hitInfo.collider))
                    {
                        seeOthers = true;
                    }
                }
                if (seeOthers)
                {
                    TurretTurnTo(oppTank.Position);
                    Vector3 toTarget = oppTank.Position - FirePos;
                    toTarget.y = 0;
                    toTarget.Normalize();

                    Vector3 tar = GetVerticalDir(toTarget);
                    if (Vector3.Distance(oppTank.Position, Position) > 50)
                    {
                        Move(Position + GetVerticalDir(toTarget) * 5);
                    }
                    if (Vector3.Dot(TurretAiming, toTarget) > 0.98f)
                    {
                        Fire();
                    }
                }
                else
                {
                    TurretTurnTo(Position + Forward);
                }
            }
        }
예제 #6
0
        protected override void OnUpdate()
        {
            bool    HaveSuperStar = false;
            Vector3 SuperPos      = Vector3.zero;

            base.OnUpdate();
            FindStar(2);
            foreach (var pair in Match.instance.GetStars())
            {
                Star s = pair.Value;
                if (s.IsSuperStar)
                {
                    HaveSuperStar = true;
                    SuperPos      = s.Position;
                }
            }
            if (HaveSuperStar)
            {
                Tank       oppTank = Match.instance.GetOppositeTank(Team);
                RaycastHit hitInfo;
                if (Physics.Linecast(FirePos, oppTank.Position, out hitInfo, PhysicsUtils.LayerMaskCollsion))
                {
                    if (PhysicsUtils.IsFireCollider(hitInfo.collider))
                    {
                        Fight(oppTank);
                    }
                }
                Move(SuperPos);
            }
            else
            {
                Tank oppTank = Match.instance.GetOppositeTank(Team);
                if (oppTank != null)
                {
                    bool seeOthers = false;
                    TurretTurnTo(oppTank.Position);
                    Condition  backhome = new HpBelow(HP, oppTank.HP, 30);
                    RaycastHit hitInfo;
                    if (Physics.Linecast(FirePos, oppTank.Position, out hitInfo, PhysicsUtils.LayerMaskCollsion))
                    {
                        if (PhysicsUtils.IsFireCollider(hitInfo.collider))
                        {
                            seeOthers = true;
                        }
                    }
                    if (seeOthers)
                    {
                        if (Vector3.Distance(Position, oppTank.Position) < 16.0f)
                        {
                            FindStar(1);
                            Fight(oppTank);
                        }
                        else
                        {
                            Miss();
                            Fight(oppTank);
                        }
                    }
                    else
                    {
                        if (backhome.Istrue() && !seeOthers)
                        {
                            Move(Match.instance.GetRebornPos(Team));
                        }
                        else
                        {
                            FindStar(2);
                        }
                    }
                }
            }
        }