private void SetStats() { health = baseHealth * diffMng.GetDifficultyMultiplier(); moveSpeed = baseMoveSpeed * diffMng.GetDifficultyMultiplier(); rotationSpeed = baseRotationSpeed * diffMng.GetDifficultyMultiplier(); expCount = baseExpCount * diffMng.GetDifficultyMultiplier(); scoreValue = baseScoreValue * diffMng.GetDifficultyMultiplier(); healthDropValue = Random.Range(0, (baseHealthDropValue * 2) / diffMng.GetDifficultyMultiplier()); }
private void SetNextFiringInterval() { float randomIntervalCoef = Random.Range(MinFiringInterval, MaxFiringInterval); _nextFiringInterval = randomIntervalCoef / _difficultyManagerScript.GetDifficultyMultiplier(DifficultyParameter.DpShipFireRateIncrease); }
//Generate new waves and spawn them on scene private void SpawnNewWave() { EventLogger.PrintToLog("New Wave Spawn"); //determine if current wave formation has an empty space bigger than the size of the player ship const int randRange = 100; const float stepSize = (float)randRange / GameConstants.DifficultyStepCount; //step size is currently 20 // 10 30 50 70 90 no exit probability for difficulties 1 2 3 4 5 float noExitProbability = (_difficultyManagerScript.DifficultyCoefs[DifficultyParameter.DpWaveHasNoExitCoef] - 0.5f) * stepSize; bool hasNoExit = Random.Range(0, randRange) < noExitProbability; //I. Pick a random formation type int selectedFormationIndex = Random.Range(0, _formations.Count); Formation selectedFormation = _formations[selectedFormationIndex]; //determine next wave spawn interval float randomIntervalCoef = Random.Range(MinWaveSpawnIntervalCoef, MaxWaveSpawnIntervalCoef); _waveSpawnInterval = randomIntervalCoef / _difficultyManagerScript.GetDifficultyMultiplier(DifficultyParameter.DpWaveSpawnRateIncrease); //II. Determine Horizontal Distance Between Enemies float nextWaveHorizontalDistance = _waveSpawnInterval * BasicEnemy.MoveSpeed; float maxEnemyHorizontalDist = nextWaveHorizontalDistance - EnemySpawnMaxHorzDist; if (selectedFormation.HorizontalShipSpan > 1) { maxEnemyHorizontalDist /= selectedFormation.HorizontalShipSpan; } float enemyHorizontalDist; if (maxEnemyHorizontalDist < _enemySpawnMinHorzDist) { enemyHorizontalDist = maxEnemyHorizontalDist; } else { maxEnemyHorizontalDist = Mathf.Clamp(maxEnemyHorizontalDist, _enemySpawnMinHorzDist, EnemySpawnMaxHorzDist); enemyHorizontalDist = Random.Range(_enemySpawnMinHorzDist, maxEnemyHorizontalDist); } //III. Determine Vertical Distance Between Enemies float verticalMovementLength = _vertMaxShipSpawnCoord - _vertMinShipSpawnCoord; float minEnemyVerticalDist = _enemySpawnMinVertDist; if (hasNoExit) { int maxIntervalCount = selectedFormation.WaveEntities.Count - 1; float minVerticalDistance = (verticalMovementLength - ShipColliderVertSize) / maxIntervalCount; if (minVerticalDistance > minEnemyVerticalDist) { minEnemyVerticalDist = minVerticalDistance; } } float enemyVerticalDist = Random.Range(minEnemyVerticalDist, EnemySpawnMaxVertDist); //IV. Determine Number of Enemies int lowerIntervalCount = Mathf.FloorToInt((verticalMovementLength - ShipColliderVertSize) / enemyVerticalDist); int higherIntervalCount = Mathf.FloorToInt(verticalMovementLength / enemyVerticalDist); int maxPossibleVerticalIntervalCount = (lowerIntervalCount == higherIntervalCount) && !hasNoExit ? lowerIntervalCount : lowerIntervalCount + 1; float distBetweenFirstAndLastShip = enemyVerticalDist * maxPossibleVerticalIntervalCount; Assert.IsTrue(!hasNoExit || (distBetweenFirstAndLastShip >= verticalMovementLength - ShipColliderVertSize)); int maxPossibleShipCount = maxPossibleVerticalIntervalCount + 1; int enemyCount; if (hasNoExit) { enemyCount = maxPossibleShipCount; } else { //no possible no-exits here, this is why we subtract 1 from max possible ship count, we want at least a sufficient opening int enemyMaxCount = Mathf.Min(maxPossibleShipCount - 1, selectedFormation.WaveEntities.Count); int minimumEnemyCountCoef = _difficultyManagerScript.DifficultyCoefs[DifficultyParameter.DpMinimumEnemyCountCoef]; //diff param (1 2 3 4 5) : min count = max count - (4 3 2 1 0) //TODO LATER if 5 level difficulty is changed, enemy counts will break as we don't take min max difficulty difference into account int enemyMinCount = Mathf.Max(1, enemyMaxCount - (GameConstants.MaxDifficulty - minimumEnemyCountCoef)); enemyCount = Random.Range(enemyMinCount, enemyMaxCount); } int actualVerticalIntervalCount = enemyCount - 1; float minVerticalStartCoord = _vertMinShipSpawnCoord; float maxVerticalStartCoord = _vertMaxShipSpawnCoord - actualVerticalIntervalCount * enemyVerticalDist; if (maxVerticalStartCoord < minVerticalStartCoord) { //we just went off the line, this is only possible for no exit formations! Assert.IsTrue(hasNoExit); //swap these two maxVerticalStartCoord += minVerticalStartCoord; minVerticalStartCoord = maxVerticalStartCoord - minVerticalStartCoord; maxVerticalStartCoord -= minVerticalStartCoord; if (_hugeEnemyExists) { if (!Mathf.Approximately(_vertMinShipSpawnCoord, Player.MinVerticalMovementLimit)) { minVerticalStartCoord = maxVerticalStartCoord; } else if (!Mathf.Approximately(_vertMaxShipSpawnCoord, Player.MaxVerticalMovementLimit)) { maxVerticalStartCoord = minVerticalStartCoord; } else { Assert.IsTrue(false); //something is fishy, spawning a huge enemy didn't change vertical spawn coords } } } else { Assert.IsTrue(distBetweenFirstAndLastShip <= verticalMovementLength); } //V. Select Enemies From Formation List List <WaveEntity> selectedFormationEntities = SelectEnemiesFromFormation(selectedFormationIndex, enemyCount); //VI. Determine Advanced Enemy Count int enemyTypeCount = EnemyPrefabArray.Length; int[] enemyTypeSteps = new int[enemyTypeCount]; for (int i = 0; i < enemyTypeSteps.Length; ++i) { enemyTypeSteps[i] = Mathf.RoundToInt(i * 100.0f / (enemyTypeSteps.Length - 1)); //enemyTypeSteps = {0, 100} for 2 enemies, {0, 50, 100} for 3 enemies, {0, 33, 67, 100} for 4 enemies, and so on } float advancedEnemyPercentage = _difficultyManagerScript.DifficultyCoefs[DifficultyParameter.DpEnemyShipStrength] * stepSize - stepSize * 0.5f; int advEnemyTypeIndex = 1; float percentageOfStrongerEnemy = 0.0f; if (enemyTypeSteps.Length > 1) { int currentEnemyTypeStep = enemyTypeSteps[advEnemyTypeIndex]; while (advancedEnemyPercentage > currentEnemyTypeStep) { ++advEnemyTypeIndex; Assert.IsTrue(advEnemyTypeIndex < enemyTypeSteps.Length); currentEnemyTypeStep = enemyTypeSteps[advEnemyTypeIndex]; } // if we're here, we know which two enemies we're gonna use int previousEnemyTypeStep = enemyTypeSteps[advEnemyTypeIndex - 1]; percentageOfStrongerEnemy = (advancedEnemyPercentage - previousEnemyTypeStep) / (currentEnemyTypeStep - previousEnemyTypeStep); } int minAdvancedEnemyCount = Mathf.FloorToInt(percentageOfStrongerEnemy * selectedFormationEntities.Count); int maxAdvancedEnemyCount = Mathf.CeilToInt(percentageOfStrongerEnemy * selectedFormationEntities.Count); int advancedEnemyCount = Random.Range(minAdvancedEnemyCount, maxAdvancedEnemyCount + 1); //create ship types list int[] shipTypes = new int[selectedFormationEntities.Count]; for (int i = 0; i < shipTypes.Length; ++i) { if (i < advancedEnemyCount) { shipTypes[i] = advEnemyTypeIndex; } else { shipTypes[i] = advEnemyTypeIndex - 1; } } //shuffle the list for (int i = 0; i < shipTypes.Length; ++i) { int temp = shipTypes[i]; int randomIndex = Random.Range(i, shipTypes.Length); shipTypes[i] = shipTypes[randomIndex]; shipTypes[randomIndex] = temp; } //VII. Spawn Enemies SpawnEnemies(selectedFormationEntities, shipTypes, minVerticalStartCoord, maxVerticalStartCoord, enemyHorizontalDist, enemyVerticalDist, maxEnemyHorizontalDist); }