Beispiel #1
0
 public IEnumerator CR_Death()
 {
     for (int i = 0; i < DeathCheck.pairs.Count - 1; i++)
     {
         BattlePair a = DeathCheck.pairs[i];
         if (!a.isIgnored)
         {
             for (int j = i + 1; j < DeathCheck.pairs.Count; j++)
             {
                 BattlePair b = DeathCheck.pairs[j];
                 if (!b.isIgnored)
                 {
                     if (a.attackee.Equals(b.attacker) || b.attackee.Equals(a.attacker))
                     {
                         b.SetIgnored();
                     }
                 }
             }
         }
     }
     for (int i = 0; i < DeathCheck.pairs.Count; i++)
     {
         BattlePair p = DeathCheck.pairs[i];
         if (!p.isIgnored)
         {
             DeathCheck check = p.attackee.GetComponent <DeathCheck>();
             if (check.isDead)
             {
                 this.playerNetworkView = this.GetComponent <NetworkView>();
                 if (this.playerNetworkView != null)
                 {
                     if (this.playerNetworkView.isMine)
                     {
                         NetworkPlayer[] players = Network.connections;
                         if (players.Length > 0 && p.attackee != null)
                         {
                             Network.RemoveRPCsInGroup(0);
                             Network.Destroy(p.attackee);
                         }
                         else if (p.attackee != null)
                         {
                             Object.Destroy(p.attackee);
                         }
                         DeathCheck.pairs.Remove(p);
                         yield break;
                     }
                 }
             }
         }
         yield return(null);
     }
 }
Beispiel #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);
                    }
                }
            }
        }
    }