public static void StartALevel() { Debug.Log("StartALevel called for " + CurrentLevel.gameObject.name); //check that Lobby Level is currently running, if so transition to a new Level if (CurrentLevel == Level.LobbyLevel) { Level newToLoad = (_levels.ContainsKey(PlayerUser.LastLevelCompleted + 1)) ? _levels[PlayerUser.LastLevelCompleted + 1] : Level.LobbyLevel; //fallback is lobby level UnitMgr.ClearUnitsData(); Level.LobbyLevel.gameObject.SetActive(false); CurrentLevel = newToLoad; newToLoad.gameObject.SetActive(true); //TODO: at some point make a fancier scheme for difficulty selection so that holes greater or less than town count! newToLoad.Reset(PlayerUser.LastLevelCompleted + 1, PlayerUser.LastLevelCompleted + 1); PlayerUser.ResetPlayerPosition(); PlayerUser.ResetLevelStartingResources(); UnitMgr.ResetWaveLogic(); string text = $"Current Level Obtained: {PlayerUser.LastLevelCompleted + 1}"; DisplayInfoDesktop.SetDisplayInfo(text); } else { Debug.LogWarning("LevelMgr.StartALevel() called from outside the Lobby!"); } MenuInGameObject?.GetComponent <MenuInGame>()?.UpdateNow(); StatusInGameComponent?.Show(true); if (CurrentLevel == Level.LobbyLevel) //if new level not found and the lobby reloaded { StatusInGameComponent?.SetAlert("Level " + (PlayerUser.LastLevelCompleted + 1) + " not found, back to Lobby", Color.red); } else { StatusInGameComponent?.SetAlert("Level " + (PlayerUser.LastLevelCompleted + 1) + " Loaded", Color.white); } }
public override void MainLoopUpdatePing() { //Debug.Log("MainLoopUpdatePing "+GameMgr.GameTime.TotalTime); if (ThisIsTheLobbyLevel) { return; //no checking if lobby level } if (!gameObject.activeInHierarchy || LevelsMgr.CurrentLevel != this) { return; //make sure Level is alive } if (CheckIfLevelWon()) { PlayerUser.WonALevel(); LevelsMgr.BackToLobby(); string text = PlayerUser.LastLevelCompleted >= 9 ? "You beat the last level!\nYOU BEAT THE CAMPAIGN!" : "You Beat The Level!\nAll Goblin holes cleared!"; LevelsMgr.StatusInGameComponent?.SetAlert(text, Color.green); return; } if (CheckIfLevelLost()) { PlayerUser.LostALevel(); LevelsMgr.BackToLobby(); LevelsMgr.StatusInGameComponent?.SetAlert("You Lost The Level!\nAll towns destroyed!", Color.red); return; } if (GameMgr.GameTime.TotalTime - _lastGameTimeStamp >= BASE_SPAWN_PERIOD) //TODO: figure out why TotalTime wasn't made static in GameTime, hhmmm... { _lastGameTimeStamp = GameMgr.GameTime.TotalTime; OnSpawnTick?.Invoke(); //Debug.Log("Level.OnSpawnTick @ Time/TotalTime: " + Time.time + "s / " + GameMgr.GameTime.TotalTime + "s\n"); } }
public static void BackToLobby() { Debug.Log("BackToLobby called!"); //TODO: ensure PlayerUser stats updated before this was called (i.e. progress saved) MenuInGameObject?.GetComponent <MenuInGame>()?.UpdateNow(); MenuInGameObject?.GetComponent <MenuInGame>().Show(false); //_statusInGameComponent?.Show(false); if (CurrentLevel != Level.LobbyLevel) { CurrentLevel.CleanUp(); CurrentLevel.gameObject.SetActive(false); CurrentLevel = Level.LobbyLevel; Level.LobbyLevel.gameObject.SetActive(true); PlayerUser.ResetPlayerPosition(); } else { Debug.LogWarning("LevelMgr.BackToLobby() called from the Lobby!"); } DisplayInfoDesktop.SetDisplayInfo(""); }