diff --git a/Assets/Scripts/Core/DataReader/Ini/CombatCameraConfigFileReader.cs b/Assets/Scripts/Core/DataReader/Ini/CombatCameraConfigFileReader.cs index f49264df..13febb2d 100644 --- a/Assets/Scripts/Core/DataReader/Ini/CombatCameraConfigFileReader.cs +++ b/Assets/Scripts/Core/DataReader/Ini/CombatCameraConfigFileReader.cs @@ -15,17 +15,18 @@ namespace Core.DataReader.Ini public sealed class CombatCameraConfigFileReader : IFileReader { private const string DEFAULT_CAM_SECTION_HEADER_PREFIX = "DefaultCam"; + private const int DEFAULT_CODEPAGE = 936; - public CombatCameraConfigFile Read(IBinaryReader reader, int codepage) + public CombatCameraConfigFile Read(IBinaryReader reader, int _) { throw new NotImplementedException(); } - public CombatCameraConfigFile Read(byte[] data, int codepage) + public CombatCameraConfigFile Read(byte[] data, int _) { var parser = new FileIniDataParser(); using var stream = new MemoryStream(data); - using var reader = new StreamReader(stream, Encoding.GetEncoding(codepage)); + using var reader = new StreamReader(stream, Encoding.GetEncoding(DEFAULT_CODEPAGE)); IniData iniData = parser.ReadData(reader); diff --git a/Assets/Scripts/Core/DataReader/Txt/CombatScnFileReader.cs b/Assets/Scripts/Core/DataReader/Txt/CombatScnFileReader.cs index 0394dec2..2911380d 100644 --- a/Assets/Scripts/Core/DataReader/Txt/CombatScnFileReader.cs +++ b/Assets/Scripts/Core/DataReader/Txt/CombatScnFileReader.cs @@ -13,7 +13,7 @@ namespace Core.DataReader.Txt public sealed class CombatScnFileReader : IFileReader { - private const int COMBAT_SCN_FILE_CODEPAGE = 936; + private const int DEFAULT_CODEPAGE = 936; public CombatScnFile Read(IBinaryReader reader, int _) { @@ -22,7 +22,7 @@ namespace Core.DataReader.Txt public CombatScnFile Read(byte[] data, int _) { - var content = Encoding.GetEncoding(COMBAT_SCN_FILE_CODEPAGE).GetString(data, 0, data.Length); + var content = Encoding.GetEncoding(DEFAULT_CODEPAGE).GetString(data, 0, data.Length); var lines = content.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries); string currentCombatSceneName = string.Empty; diff --git a/Assets/Scripts/Pal3/Actor/Controllers/ActorController.cs b/Assets/Scripts/Pal3/Actor/Controllers/ActorController.cs index 93f85863..3e4e10c8 100644 --- a/Assets/Scripts/Pal3/Actor/Controllers/ActorController.cs +++ b/Assets/Scripts/Pal3/Actor/Controllers/ActorController.cs @@ -178,12 +178,14 @@ namespace Pal3.Actor.Controllers .GetPlayerActor() == actorController.GetActor().Info.Id) { // Player actor collides with combat NPC in maze - CommandDispatcher.Instance.Dispatch( new ActorActivateCommand(_actor.Info.Id, 0)); if (ServiceLocator.Instance.Get().IsTurnBasedCombatEnabled) { + CommandDispatcher.Instance.Dispatch( + new ActorStopActionAndStandCommand(ActorConstants.PlayerActorVirtualID)); + CommandDispatcher.Instance.Dispatch( new CombatEnterNormalFightCommand( _actor.Info.NumberOfMonsters, diff --git a/Assets/Scripts/Pal3/Audio/AudioManager.cs b/Assets/Scripts/Pal3/Audio/AudioManager.cs index e88d3479..93e32d69 100644 --- a/Assets/Scripts/Pal3/Audio/AudioManager.cs +++ b/Assets/Scripts/Pal3/Audio/AudioManager.cs @@ -432,8 +432,11 @@ namespace Pal3.Audio _currentScriptMusic = string.Empty; _currentMusicClipName = string.Empty; - ScnSceneInfo sceneInfo = _sceneManager.GetCurrentScene().GetSceneInfo(); - Pal3.Instance.StartCoroutine(PlaySceneMusicAsync(sceneInfo.CityName, sceneInfo.SceneName)); + if (_sceneManager.GetCurrentScene() is {} scene) + { + ScnSceneInfo sceneInfo = scene.GetSceneInfo(); + Pal3.Instance.StartCoroutine(PlaySceneMusicAsync(sceneInfo.CityName, sceneInfo.SceneName)); + } } public void Execute(ScenePreLoadingNotification command) diff --git a/Assets/Scripts/Pal3/Combat/CombatContext.cs b/Assets/Scripts/Pal3/Combat/CombatContext.cs index 073ef89e..3fdf25c6 100644 --- a/Assets/Scripts/Pal3/Combat/CombatContext.cs +++ b/Assets/Scripts/Pal3/Combat/CombatContext.cs @@ -6,12 +6,14 @@ namespace Pal3.Combat { using Core.DataReader.Gdb; + using Script.Waiter; /// /// Data contract for combat context. /// public sealed class CombatContext { + public WaitUntilCanceled ScriptWaiter { get; private set; } public string CombatSceneName { get; private set; } public ElementType CombatSceneElementType { get; private set; } public string CombatMusicName { get; private set; } @@ -25,6 +27,11 @@ namespace Pal3.Combat ResetContext(); } + public void SetScriptWaiter(WaitUntilCanceled scriptWaiter) + { + ScriptWaiter = scriptWaiter; + } + public void SetCombatSceneName(string combatSceneName) { CombatSceneName = combatSceneName; @@ -76,6 +83,7 @@ namespace Pal3.Combat public void ResetContext() { + ScriptWaiter = null; CombatSceneName = string.Empty; CombatSceneElementType = ElementType.None; CombatMusicName = string.Empty; @@ -87,7 +95,8 @@ namespace Pal3.Combat public override string ToString() { - return $"CombatContext: CombatScene: {CombatSceneName} " + + return $"CombatContext: " + + $"CombatScene: {CombatSceneName} " + $"ElementType: {CombatSceneElementType} " + $"CombatMusic: {CombatMusicName} " + $"MaxRound: {MaxRound} " + diff --git a/Assets/Scripts/Pal3/Combat/CombatCoordinator.cs b/Assets/Scripts/Pal3/Combat/CombatCoordinator.cs index a194651d..8ce51b48 100644 --- a/Assets/Scripts/Pal3/Combat/CombatCoordinator.cs +++ b/Assets/Scripts/Pal3/Combat/CombatCoordinator.cs @@ -15,13 +15,16 @@ namespace Pal3.Combat using Command.SceCommands; using Core.DataReader.Gdb; using Core.DataReader.Nav; + using Core.DataReader.Scn; using Core.DataReader.Txt; using Core.Utils; using Data; using GamePlay; using MetaData; using Scene; + using Script.Waiter; using Settings; + using State; using UnityEngine; using Random = System.Random; @@ -33,6 +36,7 @@ namespace Pal3.Combat ICommandExecutor, #if PAL3A ICommandExecutor, + ICommandExecutor, #endif ICommandExecutor, ICommandExecutor, @@ -46,6 +50,7 @@ namespace Pal3.Combat private readonly PlayerActorManager _playerActorManager; private readonly AudioManager _audioManager; private readonly SceneManager _sceneManager; + private readonly GameStateManager _gameStateManager; private readonly CombatScnFile _combatScnFile; private readonly CombatContext _currentCombatContext = new(); @@ -55,7 +60,8 @@ namespace Pal3.Combat CombatManager combatManager, PlayerActorManager playerActorManager, AudioManager audioManager, - SceneManager sceneManager) + SceneManager sceneManager, + GameStateManager gameStateManager) { Requires.IsNotNull(resourceProvider, nameof(resourceProvider)); _gameSettings = Requires.IsNotNull(gameSettings, nameof(gameSettings)); @@ -63,15 +69,18 @@ namespace Pal3.Combat _playerActorManager = Requires.IsNotNull(playerActorManager, nameof(playerActorManager)); _audioManager = Requires.IsNotNull(audioManager, nameof(audioManager)); _sceneManager = Requires.IsNotNull(sceneManager, nameof(sceneManager)); + _gameStateManager = Requires.IsNotNull(gameStateManager, nameof(gameStateManager)); _combatScnFile = resourceProvider.GetGameResourceFile( FileConstants.DataScriptFolderVirtualPath + COMBAT_SCN_FILE_NAME); + _combatManager.OnCombatFinished += OnOnCombatFinished; CommandExecutorRegistry.Instance.Register(this); } public void Dispose() { + _combatManager.OnCombatFinished -= OnOnCombatFinished; CommandExecutorRegistry.Instance.UnRegister(this); } @@ -105,12 +114,39 @@ namespace Pal3.Combat } } + // Check current state and add script waiter to pause script execution + // if we are in cutscene state. + if (_gameStateManager.GetCurrentState() == GameState.Cutscene) + { + var combatWaiter = new WaitUntilCanceled(); + CommandDispatcher.Instance.Dispatch( + new ScriptRunnerAddWaiterRequest(combatWaiter)); + _currentCombatContext.SetScriptWaiter(combatWaiter); + } + // Start combat Debug.LogWarning($"[{nameof(CombatCoordinator)}] Starting combat with context: {_currentCombatContext}"); + _gameStateManager.TryGoToState(GameState.Combat); _combatManager.EnterCombat(_currentCombatContext); + } - // Reset combat context - _currentCombatContext.ResetContext(); + private void OnOnCombatFinished(object sender, bool isPlayerWin) + { + if (isPlayerWin) + { + // Stop combat music + CommandDispatcher.Instance.Dispatch(new StopMusicCommand()); + + _sceneManager.UnloadCombatScene(); + _currentCombatContext.ScriptWaiter?.CancelWait(); + + _gameStateManager.GoToPreviousState(); + _currentCombatContext.ResetContext(); + } + else + { + CommandDispatcher.Instance.Dispatch(new GameSwitchToMainMenuCommand()); + } } private string GetCombatSceneName(Scene currentScene) @@ -219,6 +255,20 @@ namespace Pal3.Combat _currentCombatContext.SetCombatMusicName(command.CombatMusicName); StartCombat(); } + + public void Execute(CombatEnterBossFightUsingMusicWithSpecialActorCommand command) + { + _currentCombatContext.SetMonsterIds( + command.Monster1Id, + command.Monster2Id, + command.Monster3Id, + command.Monster4Id, + command.Monster5Id, + command.Monster6Id); + _currentCombatContext.SetCombatMusicName(command.CombatMusicName); + // TODO: NanGoongHuang enter fight using wolf state + StartCombat(); + } #endif public void Execute(CombatSetUnbeatableCommand command) diff --git a/Assets/Scripts/Pal3/Combat/CombatManager.cs b/Assets/Scripts/Pal3/Combat/CombatManager.cs index be643206..001f9151 100644 --- a/Assets/Scripts/Pal3/Combat/CombatManager.cs +++ b/Assets/Scripts/Pal3/Combat/CombatManager.cs @@ -5,7 +5,7 @@ namespace Pal3.Combat { - using Audio; + using System; using Command; using Command.SceCommands; using Core.DataReader.Ini; @@ -16,9 +16,12 @@ namespace Pal3.Combat using Scene; using State; using UnityEngine; + using UnityEngine.InputSystem; public sealed class CombatManager { + public event EventHandler OnCombatFinished; + private const string COMBAT_CONFIG_FILE_NAME = "combat.ini"; private const string COMBAT_CAMERA_CONFIG_FILE_NAME = "cbCam.ini"; @@ -32,15 +35,17 @@ namespace Pal3.Combat private readonly CombatConfigFile _combatConfigFile; private readonly CombatCameraConfigFile _combatCameraConfigFile; + private Vector3 _cameraPositionBeforeCombat; + private Quaternion _cameraRotationBeforeCombat; + private float _cameraFovBeforeCombat; + public CombatManager(GameResourceProvider resourceProvider, Camera mainCamera, - SceneManager sceneManager, - GameStateManager gameStateManager) + SceneManager sceneManager) { _resourceProvider = Requires.IsNotNull(resourceProvider, nameof(resourceProvider)); _mainCamera = Requires.IsNotNull(mainCamera, nameof(mainCamera)); _sceneManager = Requires.IsNotNull(sceneManager, nameof(sceneManager)); - _gameStateManager = Requires.IsNotNull(gameStateManager, nameof(gameStateManager)); _combatConfigFile = _resourceProvider.GetGameResourceFile( FileConstants.DataScriptFolderVirtualPath + COMBAT_CONFIG_FILE_NAME); @@ -50,9 +55,12 @@ namespace Pal3.Combat public void EnterCombat(CombatContext combatContext) { - CommandDispatcher.Instance.Dispatch(new CameraFollowPlayerCommand(0)); + _mainCamera.transform.GetPositionAndRotation(out _cameraPositionBeforeCombat, + out _cameraRotationBeforeCombat); + _cameraFovBeforeCombat = _mainCamera.fieldOfView; - _gameStateManager.TryGoToState(GameState.Combat); + CommandDispatcher.Instance.Dispatch(new CameraFollowPlayerCommand(0)); + CommandDispatcher.Instance.Dispatch(new CameraFadeInCommand()); _sceneManager.LoadCombatScene(combatContext.CombatSceneName); @@ -67,9 +75,11 @@ namespace Pal3.Combat private void SetCameraPosition(CombatCameraConfig config) { - _mainCamera.transform.position = GameBoxInterpreter.ToUnityPosition( + var cameraPosition = GameBoxInterpreter.ToUnityPosition( new Vector3(config.GameBoxPositionX, config.GameBoxPositionY, config.GameBoxPositionZ)); + _mainCamera.transform.position = cameraPosition; + // _mainCamera.transform.rotation = GameBoxInterpreter.ToUnityRotation( // config.Pitch, config.Yaw, config.Roll); @@ -77,9 +87,25 @@ namespace Pal3.Combat _mainCamera.fieldOfView = COMBAT_CAMERA_DEFAULT_FOV; } + private void ResetCameraPosition() + { + _mainCamera.transform.SetPositionAndRotation(_cameraPositionBeforeCombat, + _cameraRotationBeforeCombat); + _mainCamera.fieldOfView = _cameraFovBeforeCombat; + } + public void Update(float deltaTime) { - + if (Keyboard.current.f1Key.wasPressedThisFrame) + { + ResetCameraPosition(); + OnCombatFinished?.Invoke(this, true); + } + else if (Keyboard.current.f2Key.wasPressedThisFrame) + { + ResetCameraPosition(); + OnCombatFinished?.Invoke(this, false); + } } } } \ No newline at end of file diff --git a/Assets/Scripts/Pal3/Command/ConsoleCommands.PAL3.g.cs b/Assets/Scripts/Pal3/Command/ConsoleCommands.PAL3.g.cs index b98f3ba8..03882e2c 100644 --- a/Assets/Scripts/Pal3/Command/ConsoleCommands.PAL3.g.cs +++ b/Assets/Scripts/Pal3/Command/ConsoleCommands.PAL3.g.cs @@ -792,11 +792,11 @@ namespace Pal3.Command } // - [ConsoleMethodAttribute("SceneLoad", "切换场景,参数:场景关(文件)名称,场景区块名称")] - public static void SceneLoad(System.String sceneFileName, System.String sceneName) + [ConsoleMethodAttribute("SceneLoad", "切换场景,参数:场景城市/关卡(文件)名称,场景名称")] + public static void SceneLoad(System.String sceneCityName, System.String sceneName) { CommandDispatcher.Instance.Dispatch( - new SceneLoadCommand(sceneFileName, sceneName)); + new SceneLoadCommand(sceneCityName, sceneName)); } // diff --git a/Assets/Scripts/Pal3/Command/ConsoleCommands.PAL3A.g.cs b/Assets/Scripts/Pal3/Command/ConsoleCommands.PAL3A.g.cs index 2ee63c6f..f40e7ffd 100644 --- a/Assets/Scripts/Pal3/Command/ConsoleCommands.PAL3A.g.cs +++ b/Assets/Scripts/Pal3/Command/ConsoleCommands.PAL3A.g.cs @@ -471,6 +471,14 @@ namespace Pal3.Command new CombatEnterBossFightUsingMusicCommand(monster1Id, monster2Id, monster3Id, monster4Id, monster5Id, monster6Id, combatMusicName)); } + // + [ConsoleMethodAttribute("CombatEnterBossFightUsingMusicWithSpecialActor", "南宫煌以变身状态下进入Boss战斗")] + public static void CombatEnterBossFightUsingMusicWithSpecialActor(System.UInt32 monster1Id, System.UInt32 monster2Id, System.UInt32 monster3Id, System.UInt32 monster4Id, System.UInt32 monster5Id, System.UInt32 monster6Id, System.String combatMusicName, System.Int32 combatCommandId) + { + CommandDispatcher.Instance.Dispatch( + new CombatEnterBossFightUsingMusicWithSpecialActorCommand(monster1Id, monster2Id, monster3Id, monster4Id, monster5Id, monster6Id, combatMusicName, combatCommandId)); + } + // [ConsoleMethodAttribute("CombatEnterNormalFight", "进入普通战斗")] public static void CombatEnterNormalFight(System.UInt32 numberOfMonster, System.UInt32 monster1Id, System.UInt32 monster2Id, System.UInt32 monster3Id) @@ -784,11 +792,11 @@ namespace Pal3.Command } // - [ConsoleMethodAttribute("SceneLoad", "切换场景,参数:场景关(文件)名称,场景区块名称")] - public static void SceneLoad(System.String sceneFileName, System.String sceneName) + [ConsoleMethodAttribute("SceneLoad", "切换场景,参数:场景城市/关卡(文件)名称,场景名称")] + public static void SceneLoad(System.String sceneCityName, System.String sceneName) { CommandDispatcher.Instance.Dispatch( - new SceneLoadCommand(sceneFileName, sceneName)); + new SceneLoadCommand(sceneCityName, sceneName)); } // @@ -1223,14 +1231,6 @@ namespace Pal3.Command new UnknownCommand185(unknown1, unknown2, unknown3, unknown4, unknown5, unknown6, unknown7, unknown8)); } - // - [ConsoleMethodAttribute("Unknown192", "南宫煌以变身状态下进入Boss战斗?")] - public static void Unknown192(System.UInt32 monster1Id, System.UInt32 monster2Id, System.UInt32 monster3Id, System.UInt32 monster4Id, System.UInt32 monster5Id, System.UInt32 monster6Id, System.String combatMusic, System.Int32 unknown) - { - CommandDispatcher.Instance.Dispatch( - new UnknownCommand192(monster1Id, monster2Id, monster3Id, monster4Id, monster5Id, monster6Id, combatMusic, unknown)); - } - // [ConsoleMethodAttribute("Unknown193", "???")] public static void Unknown193(System.Int32 unknown1, System.Int32 unknown2) diff --git a/Assets/Scripts/Pal3/Command/SceCommands/UnknownCommand192.cs b/Assets/Scripts/Pal3/Command/SceCommands/CombatEnterBossFightUsingMusicWithSpecialActorCommand.cs similarity index 73% rename from Assets/Scripts/Pal3/Command/SceCommands/UnknownCommand192.cs rename to Assets/Scripts/Pal3/Command/SceCommands/CombatEnterBossFightUsingMusicWithSpecialActorCommand.cs index f756d9e0..f0fddb22 100644 --- a/Assets/Scripts/Pal3/Command/SceCommands/UnknownCommand192.cs +++ b/Assets/Scripts/Pal3/Command/SceCommands/CombatEnterBossFightUsingMusicWithSpecialActorCommand.cs @@ -7,18 +7,18 @@ namespace Pal3.Command.SceCommands { #if PAL3A [AvailableInConsole] - [SceCommand(192, "南宫煌以变身状态下进入Boss战斗?")] - public class UnknownCommand192 : ICommand + [SceCommand(192, "南宫煌以变身状态下进入Boss战斗")] + public class CombatEnterBossFightUsingMusicWithSpecialActorCommand : ICommand { - public UnknownCommand192( + public CombatEnterBossFightUsingMusicWithSpecialActorCommand( uint monster1Id, uint monster2Id, uint monster3Id, uint monster4Id, uint monster5Id, uint monster6Id, - string combatMusic, - int unknown) + string combatMusicName, + int combatCommandId) { Monster1Id = monster1Id; Monster2Id = monster2Id; @@ -26,8 +26,8 @@ namespace Pal3.Command.SceCommands Monster4Id = monster4Id; Monster5Id = monster5Id; Monster6Id = monster6Id; - CombatMusic = combatMusic; - Unknown = unknown; + CombatMusicName = combatMusicName; + CombatCommandId = combatCommandId; } public uint Monster1Id { get; } @@ -36,8 +36,8 @@ namespace Pal3.Command.SceCommands public uint Monster4Id { get; } public uint Monster5Id { get; } public uint Monster6Id { get; } - public string CombatMusic { get; } - public int Unknown { get; } + public string CombatMusicName { get; } + public int CombatCommandId { get; } } #endif } \ No newline at end of file diff --git a/Assets/Scripts/Pal3/Command/SceCommands/UnknownCommand192.cs.meta b/Assets/Scripts/Pal3/Command/SceCommands/CombatEnterBossFightUsingMusicWithSpecialActorCommand.cs.meta similarity index 100% rename from Assets/Scripts/Pal3/Command/SceCommands/UnknownCommand192.cs.meta rename to Assets/Scripts/Pal3/Command/SceCommands/CombatEnterBossFightUsingMusicWithSpecialActorCommand.cs.meta diff --git a/Assets/Scripts/Pal3/Command/SceCommands/SceneLoadCommand.cs b/Assets/Scripts/Pal3/Command/SceCommands/SceneLoadCommand.cs index 7f9ffa45..00237d87 100644 --- a/Assets/Scripts/Pal3/Command/SceCommands/SceneLoadCommand.cs +++ b/Assets/Scripts/Pal3/Command/SceCommands/SceneLoadCommand.cs @@ -7,16 +7,16 @@ namespace Pal3.Command.SceCommands { [AvailableInConsole] [SceCommand(63, "切换场景," + - "参数:场景关(文件)名称,场景区块名称")] + "参数:场景城市/关卡(文件)名称,场景名称")] public class SceneLoadCommand : ICommand { - public SceneLoadCommand(string sceneFileName, string sceneName) + public SceneLoadCommand(string sceneCityName, string sceneName) { - SceneFileName = sceneFileName; + SceneCityName = sceneCityName; SceneName = sceneName; } - public string SceneFileName { get; } + public string SceneCityName { get; } public string SceneName { get; } } } \ No newline at end of file diff --git a/Assets/Scripts/Pal3/GameSystem/HotelManager.cs b/Assets/Scripts/Pal3/GameSystem/HotelManager.cs index 1de7d8cc..e6e76dd7 100644 --- a/Assets/Scripts/Pal3/GameSystem/HotelManager.cs +++ b/Assets/Scripts/Pal3/GameSystem/HotelManager.cs @@ -33,9 +33,9 @@ namespace Pal3.GameSystem CommandExecutorRegistry.Instance.UnRegister(this); } - private void Rest(string sceneFileName, string sceneName, uint afterRestTalkScript) + private void Rest(string sceneCityName, string sceneName, uint afterRestTalkScript) { - _sceneManager.LoadScene(sceneFileName, sceneName); + _sceneManager.LoadScene(sceneCityName, sceneName); CommandDispatcher.Instance.Dispatch(new GameStateChangeRequest(GameState.Cutscene)); CommandDispatcher.Instance.Dispatch(new CameraFadeInCommand()); _scriptManager.AddScript(afterRestTalkScript); diff --git a/Assets/Scripts/Pal3/MetaData/FileConstants.cs b/Assets/Scripts/Pal3/MetaData/FileConstants.cs index 1b7c7154..24ad80ba 100644 --- a/Assets/Scripts/Pal3/MetaData/FileConstants.cs +++ b/Assets/Scripts/Pal3/MetaData/FileConstants.cs @@ -199,35 +199,35 @@ namespace Pal3.MetaData $"{ACTOR_FOLDER_NAME}{DIR_SEPARATOR}{actorName}{DIR_SEPARATOR}"; } - public static string GetNavFileVirtualPath(string sceneFileName, string modelName) + public static string GetNavFileVirtualPath(string sceneCityName, string modelName) { #if PAL3 - var navFilePath = $"{sceneFileName}{CpkConstants.FileExtension}{DIR_SEPARATOR}" + + var navFilePath = $"{sceneCityName}{CpkConstants.FileExtension}{DIR_SEPARATOR}" + $"{modelName}{DIR_SEPARATOR}{modelName}.nav"; #elif PAL3A var navFilePath = $"{SCN_CPK_FILE_NAME}{DIR_SEPARATOR}SCN{DIR_SEPARATOR}" + - $"{sceneFileName}{DIR_SEPARATOR}{modelName}{DIR_SEPARATOR}{modelName}.nav"; + $"{sceneCityName}{DIR_SEPARATOR}{modelName}{DIR_SEPARATOR}{modelName}.nav"; #endif return navFilePath; } - public static string GetScnFileVirtualPath(string sceneFileName, string sceneName) + public static string GetScnFileVirtualPath(string sceneCityName, string sceneName) { #if PAL3 - var scnFilePath = $"{sceneFileName}{CpkConstants.FileExtension}{DIR_SEPARATOR}{sceneName}.scn"; + var scnFilePath = $"{sceneCityName}{CpkConstants.FileExtension}{DIR_SEPARATOR}{sceneName}.scn"; #elif PAL3A var scnFilePath = $"{SCN_CPK_FILE_NAME}{DIR_SEPARATOR}SCN{DIR_SEPARATOR}" + - $"{sceneFileName}{DIR_SEPARATOR}{sceneFileName}_{sceneName}.scn"; + $"{sceneCityName}{DIR_SEPARATOR}{sceneCityName}_{sceneName}.scn"; #endif return scnFilePath; } - public static string GetSceneSceFileVirtualPath(string sceneFileName) + public static string GetSceneSceFileVirtualPath(string sceneCityName) { #if PAL3 - var sceFilePath = $"{sceneFileName}{CpkConstants.FileExtension}{DIR_SEPARATOR}{sceneFileName}.sce"; + var sceFilePath = $"{sceneCityName}{CpkConstants.FileExtension}{DIR_SEPARATOR}{sceneCityName}.sce"; #elif PAL3A - var sceFilePath = $"{SCE_CPK_FILE_NAME}{DIR_SEPARATOR}Sce{DIR_SEPARATOR}{sceneFileName}.sce"; + var sceFilePath = $"{SCE_CPK_FILE_NAME}{DIR_SEPARATOR}Sce{DIR_SEPARATOR}{sceneCityName}.sce"; #endif return sceFilePath; } diff --git a/Assets/Scripts/Pal3/Pal3.cs b/Assets/Scripts/Pal3/Pal3.cs index e31254a0..4751ec4b 100644 --- a/Assets/Scripts/Pal3/Pal3.cs +++ b/Assets/Scripts/Pal3/Pal3.cs @@ -324,11 +324,12 @@ namespace Pal3 ServiceLocator.Instance.Register(_dialogueManager); _combatManager = new CombatManager(_gameResourceProvider, - mainCamera, _sceneManager, _gameStateManager); + mainCamera, _sceneManager); ServiceLocator.Instance.Register(_combatManager); _combatCoordinator = new CombatCoordinator(_gameResourceProvider, - _gameSettings, _combatManager, _playerActorManager, _audioManager, _sceneManager); + _gameSettings, _combatManager, _playerActorManager, + _audioManager, _sceneManager, _gameStateManager); ServiceLocator.Instance.Register(_combatCoordinator); _saveManager = new SaveManager(_sceneManager, _playerActorManager, @@ -467,7 +468,6 @@ namespace Pal3 currentState != GameState.Combat) { _scriptManager.Update(deltaTime); - _playerGamePlayManager.Update(deltaTime); _dialogueManager.Update(deltaTime); } @@ -476,6 +476,7 @@ namespace Pal3 _combatManager.Update(deltaTime); } + _playerGamePlayManager.Update(deltaTime); _informationManager.Update(deltaTime); _renderingSettingsManager.Update(deltaTime); } diff --git a/Assets/Scripts/Pal3/Scene/CombatScene.cs b/Assets/Scripts/Pal3/Scene/CombatScene.cs index baac4739..277c1b22 100644 --- a/Assets/Scripts/Pal3/Scene/CombatScene.cs +++ b/Assets/Scripts/Pal3/Scene/CombatScene.cs @@ -8,7 +8,6 @@ namespace Pal3.Scene using Core.DataLoader; using Core.DataReader.Cpk; using Core.DataReader.Pol; - using Core.DataReader.Scn; using Data; using MetaData; using Rendering.Material; @@ -18,9 +17,8 @@ namespace Pal3.Scene public sealed class CombatScene : MonoBehaviour { private GameResourceProvider _resourceProvider; - private bool _isLightingEnabled; private IMaterialFactory _materialFactory; - private static int _lightCullingMask; + private string _combatSceneName; private GameObject _parent; @@ -29,13 +27,9 @@ namespace Pal3.Scene private (PolFile PolFile, ITextureResourceProvider TextureProvider) _scenePolyMesh; - public void Init(GameResourceProvider resourceProvider, - bool isLightingEnabled) + public void Init(GameResourceProvider resourceProvider) { _resourceProvider = resourceProvider; - _isLightingEnabled = isLightingEnabled; - _lightCullingMask = (1 << LayerMask.NameToLayer("Default")) | - (1 << LayerMask.NameToLayer("VFX")); _materialFactory = resourceProvider.GetMaterialFactory(); } @@ -56,11 +50,6 @@ namespace Pal3.Scene _scenePolyMesh = (polFile, sceneTextureProvider); RenderMesh(); - - if (_isLightingEnabled) - { - SetupEnvironmentLighting(); - } } private void RenderMesh() @@ -80,29 +69,5 @@ namespace Pal3.Scene isStaticObject: true, // Scene mesh is static Color.white); } - - private void SetupEnvironmentLighting() - { - Vector3 mainLightPosition = new Vector3(0, 20f, 0); - Quaternion mainLightRotation = Quaternion.Euler(70f, -30f, 0f); - - var mainLightGo = new GameObject($"LightSource_Main"); - mainLightGo.transform.SetParent(_parent.transform, false); - mainLightGo.transform.SetPositionAndRotation(mainLightPosition, mainLightRotation); - - _mainLight = mainLightGo.AddComponent(); - _mainLight.type = LightType.Directional; - _mainLight.range = 500f; - _mainLight.shadows = LightShadows.Soft; - _mainLight.cullingMask = _lightCullingMask; - RenderSettings.sun = _mainLight; - - _mainLight.color = new Color(220f / 255f, 210f / 255f, 200f / 255f); - _mainLight.intensity = 0.9f; - - // Ambient light - RenderSettings.ambientIntensity = 1f; - RenderSettings.ambientLight = new Color(180f / 255f, 180f / 255f, 160f / 255f); - } } } \ No newline at end of file diff --git a/Assets/Scripts/Pal3/Scene/SceneManager.cs b/Assets/Scripts/Pal3/Scene/SceneManager.cs index 50b8453d..ddc05d0a 100644 --- a/Assets/Scripts/Pal3/Scene/SceneManager.cs +++ b/Assets/Scripts/Pal3/Scene/SceneManager.cs @@ -8,6 +8,7 @@ namespace Pal3.Scene using System; using System.Collections.Generic; using System.Diagnostics; + using Actor.Controllers; using Command; using Command.InternalCommands; using Command.SceCommands; @@ -36,6 +37,7 @@ namespace Pal3.Scene private readonly Camera _mainCamera; private GameObject _currentSceneRoot; + private GameObject _currentCombatSceneRoot; private Scene _currentScene; private CombatScene _currentCombatScene; @@ -72,19 +74,19 @@ namespace Pal3.Scene return _currentSceneRoot; } - public void LoadScene(string sceneFileName, string sceneName) + public void LoadScene(string sceneCityName, string sceneName) { var timer = new Stopwatch(); timer.Start(); DisposeCurrentScene(); ScnFile scnFile = _resourceProvider.GetGameResourceFile( - FileConstants.GetScnFileVirtualPath(sceneFileName, sceneName)); + FileConstants.GetScnFileVirtualPath(sceneCityName, sceneName)); CommandDispatcher.Instance.Dispatch(new ScenePreLoadingNotification(scnFile.SceneInfo)); Debug.Log($"[{nameof(SceneManager)}] Loading scene: " + JsonConvert.SerializeObject(scnFile.SceneInfo)); - _currentSceneRoot = new GameObject($"Scene_{sceneFileName}_{sceneName}"); + _currentSceneRoot = new GameObject($"Scene_{sceneCityName}_{sceneName}"); _currentSceneRoot.transform.SetParent(null); _currentScene = _currentSceneRoot.AddComponent(); _currentScene.Init(_resourceProvider, @@ -98,10 +100,11 @@ namespace Pal3.Scene _sceneObjectIdsToNotLoadFromSaveState.Clear(); // Add scene script if exists. - SceFile sceFile = _resourceProvider.GetGameResourceFile(FileConstants.GetSceneSceFileVirtualPath(sceneFileName)); + SceFile sceFile = _resourceProvider.GetGameResourceFile( + FileConstants.GetSceneSceFileVirtualPath(sceneCityName)); CommandDispatcher.Instance.Dispatch( - _scriptManager.TryAddSceneScript(sceFile, $"_{sceneFileName}_{sceneName}", out var sceneScriptId) + _scriptManager.TryAddSceneScript(sceFile, $"_{sceneCityName}_{sceneName}", out var sceneScriptId) ? new ScenePostLoadingNotification(scnFile.SceneInfo, sceneScriptId) : new ScenePostLoadingNotification(scnFile.SceneInfo, ScriptConstants.InvalidScriptId)); @@ -116,14 +119,16 @@ namespace Pal3.Scene { var timer = new Stopwatch(); timer.Start(); - DisposeCurrentScene(); - _currentSceneRoot = new GameObject($"CombatScene_{combatSceneName}"); - _currentSceneRoot.transform.SetParent(null); - _currentCombatScene = _currentSceneRoot.AddComponent(); - _currentCombatScene.Init(_resourceProvider, - _gameSettings.IsRealtimeLightingAndShadowsEnabled); - _currentCombatScene.Load(_currentSceneRoot, combatSceneName); + HideCurrentScene(); + + _currentCombatSceneRoot = new GameObject($"CombatScene_{combatSceneName}"); + _currentCombatSceneRoot.transform.SetParent(null); + _currentCombatSceneRoot.transform.localPosition = new Vector3(0f, 0f, 0f); + + _currentCombatScene = _currentCombatSceneRoot.AddComponent(); + _currentCombatScene.Init(_resourceProvider); + _currentCombatScene.Load(_currentCombatSceneRoot, combatSceneName); timer.Stop(); Debug.Log($"[{nameof(SceneManager)}] CombatScene loaded in {timer.Elapsed.TotalSeconds} seconds."); @@ -132,6 +137,64 @@ namespace Pal3.Scene System.GC.Collect(); } + public void UnloadCombatScene() + { + if (_currentCombatScene != null) + { + _currentCombatScene.Destroy(); + _currentCombatScene = null; + } + + if (_currentCombatSceneRoot != null) + { + _currentCombatSceneRoot.Destroy(); + _currentCombatSceneRoot = null; + } + + ShowCurrentScene(); + } + + private void HideCurrentScene() + { + foreach (ActorMovementController movementController in + _currentSceneRoot.GetComponentsInChildren()) + { + movementController.PauseMovement(); + } + + foreach (MeshRenderer meshRenderer in + _currentSceneRoot.GetComponentsInChildren()) + { + meshRenderer.enabled = false; + } + + foreach (SpriteRenderer spriteRenderer in + _currentSceneRoot.GetComponentsInChildren()) + { + spriteRenderer.enabled = false; + } + } + + private void ShowCurrentScene() + { + foreach (SpriteRenderer spriteRenderer in + _currentSceneRoot.GetComponentsInChildren()) + { + spriteRenderer.enabled = true; + } + + foreach (MeshRenderer meshRenderer in _currentSceneRoot.GetComponentsInChildren()) + { + meshRenderer.enabled = true; + } + + foreach (ActorMovementController movementController in + _currentSceneRoot.GetComponentsInChildren()) + { + movementController.ResumeMovement(); + } + } + private void DisposeCurrentScene() { if (_currentScene != null) @@ -156,7 +219,7 @@ namespace Pal3.Scene public void Execute(SceneLoadCommand command) { - LoadScene(command.SceneFileName, command.SceneName); + LoadScene(command.SceneCityName, command.SceneName); } public void Execute(ResetGameStateCommand command)