Exemple #1
0
        /// <summary>
        /// Ends the current game session and shows the titlescreen.
        /// </summary>
        /// <remarks>Only works when <see cref="GM.GameState"/> is <see cref="GameState.PUZZLE"/> or <see cref="GameState.SIM"/> and the tutorial has been completed.</remarks>
        /// <param name="saveGame">When <c>true</c>, save the current game session to the active save file.</param>
        /// <param name="revertDates">When <c>true</c> and <paramref name="saveGame"/> is also <c>true</c>, will set <see cref="GirlPlayerData.dayDated"/> to false when on a puzzle/date.</param>
        /// <param name="triggerValediction">When <c>true</c>, trigger a valediction dialog (goodbye) on the main girl.</param>
        /// <returns><c>True</c> when the session was ended, <c>false</c> when ending the session was blocked due to the game's current state.</returns>
        public static bool EndGameSession(bool saveGame = true, bool revertDates = true, bool triggerValediction = true)
        {
            if (!GM.System.Player.tutorialComplete || GetAvailableGirls(availableOnly: false, excludeCurrentGirl: false).Count == 0)
            {
                ShowNotification(CellNotificationType.MESSAGE, "Cannot leave the tutorial");
                return(false);
            }

            //base HunieMod could just use Input.GetMouseButtonDown(0) I think
            if (Input.GetMouseButtonDown(0) || InputPatches.mouseDown)
            {
                ShowNotification(CellNotificationType.MESSAGE, "Cannot leave with the mouse button clicked");
                return(false);
            }

            if (GM.System == null || GM.System.GameState == GameState.TITLE || GM.System.GameState == GameState.LOADING || !GM.System.Location.IsLocationSettled() ||
                (GM.System.Location.currentLocation.type == LocationType.NORMAL && !GM.Stage.uiWindows.IsDefaultWindowActive(true)))
            {
                ShowNotification(CellNotificationType.MESSAGE, "Cannot leave unless you could use the Girl Finder");
                return(false);
            }
            if (GM.Stage.cellPhone.IsOpen())
            {
                ShowNotification(CellNotificationType.MESSAGE, "Cannot leave with the HunieBee open");
                return(false);
            }

            if (GM.System.GameState == GameState.PUZZLE)
            {
                if (GM.System.Puzzle.Game.puzzleGameState != PuzzleGameState.WAITING)
                {
                    ShowNotification(CellNotificationType.MESSAGE, "Can only leave when you could make a move");
                    return(false);
                }
                if (saveGame)
                {
                    GM.System.Player.GetGirlData(GM.System.Location.currentGirl).dayDated = !revertDates;
                    var returnTo = (LocationDefinition)AccessTools.Field(typeof(PuzzleManager), "_returnToLocation")?.GetValue(GM.System.Puzzle);
                    if (returnTo != null)
                    {
                        GM.System.Player.currentLocation = returnTo;
                    }
                }
                HidePuzzleGame(true);
            }
            else
            {
                GM.Stage.uiGirl.stats.localY = UIGirl.GIRL_STATS_HIDDEN_Y_POS;
            }

            GM.Stage.uiTop.buttonHuniebee.interactive = false;

            GM.Stage.SetPausable(false);
            if (GM.Stage.cellPhone.IsOpen())
            {
                ShowCellPhone(false, true);
            }

            ClearActiveDialogScene();
            GM.Stage.altGirl.girlPieceContainers.localX = -GameCamera.SCREEN_DEFAULT_WIDTH_HALF;
            GM.Stage.altGirl.ClearGirl();
            GM.Stage.background.StopBackgroundMusic();
            GM.Stage.background.locationBackgrounds.gameObj.transform.localScale = Vector3.one * 0.95f;
            GM.Stage.uiWindows.HideActiveWindow();

            if (triggerValediction)
            {
                StaticCoroutine.Do(TriggerValedictionDialog());
            }

            if (saveGame)
            {
                GM.System.SaveGame();
            }

            //remove blinking message icon
            GM.System.Player.messages[0].viewed = true;
            GM.Stage.uiTop.RefreshMessageAlert();
            //reset cell phone defaults
            GameManager.Stage.cellPhone.cellMemory = new Dictionary <string, int>();
            GameManager.Stage.cellPhone.SetCellApp(GameManager.Stage.cellPhone.defaultCellApp);

            GM.System.Location.currentGirl     = null;
            GM.System.Location.currentLocation = null;
            AccessTools.Field(typeof(GM), "_saveFile").SetValue(GM.System, null);
            AccessTools.Method(typeof(LocationManager), "Awake").Invoke(GM.System.Location, null);

            GM.System.GameState = GameState.TITLE;
            GM.Stage.uiTitle.ShowTitleScreen();
            GM.Stage.uiTitle.SaveFileSelectedEvent += OnSaveFileSelected;

            return(true);
        }