Exemplo n.º 1
0
    /*
     * private IEnumerator RoomDmgLoop (int _amount) {
     *      isOccupied = true;
     *
     *      RoomScript _room = LevelManager.Instance.Tiles [crewPos].transform.GetChild (0).GetChild (0).GetComponent <RoomScript> ();
     *
     *      yield return new WaitForSeconds (1f);
     *
     *      while (true) {
     *              _room.TakeCrewDamage (_amount);
     *              //Debug.Log ("took " + _amount + " damage!");
     *
     *              if (_amount > 0) {
     *                      if (_room.IsFullyDamaged) {
     *                              //Debug.Log ("break!");
     *                              break;
     *                      }
     *              } else if (_amount < 0) {
     *                      if (_room.IsFullyRepaired) {
     *                              //Debug.Log ("break!");
     *                              break;
     *                      }
     *              }
     *
     *              yield return new WaitForSeconds (1f);
     *      }
     *
     *      isOccupied = false;
     * }
     */

    private IEnumerator DmgLoop(int _amount)
    {
        isOccupied = true;
        TileScript _tile = LevelManager.Instance.Tiles [crewPos];

        //RoomScript _room = LevelManager.Instance.Tiles [crewPos].transform.GetChild (0).GetChild (0).GetComponent <RoomScript> ();

        HealthScript[] _hScrArr = _tile.GetHScripts(_amount, _amount, _amount);

        yield return(new WaitForSeconds(1f));

        bool _hasSys = false;

        if (_hScrArr [1] != null)
        {
            _hasSys = true;
        }

        bool _hasSubSys = false;

        if (_hScrArr [2] != null)
        {
            _hasSubSys = true;
        }

        while (true)
        {
            //_tile.TakeCrewDamage (_amount, 0, 0);
            _hScrArr [0].TakeCrewDamage(_amount);
            if (_hasSys)
            {
                _hScrArr [1].TakeCrewDamage(_amount - 2);
            }
            if (_hasSubSys)
            {
                _hScrArr [2].TakeCrewDamage(_amount + 2);
            }

            //Debug.Log ("took " + _amount + " damage!");



            //this should happen if all obj on that tile are completely destroyed or repaired...
            if (_amount > 0)
            {
                if (_hScrArr[0].IsFullyDamaged)
                {
                    if (_hasSys)
                    {
                        if (_hScrArr [1].IsFullyDamaged)
                        {
                            if (_hasSubSys)
                            {
                                if (_hScrArr [2].IsFullyDamaged)
                                {
                                    break;
                                }
                            }
                            else
                            {
                                break;
                            }
                        }
                    }
                    else if (_hasSubSys)
                    {
                        if (_hScrArr [2].IsFullyDamaged)
                        {
                            break;
                        }
                    }
                    else
                    {
                        break;
                    }
                }
            }
            else if (_amount < 0)
            {
                if (_hScrArr [0].IsFullyRepaired)
                {
                    if (_hasSys)
                    {
                        if (_hScrArr [1].IsFullyRepaired)
                        {
                            if (_hasSubSys)
                            {
                                if (_hScrArr [2].IsFullyRepaired)
                                {
                                    break;
                                }
                            }
                            else
                            {
                                break;
                            }
                        }
                    }
                    else if (_hasSubSys)
                    {
                        if (_hScrArr [2].IsFullyRepaired)
                        {
                            break;
                        }
                    }
                    else
                    {
                        //Debug.Log ("break!");
                        break;
                    }
                }
            }



            yield return(new WaitForSeconds(0.2f));
        }

        isOccupied = false;
    }