/// <summary> /// Writes puzzles done in a .txt /// </summary> /// <param name="player">PlayerGeneralInfo to know puzzles done /// information</param> public void AddToTxt(PlayerGeneralInfo player) { using (StreamWriter sw = File.CreateText(path)) { sw.WriteLine(player.PuzzlesDone); } }
/// <summary> /// Abstract method to execute a certain action /// Plays victory or gives a certain objet to the player /// Adds a puzzle done to PlayerGeneralInfo and writes to txt /// </summary> public override void Execute() { // Adds puzzle to player's puzzles done PlayerGeneralInfo playerInfo = FindObjectOfType <PlayerGeneralInfo>(); playerInfo.PuzzlesDone |= puzzleName; // Writes puzzles done to a txt FileWriter writer = new FileWriter(FilePath.puzzlePath); writer.AddToTxt(playerInfo); // Does an action to complete the puzzle switch (assistModeType) { case AssistModeType.PlayVictory: if (puzzleVariable != null) { base.ExecuteVictory(puzzleVariable); } break; case AssistModeType.AddPrizeToInventory: base.AddPrizeToInventory(); break; } }
/// <summary> /// Awake method for PuzzleBase. Subclasses must not use Awake method /// or it will cancel this awake method. /// </summary> private void Awake() { player = FindObjectOfType <PlayerGeneralInfo>(); inventory = FindObjectOfType <Inventory>(); // Reads the file after 0.25 seconds // This 0.25 delay is used as a safe precaution, so it always happens // after everything started in the room if (readPuzzlesDoneTxtCoroutine == null) { readPuzzlesDoneTxtCoroutine = StartCoroutine(ReadPuzzlesDoneTxt()); } }
private void Start() { _playerInfo = GetComponent <PlayerGeneralInfo>(); if (!GetComponent <PhotonView>().IsMine) { enabled = false; return; } _gameNetwork = InGameCommon.CurrentGame.GetComponent <PhotonView>(); _cooldownValue = Cooldown; CreateAbilityBar(); }
/// <summary> /// Coroutine used to get next line from DialogText. /// This Coroutine also checks NPC's conditions to know if it can /// give items, or open a locked door /// </summary> /// <returns>Returns null</returns> private IEnumerator GetNextAction() { StartCoroutine(dialog.GetNextLine()); yield return(waitForSecs); // If player has a not rewound audio tape if (dialog.OpenDoor) { doorToOpen.SetTrigger("Open Door"); PlayerGeneralInfo player = FindObjectOfType <PlayerGeneralInfo>(); // Adds mypuzzle to player's puzzles done player.PuzzlesDone |= PuzzlesEnum.Puzzle2; // Save puzzle to txt, so the txt will know which puzzles the player // has alreayd done FileWriter fw = new FileWriter(FilePath.puzzlePath); fw.AddToTxt(player); } // Give a map on the first time speaking else if (speakCounter == 0) { Inventory inventory = FindObjectOfType <Inventory>(); inventory.Bag.Add(itemComparer.Map); speakCounter++; } else { speakCounter++; } // If speakcounter reaches max number of texts, resets the text // to a certain value if (speakCounter == dialog.LinesOfText.Length) { speakCounter = 1; } // Sets the coroutine to false so it can be called again ThisCoroutine = default; // Changes type of input input.ChangeTypeOfControl(TypeOfControl.InGameplay); yield break; }
/// <summary> /// Reads puzzles done from a .txt /// </summary> /// <param name="player">PlayerGeneralInfo to know puzzles done /// information</param> public void ReadFromTXT(PlayerGeneralInfo player) { using (StreamReader sr = File.OpenText(path)) { char[] charsToSplit = { ',', ' ' }; string[] strs = sr.ReadLine().Split(charsToSplit); foreach (string str in strs) { // If puzzle is in PuzzlesEnum, returns result and adds it to // player.PuzzlesDone if (PuzzlesEnum.TryParse(str, out PuzzlesEnum result)) { player.PuzzlesDone |= result; } } } }
/// <summary> /// Awake method for InteractionDoorWithCode /// </summary> private void Awake() => playerInfo = FindObjectOfType <PlayerGeneralInfo>();