Esempio n. 1
0
    public void DestroyOre(bool minedByPlayer)
    {
        _gridBehavior.InstantiateNewGridPrefab(transform.position);

        if (minedByPlayer)
        {
            extractedOresCounter.GetOre(index,
                                        BoostersController.boosters[2].activeSelf ? 2 : 1);
            animatorController.InvertIsMiningVar();
            progressBar.IncreaseValue(transform.position);
            ChestSpawnController.Try2SpawnChest(transform.position);

            if (Statistics.minedOres[index] == false)
            {
                Statistics.GetNewMinedOre(index);
            }

            foreach (var type in boosterTypes)
            {
                ChanceToGetBooster(type);
            }

            _oreGenerator.GenerateNewOres(this.transform.position);
        }

        Mining.isMining = false;
        SelectionController.RemoveSelection();
        Destroy(gameObject);
    }
Esempio n. 2
0
    public void GenerateOres(bool newOres)
    {
        DevController.MeasureElapsedTimeStart();

        _emptyPoints      = GenerateLevel.GetEmptyPoints();
        _emptyPointsIndex = 0;
        values            = chancesGenerator.GetChance();

        if (values.Sum() != 100)
        {
            Debug.LogError("ERROR");
        }

        if (newOres) // generate new ores
        {
            randNumbers = new float[GridBehavior.WIDTH, GridBehavior.HEIGHT];

            var spawnPointIndex = _gridBehaviour.GetArrayIndex(player.transform.position);

            for (int x = 0; x < GridBehavior.WIDTH; x++)
            {
                for (int y = 0; y < GridBehavior.HEIGHT; y++)
                {
                    if (Math.Abs(spawnPointIndex.x - x) > 9 || Math.Abs(spawnPointIndex.y - y) > 6)
                    {
                        randNumbers[x, y] = -1;
                        continue;
                    }

                    if (new Vector3Int(x, y, 0) == _gridBehaviour.GetArrayIndex(_emptyPoints[_emptyPointsIndex]))
                    {
                        _gridBehaviour.InstantiateNewGridPrefab(_emptyPoints[_emptyPointsIndex]);
                        randNumbers[x, y] = -1;
                        if (_emptyPointsIndex < _emptyPoints.Length - 1)
                        {
                            _emptyPointsIndex++;
                        }
                    }
                    else
                    {
                        GenerateOre(x, y);
                    }
                }
            }
        }
        else // load old ores
        {
            Debug.Log("load ores");

            for (int x = 0; x < GridBehavior.WIDTH; x++)
            {
                for (int y = 0; y < GridBehavior.HEIGHT; y++)
                {
                    if (_gridBehaviour.gridArray[x, y] == null &&
                        _gridBehaviour.descentPos != new Vector2(x, y) && randNumbers[x, y] != -1)
                    {
                        GenerateOre(x, y, randNumbers[x, y]);
                    }
                }
            }

            NextLevelLoadController.needsToLoadNextLevel = false;
        }

        DevController.MeasureElapsedTimeEnd("Ore generation");
    }