public void RemoveBridgePiece(BridgePiece bridgePieceAttribute = null)
    {
        if (bridgePieceAttribute == null)
        {
            bridgePieceAttribute = (BridgePiece)_tile.GetAttributes().FirstOrDefault(attribute => attribute is BridgePiece);
        }

        if (bridgePieceAttribute == null)
        {
            return;
        }

        bridgePieceAttribute.RemoveObsoleteBridgeEdges();

        _tile.RemoveAttribute(bridgePieceAttribute);
        bridgePieceAttribute.Remove();

        //Update path connections of neighbours
        foreach (KeyValuePair <ObjectDirection, Tile> neighbour in _tile.Neighbours)
        {
            if (!neighbour.Value)
            {
                continue;
            }

            TilePath mazeTilePathOnNeighbour = neighbour.Value.TryGetTilePath();

            if (mazeTilePathOnNeighbour == null)
            {
                continue;
            }

            int oldConnectionScoreOnNeighbour = mazeTilePathOnNeighbour.ConnectionScore;
            TileConnectionScoreInfo mazeTilePathConnectionScoreOnNeighbourInfo = NeighbourTileCalculator.MapNeighbourPathsOfTile(neighbour.Value, mazeTilePathOnNeighbour.TilePathType);

            //update connection score on neighbour
            mazeTilePathOnNeighbour.WithConnectionScoreInfo(mazeTilePathConnectionScoreOnNeighbourInfo);
        }
    }
Ejemplo n.º 2
0
    public override void RemovePath()
    {
        MazeTilePath mazeTilePath = (MazeTilePath)_tile.GetBackgrounds().FirstOrDefault(background => background is MazeTilePath);

        if (mazeTilePath == null)
        {
            return;
        }

        Logger.Log(mazeTilePath.TilePathType);
        IPathType mazeTilePathType   = mazeTilePath.TilePathType;
        int       oldConnectionScore = mazeTilePath.ConnectionScore;

        Logger.Log($"Old path score: {oldConnectionScore}");

        // If needed, place a background in the gap that the removed path left
        if (oldConnectionScore == NeighbourTileCalculator.ConnectionOnAllSidesScore)
        {
            Logger.Log($"Place background in gap at {_tile.GridLocation.X},{_tile.GridLocation.Y}.");
            EditorMazeTileBackgroundPlacer tileBackgroundPlacer = new EditorMazeTileBackgroundPlacer(_tile);
            tileBackgroundPlacer.PlaceCoveringBaseGround(); // place background with connections on all sides
        }

        _tile.RemoveBackground(mazeTilePath);
        mazeTilePath.Remove();

        TrySetTileNotMarkable();


        //After removing tile, check with neighbour tiles if wall connections should be updated
        foreach (KeyValuePair <ObjectDirection, Tile> neighbour in _tile.Neighbours)
        {
            if (!neighbour.Value)
            {
                continue;
            }

            TilePath mazeTilePathOnNeighbour = neighbour.Value.TryGetTilePath();

            if (mazeTilePathOnNeighbour == null)
            {
                continue;
            }

            int oldConnectionScoreOnNeighbour = mazeTilePathOnNeighbour.ConnectionScore;

            Logger.Warning($"We will now look for connections for neighbour {neighbour.Value.GridLocation.X},{neighbour.Value.GridLocation.Y}, which is {neighbour.Key} of {_tile.GridLocation.X},{_tile.GridLocation.Y}");
            TileConnectionScoreInfo mazeTilePathConnectionScoreOnNeighbourInfo = NeighbourTileCalculator.MapNeighbourPathsOfTile(neighbour.Value, mazeTilePathType);
            Logger.Log($"We calculated an path connection type score of {mazeTilePathConnectionScoreOnNeighbourInfo.RawConnectionScore} for location {neighbour.Value.GridLocation.X}, {neighbour.Value.GridLocation.Y}");

            //update connection score on neighbour
            mazeTilePathOnNeighbour.WithConnectionScoreInfo(mazeTilePathConnectionScoreOnNeighbourInfo);

            //Add background where needed
            if (oldConnectionScoreOnNeighbour == NeighbourTileCalculator.ConnectionOnAllSidesScore &&
                mazeTilePathConnectionScoreOnNeighbourInfo.RawConnectionScore != NeighbourTileCalculator.ConnectionOnAllSidesScore)
            {
                EditorMazeTileBackgroundPlacer tileBackgroundPlacer = new EditorMazeTileBackgroundPlacer(neighbour.Value as EditorMazeTile);
                tileBackgroundPlacer.PlaceCoveringBaseGround();
            }
        }

        _tile.RemoveTileAsBeautificationTrigger();
    }
    public override void RemovePath()
    {
        OverworldTilePath overworldTilePath = (OverworldTilePath)_tile.GetBackgrounds().FirstOrDefault(background => background is OverworldTilePath);

        if (overworldTilePath == null)
        {
            return;
        }

        Logger.Log(overworldTilePath.TilePathType);
        IPathType overworldTilePathType = overworldTilePath.TilePathType;
        int       oldConnectionScore    = overworldTilePath.ConnectionScore;

        // If needed, place a background in the gap that the removed path left
        if (oldConnectionScore == NeighbourTileCalculator.ConnectionOnAllSidesScore)
        {
            EditorOverworldTileBackgroundPlacer tileBackgroundPlacer = new EditorOverworldTileBackgroundPlacer(_tile);
            tileBackgroundPlacer.PlaceBackground <OverworldTileBaseGround>();
        }

        _tile.RemoveBackground(overworldTilePath);
        overworldTilePath.Remove();

        //After removing tile, check with neighbour tiles if wall connections should be updated
        foreach (KeyValuePair <ObjectDirection, Tile> neighbour in _tile.Neighbours)
        {
            if (!neighbour.Value)
            {
                continue;
            }

            TilePath overworldTilePathOnNeighbour = neighbour.Value.TryGetTilePath();

            if (overworldTilePathOnNeighbour == null)
            {
                continue;
            }

            int oldConnectionScoreOnNeighbour = overworldTilePathOnNeighbour.ConnectionScore;

            Logger.Warning($"We will now look for connections for neighbour {neighbour.Value.GridLocation.X},{neighbour.Value.GridLocation.Y}, which is {neighbour.Key} of {_tile.GridLocation.X},{_tile.GridLocation.Y}");
            TileConnectionScoreInfo overworldTilePathConnectionScoreOnNeighbourInfo = NeighbourTileCalculator.MapNeighbourPathsOfTile(neighbour.Value, overworldTilePathType);
            Logger.Log($"We calculated an path connection type score of {overworldTilePathConnectionScoreOnNeighbourInfo.RawConnectionScore} for location {neighbour.Value.GridLocation.X}, {neighbour.Value.GridLocation.Y}");

            //update connection score on neighbour
            overworldTilePathOnNeighbour.WithConnectionScoreInfo(overworldTilePathConnectionScoreOnNeighbourInfo);

            //Add background where needed
            if (oldConnectionScoreOnNeighbour == NeighbourTileCalculator.ConnectionOnAllSidesScore && overworldTilePathConnectionScoreOnNeighbourInfo.RawConnectionScore != NeighbourTileCalculator.ConnectionOnAllSidesScore)
            {
                EditorOverworldTileBackgroundPlacer tileBackgroundPlacer = new EditorOverworldTileBackgroundPlacer(neighbour.Value as EditorOverworldTile);
                tileBackgroundPlacer.PlaceBackground <OverworldTileBaseGround>();
            }
        }
    }