Пример #1
0
        /// <inheritdoc />
        public void Process(ISegmentImporter importer, IImportedRegion convertibleRegion, SegmentRegion convertedRegion)
        {
            var matches = convertedRegion.GetTiles(tile => true);

            foreach (var tile in matches)
            {
                foreach (var direction in Direction.Cardinal)
                {
                    var neighbor = convertedRegion.GetTile(tile, direction);

                    if (neighbor != null)
                    {
                        var staticComponents = neighbor.GetComponents <StaticComponent>(component => _targets.Contains(component.Static));

                        if (staticComponents.Count() > 1)
                        {
                            throw new Exception("Encountered multiple counter candidates.");
                        }

                        foreach (var component in staticComponents)
                        {
                            neighbor.ReplaceComponent(component, new CounterComponent(component.Static, direction.Opposite));
                        }
                    }
                }
            }
        }
Пример #2
0
        /// <inheritdoc />
        public void Process(ISegmentImporter importer, IImportedRegion convertibleRegion, SegmentRegion convertedRegion)
        {
            var matches = convertedRegion.GetTiles(tile => true);

            /* First Pass */
            foreach (var tile in matches)
            {
                var staticComponents = tile.GetComponents <StaticComponent>(
                    component => _targets.Contains(component.Static)).ToList();

                if (staticComponents.Count() > 2)
                {
                    throw new Exception("Encountered multiple wall candidates.");
                }

                foreach (var component in staticComponents)
                {
                    tile.ReplaceComponent(component, new WallComponent(component.Static, GetDestroyedId(component.Static), GetRuinsId(component.Static)));
                }
            }

            /* Second Pass to catch corner walls as indestructible */
            foreach (var tile in matches)
            {
                if (tile.OfType <WallComponent>().Count() > 1)
                {
                    var north = convertedRegion.GetTile(tile, Direction.North);
                    var west  = convertedRegion.GetTile(tile, Direction.West);

                    var northIndestructible = north != null && north.OfType <WallComponent>().Any(wall => wall.IsIndestructible);
                    var westIndestructible  = west != null && west.OfType <WallComponent>().Any(wall => wall.IsIndestructible);

                    if (northIndestructible || westIndestructible)
                    {
                        foreach (var wall in tile.OfType <WallComponent>())
                        {
                            wall.IsIndestructible = true;
                        }

                        tile.UpdateTerrain();
                    }
                }
            }

            var pillars = new List <int>()
            {
                32, 33, 34, 143, 155, 159, 262, 355, 357, 359, 366, 407, 409, 417, 443, 463, 480
            };

            bool isPillar(WallComponent wall)
            {
                return(pillars.Contains(wall.Wall));
            }

            /* Third Pass to catch pillars */
            foreach (var tile in matches)
            {
                if (tile.OfType <WallComponent>().All(isPillar))
                {
                    var south = convertedRegion.GetTile(tile, Direction.South);
                    var east  = convertedRegion.GetTile(tile, Direction.East);

                    var southIndestructible = south != null && south.OfType <WallComponent>().Any(wall => wall.IsIndestructible);
                    var eastIndestructible  = east != null && east.OfType <WallComponent>().Any(wall => wall.IsIndestructible);

                    if (southIndestructible && eastIndestructible)
                    {
                        foreach (var wall in tile.OfType <WallComponent>())
                        {
                            wall.IsIndestructible = true;
                        }

                        tile.UpdateTerrain();
                    }
                }
            }
        }