public override void PlaceAttribute(EditorMazeTile tile) { if (tile.TileMainMaterial.GetType() != typeof(WaterMainMaterial)) { Logger.Log("TODO: Check if this works. Bridge can also be placed on any tile with a coastline"); return; } EditorMazeTileAttributePlacer tileAttributePlacer = new EditorMazeTileAttributePlacer(tile); MazeTileAttributeRemover tileAttributeRemover = new MazeTileAttributeRemover(tile); BridgePiece bridgePiece = (BridgePiece)tile.GetAttributes().FirstOrDefault(attribute => (attribute is BridgePiece)); if (bridgePiece == null) { tileAttributePlacer.PlaceBridgePiece(BridgePieceDirection.Horizontal); } else if (bridgePiece.BridgePieceDirection == BridgePieceDirection.Horizontal) { tileAttributeRemover.RemoveBridgePiece(); tileAttributePlacer.PlaceBridgePiece(BridgePieceDirection.Vertical); } else { tileAttributeRemover.RemoveBridgePiece(); } }
public bool ValidateTarget(TargetLocation targetLocation) { if (GameManager.Instance.CurrentGameLevel.TilesByLocation.TryGetValue(targetLocation.TargetGridLocation, out Tile targetTile)) { ObjectDirection direction = targetLocation.TargetDirection; if (targetTile.Walkable) { Tile currentTile = GameManager.Instance.CurrentGameLevel.TilesByLocation[CurrentGridLocation]; BridgePiece bridgePieceOnCurrentTile = currentTile.TryGetBridgePiece(); BridgePiece bridgePieceOnTarget = targetTile.TryGetBridgePiece(); // optimisation: keep bridge locations of the level in a separate list, so we don't have to go over all the tiles in the level // there are no bridges involved if (bridgePieceOnCurrentTile == null && bridgePieceOnTarget == null) { return(true); } // Make sure we go in the correct bridge direction if (bridgePieceOnCurrentTile && bridgePieceOnTarget) { if (bridgePieceOnCurrentTile.BridgePieceDirection == BridgePieceDirection.Horizontal && bridgePieceOnTarget.BridgePieceDirection == BridgePieceDirection.Horizontal && (direction == ObjectDirection.Left || direction == ObjectDirection.Right)) { return(true); } if (bridgePieceOnCurrentTile.BridgePieceDirection == BridgePieceDirection.Vertical && bridgePieceOnTarget.BridgePieceDirection == BridgePieceDirection.Vertical && (direction == ObjectDirection.Up || direction == ObjectDirection.Down)) { return(true); } return(false); } if ((bridgePieceOnCurrentTile?.BridgePieceDirection == BridgePieceDirection.Horizontal || bridgePieceOnTarget?.BridgePieceDirection == BridgePieceDirection.Horizontal) && (direction == ObjectDirection.Left || direction == ObjectDirection.Right)) { return(true); } if ((bridgePieceOnCurrentTile?.BridgePieceDirection == BridgePieceDirection.Vertical || bridgePieceOnTarget?.BridgePieceDirection == BridgePieceDirection.Vertical) && (direction == ObjectDirection.Up || direction == ObjectDirection.Down)) { return(true); } return(false); } } return(false); }
public bool ValidateForBridge(PathNode currentNode, PathNode targetNode, ObjectDirection direction) { Tile targetTile = targetNode.Tile; Tile currentTile = currentNode.Tile; if (targetTile.Walkable) { BridgePiece bridgePieceOnCurrentTile = currentTile.TryGetBridgePiece(); BridgePiece bridgePieceOnTarget = targetTile.TryGetBridgePiece(); // optimisation: keep bridge locations of the level in a separate list, so we don't have to go over all the tiles in the level // there are no bridges involved if (bridgePieceOnCurrentTile == null && bridgePieceOnTarget == null) { return(true); } // Make sure we go in the correct bridge direction if (bridgePieceOnCurrentTile && bridgePieceOnTarget) { if (bridgePieceOnCurrentTile.BridgePieceDirection == BridgePieceDirection.Horizontal && bridgePieceOnTarget.BridgePieceDirection == BridgePieceDirection.Horizontal && (direction == ObjectDirection.Left || direction == ObjectDirection.Right)) { return(true); } if (bridgePieceOnCurrentTile.BridgePieceDirection == BridgePieceDirection.Vertical && bridgePieceOnTarget.BridgePieceDirection == BridgePieceDirection.Vertical && (direction == ObjectDirection.Up || direction == ObjectDirection.Down)) { return(true); } return(false); } if ((bridgePieceOnCurrentTile?.BridgePieceDirection == BridgePieceDirection.Horizontal || bridgePieceOnTarget?.BridgePieceDirection == BridgePieceDirection.Horizontal) && (direction == ObjectDirection.Left || direction == ObjectDirection.Right)) { return(true); } if ((bridgePieceOnCurrentTile?.BridgePieceDirection == BridgePieceDirection.Vertical || bridgePieceOnTarget?.BridgePieceDirection == BridgePieceDirection.Vertical) && (direction == ObjectDirection.Up || direction == ObjectDirection.Down)) { return(true); } return(false); } return(false); }
private void ConnectBridgeEdgesToTheirBridgePieces() { for (int i = 0; i < Tiles.Count; i++) { InGameMazeTile tile = Tiles[i] as InGameMazeTile; List <BridgeEdge> bridgeEdges = tile.GetBridgeEdges(); for (int j = 0; j < bridgeEdges.Count; j++) { Direction edgeSide = bridgeEdges[j].EdgeSide; InGameMazeTile neighbourTile = null; switch (edgeSide) { case Direction.Up: neighbourTile = tile.Neighbours[ObjectDirection.Up] as InGameMazeTile; break; case Direction.Right: neighbourTile = tile.Neighbours[ObjectDirection.Right] as InGameMazeTile; break; case Direction.Down: neighbourTile = tile.Neighbours[ObjectDirection.Down] as InGameMazeTile; break; case Direction.Left: neighbourTile = tile.Neighbours[ObjectDirection.Left] as InGameMazeTile; break; default: break; } if (neighbourTile) { BridgePiece bridgePiece = neighbourTile.TryGetBridgePiece(); if (bridgePiece == null) { Logger.Error($"Expected but could not find bridge piece at {neighbourTile.GridLocation.X}, {neighbourTile.GridLocation.Y}."); return; } bridgeEdges[j].WithBridgePieceConnection(bridgePiece); } } } }
public void PlaceBridgePiece(BridgeType bridgeType, BridgePieceDirection bridgePieceDirection) { BridgePiece bridgePiece = (BridgePiece)InstantiateTileAttributeGO <BridgePiece>(); bridgePiece.WithBridgeType(bridgeType); bridgePiece.WithBridgePieceDirection(bridgePieceDirection); bridgePiece.SetSprite(); Tile.SetWalkable(true); Tile.TryMakeMarkable(false); Tile.AddAttribute(bridgePiece); TileWater tileWater = Tile.TryGetTileWater(); if (tileWater) { tileWater.SetWalkabilityForBridge(bridgePieceDirection); } }
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); } }
private ISerialisableTileAttribute CreateSerialisableTileAttribute(Tile tile, ITileAttribute tileAttribute) { if (tileAttribute.GetType() == typeof(TileObstacle)) { TileObstacle tileObstacle = tileAttribute as TileObstacle; SerialisableTileObstacleAttribute serialisableTileObstacleAttribute = new SerialisableTileObstacleAttribute( new TileConnectionScoreInfo(tileObstacle.ConnectionScore, tileObstacle.SpriteNumber)); return(serialisableTileObstacleAttribute); } else if (tileAttribute.GetType() == typeof(PlayerExit)) { PlayerExit playerExit = tileAttribute as PlayerExit; SerialisablePlayerExitAttribute serialisablePlayerExitAttribute = new SerialisablePlayerExitAttribute( new TileConnectionScoreInfo(playerExit.ConnectionScore, playerExit.SpriteNumber)); return(serialisablePlayerExitAttribute); } else if (tileAttribute.GetType() == typeof(PlayerOnly)) { SerialisablePlayerOnlyAttribute serialisablePlayerOnlyAttribute = new SerialisablePlayerOnlyAttribute(); return(serialisablePlayerOnlyAttribute); } else if (tileAttribute.GetType() == typeof(PlayerSpawnpoint)) { SerialisablePlayerSpawnpointAttribute serialisablePlayerSpawnpointAttribute = new SerialisablePlayerSpawnpointAttribute(); return(serialisablePlayerSpawnpointAttribute); } else if (tileAttribute.GetType() == typeof(EnemySpawnpoint)) { EnemySpawnpoint enemySpawnpoint = tileAttribute as EnemySpawnpoint; SerialisableEnemySpawnpointAttribute serialisableEnemySpawnpointAttribute = new SerialisableEnemySpawnpointAttribute(enemySpawnpoint.TileAreas); return(serialisableEnemySpawnpointAttribute); } else if (tileAttribute.GetType() == typeof(MazeLevelEntry)) { MazeLevelEntry mazeLevelEntry = tileAttribute as MazeLevelEntry; SerialisableMazeLevelEntryAttribute serialisableMazeLevelEntryAttribute = new SerialisableMazeLevelEntryAttribute(mazeLevelEntry.MazeLevelName); return(serialisableMazeLevelEntryAttribute); } else if (tileAttribute.GetType() == typeof(BridgePiece)) { BridgePiece bridgePiece = tileAttribute as BridgePiece; BridgePieceDirection bridgePieceDirection = bridgePiece.BridgePieceDirection; SerialisableBridgePieceAttribute serialisableBridgePieceAttribute = new SerialisableBridgePieceAttribute(bridgePieceDirection); return(serialisableBridgePieceAttribute); } else if (tileAttribute.GetType() == typeof(BridgeEdge)) { BridgeEdge bridgeEdge = tileAttribute as BridgeEdge; SerialisableBridgeEdgeAttribute serialisableBridgeEdgeAttribute = new SerialisableBridgeEdgeAttribute(bridgeEdge.EdgeSide); return(serialisableBridgeEdgeAttribute); } else if (tileAttribute.GetType() == typeof(MusicInstrumentCase)) { SerialisableMusicInstrumentCaseAttribute serialisableMusicInstrumentCaseAttribute = new SerialisableMusicInstrumentCaseAttribute(); return(serialisableMusicInstrumentCaseAttribute); } else { Logger.Error($"Could not serialise the tile attribute {tileAttribute.GetType()}"); return(null); } }
public static TileConnectionScoreInfo MapNeighbourPathsOfTile(Tile tile, IPathType pathType) { Logger.Log($"---------Map neighbours of {tile.GridLocation.X},{tile.GridLocation.Y}--------"); TileModifierConnectionInfo <TilePath> pathRight = new TileModifierConnectionInfo <TilePath>(Direction.Right); TileModifierConnectionInfo <TilePath> pathDown = new TileModifierConnectionInfo <TilePath>(Direction.Down); TileModifierConnectionInfo <TilePath> pathLeft = new TileModifierConnectionInfo <TilePath>(Direction.Left); TileModifierConnectionInfo <TilePath> pathUp = new TileModifierConnectionInfo <TilePath>(Direction.Up); if (!EditorManager.InEditor) { Logger.Error("MapNeighbourPathsOfTile was not called from the editor"); return(null); } foreach (KeyValuePair <ObjectDirection, Tile> neighbour in tile.Neighbours) { if (!neighbour.Value) { // if there is no tile as neighbour, it must mean it as the level edge. This counts as a connection. if (neighbour.Key == ObjectDirection.Right) { pathRight.HasConnection = true; } else if (neighbour.Key == ObjectDirection.Down) { pathDown.HasConnection = true; } else if (neighbour.Key == ObjectDirection.Left) { pathLeft.HasConnection = true; } else if (neighbour.Key == ObjectDirection.Up) { pathUp.HasConnection = true; } continue; } Logger.Warning($"Neighbour at {neighbour.Value.GridLocation.X},{neighbour.Value.GridLocation.Y} is {neighbour.Key} of {tile.GridLocation.X},{tile.GridLocation.Y}."); // Check if the neighbour has a connection which is a PATH or a BRIDGE TilePath tilePath = neighbour.Value.TryGetTilePath(); if (tilePath == null || tilePath.TilePathType?.GetType() != pathType.GetType()) { BridgePiece bridgePiece = neighbour.Value.TryGetBridgePiece(); if (bridgePiece == null) { continue; } bool hasBridgeConnection = false; if ((neighbour.Key == ObjectDirection.Right || neighbour.Key == ObjectDirection.Left) && bridgePiece.BridgePieceDirection == BridgePieceDirection.Horizontal) { hasBridgeConnection = true; } else if ((neighbour.Key == ObjectDirection.Down || neighbour.Key == ObjectDirection.Up) && bridgePiece.BridgePieceDirection == BridgePieceDirection.Vertical) { hasBridgeConnection = true; } if (hasBridgeConnection == false) { continue; } } if (neighbour.Key == ObjectDirection.Right) { pathRight.HasConnection = true; pathRight.TileModifier = tilePath; } else if (neighbour.Key == ObjectDirection.Down) { pathDown.HasConnection = true; pathDown.TileModifier = tilePath; } else if (neighbour.Key == ObjectDirection.Left) { pathLeft.HasConnection = true; pathLeft.TileModifier = tilePath; } else if (neighbour.Key == ObjectDirection.Up) { pathUp.HasConnection = true; pathUp.TileModifier = tilePath; } } return(TileConnectionRegister.CalculateTileConnectionScore(pathRight, pathDown, pathLeft, pathUp)); }