Пример #1
0
    public void SetupSegment(int expectedDiff)
    {
        int diffTotal = segmentDifficulty;
        int cosmeticPos, obstaclePos;
        int cosmeticsQuantity = Random.Range(minCosmetics, maxCosmetics);

        expectedDiff -= segmentDifficulty;

        int check = 0;

        for (int i = 0; i < cosmeticsQuantity; i++)
        {
            do
            {
                cosmeticPos = Random.Range(0, cosmeticPositions.Count);
                check++;
                if (check > 100)
                {
                    Debug.LogError("Error in SetupSegment(first do-while) in " + transform.name);
                    return;
                }
            } while (usedCosmeticPositions.Contains(cosmeticPos));

            usedCosmeticPositions.Add(cosmeticPos);
            usedCosmetic.Add(cosmeticsManager.UseRandomElement());
            usedCosmetic[i].transform.position = cosmeticPositions[cosmeticPos].position;

            if (DeveloperOptions.Instance.segmentLog.environmentGeneration)
            {
                Debug.Log(usedCosmetic[i].name + " on pos " + cosmeticPositions[cosmeticPos].name + "(" + cosmeticPositions[cosmeticPos].parent.name + ")");
            }
        }

        //int obstaclesQuantity = Random.Range(obstaclePositions.Count / 4, obstaclePositions.Count);
        while (expectedDiff > 0)
        {
            do
            {
                obstaclePos = Random.Range(0, obstaclePositions.Count);
                check++;
                if (check > 100)
                {
                    Debug.LogError("Error in SetupSegment(second do-while) in " + transform.name);
                    return;
                }
            } while (usedObstaclesPositions.Contains(obstaclePos));

            //TODO: temp
            int diff = RoundToFive(Random.Range(minDifficultyLevel, expectedDiff));
            if (diff == 0)
            {
                Debug.LogError("Can't find obstacle here: (" + transform.name + ')');
                break;
            }
            expectedDiff -= diff;
            diffTotal    += diff;
            usedObstaclesPositions.Add(obstaclePos);
            usedObstacles.Add(obstaclesManager.UseRandomElement(diff));
            usedObstacles[usedObstacles.Count - 1].transform.position = obstaclePositions[obstaclePos].position;

            if (DeveloperOptions.Instance.segmentLog.obstaclesGeneration)
            {
                Debug.Log(usedObstacles[usedObstacles.Count - 1].name + " on pos " + obstaclePositions[obstaclePos].name + "(" + obstaclePositions[obstaclePos].parent.name + ")");
            }
        }
        if (DeveloperOptions.Instance.segmentCanvas.segmentDifficulty)
        {
            DeveloperOptions.Instance.segmentDifficulty.text = diffTotal.ToString();
        }

        List <IntTransformPair> temp;

        if (segmentDifficulty == 0)
        {
            if (usedObstaclesPositions.Contains(0))
            {
                MoveCoinsObstacle(0);
            }
            else
            {
                MoveCoins(0);
            }
            if (usedObstaclesPositions.Contains(1))
            {
                MoveCoinsObstacle(1);
            }
            else
            {
                MoveCoins(1);
            }
            if (usedObstaclesPositions.Contains(2))
            {
                MoveCoinsObstacle(2);
            }
            else
            {
                MoveCoins(2);
            }
        }
        else if (waterSegment)
        {
            if (usedObstaclesPositions.Contains(0))
            {
                if (ProcentChancesRandom(coinObstacleChance))
                {
                    temp = coinPositions.FindAll(item => item.number == 0);
                    usedCoins.Add(coinsManager.UseRandomCoin());
                    usedCoins[usedCoins.Count - 1].transform.position = temp[1].transform.gameObject.transform.position;
                }
            }
            if (usedObstaclesPositions.Contains(1))
            {
                if (ProcentChancesRandom(coinObstacleChance))
                {
                    temp = coinPositions.FindAll(item => item.number == 4);
                    usedCoins.Add(coinsManager.UseRandomCoin());
                    usedCoins[usedCoins.Count - 1].transform.position = temp[1].transform.gameObject.transform.position;
                }
            }
            if (ProcentChancesRandom(coinNearObstacleChance))
            {
                temp = coinPositions.FindAll(item => item.number == 1);
                usedCoins.Add(coinsManager.UseRandomCoin());
                usedCoins[usedCoins.Count - 1].transform.position = temp[0].transform.gameObject.transform.position;
            }
            if (ProcentChancesRandom(coinNearObstacleChance))
            {
                temp = coinPositions.FindAll(item => item.number == 2);
                usedCoins.Add(coinsManager.UseRandomCoin());
                usedCoins[usedCoins.Count - 1].transform.position = temp[0].transform.gameObject.transform.position;
            }
            if (ProcentChancesRandom(coinNearObstacleChance))
            {
                temp = coinPositions.FindAll(item => item.number == 3);
                usedCoins.Add(coinsManager.UseRandomCoin());
                usedCoins[usedCoins.Count - 1].transform.position = temp[0].transform.gameObject.transform.position;
            }
        }
        else if (doubleWaterSegment)
        {
            for (int i = 0; i < 5; i++)
            {
                if (ProcentChancesRandom(coinNearObstacleChance))
                {
                    temp = coinPositions.FindAll(item => item.number == i);
                    usedCoins.Add(coinsManager.UseRandomCoin());
                    usedCoins[usedCoins.Count - 1].transform.position = temp[0].transform.gameObject.transform.position;
                }
            }
        }
        if (DeveloperOptions.Instance.segmentLog.coinGeneration)
        {
            int value = 0;
            foreach (GameObject item in usedCoins)
            {
                value += item.GetComponent <Coin>().value;
            }
            Debug.Log("Coins in segment " + transform.name + ": " + value);
        }
    }