public void LoadMaze() { Logger.Log("Load maze (in editor)"); if (string.IsNullOrWhiteSpace(_mazeName)) { Logger.Warning(Logger.Datawriting, "In order to save the maze level, please fill in a maze name"); return; } bool mazeLevelNameExists = MazeLevelLoader.MazeLevelExists(_mazeName); if (mazeLevelNameExists) { MazeLevelGameplayManager.Instance.UnloadLevel(); MazeLevelData mazeLevelData = MazeLevelLoader.LoadMazeLevelData(_mazeName); MazeLevelLoader.LoadMazeLevelForEditor(mazeLevelData); } EditorSelectedMazeTileModifierContainer selectedTileModifierContainer = EditorCanvasUI.Instance.SelectedTileModifierContainer as EditorSelectedMazeTileModifierContainer; selectedTileModifierContainer?.SetInitialModifierValues(); EditorMazeTileModificationPanel.Instance?.Reset(); EditorMazeTileModificationPanel.Instance?.DestroyModifierActions(); }
public void Configure(List <string> arguments) { try { if (arguments.Count < 1) { string message = "The command '<color=" + ConsoleConfiguration.HighlightColour + ">configure default-maze</color>' needs an additional argument with the name of the level that should be the new default.json"; message += ConfigureCommand.GetConfigurableArguments(); throw new NotEnoughArgumentsConsoleException(message); } string sanatisedLevelName = arguments[0].ToLower().Replace(" ", "-"); bool levelExists = MazeLevelLoader.MazeLevelExists(sanatisedLevelName); if (!levelExists) { string message = $"Could not find a maze level with the name {sanatisedLevelName}."; throw new CouldNotFindMazeLevelConsoleException(message); } MazeLevelLoader.ReplaceMazeLevel(sanatisedLevelName, "default"); Console.Instance.PrintToReportText($"{sanatisedLevelName} is now the default maze level."); } catch (System.Exception) { throw; } }
public override void Help() { string printLine = "To load a maze level with argument 'maze' and then the name of the level. Without extra maze name argument, 'maze' will load the default maze level. \n\n"; printLine += "The Currently available levels are: \n"; printLine = MazeLevelLoader.GetAllMazeLevelNamesForPrint(printLine); printLine += "To load the overworld use the argument 'overworld', with optionally an additional argument for the name of a specific overworld version. Without extra overworld name, the default overworld is loaded. \n\n"; Console.Instance.PrintToReportText(printLine); }
public void LoadMazeLevel(List <string> arguments) { if (MazeLevelGameplayManager.Instance == null) { if (PersistentGameManager.CurrentSceneType == SceneType.Overworld) { Logger.Warning("We are currently in the overworld scene. Switching scenes."); PersistentGameManager.SetLastMazeLevelName("default"); PersistentGameManager.SetCurrentSceneName("default"); PhotonNetwork.LoadLevel("Maze"); // TODO this loads the default maze, should load specific maze } else { Logger.Error("Cannot find MazeLevelManager. Returning."); } return; } MazeLevelData mazeLevelData; if (arguments.Count < 2) { PersistentGameManager.SetLastMazeLevelName("default"); PersistentGameManager.SetCurrentSceneName("default"); mazeLevelData = MazeLevelLoader.LoadMazeLevelData(PersistentGameManager.CurrentSceneName); MazeLevelLoader.LoadMazeLevel(mazeLevelData); return; //string message = "The command '<color=" + ConsoleConfiguration.HighlightColour + ">load maze</color>' needs an additional argument with the name of the maze level"; //Logger.Warning(message); //message += "\nThe Currently available levels are: \n"; //message = MazeLevelLoader.GetAllMazeLevelNamesForPrint(message); //throw new NotEnoughArgumentsConsoleException(message); } string mazeName = arguments[1]; mazeLevelData = MazeLevelLoader.LoadMazeLevelData(mazeName); if (mazeLevelData == null && Console.Instance.ConsoleState != ConsoleState.Closed) { string printLine = "<color=" + ConsoleConfiguration.HighlightColour + ">" + arguments[1] + "</color> is not a known maze level and cannot be loaded.\n\n"; printLine += "The Currently available levels are: \n"; printLine = MazeLevelLoader.GetAllMazeLevelNamesForPrint(printLine); Console.Instance.PrintToReportText(printLine); } PersistentGameManager.SetLastMazeLevelName(mazeName); PersistentGameManager.SetCurrentSceneName(mazeName); mazeLevelData = MazeLevelLoader.LoadMazeLevelData(PersistentGameManager.CurrentSceneName); MazeLevelLoader.LoadMazeLevel(mazeLevelData); }
private MazeLevelNameData GetMazeLevelNameData(string sanatisedLevelName) { MazeLevelNamesData mazeLevelNamesData = MazeLevelLoader.GetAllMazeLevelNamesData(); MazeLevelNameData mazeLevelName = mazeLevelNamesData.LevelNames.FirstOrDefault(level => level.LevelName == sanatisedLevelName); if (mazeLevelName == null) { string message = $"Could not find a maze level with the name '<color={sanatisedLevelName}>info maze</color>' in the level list.\n"; throw new MazeLevelNameNotFoundConsoleException(message); } return(mazeLevelName); }
private MazeLevelData GetMazeLevelData(string sanatisedLevelName) { bool levelExists = MazeLevelLoader.MazeLevelExists(sanatisedLevelName); if (!levelExists) { string message = $"Could not find a maze level with the name '<color={sanatisedLevelName}>info maze</color>'.\n"; throw new MazeLevelNameNotFoundConsoleException(message); } MazeLevelData mazeLevelData = MazeLevelLoader.LoadMazeLevelData(sanatisedLevelName); return(mazeLevelData); }
public void ToNextLevel() { _screenIsOpen = false; // pick a random level from the list of playable levels if (GameManager.Instance.PlayableLevelNames.Count == 0) // there are no levels left to choose from, reload all random levels. { Logger.Warning("We played all playable levels. Starting the random selection from the beginning"); GameManager.Instance.PlayableLevelNames = MazeLevelLoader.GetAllPlayableLevelNames(); } Logger.Log("number of found levels: " + GameManager.Instance.PlayableLevelNames.Count); int randomIndex = Random.Range(0, GameManager.Instance.PlayableLevelNames.Count); string pickedLevel = GameManager.Instance.PlayableLevelNames[randomIndex]; Logger.Log($"Load next random level: {pickedLevel}"); MazeLevelGameplayManager.Instance.LoadNextLevel(pickedLevel); // triggers load next level event for both players }
public EditorOverworld(OverworldData overworldData) { GameManager.Instance.CurrentEditorLevel = this; Name = overworldData.Name; if (TilesContainer.Instance != null) { GameObject.Destroy(TilesContainer.Instance.gameObject); TilesContainer.Instance = null; } _overworldContainer = new GameObject(Name); _overworldContainer.transform.SetParent(GameManager.Instance.GridGO.transform); _overworldContainer.transform.position = new Vector3(0, 0, 0); _overworldContainer.AddComponent <TilesContainer>(); _overworldContainer.SetActive(true); BuildTiles(overworldData); MazeLevelNames = MazeLevelLoader.GetAllPlayableLevelNames(); }
public void Start() { switch (PersistentGameManager.CurrentSceneType) { case SceneType.Overworld: Logger.Log("instantiate overworld sprites, tiles and characters"); if (PersistentGameManager.SceneLoadOrigin == SceneLoadOrigin.Gameplay) { if (PersistentGameManager.OverworldName == "") { PersistentGameManager.SetOverworldName("overworld"); } string overworldName = PersistentGameManager.OverworldName; Logger.Log($"We will load the maze '{overworldName}'"); OverworldData startUpOverworldData = OverworldLoader.LoadOverworldData(overworldName); if (startUpOverworldData == null) { Logger.Error("Could not find the default overworld for startup"); } OverworldLoader.LoadOverworld(startUpOverworldData); if (OverworldGameplayManager.Instance.Overworld == null) { Logger.Log(Logger.Initialisation, "No overworld loaded on startup. Returning"); return; } } // We loaded a overworld scene through the editor. Set up an empty grid for in the editor else { Logger.Log("create empty grid"); EditorCanvasUI.Instance.OverworldModificationPanel.GenerateTiles(); } break; case SceneType.Maze: // We loaded a maze scene through the game. Set up the maze level if (PersistentGameManager.SceneLoadOrigin == SceneLoadOrigin.Gameplay) { if (PersistentGameManager.CurrentSceneName == "") { PersistentGameManager.SetCurrentSceneName("default"); } string mazeName = PersistentGameManager.CurrentSceneName; PersistentGameManager.SetLastMazeLevelName(mazeName); Logger.Log($"We will load the maze '{mazeName}'"); MazeLevelData startUpMazeLevelData = MazeLevelLoader.LoadMazeLevelData(mazeName); if (startUpMazeLevelData == null) { Logger.Error($"Could not find the level {mazeName} for startup. Will load defult level instead."); mazeName = "default"; startUpMazeLevelData = MazeLevelLoader.LoadMazeLevelData(mazeName); } MazeLevelLoader.LoadMazeLevel(startUpMazeLevelData); if (CurrentGameLevel == null) { Logger.Log(Logger.Initialisation, "No level loaded on startup. Returning"); return; } if (CurrentGameLevel.PlayerCharacterSpawnpoints.Count == 0) { return; } PlayableLevelNames = MazeLevelLoader.GetAllPlayableLevelNames(); } // We loaded a maze scene through the editor. Set up an empty grid for in the editor else { Logger.Log("create empty grid"); EditorCanvasUI.Instance.MazeModificationPanel.GenerateTiles(); } break; default: Logger.Error($"Scenetype {PersistentGameManager.CurrentSceneType} is not implemented yet"); break; } }
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); } }
public void GenerateTiles() { if (_gridWidth < 3) { Logger.Warning(Logger.Level, "Cannot generate a tile grid with a width of {0}. The minimum generatable grid width is 3", _gridWidth); return; } if (_gridWidth > 25) { Logger.Warning(Logger.Level, "Cannot generate a tile grid with a width of {0}. The maximum generatable grid width is 20", _gridWidth); return; } if (_gridHeight < 3) { Logger.Warning(Logger.Level, "Cannot generate a tile grid with a height of {0}. The minimum generatable grid height is 3", _gridHeight); return; } if (_gridHeight > 25) { Logger.Warning(Logger.Level, "Cannot generate a tile grid with a height of {0}. The maximum generatable grid height is 20", _gridHeight); return; } Logger.Log("Generate tile grid with a width of {0} and a height of {1}", _gridWidth, _gridHeight); // remove everything from the currently loaded level MazeLevelGameplayManager.Instance.UnloadLevel(); // Create a new level from scratch with a obstacle ring at the edges List <SerialisableTile> tiles = new List <SerialisableTile>(); for (int i = 0; i < _gridWidth; i++) { for (int j = 0; j < _gridHeight; j++) { string tileId = Guid.NewGuid().ToString(); GridLocation gridLocation = new GridLocation(i, j); List <SerialisableTileAttribute> tileAttributes = new List <SerialisableTileAttribute>(); List <SerialisableTileBackground> tileBackgrounds = new List <SerialisableTileBackground>(); List <SerialisableTileCornerFiller> tileCornerFillers = new List <SerialisableTileCornerFiller>(); SerialisableTileMainMaterial mainMaterial = new SerialisableTileMainMaterial("GroundMainMaterial", new SerialisableLandMaterial()); SerialisableTileObstacleAttribute edgeObstacle = TryAddEdgeObstacle(gridLocation); if (edgeObstacle != null) { tileAttributes.Add(new SerialisableTileAttribute(edgeObstacle.GetType().ToString(), edgeObstacle)); } SerialisableTilePathBackground mazeTilePath = TryAddPathsForNewMaze(gridLocation, tileAttributes); if (mazeTilePath != null) { tileBackgrounds.Add(new SerialisableTileBackground(mazeTilePath.GetType().ToString(), mazeTilePath)); } SerialisableTileBaseGround baseBackground = TryAddBaseBackgroundForNewMaze(tileBackgrounds, tileAttributes); if (baseBackground != null) { tileBackgrounds.Add(new SerialisableTileBackground(baseBackground.GetType().ToString(), baseBackground)); } SerialisableTile tile = new SerialisableTile(tileId, mainMaterial, tileAttributes, tileBackgrounds, tileCornerFillers, gridLocation.X, gridLocation.Y); tiles.Add(tile); } } MazeLevelData newMazeLevelData = new MazeLevelData(); newMazeLevelData.Tiles = tiles; MazeLevelLoader.LoadMazeLevelForEditor(newMazeLevelData); }