示例#1
0
    private void FloodAllAsOcean()
    {
        _flood = false;
        var blockHeight  = _block.GetGridPosition().y;
        var nearbyBlocks = _worldPlane
                           .GetNearbyLandOrLake(_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())
            {
                var waterBlockBelow = NewOceanFullHeightWaterBlock().GetComponentInChildren <Block>();
                _worldPlane.ReplaceBlock(nearbyBlock, waterBlockBelow);

                var lowestBlock = waterBlockBelow;

                for (var y = lowestBlock.GetGridPosition().y + 1; y <= Block.GroundLevel - 1; y++)
                {
                    var water      = NewOceanFullHeightWaterBlock();
                    var waterBlock = water.GetComponentInChildren <Block>();
                    _worldPlane.AddBlockOnTopOf(waterBlock, water, lowestBlock);

                    lowestBlock = waterBlock;
                }

                var ocean      = NewOceanShallowWaterBlock();
                var oceanBlock = ocean.GetComponentInChildren <Block>();
                _worldPlane.AddBlockOnTopOf(oceanBlock, ocean, lowestBlock);
            }
        }
    }