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]; } }
// Previously tried solution with collision detection on all separate clients for all players(instead of events). // But the result was that some tile marking got skipped if the clients skipped walking over them because of a bad connection. // This way we can be sure all tiles are getting marked. public void SetTileMarker(InGameMazeTile tile, PlayerCharacter player) { if (GameRules.GamePlayerType == GamePlayerType.SinglePlayer || GameRules.GamePlayerType == GamePlayerType.SplitScreenMultiplayer) { player.LastTile = tile; MazeTilePath mazeTilePath = (MazeTilePath)tile.GetBackgrounds().FirstOrDefault(background => background is MazeTilePath); if (mazeTilePath == null) { return; } PlayerMark playerMark = new PlayerMark(mazeTilePath.ConnectionScore); HandlePlayerMarkerSprite(tile, player.PlayerNumber, playerMark); HandlePlayerTileMarkerEnds(tile); HandleNumberOfUnmarkedTiles(); tile.ResetPlayerMarkEndsRenderer(); tile.TriggerTransformations(); } else { PlayerMarksTileEvent playerMarksTileEvent = new PlayerMarksTileEvent(); playerMarksTileEvent.SendPlayerMarksTileEvent(tile.GridLocation, player); } }
private void TrySetTileNotMarkable() { MazeTilePath mazeTilePath = (MazeTilePath)_tile.GetBackgrounds().FirstOrDefault(background => background is MazeTilePath); if (mazeTilePath == null) { _tile.TryMakeMarkable(false); } }
// 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 void TryMakeMarkable(bool isMarkable) { MazeTilePath mazeTilePath = (MazeTilePath)_tileBackgrounds.FirstOrDefault(background => background is MazeTilePath); if (mazeTilePath == null) { Markable = false; return; } for (int i = 0; i < _tileAttributes.Count; i++) { if (_tileAttributes[i] is PlayerExit) { Markable = false; return; } } Markable = isMarkable; }
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 void OnEvent(EventData photonEvent) { byte eventCode = photonEvent.Code; if (eventCode == PlayerMarksTileEvent.PlayerMarksTileEventCode) { object[] data = (object[])photonEvent.CustomData; GridLocation tileLocation = new GridLocation((int)data[0], (int)data[1]); PlayerNumber playerNumber = (PlayerNumber)data[2]; InGameMazeTile tile = Level.TilesByLocation[tileLocation] as InGameMazeTile; MazeTilePath mazeTilePath = (MazeTilePath)tile.GetBackgrounds().FirstOrDefault(background => background is MazeTilePath); if (mazeTilePath == null) { return; } PlayerMark playerMark = new PlayerMark(mazeTilePath.ConnectionScore); HandlePlayerMarkerSprite(tile, playerNumber, playerMark); HandlePlayerTileMarkerEnds(tile); HandleNumberOfUnmarkedTiles(); tile.ResetPlayerMarkEndsRenderer(); tile.TriggerTransformations(); } else if (eventCode == LoadNextMazeLevelEvent.LoadNextMazeLevelEventCode) { object[] data = (object[])photonEvent.CustomData; string pickedLevel = (string)data[0]; MazeLevelData mazeLevelData = MazeLevelLoader.LoadMazeLevelData(pickedLevel); if (mazeLevelData == null) { Logger.Error($"Could not load maze level data for the randomly picked maze level {pickedLevel}"); } PersistentGameManager.SetCurrentSceneName(pickedLevel); IEnumerator loadLevelCoroutine = LoadOverworldCoroutine("Overworld"); StartCoroutine(loadLevelCoroutine); } else if (eventCode == LoadOverworldEvent.LoadOverworldEventCode) { object[] data = (object[])photonEvent.CustomData; string overworldName = (string)data[0]; PersistentGameManager.SetLastMazeLevelName(PersistentGameManager.CurrentSceneName); PersistentGameManager.SetCurrentSceneName(PersistentGameManager.OverworldName); IEnumerator loadLevelCoroutine = LoadOverworldCoroutine("Overworld"); StartCoroutine(loadLevelCoroutine); } else if (eventCode == PlayerCollidesWithMusicInstrumentCaseEvent.PlayerCollidesWithMusicInstrumentCaseEventCode) { object[] data = (object[])photonEvent.CustomData; GridLocation tileLocation = new GridLocation((int)data[0], (int)data[1]); PlayerNumber playerNumber = (PlayerNumber)data[2]; InGameMazeTile tile = Level.TilesByLocation[tileLocation] as InGameMazeTile; MusicInstrumentCase musicInstrumentCase = (MusicInstrumentCase)tile.GetAttributes().FirstOrDefault(attribute => attribute is MusicInstrumentCase); if (musicInstrumentCase == null) { Logger.Error("Could not find musicInstrumentCase"); } MazePlayerCharacter player = GameManager.Instance.CharacterManager.GetPlayers <MazePlayerCharacter>()[playerNumber]; musicInstrumentCase.PlayerCollisionOnTile(player); } else if (eventCode == EnemyCollidesWithMusicInstrumentCaseEvent.EnemyCollidesWithMusicInstrumentCaseEventCode) { object[] data = (object[])photonEvent.CustomData; GridLocation tileLocation = new GridLocation((int)data[0], (int)data[1]); int enemyId = (int)data[2]; InGameMazeTile tile = Level.TilesByLocation[tileLocation] as InGameMazeTile; MusicInstrumentCase musicInstrumentCase = (MusicInstrumentCase)tile.GetAttributes().FirstOrDefault(attribute => attribute is MusicInstrumentCase); if (musicInstrumentCase == null) { Logger.Error("Could not find musicInstrumentCase"); } MazeCharacterManager characterManager = GameManager.Instance.CharacterManager as MazeCharacterManager; EnemyCharacter enemyCharacter = characterManager.Enemies.FirstOrDefault(enemy => enemy.PhotonView.ViewID == enemyId); if (enemyCharacter == null) { Logger.Error("Could not find enemy character"); } musicInstrumentCase.EnemyCollisinOnTile(enemyCharacter); } }