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 FloodAll()
    {
        _flood = false;
        var blockHeight  = _block.GetGridPosition().y;
        var nearbyBlocks = _worldPlane
                           .GetNearbyLand(_block.GetGridPosition())
                           .Where(otherBlock => otherBlock.GetGridPosition().y < blockHeight);
        var nearbyEmptyBlocks = CreateWaterForNearbyEmptyPositions();
        var allNearbyBlocks   = nearbyBlocks.Concat(nearbyEmptyBlocks);

        foreach (var nearbyBlock in allNearbyBlocks)
        {
            if (nearbyBlock.HasOccupant() && !nearbyBlock.OccupiedByBlock())
            {
                nearbyBlock.DestroyOccupant();
            }

            if (nearbyBlock.IsVacant())
            {
                Block lowestBlock = nearbyBlock;

                if (!nearbyBlock.IsWater())
                {
                    var waterBlockBelow = NewFullHeightWaterBlock().GetComponentInChildren <Block>();
                    _worldPlane.ReplaceBlock(nearbyBlock, waterBlockBelow);

                    lowestBlock = waterBlockBelow;
                }

                for (var y = lowestBlock.GetGridPosition().y + 1; y <= blockHeight; y++)
                {
                    var useFullHeightWater = Math.Abs(y - blockHeight) > .5f;
                    var water      = useFullHeightWater ? NewFullHeightWaterBlock() : NewShallowWater();
                    var waterBlock = water.GetComponentInChildren <Block>();
                    _worldPlane.AddBlockOnTopOf(waterBlock, water, lowestBlock);

                    lowestBlock = waterBlock;
                }
            }
        }
    }
Ejemplo n.º 3
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);
    }
Ejemplo n.º 4
0
    public Block MakeToSoilWith(Block block, GameObject blockToBeOccupant)
    {
        var soilRoot  = Instantiate(soilTemplate);
        var soilBlock = soilRoot.GetComponentInChildren <Block>();

        soilBlock.GetComponent <SoilNode>().farmController = this;

        _worldPlane.ReplaceBlock(block, soilBlock);

        soilBlock.Occupy(blockToBeOccupant);

        soilBlock.BeforeDestroy += () =>
        {
            _soils.Remove(soilBlock);
            if (!_soils.Any())
            {
                Destroy(gameObject);
            }
        };
        _soils.Add(soilBlock);

        return(soilBlock);
    }