mirror of
https://github.com/0x7c13/Pal3.Unity.git
synced 2026-11-26 17:38:10 +08:00
Combat system WIP
This commit is contained in:
1 parent
78f0a1a8f7
commit
ca27dea76f
17 files changed
+231
-111
No files matched your search
@@ -15,17 +15,18 @@ namespace Core.DataReader.Ini
|
||||
public sealed class CombatCameraConfigFileReader : IFileReader<CombatCameraConfigFile>
|
||||
{
|
||||
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);
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ namespace Core.DataReader.Txt
|
||||
|
||||
public sealed class CombatScnFileReader : IFileReader<CombatScnFile>
|
||||
{
|
||||
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;
|
||||
|
||||
@@ -178,12 +178,14 @@ namespace Pal3.Actor.Controllers
|
||||
.GetPlayerActor() == actorController.GetActor().Info.Id)
|
||||
{
|
||||
// Player actor collides with combat NPC in maze
|
||||
|
||||
CommandDispatcher<ICommand>.Instance.Dispatch(
|
||||
new ActorActivateCommand(_actor.Info.Id, 0));
|
||||
|
||||
if (ServiceLocator.Instance.Get<GameSettings>().IsTurnBasedCombatEnabled)
|
||||
{
|
||||
CommandDispatcher<ICommand>.Instance.Dispatch(
|
||||
new ActorStopActionAndStandCommand(ActorConstants.PlayerActorVirtualID));
|
||||
|
||||
CommandDispatcher<ICommand>.Instance.Dispatch(
|
||||
new CombatEnterNormalFightCommand(
|
||||
_actor.Info.NumberOfMonsters,
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -6,12 +6,14 @@
|
||||
namespace Pal3.Combat
|
||||
{
|
||||
using Core.DataReader.Gdb;
|
||||
using Script.Waiter;
|
||||
|
||||
/// <summary>
|
||||
/// Data contract for combat context.
|
||||
/// </summary>
|
||||
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} " +
|
||||
|
||||
@@ -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<CombatEnterBossFightCommand>,
|
||||
#if PAL3A
|
||||
ICommandExecutor<CombatEnterBossFightUsingMusicCommand>,
|
||||
ICommandExecutor<CombatEnterBossFightUsingMusicWithSpecialActorCommand>,
|
||||
#endif
|
||||
ICommandExecutor<CombatSetUnbeatableCommand>,
|
||||
ICommandExecutor<CombatSetMaxRoundCommand>,
|
||||
@@ -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<CombatScnFile>(
|
||||
FileConstants.DataScriptFolderVirtualPath + COMBAT_SCN_FILE_NAME);
|
||||
|
||||
_combatManager.OnCombatFinished += OnOnCombatFinished;
|
||||
CommandExecutorRegistry<ICommand>.Instance.Register(this);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_combatManager.OnCombatFinished -= OnOnCombatFinished;
|
||||
CommandExecutorRegistry<ICommand>.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<ICommand>.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<ICommand>.Instance.Dispatch(new StopMusicCommand());
|
||||
|
||||
_sceneManager.UnloadCombatScene();
|
||||
_currentCombatContext.ScriptWaiter?.CancelWait();
|
||||
|
||||
_gameStateManager.GoToPreviousState();
|
||||
_currentCombatContext.ResetContext();
|
||||
}
|
||||
else
|
||||
{
|
||||
CommandDispatcher<ICommand>.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)
|
||||
|
||||
@@ -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<bool> 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<CombatConfigFile>(
|
||||
FileConstants.DataScriptFolderVirtualPath + COMBAT_CONFIG_FILE_NAME);
|
||||
@@ -50,9 +55,12 @@ namespace Pal3.Combat
|
||||
|
||||
public void EnterCombat(CombatContext combatContext)
|
||||
{
|
||||
CommandDispatcher<ICommand>.Instance.Dispatch(new CameraFollowPlayerCommand(0));
|
||||
_mainCamera.transform.GetPositionAndRotation(out _cameraPositionBeforeCombat,
|
||||
out _cameraRotationBeforeCombat);
|
||||
_cameraFovBeforeCombat = _mainCamera.fieldOfView;
|
||||
|
||||
_gameStateManager.TryGoToState(GameState.Combat);
|
||||
CommandDispatcher<ICommand>.Instance.Dispatch(new CameraFollowPlayerCommand(0));
|
||||
CommandDispatcher<ICommand>.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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -792,11 +792,11 @@ namespace Pal3.Command
|
||||
}
|
||||
|
||||
// <auto-generated/>
|
||||
[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<ICommand>.Instance.Dispatch(
|
||||
new SceneLoadCommand(sceneFileName, sceneName));
|
||||
new SceneLoadCommand(sceneCityName, sceneName));
|
||||
}
|
||||
|
||||
// <auto-generated/>
|
||||
|
||||
@@ -471,6 +471,14 @@ namespace Pal3.Command
|
||||
new CombatEnterBossFightUsingMusicCommand(monster1Id, monster2Id, monster3Id, monster4Id, monster5Id, monster6Id, combatMusicName));
|
||||
}
|
||||
|
||||
// <auto-generated/>
|
||||
[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<ICommand>.Instance.Dispatch(
|
||||
new CombatEnterBossFightUsingMusicWithSpecialActorCommand(monster1Id, monster2Id, monster3Id, monster4Id, monster5Id, monster6Id, combatMusicName, combatCommandId));
|
||||
}
|
||||
|
||||
// <auto-generated/>
|
||||
[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
|
||||
}
|
||||
|
||||
// <auto-generated/>
|
||||
[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<ICommand>.Instance.Dispatch(
|
||||
new SceneLoadCommand(sceneFileName, sceneName));
|
||||
new SceneLoadCommand(sceneCityName, sceneName));
|
||||
}
|
||||
|
||||
// <auto-generated/>
|
||||
@@ -1223,14 +1231,6 @@ namespace Pal3.Command
|
||||
new UnknownCommand185(unknown1, unknown2, unknown3, unknown4, unknown5, unknown6, unknown7, unknown8));
|
||||
}
|
||||
|
||||
// <auto-generated/>
|
||||
[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<ICommand>.Instance.Dispatch(
|
||||
new UnknownCommand192(monster1Id, monster2Id, monster3Id, monster4Id, monster5Id, monster6Id, combatMusic, unknown));
|
||||
}
|
||||
|
||||
// <auto-generated/>
|
||||
[ConsoleMethodAttribute("Unknown193", "???")]
|
||||
public static void Unknown193(System.Int32 unknown1, System.Int32 unknown2)
|
||||
|
||||
+9
-9
@@ -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
|
||||
}
|
||||
File renamed without changes.
@@ -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; }
|
||||
}
|
||||
}
|
||||
@@ -33,9 +33,9 @@ namespace Pal3.GameSystem
|
||||
CommandExecutorRegistry<ICommand>.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<ICommand>.Instance.Dispatch(new GameStateChangeRequest(GameState.Cutscene));
|
||||
CommandDispatcher<ICommand>.Instance.Dispatch(new CameraFadeInCommand());
|
||||
_scriptManager.AddScript(afterRestTalkScript);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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<Light>();
|
||||
_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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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<ScnFile>(
|
||||
FileConstants.GetScnFileVirtualPath(sceneFileName, sceneName));
|
||||
FileConstants.GetScnFileVirtualPath(sceneCityName, sceneName));
|
||||
|
||||
CommandDispatcher<ICommand>.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<Scene>();
|
||||
_currentScene.Init(_resourceProvider,
|
||||
@@ -98,10 +100,11 @@ namespace Pal3.Scene
|
||||
_sceneObjectIdsToNotLoadFromSaveState.Clear();
|
||||
|
||||
// Add scene script if exists.
|
||||
SceFile sceFile = _resourceProvider.GetGameResourceFile<SceFile>(FileConstants.GetSceneSceFileVirtualPath(sceneFileName));
|
||||
SceFile sceFile = _resourceProvider.GetGameResourceFile<SceFile>(
|
||||
FileConstants.GetSceneSceFileVirtualPath(sceneCityName));
|
||||
|
||||
CommandDispatcher<ICommand>.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<CombatScene>();
|
||||
_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<CombatScene>();
|
||||
_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<ActorMovementController>())
|
||||
{
|
||||
movementController.PauseMovement();
|
||||
}
|
||||
|
||||
foreach (MeshRenderer meshRenderer in
|
||||
_currentSceneRoot.GetComponentsInChildren<MeshRenderer>())
|
||||
{
|
||||
meshRenderer.enabled = false;
|
||||
}
|
||||
|
||||
foreach (SpriteRenderer spriteRenderer in
|
||||
_currentSceneRoot.GetComponentsInChildren<SpriteRenderer>())
|
||||
{
|
||||
spriteRenderer.enabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
private void ShowCurrentScene()
|
||||
{
|
||||
foreach (SpriteRenderer spriteRenderer in
|
||||
_currentSceneRoot.GetComponentsInChildren<SpriteRenderer>())
|
||||
{
|
||||
spriteRenderer.enabled = true;
|
||||
}
|
||||
|
||||
foreach (MeshRenderer meshRenderer in _currentSceneRoot.GetComponentsInChildren<MeshRenderer>())
|
||||
{
|
||||
meshRenderer.enabled = true;
|
||||
}
|
||||
|
||||
foreach (ActorMovementController movementController in
|
||||
_currentSceneRoot.GetComponentsInChildren<ActorMovementController>())
|
||||
{
|
||||
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)
|
||||
|
||||
Reference in new issue
Block a user