Exemplo n.º 1
0
 private void Update()
 {
     if (this.spawnGroups.Count > 0)
     {
         for (int i = 0; i < this.spawnGroups.Count; i++)
         {
             MoveToPosition(i);
             Cooldown(i);
             UpdateGroup(i);
         }
         foreach (SpawnGroup group in this.spawnGroups)
         {
             if (group.elapsedTime > 1f)
             {
                 this.remove.Add(group);
             }
         }
     }
     if (this.remove.Count > 0)
     {
         foreach (SpawnGroup group in this.remove)
         {
             Divisible div = group.owner.GetComponent <Divisible>();
             if (!div.IsDivisibleStateReady())
             {
                 div.SetDivisibleReady();
             }
             div = group.spawnedUnit.GetComponent <Divisible>();
             if (!div.IsDivisibleStateReady())
             {
                 div.SetDivisibleReady();
             }
             this.spawnGroups.Remove(group);
         }
         this.remove.Clear();
     }
 }
Exemplo n.º 2
0
    private void AttackEnemies()
    {
        if (this.attackTargetUnits.Count > 0)
        {
            GameObject enemy = this.attackTargetUnits[0];
            if (enemy == null)
            {
                this.attackTargetUnits.RemoveAt(0);
                return;
            }
            Selectable enemySelect = enemy.GetComponent <Selectable>();
            if (enemySelect == null)
            {
                this.attackTargetUnits.RemoveAt(0);
                return;
            }
            if (enemySelect.UUID.Equals(this.selectable.UUID))
            {
                this.attackTargetUnits.RemoveAt(0);
                return;
            }
            DeathCheck check = enemy.GetComponent <DeathCheck>();
            if (check != null && !check.isDead)
            {
                if (Vector3.Distance(enemy.transform.position, this.gameObject.transform.position) <= 2.5f)
                {
                    if (this.gameObject != null && enemy.gameObject != null)
                    {
                        BattlePair p = new BattlePair(this.gameObject, enemy);
                        if (!DeathCheck.pairs.Contains(p))
                        {
                            //TODO: Swap this to another script that keeps track of strength and HP.
                            Attackable attack = enemy.GetComponent <Attackable>();
                            if (attack != null)
                            {
                                if (attack.attackCooldown <= 0f)
                                {
                                    NetworkViewID viewID = enemy.GetComponent <NetworkView>().viewID;
                                    this.attackableNetworkView.RPC("RPC_DecreaseHealth", RPCMode.AllBuffered, viewID);

                                    HealthBar bar = enemy.GetComponent <HealthBar>();
                                    Divisible div = enemy.GetComponent <Divisible>();
                                    if (bar.currentHealth <= 0f || bar.healthPercentage <= 0f || !div.IsDivisibleStateReady())
                                    {
                                        check.Kill();
                                        DeathCheck.pairs.Add(p);
                                    }

                                    attack.attackCooldown = 1.414f;
                                }
                                else
                                {
                                    attack.attackCooldown -= Time.deltaTime;
                                }
                            }
                        }
                    }
                }
                else
                {
                    Vector3 unitVector = (enemy.transform.position - this.gameObject.transform.position).normalized;
                    if (this.attackableNetworkView != null && !this.receivedAttackCommand)
                    {
                        this.receivedAttackCommand = true;
                        this.attackableNetworkView.RPC("RPC_Attack", RPCMode.AllBuffered, this.gameObject.transform.position + unitVector);
                    }
                }
            }
        }
    }