296 lines
9.2 KiB
C#
296 lines
9.2 KiB
C#
using UnityEngine;
|
|
using System;
|
|
using UnityEngine.Events;
|
|
using System.Collections;
|
|
|
|
|
|
public class MainHouseP2Manager : MonoBehaviour
|
|
{
|
|
public enum MainHousePart2State
|
|
{
|
|
CheckLoad,
|
|
LongHallwayBeforeDanielOffice,
|
|
DanielOffice,
|
|
AfterDanielOfficePuzzle
|
|
}
|
|
|
|
[SerializeField] private Transform playerStartPosition;
|
|
[SerializeField] private GameObject puzzleGameObject;
|
|
[SerializeField] private GameObject puzzleSolvedEffects;
|
|
|
|
[SerializeField] SaveableObjectsOnSceneManager saveableObjectsOnSceneManager;
|
|
|
|
[SerializeField] MainHouseP1EventsData mainHouseP1EventsData;
|
|
[SerializeField] MainHouseP1StatesData mainHouseP1StatesData;
|
|
[SerializeField] MainHouseP1Triggers mainHouseP1Triggers;
|
|
[SerializeField] MainHouseP1Objects mainHouseP1Objects;
|
|
|
|
public bool isLoadingMainHouseP2Related;
|
|
public MainHousePart2State mainHousePart1State = MainHousePart2State.CheckLoad;
|
|
|
|
private void Awake()
|
|
{
|
|
GameManager.GetInstance().mainHouseP2Manager = this;
|
|
if (LoadManager.GetInstance().LoadingGame)
|
|
{
|
|
isLoadingMainHouseP2Related = true;
|
|
}
|
|
}
|
|
|
|
public void Activate()
|
|
{
|
|
Debug.Log("Main House Part 2 Manager Activated: Initializing events.");
|
|
TryLoadSavedState();
|
|
UpdateStoryline();
|
|
}
|
|
|
|
public void Deactivate()
|
|
{
|
|
Debug.Log("Main House Part 2 Manager Deactivated.");
|
|
|
|
StopAllCoroutines();
|
|
CleanupPlayerSettings();
|
|
SaveStorylineState();
|
|
NotifyCompletion();
|
|
}
|
|
|
|
public void LoadMainHouseP2Related()
|
|
{
|
|
foreach (var saveableObject in saveableObjectsOnSceneManager.SaveableObjects)
|
|
{
|
|
if (saveableObject.IsSetActiveTrueAfterLoad == true)
|
|
{
|
|
saveableObject.gameObject.SetActive(true);
|
|
}
|
|
else
|
|
{
|
|
saveableObject.gameObject.SetActive(false);
|
|
}
|
|
}
|
|
|
|
//foreach (var saveableDoor in saveableObjectsOnSceneManager.SaveableDoors)
|
|
//{
|
|
// if (saveableDoor.IsLockedAfterLoad == true)
|
|
// {
|
|
// saveableDoor.doorBehaviour.DoorRequiresKey = true;
|
|
// print("SAVEABLE DOOR REQUIRES KEY BRUH");
|
|
// }
|
|
// else
|
|
// {
|
|
// saveableDoor.doorBehaviour.DoorRequiresKey = false;
|
|
// print("SAVEABLE DOOR DOESNT REQUIRE KEY BRUH");
|
|
// }
|
|
//}
|
|
print("Successfully loaded main house p2 related");
|
|
}
|
|
|
|
public void UpdateStoryline()
|
|
{
|
|
switch (mainHousePart1State)
|
|
{
|
|
case MainHousePart2State.CheckLoad:
|
|
TryLoadSavedState();
|
|
break;
|
|
case MainHousePart2State.LongHallwayBeforeDanielOffice:
|
|
if (isLoadingMainHouseP2Related)
|
|
{
|
|
isLoadingMainHouseP2Related = false;
|
|
}
|
|
SaveStorylineState();
|
|
break;
|
|
case MainHousePart2State.DanielOffice:
|
|
if (isLoadingMainHouseP2Related)
|
|
{
|
|
isLoadingMainHouseP2Related = false;
|
|
}
|
|
SaveStorylineState();
|
|
break;
|
|
case MainHousePart2State.AfterDanielOfficePuzzle:
|
|
if (isLoadingMainHouseP2Related)
|
|
{
|
|
isLoadingMainHouseP2Related = false;
|
|
}
|
|
SaveStorylineState();
|
|
break;
|
|
}
|
|
LoadMainHouseP2Related();
|
|
}
|
|
|
|
public void UpdateToNextStorylineState()
|
|
{
|
|
MainHousePart2State[] allStates = (MainHousePart2State[])Enum.GetValues(typeof(MainHousePart2State));
|
|
int currentIndex = Array.IndexOf(allStates, mainHousePart1State);
|
|
|
|
if (currentIndex < allStates.Length - 1)
|
|
{
|
|
mainHousePart1State = allStates[currentIndex + 1];
|
|
UpdateStoryline();
|
|
}
|
|
else
|
|
{
|
|
Debug.Log("Main House Part 2 storyline is complete.");
|
|
NotifyCompletion();
|
|
}
|
|
}
|
|
|
|
private void HandleCheckLoadState()
|
|
{
|
|
if (IsInitialCutscenePlayed())
|
|
{
|
|
print("Try Load Saved State");
|
|
TryLoadSavedState();
|
|
}
|
|
else //If started new game for the first time:
|
|
{
|
|
print("New game started");
|
|
PlayInitialCutscene();
|
|
//SetupPlayer(playerNewGameStartPosition, enableCameraCarMovement: false, enablePlayerController: true,
|
|
// pocketWatchIsObtained: true);
|
|
UpdateStoryline();
|
|
}
|
|
}
|
|
private bool IsInitialCutscenePlayed() => GameProgressManager.GetInstance().initialCutscenePlayed;
|
|
|
|
private void HandlePuzzlePhase()
|
|
{
|
|
Debug.Log("Setting up Puzzle phase...");
|
|
|
|
puzzleGameObject.SetActive(true);
|
|
|
|
if (isLoadingMainHouseP2Related)
|
|
{
|
|
// Re-enable puzzle components if needed
|
|
isLoadingMainHouseP2Related = false;
|
|
}
|
|
|
|
SaveStorylineState();
|
|
}
|
|
|
|
private void PlayInitialCutscene()
|
|
{
|
|
Debug.Log("Playing initial cutscene...");
|
|
SetInitialCutscenePlayed(true);
|
|
var gameProgressManager = GameProgressManager.GetInstance();
|
|
gameProgressManager.playerControllerShouldBeEnabledOnGameLoad = false;
|
|
gameProgressManager.playerCameraControllerShouldBeEnabledOnGameLoad = true;
|
|
}
|
|
private void SetInitialCutscenePlayed(bool value) => GameProgressManager.GetInstance().initialCutscenePlayed = value;
|
|
|
|
private void HandleAfterPuzzlePhase()
|
|
{
|
|
Debug.Log("Setting up After Puzzle phase...");
|
|
|
|
puzzleGameObject.SetActive(false);
|
|
if (puzzleSolvedEffects != null)
|
|
{
|
|
puzzleSolvedEffects.SetActive(true);
|
|
}
|
|
|
|
// Trigger post-puzzle events
|
|
TriggerPostPuzzleEvents();
|
|
SaveStorylineState();
|
|
NotifyCompletion();
|
|
}
|
|
|
|
private void SaveStorylineState()
|
|
{
|
|
GameProgressManager.GetInstance().currentStorylineState = mainHousePart1State.ToString();
|
|
}
|
|
|
|
private void TryLoadSavedState()
|
|
{
|
|
if (Enum.TryParse(GameProgressManager.GetInstance().currentStorylineState, out MainHousePart2State parsedState))
|
|
{
|
|
mainHousePart1State = parsedState;
|
|
Debug.Log($"Loaded saved state for Main House Part 2: {mainHousePart1State}");
|
|
UpdateStoryline();
|
|
}
|
|
else
|
|
{
|
|
Debug.LogWarning("Invalid saved state for Main House Part 2. Defaulting to LongHallwayBeforeDanielOffice.");
|
|
mainHousePart1State = MainHousePart2State.LongHallwayBeforeDanielOffice;
|
|
}
|
|
}
|
|
|
|
private void SetupPlayer(Transform newPosition, bool enablePlayerController)
|
|
{
|
|
var playerManager = PlayerManager.GetInstance();
|
|
if (playerManager == null)
|
|
{
|
|
Debug.LogError("PlayerManager instance is missing!");
|
|
return;
|
|
}
|
|
|
|
playerManager.DisablePlayerMovement();
|
|
playerManager.playerGameObj.transform.position = newPosition.position;
|
|
playerManager.playerGameObj.transform.rotation = newPosition.rotation;
|
|
|
|
var gameProgressManager = GameProgressManager.GetInstance();
|
|
gameProgressManager.playerControllerShouldBeEnabledOnGameLoad = enablePlayerController;
|
|
}
|
|
|
|
private void CleanupPlayerSettings()
|
|
{
|
|
var playerManager = PlayerManager.GetInstance();
|
|
if (playerManager != null)
|
|
{
|
|
playerManager.DisablePlayerMovement();
|
|
}
|
|
|
|
// Add additional cleanup logic here if needed
|
|
}
|
|
|
|
private void TriggerPostPuzzleEvents()
|
|
{
|
|
Debug.Log("Triggering post-puzzle events...");
|
|
// Implement logic for events triggered after the puzzle is solved.
|
|
// For example:
|
|
// UnlockNextArea();
|
|
// ShowCompletionCutscene();
|
|
}
|
|
|
|
private void NotifyCompletion()
|
|
{
|
|
GameManager.GetInstance().OnStorySectionComplete(GameManager.StoryState.MainHousePart1);
|
|
}
|
|
|
|
public void ActivatePlayersSanity()
|
|
{
|
|
PlayerManager.GetInstance().playerSanity.enabled = true;
|
|
GameProgressManager.GetInstance().playerSanityShouldBeEnabledOnGameLoad = true;
|
|
}
|
|
}
|
|
[Serializable]
|
|
public class MainHouseP2EventsData
|
|
{
|
|
public UnityEvent beforeDiscoveringPortraitPuzzle;
|
|
public UnityEvent afterCleanedPortraitPuzzleDust;
|
|
public UnityEvent BeforePlayerObtainsPocketWatchEvent;
|
|
public UnityEvent AfterPlayerObtainsPocketWatchEvent;
|
|
public UnityEvent LibraryPuzzleTimeEventsEvent;
|
|
public UnityEvent LibraryPuzzleStandColumnsEventAfterBooksPuzzle;
|
|
public UnityEvent AfterLibraryMedallionsPuzzleSolutionEvent;
|
|
public UnityEvent AfterPadlockPortraitPuzzleSolutionEvent;
|
|
}
|
|
[Serializable]
|
|
public class MainHouseP2StatesData
|
|
{
|
|
public GameObject PrologueOnStorySectionComplete_PrologueCompleted;
|
|
public GameObject BeforeObtainingKeyFromStatueTrigger;
|
|
public GameObject BeforeTriggeredLibraryPuzzleTrigger;
|
|
}
|
|
[Serializable]
|
|
public class MainHouseP2Triggers
|
|
{
|
|
public GameObject MainDoorCloseAndBrokenTrigger;
|
|
public GameObject ActivateStatuesAITrigger;
|
|
}
|
|
[Serializable]
|
|
public class MainHouseP2Objects
|
|
{
|
|
public GameObject FamilyPortraitBeforeSave;
|
|
public GameObject FamilyPortraitAfterSave;
|
|
}
|
|
|
|
|