private void HandlePlayerTileMarkerEnds(MazeTile tile) { foreach (KeyValuePair <ObjectDirection, Tile> item in tile.Neighbours) { MazeTile neighbour = item.Value as MazeTile; if (!neighbour) { continue; } MazeTilePath mazeTilePath = (MazeTilePath)neighbour.GetBackgrounds().FirstOrDefault(background => background is MazeTilePath); if (mazeTilePath == null) { continue; } if (neighbour.PlayerMark != null && neighbour.PlayerMark.Owner != PlayerMarkOwner.None) { continue; } TileConnectionScoreInfo neighbourConnectionScoreInfo = NeighbourTileCalculator.MapNeighbourPlayerMarkEndsOfTile(neighbour); neighbour.PlayerMarkEndsRenderer.sprite = MazeSpriteManager.Instance.PlayerTileMarkerEdge[neighbourConnectionScoreInfo.SpriteNumber - 1]; } }
private void UpdateNeighboursForRemovedObstacle(ObstacleType obstacleType) { foreach (KeyValuePair <ObjectDirection, Tile> neighbour in _tile.Neighbours) { if (!neighbour.Value) { continue; } TileObstacle tileObstacleOnNeighbour = neighbour.Value.TryGetTileObstacle(); if (tileObstacleOnNeighbour == null) { continue; } Logger.Log($"We will 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 obstacleConnectionScoreOnNeighbour = NeighbourTileCalculator.MapNeighbourObstaclesOfTile(neighbour.Value, obstacleType); Logger.Log($"We calculated an obstacle connection type score of {obstacleConnectionScoreOnNeighbour} for location {neighbour.Value.GridLocation.X}, {neighbour.Value.GridLocation.Y}"); //update connection score on neighbour tileObstacleOnNeighbour.WithConnectionScoreInfo(obstacleConnectionScoreOnNeighbour); // If needed, place a background if (obstacleConnectionScoreOnNeighbour.RawConnectionScore != NeighbourTileCalculator.ConnectionOnAllSidesScore) { EditorOverworldTileBackgroundPlacer tileBackgroundPlacer = new EditorOverworldTileBackgroundPlacer(neighbour.Value as EditorOverworldTile); tileBackgroundPlacer.PlaceBackground <OverworldTileBaseGround>(); } } }
public override void WithConnectionScoreInfo(TileConnectionScoreInfo connectionScoreInfo) { ConnectionScore = connectionScoreInfo.RawConnectionScore; SpriteNumber = connectionScoreInfo.SpriteNumber; _sprite = OverworldSpriteManager.Instance.DefaultOverworldTileBackground[SpriteNumber - 1]; _tileSpriteContainer.SetSprite(_sprite); }
public override void WithConnectionScoreInfo(TileConnectionScoreInfo connectionScoreInfo) { ConnectionScore = connectionScoreInfo.RawConnectionScore; SpriteNumber = connectionScoreInfo.SpriteNumber; _sprite = MazeSpriteManager.Instance.DefaultPath[SpriteNumber - 1]; _spriteRenderer.sprite = _sprite; }
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>(); } } }
public override void PlaceGround(IBaseBackgroundType groundType, TileConnectionScoreInfo connectionScoreInfo) { GameObject groundGO = GameObject.Instantiate(OverworldGameplayManager.Instance.GetTileBackgroundPrefab <OverworldTileBaseGround>(), Tile.BackgroundsContainer); OverworldTileBaseGround mazeTileBaseGround = groundGO.GetComponent <OverworldTileBaseGround>(); mazeTileBaseGround.WithType(groundType); mazeTileBaseGround.WithConnectionScoreInfo(connectionScoreInfo); mazeTileBaseGround.SetTile(Tile); Tile.AddBackground(mazeTileBaseGround); }
// Called in game when we already have the connection score public override void PlacePath(IPathType tilePathType, TileConnectionScoreInfo pathConnectionScoreInfo) { GameObject overworldTilePathGO = GameObject.Instantiate(OverworldGameplayManager.Instance.GetTileBackgroundPrefab <OverworldTilePath>(), Tile.BackgroundsContainer); OverworldTilePath overworldTilePath = overworldTilePathGO.GetComponent <OverworldTilePath>(); overworldTilePath.WithType(tilePathType as IBackgroundType); overworldTilePath.WithConnectionScoreInfo(pathConnectionScoreInfo); overworldTilePath.SetTile(Tile); Tile.AddBackground(overworldTilePath); }
// Loading a tile obstacle for a tile, not creating a new one. We already have the connection score public void PlaceTileObstacle(ObstacleType obstacleType, TileConnectionScoreInfo obstacleConnectionScore) { TileObstacle tileObstacle = (TileObstacle)InstantiateTileAttributeGO <TileObstacle>(); tileObstacle.WithObstacleType(obstacleType); tileObstacle.WithConnectionScoreInfo(obstacleConnectionScore); Tile.SetWalkable(false); Tile.TryMakeMarkable(false); Tile.AddAttribute(tileObstacle); }
// Loading a player exit for a tile, not creating a new one. We already have the connection score public void PlacePlayerExit(ObstacleType obstacleType, TileConnectionScoreInfo obstacleConnectionScoreInfo) { PlayerExit playerExit = (PlayerExit)InstantiateTileAttributeGO <PlayerExit>(); playerExit.WithObstacleType(obstacleType); playerExit.WithConnectionScoreInfo(obstacleConnectionScoreInfo); Tile.SetWalkable(false); Tile.TryMakeMarkable(false); Tile.AddAttribute(playerExit); }
// Called in game when we already have the connection score public override void PlacePath(IPathType mazeTilePathType, TileConnectionScoreInfo pathConnectionScoreInfo) { GameObject mazeTilePathGO = GameObject.Instantiate(MazeLevelGameplayManager.Instance.GetTileBackgroundPrefab <MazeTilePath>(), Tile.BackgroundsContainer); MazeTilePath mazeTilePath = mazeTilePathGO.GetComponent <MazeTilePath>(); mazeTilePath.WithType(mazeTilePathType as IBackgroundType); mazeTilePath.WithConnectionScoreInfo(pathConnectionScoreInfo); mazeTilePath.SetTile(Tile); Tile.AddBackground(mazeTilePath); Tile.TryMakeMarkable(true); }
public override void PlaceWater(IBaseBackgroundType waterType, TileConnectionScoreInfo pathConnectionScoreInfo) { GameObject waterGO = GameObject.Instantiate(MazeLevelGameplayManager.Instance.GetTileBackgroundPrefab <MazeTileBaseWater>(), Tile.BackgroundsContainer); MazeTileBaseWater mazeTileBaseWater = waterGO.GetComponent <MazeTileBaseWater>(); mazeTileBaseWater.WithType(waterType); mazeTileBaseWater.SetTile(Tile); Tile.SetMainMaterial(new WaterMainMaterial()); Tile.AddBackground(mazeTileBaseWater); Tile.TryMakeMarkable(false); Tile.SetWalkable(false); }
public override void PlaceWater(IBaseBackgroundType waterType, TileConnectionScoreInfo pathConnectionScoreInfo) { if (Tile.GridLocation.X == 0 && Tile.GridLocation.Y == 0) { Logger.Warning($"Set water HAMASDKQ"); } GameObject waterGO = GameObject.Instantiate(OverworldGameplayManager.Instance.GetTileBackgroundPrefab <OverworldTileBaseWater>(), Tile.BackgroundsContainer); OverworldTileBaseWater overworldTileBaseWater = waterGO.GetComponent <OverworldTileBaseWater>(); overworldTileBaseWater.WithType(waterType); overworldTileBaseWater.SetTile(Tile); Tile.AddBackground(overworldTileBaseWater); Tile.SetWalkable(false); }
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); } }
public SerialisableTileObstacleAttribute(TileConnectionScoreInfo obstacleConnectionScoreInfo) { ConnectionScore = obstacleConnectionScoreInfo.RawConnectionScore; SpriteNumber = obstacleConnectionScoreInfo.SpriteNumber; }
public SerialisablePlayerExitAttribute(TileConnectionScoreInfo ConnectionScoreInfo) { ConnectionScore = ConnectionScoreInfo.RawConnectionScore; SpriteNumber = ConnectionScoreInfo.SpriteNumber; }
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 abstract void PlaceGround(IBaseBackgroundType groundType, TileConnectionScoreInfo pathConnectionScoreInfo);
public abstract void PlaceWater(IBaseBackgroundType waterType, TileConnectionScoreInfo pathConnectionScoreInfo);
public abstract void PlacePath(IPathType tilePathType, TileConnectionScoreInfo pathConnectionScoreInfo);