protected virtual void FireAt(GameplayObject target)
 {
     GameObject obj = (GameObject.Instantiate(m_projectilePrefab,
         CachedTransform.position, transform.rotation) as GameObject);
     m_lastShotProjectile = obj.GetComponent<Projectile>();
     m_lastShotProjectile.Fire(target);
 }
        protected virtual void FireAt(GameplayObject target)
        {
            GameObject obj = (GameObject.Instantiate(m_projectilePrefab,
                                                     CachedTransform.position, transform.rotation) as GameObject);

            m_lastShotProjectile = obj.GetComponent <Projectile>();
            m_lastShotProjectile.Fire(target);
        }
 protected virtual bool CanTargetObject(GameplayObject target)
 {
     if (m_targetCandidate == null || m_targetCandidate.IsDead() ||
         !CanSeeObject(m_targetCandidate))
     {
         return(false);
     }
     else
     {
         return(true);
     }
 }
        public void Fire(GameplayObject target)
        {
            m_intendedTarget = target;

            m_startPos = CachedTransform.position;
            m_endPos = target.CachedTransform.position;

            m_distance = (m_endPos - m_startPos).magnitude;
            m_duration = m_distance / m_speed;

            m_startTime = Time.time;
        }
Beispiel #5
0
        public void Fire(GameplayObject target)
        {
            m_intendedTarget = target;

            m_startPos = CachedTransform.position;
            m_endPos   = target.CachedTransform.position;

            m_distance = (m_endPos - m_startPos).magnitude;
            m_duration = m_distance / m_speed;

            m_startTime = Time.time;
        }
 protected virtual bool CanSeeObject(GameplayObject obj)
 {
     if ((obj.CachedTransform.position
          - GetEnemySearchCenter()).sqrMagnitude
         < GetVisualRangeSqr())
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
        protected virtual void EnemyDiedEventHandler()
        {
            // Cancel if we already don't have a target any more.
            if (m_enemyTarget == null)
            {
                return;
            }

            // Unsubscribe to the die event.
            m_enemyTarget.DiedEvent -= EnemyDiedEventHandler;

            // Forget about the enemy.
            m_enemyTarget = null;
        }
 public void RemoveObject(GameplayObject obj)
 {
     if (obj == null)
     {
         return;
     }
     if (obj is Unit)
     {
         m_units.Remove(obj as Unit);
     }
     if (obj is Building)
     {
         m_buildings.Remove(obj as Building);
     }
     m_objects.Remove(obj);
 }
Beispiel #9
0
 public void RemoveObject(GameplayObject obj)
 {
     if (obj == null)
     {
         return;
     }
     if (obj is Unit)
     {
         m_units.Remove(obj as Unit);
     }
     if (obj is Building)
     {
         m_buildings.Remove(obj as Building);
     }
     m_objects.Remove(obj);
 }
Beispiel #10
0
        /// <summary>
        /// Try to persuade the object to join us.
        /// If we were successful, keep track of it.
        /// </summary>
        /// <param name="obj">Object to recruit.</param>
        protected virtual void Recruit(GameplayObject obj)
        {
            if (obj.PersuadeToJoinFaction(this))
            {
                // Add to unit list if it's a unit.
                if (obj is Unit)
                {
                    m_units.Add(obj as Unit);
                }

                // Add to building list if it's a building.
                if (obj is Unit)
                {
                    m_units.Add(obj as Unit);
                }
            }
        }
        protected virtual void SetEnemyTarget(GameplayObject target)
        {
            // Unsubscribe to the old target's death event.
            if (m_enemyTarget != null && m_enemyTarget != target)
            {
                m_enemyTarget.DiedEvent -= EnemyDiedEventHandler;
            }

            // Set the new target.
            m_enemyTarget = target;

            // Subscribe to the new target's death event.
            if (m_enemyTarget != null)
            {
                m_enemyTarget.DiedEvent += EnemyDiedEventHandler;
            }
        }
        protected virtual void LookForEnemyTarget()
        {
            // Stop if we already have a target.
            // In the future, this should consider more conditions.
            if (HaveEnemyTarget() && !ConsiderAbandoningTarget())
            {
                return;
            }

            // Initialize the search.
            m_targetBestCandidate         = null;
            m_targetBestCandidateDistance = float.MaxValue;

            // Go through all potential enemies.
            for (int i = 0; i < m_faction.GetEnemyUnits().Count; i++)
            {
                // Find the candidate.
                m_targetCandidate = m_faction.GetEnemyUnits()[i];

                // Filter out invalid candidates.
                if (!CanTargetObject(m_targetCandidate))
                {
                    continue;
                }

                // Find out how close it is to us.
                m_targetCandidateDistance =
                    (m_targetCandidate.CachedTransform.position
                     - CachedTransform.position).sqrMagnitude;

                // Find out if it is the best one.
                if (m_targetCandidateDistance < m_targetBestCandidateDistance)
                {
                    m_targetBestCandidateDistance = m_targetCandidateDistance;
                    m_targetBestCandidate         = m_targetCandidate;
                }
            }
            m_targetCandidate = null;

            // Assume the new target.
            if (m_targetBestCandidate != null)
            {
                SetEnemyTarget(m_targetBestCandidate);
            }
        }
 protected virtual bool CanTargetObject(GameplayObject target)
 {
     if (m_targetCandidate == null || m_targetCandidate.IsDead()
             || !CanSeeObject(m_targetCandidate))
     {
         return false;
     }
     else
     {
         return true;
     }
 }
        /// <summary>
        /// Try to persuade the object to join us.
        /// If we were successful, keep track of it.
        /// </summary>
        /// <param name="obj">Object to recruit.</param>
        protected virtual void Recruit(GameplayObject obj)
        {
            if (obj.PersuadeToJoinFaction(this))
            {
                // Add to unit list if it's a unit.
                if (obj is Unit)
                {
                    m_units.Add(obj as Unit);
                }

                // Add to building list if it's a building.
                if (obj is Unit)
                {
                    m_units.Add(obj as Unit);
                }
            }
        }
 protected virtual bool CanSeeObject(GameplayObject obj)
 {
     if ((obj.CachedTransform.position
         - GetEnemySearchCenter()).sqrMagnitude
         < GetVisualRangeSqr())
     {
         return true;
     }
     else
     {
         return false;
     }
 }
 protected override void SetEnemyTarget(GameplayObject target)
 {
     base.SetEnemyTarget(target);
     MoveToEnemy();
 }
        protected virtual void SetEnemyTarget(GameplayObject target)
        {
            // Unsubscribe to the old target's death event.
            if (m_enemyTarget != null && m_enemyTarget != target)
            {
                m_enemyTarget.DiedEvent -= EnemyDiedEventHandler;
            }

            // Set the new target.
            m_enemyTarget = target;

            // Subscribe to the new target's death event.
            if (m_enemyTarget != null)
            {
                m_enemyTarget.DiedEvent += EnemyDiedEventHandler;
            }
        }
        protected virtual void LookForEnemyTarget()
        {
            // Stop if we already have a target.
            // In the future, this should consider more conditions.
            if (HaveEnemyTarget() && !ConsiderAbandoningTarget())
            {
                return;
            }

            // Initialize the search.
            m_targetBestCandidate = null;
            m_targetBestCandidateDistance = float.MaxValue;

            // Go through all potential enemies.
            for (int i = 0; i < m_faction.GetEnemyUnits().Count; i++)
            {
                // Find the candidate.
                m_targetCandidate = m_faction.GetEnemyUnits()[i];

                // Filter out invalid candidates.
                if (!CanTargetObject(m_targetCandidate))
                {
                    continue;
                }

                // Find out how close it is to us.
                m_targetCandidateDistance =
                    (m_targetCandidate.CachedTransform.position
                    - CachedTransform.position).sqrMagnitude;

                // Find out if it is the best one.
                if (m_targetCandidateDistance < m_targetBestCandidateDistance)
                {
                    m_targetBestCandidateDistance = m_targetCandidateDistance;
                    m_targetBestCandidate = m_targetCandidate;
                }
            }
            m_targetCandidate = null;

            // Assume the new target.
            if (m_targetBestCandidate != null)
            {
                SetEnemyTarget(m_targetBestCandidate);
            }
        }
 protected override void SetEnemyTarget(GameplayObject target)
 {
     base.SetEnemyTarget(target);
     MoveToEnemy();
 }
        protected virtual void EnemyDiedEventHandler()
        {
            // Cancel if we already don't have a target any more.
            if (m_enemyTarget == null)
            {
                return;
            }

            // Unsubscribe to the die event.
            m_enemyTarget.DiedEvent -= EnemyDiedEventHandler;

            // Forget about the enemy.
            m_enemyTarget = null;
        }