Ejemplo n.º 1
0
    private void Update()
    {
        if (_featureToggles.desertsAreBeaches)
        {
            return;
        }

        var sandSpreadController = _sandSpreadController;

        if (Random.value < sandSpreadController.chance)
        {
            var block = _worldPlane.GetNearbyBlocks(_block.GetGridPosition())
                        .Where(b => _worldPlane.BlockCanBeReplacedBySandBlock(b))
                        .ToList()
                        .OrderBy(_ => Random.value)
                        .First();

            var score = _worldPlane.NatureScore(block.GetGridPosition(), sandSpreadController.natureScoreRadius);
            if (score < _sandSpreadController.spreadResistanceThreshold)
            {
                var sandBlockRoot = Instantiate(sandBlockTemplate);
                var sandBlock     = sandBlockRoot.GetComponentInChildren <Block>();
                _worldPlane.ReplaceBlock(block, sandBlock);
            }
            else if (score > _sandSpreadController.spreadCombatThreshold)
            {
                var grassBlockRoot = Instantiate(grassBlockTemplate);
                var grassBlock     = grassBlockRoot.GetComponentInChildren <Block>();
                _worldPlane.ReplaceBlock(_block, grassBlock);
            }
        }
    }
Ejemplo n.º 2
0
    private void SpawnSandBlock()
    {
        var sandBlockRoot = Instantiate(sandBlockTemplate);
        var block         = _worldPlane
                            .GetVacantBlocksStream()
                            .Where(vacantBlock => _worldPlane.BlockCanBeReplacedBySandBlock(vacantBlock))
                            .OrderBy(_ => Random.value)
                            .First();

        var sandBlock = sandBlockRoot.GetComponentInChildren <Block>();

        _worldPlane.ReplaceBlock(block, sandBlock);
    }