Inheritance: ScriptableObject
コード例 #1
0
 public void ContinueGame(bool withSound = false)
 {
     if (withSound)
     {
         AudioController.MenuButtonSound();
     }
     if (gameSessionActive)
     {
         menuInterface.SetActive(false);
         gameInterface.SetActive(true);
         StopWatch.stopWatch.stopWatchActive = true;
     }
     else
     {
         ClearScene();
         gameSessionInfo  = SaveLoad.LoadGameSessionInfo();
         level            = SaveLoad.LoadLevel(gameSessionInfo.currentLevel);
         stepsCounter     = 0;
         currentLevelInfo = gameSessionInfo.levels.Find(l => l.levelID == gameSessionInfo.currentLevel);
         menuInterface.SetActive(false);
         levelCompleteDialog.SetActive(false);
         gameInterface.SetActive(true);
         SkinController.skinController.SetTheme(gameSessionInfo.currentTheme);
         DrawLevel();
         gameSessionActive = true;
     }
 }
コード例 #2
0
        private void ParseMetadata()
        {
            string          metaFilePath    = Path.ChangeExtension(FilePath, GameSessionManager.SavedGameMetaExtension);
            GameSessionInfo gameSessionInfo = GameSessionInfo.ParseFromFile(metaFilePath);

            if (gameSessionInfo != null)
            {
                SessionInfo = gameSessionInfo;
            }
        }
コード例 #3
0
 public void NewGame()
 {
     SaveLoad.DestroySaves();
     gameSessionInfo           = new GameSessionInfo();
     gameSessionInfo.shopItems = ShopPage.shopPage.ThemesList();
     NewLevel();
     menuInterface.SetActive(false);
     gameInterface.SetActive(true);
     SaveLoad.SaveGameSessionInfo(gameSessionInfo);
     SkinController.skinController.SetTheme(gameSessionInfo.currentTheme);
     gameSessionActive = true;
 }
コード例 #4
0
ファイル: SaveLoad.cs プロジェクト: drweavil/EntangledGame
    public static void SaveGameSessionInfo(GameSessionInfo info)
    {
        FileStream      file;
        BinaryFormatter bf   = new BinaryFormatter();
        string          path = Application.persistentDataPath + "/Resources/currentGameInfo.gameInfo";

        if (File.Exists(path))
        {
            File.Delete(path);
        }
        file = File.Create(path);
        bf.Serialize(file, info);
        file.Close();
    }
コード例 #5
0
ファイル: SaveLoad.cs プロジェクト: drweavil/EntangledGame
    public static GameSessionInfo LoadGameSessionInfo()
    {
        string          path = Application.persistentDataPath + "/Resources/currentGameInfo.gameInfo";
        GameSessionInfo loadedInfo = new GameSessionInfo();
        FileStream      file; BinaryFormatter bf = new BinaryFormatter();

        if (File.Exists(path))
        {
            file       = File.Open(path, FileMode.Open);
            loadedInfo = (GameSessionInfo)bf.Deserialize(file);
            file.Close();
        }
        return(loadedInfo);
    }
コード例 #6
0
 void Awake()
 {
     //Debug.Log (Screen.height);
     //canvasScaler.referenceResolution = new Vector2(Screen.currentResolution.height, Screen.currentResolution.width);
     //canvasScaler.referenceResolution = new Vector2(Screen.width, Screen.height);
     levelController = this;
     if (SaveLoad.GameSessionInfoExist())
     {
         gameSessionInfo = SaveLoad.LoadGameSessionInfo();
         continueButton.SetActive(true);
     }
     else
     {
         continueButton.SetActive(false);
     }
 }
 // Not used in the example but can be used to request game session directly from the fleet without matchmaking
 public GameSessionInfo RequestGameSession()
 {
     try
     {
         //Make the signed request and wait for max 10 seconds to complete
         var response = Task.Run(() => this.SendSignedGetRequest(apiEndpoint + "requestgamesession"));
         response.Wait(10000);
         string          jsonResponse = response.Result;
         GameSessionInfo info         = JsonUtility.FromJson <GameSessionInfo>(jsonResponse);
         return(info);
     }
     catch (Exception e)
     {
         Debug.Log(e.Message);
         return(null);
     }
 }
コード例 #8
0
    public IEnumerator RequestGameSession()
    {
        Debug.Log("Request matchmaking...");
        GameObject.FindObjectOfType <UIManager>().SetTextBox("Requesting game session...");
        yield return(null);

        bool gameSessionFound = false;
        int  tries            = 0;

        while (!gameSessionFound)
        {
            GameObject.FindObjectOfType <UIManager>().SetTextBox("Requesting game session...");
            yield return(null);

            this.gameSessionInfo = this.matchmakingClient.RequestGameSession();
            if (gameSessionInfo == null)
            {
                GameObject.FindObjectOfType <UIManager>().SetTextBox("No game session found yet, trying again...");
                yield return(new WaitForSeconds(1.0f));
            }
            else
            {
                Debug.Log("Got session: " + gameSessionInfo.publicIP + " " + gameSessionInfo.port);
                GameObject.FindObjectOfType <UIManager>().SetTextBox("Found a game server, connecting...");
                yield return(null);

                gameSessionFound = true;
                // game session found, connect to the server
                Connect();
            }
            tries++;

            if (tries > 20)
            {
                GameObject.FindObjectOfType <UIManager>().SetTextBox("Aborting game session search, no game found in 20 seconds");
                Debug.Log("Aborting game session search, no game found in 20 seconds");
                yield return(null);

                break;
            }
        }
    }
コード例 #9
0
 public SavedGame(string filePath, long uniqueSessionId)
 {
     FilePath    = filePath;
     SessionInfo = new GameSessionInfo(GameSessionType.UNKNOWN, uniqueSessionId);
 }
コード例 #10
0
        /// <summary>
        /// Parses singleplayer mission completion info from the game output files.
        /// Call this when the game has exited after the user has started or loaded
        /// a singleplayer mission.
        /// </summary>
        public void PostGameExitOnSingleplayerMission(GameSessionInfo sessionInfo)
        {
            if (sessionInfo.SessionType != GameSessionType.SINGLEPLAYER)
            {
                throw new ArgumentException(nameof(CampaignHandler) + "." + nameof(PostGameExitOnSingleplayerMission) + " should only be called after playing a singleplayer mission.");
            }

            string logFileName = LogFileFinder.GetLogFilePath();

            if (!File.Exists(ProgramConstants.GamePath + logFileName))
            {
                Logger.Log("WARNING: Could not parse log file after game end because the log file was not found!");
                return;
            }

            string[] lines = File.ReadAllLines(ProgramConstants.GamePath + logFileName);
            bool     scoreScreenLineFound = false;

            bool[] globalVariableStates = new bool[GLOBAL_VARIABLE_MAX];

            foreach (string line in lines)
            {
                if (line.StartsWith("ScoreScreen: Loaded "))
                {
                    scoreScreenLineFound = true;
                }

                // Also parse global variables from the log file
                if (line.StartsWith("Global variables: "))
                {
                    string   gvarString = line.Substring(18);
                    string[] gVarValues = gvarString.Split(',');

                    for (int i = 0; i < gVarValues.Length && i < globalVariableStates.Length; i++)
                    {
                        globalVariableStates[i] = gVarValues[i] == "1";
                    }
                }
            }

            if (!scoreScreenLineFound)
            {
                Logger.Log("Relevant line not found, assuming the player did not win the mission.");
                return;
            }

            Mission mission = Missions.Find(m => m.InternalName == sessionInfo.MissionInternalName);

            if (mission == null)
            {
                Logger.Log("WARNING: Failed to set mission progression data; could not find mission " + sessionInfo.MissionInternalName);
                return;
            }

            var unlockedMissions = new List <Mission>();

            Logger.Log("Finding and unlocking missions related to " + mission.InternalName);
            foreach (string unlockMissionName in mission.UnlockMissions)
            {
                Mission otherMission = Missions.Find(m => m.InternalName == unlockMissionName);
                if (otherMission == null)
                {
                    Logger.Log("FAILED to unlock mission " + unlockMissionName + "because it was not found!");
                    continue;
                }

                if (!otherMission.IsUnlocked)
                {
                    otherMission.IsUnlocked = true;
                    unlockedMissions.Add(otherMission);
                    Logger.Log("Unlocked mission " + otherMission.InternalName);
                }
            }

            Logger.Log("Finding and unlocking conditionally unlocked missions related to " + mission.InternalName);
            foreach (var conditionalMissionUnlock in mission.ConditionalMissionUnlocks)
            {
                bool conditionsMet = true;

                foreach (var globalVariableCondition in conditionalMissionUnlock.PrerequisiteGlobalVariableStates)
                {
                    var globalVariable = GlobalVariables.Find(gv => gv.InternalName == globalVariableCondition.GlobalVariableName);

                    if (globalVariable == null)
                    {
                        Logger.Log("FAILED to check condition of global variable " + globalVariableCondition.GlobalVariableName + " because it was not found!");
                        continue;
                    }

                    if (globalVariableStates[globalVariable.Index] != globalVariableCondition.Enabled)
                    {
                        conditionsMet = false;
                        break;
                    }
                }

                if (conditionsMet)
                {
                    Mission otherMission = Missions.Find(m => m.InternalName == conditionalMissionUnlock.UnlockMissionName);
                    if (otherMission == null)
                    {
                        Logger.Log("FAILED to unlock conditional mission " + conditionalMissionUnlock.UnlockMissionName + " because it was not found!");
                        continue;
                    }

                    if (!otherMission.IsUnlocked)
                    {
                        otherMission.IsUnlocked = true;
                        unlockedMissions.Add(otherMission);
                        Logger.Log("Unlocked conditional mission " + mission.InternalName);
                    }
                }
            }

            Logger.Log("Finding and unlocking global variable states related to " + mission.InternalName);
            foreach (var globalVariableName in mission.UnlockGlobalVariables)
            {
                var globalVariable = GlobalVariables.Find(gv => gv.InternalName == globalVariableName);

                if (globalVariable == null)
                {
                    Logger.Log("FAILED to unlock global variable " + globalVariableName + " because it was not found!");
                    continue;
                }

                if (globalVariableStates[globalVariable.Index])
                {
                    Logger.Log("Unlocked 'enabled' state of " + globalVariable.InternalName);
                    globalVariable.IsEnabledUnlocked = true;
                    globalVariable.EnabledThroughPreviousScenario = true;
                }
                else
                {
                    Logger.Log("Unlocked 'disabled' state of " + globalVariable.InternalName);
                    globalVariable.IsDisabledUnlocked             = true;
                    globalVariable.EnabledThroughPreviousScenario = false;
                }
            }

            Logger.Log("Finding and setting default enabled states of global variables used in " + mission.InternalName);
            foreach (var globalVariableName in mission.UsedGlobalVariables)
            {
                var globalVariable = GlobalVariables.Find(gv => gv.InternalName == globalVariableName);

                if (globalVariable == null)
                {
                    Logger.Log("FAILED to set default state of global variable " + globalVariableName + " because it was not found!");
                    continue;
                }

                if (globalVariableStates[globalVariable.Index])
                {
                    Logger.Log("Set default state to 'enabled' for " + globalVariable.InternalName);
                    globalVariable.EnabledThroughPreviousScenario = true;
                }
                else
                {
                    Logger.Log("Set default state to 'disabled' for " + globalVariable.InternalName);
                    globalVariable.EnabledThroughPreviousScenario = false;
                }
            }

            Mission primaryUnlockedMission = unlockedMissions.Count > 0 ? unlockedMissions[0] : null;

            if (sessionInfo.IsCheatSession)
            {
                Logger.Log("The player finished the mission with modified files, skipping setting of completion rank.");
            }
            else if ((int)mission.Rank < (int)sessionInfo.Difficulty)
            {
                Logger.Log("Setting completion rank of " + mission.InternalName + " to " + sessionInfo.Difficulty);
                mission.Rank = sessionInfo.Difficulty;
                MissionRankUpdated?.Invoke(this, new MissionCompletionEventArgs(mission, primaryUnlockedMission));
            }

            MissionRankHandler.WriteData(Missions, GlobalVariables);
            MissionCompleted?.Invoke(this, new MissionCompletionEventArgs(mission, primaryUnlockedMission));
        }
コード例 #11
0
        protected void LoadGame()
        {
            File.Delete(ProgramConstants.GamePath + "spawn.ini");

            File.Copy(ProgramConstants.GamePath + ProgramConstants.SAVED_GAME_SPAWN_INI, ProgramConstants.GamePath + "spawn.ini");

            IniFile spawnIni = new IniFile(ProgramConstants.GamePath + "spawn.ini");

            int    sgIndex    = (ddSavedGame.Items.Count - 1) - ddSavedGame.SelectedIndex;
            string sgFileName = string.Format("SVGM_{0}.NET", sgIndex.ToString("D3"));

            spawnIni.SetStringValue("Settings", "SaveGameName", sgFileName);
            spawnIni.SetBooleanValue("Settings", "LoadSaveGame", true);

            PlayerInfo localPlayer = Players.Find(p => p.Name == ProgramConstants.PLAYERNAME);

            if (localPlayer == null)
            {
                return;
            }

            spawnIni.SetIntValue("Settings", "Port", localPlayer.Port);

            for (int i = 1; i < Players.Count; i++)
            {
                string otherName = spawnIni.GetStringValue("Other" + i, "Name", string.Empty);

                if (string.IsNullOrEmpty(otherName))
                {
                    continue;
                }

                PlayerInfo otherPlayer = Players.Find(p => p.Name == otherName);

                if (otherPlayer == null)
                {
                    continue;
                }

                spawnIni.SetStringValue("Other" + i, "Ip", otherPlayer.IPAddress);
                spawnIni.SetIntValue("Other" + i, "Port", otherPlayer.Port);
            }

            WriteSpawnIniAdditions(spawnIni);
            spawnIni.WriteIniFile();

            File.Delete(ProgramConstants.GamePath + "spawnmap.ini");
            StreamWriter sw = new StreamWriter(ProgramConstants.GamePath + "spawnmap.ini");

            sw.WriteLine("[Map]");
            sw.WriteLine("Size=0,0,50,50");
            sw.WriteLine("LocalSize=0,0,50,50");
            sw.WriteLine();
            sw.Close();

            gameLoadTime = DateTime.Now;

            string saveFilePath = ProgramConstants.GamePath + MultiplayerSaveGameManager.SAVED_GAMES_MP_DIRECTORY + "/" + sgFileName;
            string metaFilePath = Path.ChangeExtension(saveFilePath, GameSessionManager.SavedGameMetaExtension);
            var    meta         = GameSessionInfo.ParseFromFile(metaFilePath);

            if (meta == null)
            {
                XNAMessageBox.Show(WindowManager, "Failed to load saved multiplayer game", "Failed to load saved game: saved game meta could not be parsed!");
                return;
            }

            var gameSessionInfo = new GameSessionManager(new GameSessionInfo(GameSessionType.MULTIPLAYER, meta.UniqueId), WindowManager.AddCallback);

            gameSessionInfo.StartSession();
            GameProcessLogic.GameProcessExited += SharedUILogic_GameProcessExited;
            GameProcessLogic.StartGameProcess(gameSessionInfo);

            UpdateDiscordPresence(true);
        }