Esempio n. 1
0
 public void ActionTick()
 {
     if (!this.isTakingDamage)
     {
         if (this.isMoving || this.isAttacking)
         {
             NavMeshAgent agent = this.GetComponent <NavMeshAgent>();
             if (agent.ReachedDestination())
             {
                 SetStopMoving();
             }
             if (this.enemies.Count <= 0)
             {
                 LocateEnemies();
             }
             if (this.enemies.Count > 0)
             {
                 if (this.enemies[0] != null)
                 {
                     this.enemyTarget = this.enemies[0];
                 }
             }
             if (this.enemyTarget != null && this.enemyTarget.isEnemy)
             {
                 if (Vector3.Distance(this.transform.position, this.enemyTarget.transform.position) <= ObtainRadius(this) + this.attackRadius)
                 {
                     if (this.enemyTarget.currentHealth > 0)
                     {
                         SetAttack();
                         if (this.attackCooldownTimer <= 0f)
                         {
                             this.enemyTarget.TakeDamage(this.attackPower);
                         }
                     }
                 }
                 else
                 {
                     agent.stoppingDistance = ObtainRadius(this.enemyTarget) + this.attackRadius;
                     agent.SetDestination(this.enemyTarget.transform.position);
                 }
             }
             else
             {
                 if (agent.ReachedDestination())
                 {
                     SetAttackCancel();
                     if (this.isSelected)
                     {
                         SetSelect();
                     }
                 }
             }
         }
     }
 }
 void Update()
 {
     if (this.canExamineArea && this.isOrderedToMove)
     {
         this.isOrderedToMove = false;
     }
     if (this.canExamineArea)
     {
         ExamineArea(this.unit.attackRadius);
     }
     else if (this.isOrderedToMove)
     {
         NavMeshAgent agent = this.GetComponent <NavMeshAgent>();
         if (agent.ReachedDestination())
         {
             this.canExamineArea  = true;
             this.isOrderedToMove = false;
         }
     }
     Attack();
 }
Esempio n. 3
0
        public void Update()
        {
            //Because the game is now spawning objects from the player-owned objects (spawning from NetworkManager-spawned objects), don't check for
            //isLocalPlayer, but instead check to see if the clients have authority over the non-player owned objects spawned from the NetworkManager-spawned objects.
            //Wordy, I know...
            if (!this.hasAuthority)
            {
                return;
            }

            if (this.isSplitting || this.isMerging)
            {
                return;
            }


            //Simple, "quick," MOBA-style controls. Hence, the class name.
            if (this.isSelected)
            {
                this.selectionRing.SetActive(true);
                Vector3 screenPoint = Camera.main.ScreenToViewportPoint(Input.mousePosition);
                if (!MinimapStuffs.Instance.minimapCamera.rect.Contains(screenPoint))
                {
                    if (Input.GetMouseButtonDown(1))
                    {
                        CastRay(false, Input.mousePosition, null);
                    }
                }
            }
            else
            {
                this.selectionRing.SetActive(false);
            }

            //Obtaining the nav mesh agent here for future uses.
            NavMeshAgent agent = this.GetComponent <NavMeshAgent>();

            //Non-directed, self-defense
            LineOfSight sight = this.GetComponentInChildren <LineOfSight>();
            AttackArea  area  = this.GetComponentInChildren <AttackArea>();

            if (!this.isDirected || agent.remainingDistance < 0.5f)
            {
                //Line of Sight. Detects if there are nearby enemy game units, and if so, follow them to engage in battle.
                if (sight != null && area != null)
                {
                    //There are 4 cases when detecting an enemy in both areas, line of sight and attack range. I had to consider each of the cases
                    //in order to ease the Console error gods...
                    // (12/5/2015) Now there are 8 cases in total. Consider AI players.
                    GameUnit sightGameUnit = null;
                    if (sight.enemiesInRange.Count > 0)
                    {
                        foreach (GameUnit temp in sight.enemiesInRange)
                        {
                            if (temp != null)
                            {
                                sightGameUnit = temp;
                                break;
                            }
                        }
                    }
                    GameUnit attackGameUnit = null;
                    if (sight.enemiesInRange.Count > 0)
                    {
                        foreach (GameUnit temp in sight.enemiesInRange)
                        {
                            if (temp != null)
                            {
                                attackGameUnit = temp;
                                break;
                            }
                        }
                    }
                    AIUnit sightAiUnit = null;
                    if (sight.otherEnemies.Count > 0)
                    {
                        foreach (AIUnit temp in sight.otherEnemies)
                        {
                            if (temp != null)
                            {
                                sightAiUnit = temp;
                                break;
                            }
                        }
                    }
                    AIUnit attackAiUnit = null;
                    if (sight.otherEnemies.Count > 0)
                    {
                        foreach (AIUnit temp in sight.otherEnemies)
                        {
                            if (temp != null)
                            {
                                attackAiUnit = temp;
                                break;
                            }
                        }
                    }

                    if (sightGameUnit != null && attackGameUnit != null)
                    {
                        SetTargetEnemy(this.gameObject, sightGameUnit.gameObject, attackGameUnit.gameObject);
                        CmdSetTargetEnemy(this.gameObject, sightGameUnit.gameObject, attackGameUnit.gameObject);
                    }
                    else if (sightGameUnit != null && attackGameUnit == null)
                    {
                        SetTargetEnemy(this.gameObject, sightGameUnit.gameObject, sightGameUnit.gameObject);
                        CmdSetTargetEnemy(this.gameObject, sightGameUnit.gameObject, sightGameUnit.gameObject);
                    }
                    else if (sightGameUnit == null && attackGameUnit != null)
                    {
                        SetTargetEnemy(this.gameObject, attackGameUnit.gameObject, attackGameUnit.gameObject);
                        CmdSetTargetEnemy(this.gameObject, attackGameUnit.gameObject, attackGameUnit.gameObject);
                    }
                    else
                    {
                        SetTargetEnemy(this.gameObject, this.gameObject, this.gameObject);
                        CmdSetTargetEnemy(this.gameObject, this.gameObject, this.gameObject);
                    }

                    if (sightAiUnit != null && attackAiUnit != null)
                    {
                        SetTargetAIEnemy(this.gameObject, sightAiUnit.gameObject, attackAiUnit.gameObject);
                    }
                    else if (sightAiUnit != null && attackAiUnit == null)
                    {
                        SetTargetAIEnemy(this.gameObject, sightAiUnit.gameObject, sightAiUnit.gameObject);
                    }
                    else if (sightAiUnit == null && attackAiUnit != null)
                    {
                        SetTargetAIEnemy(this.gameObject, attackAiUnit.gameObject, attackAiUnit.gameObject);
                    }
                    else
                    {
                        SetTargetAIEnemy(this.gameObject, this.gameObject, this.gameObject);
                    }
                }
            }

            //Start attacking.
            Attack();
            //Updating status.
            UpdateStatus();

            //Keeping track of whether the game unit is carrying out a player's command, or is carrying out self-defense.
            if (agent != null && agent.ReachedDestination())
            {
                this.isDirected = false;
            }
        }