Exemplo n.º 1
0
    private List <Zombie> FillZombieList(WaveType waveType, int mainZombieCount, int extraZombieCount, CustomWaveSettings customSettings)
    {
        List <Zombie> result = new List <Zombie>();

        if (waveType == WaveType.TestBoss)
        {
            Zombie zombie = _zombiePool.GetZombieModel(_testBossType, _hpPerZombie, true);
            result.Add(zombie);
            return(result);
        }

        if (waveType == WaveType.Test)
        {
            int typesCount         = (System.Enum.GetValues(typeof(ZombieType)).Length - 1);
            int zombiePerTypeCount = _currentZombieCount / typesCount;
            for (int i = 1; i <= typesCount; i++)
            {
                ZombieType zombieType = (ZombieType)(1 << i);

                for (int j = 0; j < zombiePerTypeCount; j++)
                {
                    Zombie zombie = _zombiePool.GetZombieModel(zombieType, _hpPerZombie, false);
                    result.Add(zombie);
                }
            }
            return(result);
        }

        ZombieType mainZombieType = _currentMainZombieType;

        int waveNumberWithOffset = WaveNumber + _gameConfig.waveSettings.extraWaveFirstOffset;

        if (waveNumberWithOffset % _gameConfig.waveSettings.extraWavePeriod == 0)
        {
            if (customSettings != null)
            {
                if (customSettings.waveEvent == ZombieWaveEvent.CustomWave)
                {
                    mainZombieType = customSettings.zombieType;
                }
            }
            else
            {
                int index = UnityEngine.Random.Range(0, _otherAddTypes.Count);
                mainZombieType = _otherAddTypes[index];
            }

            for (int i = 0; i < mainZombieCount; i++)
            {
                result.Add(_zombiePool.GetZombieModel(mainZombieType, _hpPerZombie, false));
            }
        }
        else
        {
            for (int i = 0; i < mainZombieCount; i++)
            {
                result.Add(_zombiePool.GetZombieModel(_currentMainZombieType, _hpPerZombie, waveType == WaveType.Boss));
            }

            for (int i = 0; i < extraZombieCount; i++)
            {
                int        index      = UnityEngine.Random.Range(0, _otherAddTypes.Count);
                ZombieType zombieType = _otherAddTypes[index];
                result.Add(_zombiePool.GetZombieModel(zombieType, _hpPerZombie, false));
            }
        }

        return(result);
    }
Exemplo n.º 2
0
    private void StartNewWave(WaveType testWaveType = WaveType.Default)
    {
        if (_timeTravelStartLock)
        {
            Debug.Log("START NEW WAVE LOCKED BY TIME TRAVEL");
            return;
        }

        _waveStarted = true;
        Debug.Log("==================== StartNewWave START ====================");
        if (_zombies.Count > 0 && !_autoStartNewWave)
        {
            _autoStartNewWave = true;
            _GOfactory.StartNewWave(_zombies);
            _onUpdateZombiesCountSignal.Fire(_zombies.Count);
            _onWaveStartedSignal.Fire(WaveNumber, _currentWaveHP, _zombies[0].Type);
            Debug.Log("decade hp start = " + _currentDecadeStartHP.ToString());
            Debug.Log("SAVED WAVE wave = " + WaveNumber.ToString() + "; wave HP = " + _currentWaveHP.ToFullString() + "; zombie count = " + _currentZombieCount.ToString());
            Debug.Log("HP Per Zombie = " + _hpPerZombie.ToFullString());
            Debug.Log("==================== StartNewWave END ====================");
            return;
        }

        if (!_autoStartNewWave)
        {
            _autoStartNewWave = true;
        }

        WaveType waveType            = WaveType.Default;
        int      firstBossWaveNumber = _gameConfig.waveSettings.firstBossWaveNumber;

        WaveNumber++;
        CustomWaveSettings customSettings = null;

        if (_zombieConfig.IsCustomWave(WaveNumber))
        {
            customSettings = _zombieConfig.GetCustomWaveSettings(WaveNumber);
        }

        int zombiesBeforeMax = _gameConfig.waveSettings.maxZombieCount - _currentZombieCount;

        if (_currentZombieCount < _gameConfig.waveSettings.maxZombieCount)
        {
            _currentZombieCount += zombiesBeforeMax > _gameConfig.waveSettings.zombieCountStep ? _gameConfig.waveSettings.zombieCountStep : zombiesBeforeMax;
        }

        int modulo = WaveNumber % _gameConfig.waveSettings.bossPeriod;

        switch (modulo)
        {
        case 0:
            // босс волна
            if (WaveNumber >= firstBossWaveNumber)
            {
                waveType       = WaveType.Boss;
                _lastBossAlive = true;
            }
            else
            {
                waveType = WaveType.Default;
            }
            break;

        case 1:
            if (WaveNumber > firstBossWaveNumber)
            {
                waveType = WaveType.AfterBoss;
            }
            else
            {
                waveType = WaveType.Default;
            }
            break;

        default:
            waveType = WaveType.Default;
            break;
        }

        if (testWaveType != WaveType.Default)
        {
            waveType = testWaveType;
        }

        CalculateWaveHP(waveType);

        Debug.Log("decade hp start = " + _currentDecadeStartHP.ToString());

        int mainZombieCount  = 0;
        int extraZombieCount = 0;

        if (waveType == WaveType.Boss)
        {
            mainZombieCount = _currentZombieCount;
        }
        else
        {
            if (customSettings != null)
            {
                if (customSettings.waveEvent == ZombieWaveEvent.UnlockAddZombieType)
                {
                    _otherAddTypes.Add(customSettings.zombieType);
                    SetDirty();
                }
            }

            if (_otherAddTypes.Count > 0)
            {
                extraZombieCount = Mathf.CeilToInt(_currentZombieCount * _gameConfig.waveSettings.extraZombiePercent);
                mainZombieCount  = _currentZombieCount - extraZombieCount;
            }
            else
            {
                mainZombieCount = _currentZombieCount;
            }
        }

        Debug.Log("Main Zombie Count = " + mainZombieCount.ToString());
        Debug.Log("Extra Zombie Count = " + extraZombieCount.ToString());

        _hpPerZombie.Set(_currentWaveHP);
        _tempBigNumber.Set(_currentZombieCount);
        _hpPerZombie.Divide(_tempBigNumber);

        _tempBigNumber.Set(_hpPerZombie);
        _tempBigNumber.Multiply(_currentZombieCount);
        Debug.Log("HP Per Zombie = " + _hpPerZombie.ToFullString());
        Debug.Log("HP of ALL Zombies = " + _tempBigNumber.ToFullString());

        List <Zombie> newZombies = FillZombieList(waveType, mainZombieCount, extraZombieCount, customSettings);

        _zombies.AddRange(newZombies);
        _GOfactory.StartNewWave(newZombies);
        _onUpdateZombiesCountSignal.Fire(_zombies.Count);
        _onWaveStartedSignal.Fire(WaveNumber, _currentWaveHP, newZombies[0].Type);
        _analyticsManager.SendWaveStarted(WaveNumber);
        Debug.Log("==================== StartNewWave END ====================");
        SetDirty();
    }