From dfdc33c222ff41eee1124fb712af076f055d84ae Mon Sep 17 00:00:00 2001 From: Jiaqi Liu Date: Fri, 4 Aug 2023 18:44:04 -0700 Subject: [PATCH] Set different default speed for player and NPC actor --- Assets/Scripts/Core/DataReader/Scn/ScnFile.cs | 2 +- .../Core/DataReader/Scn/ScnFileReader.cs | 2 +- Assets/Scripts/Pal3/Actor/Actor.cs | 22 +++++++++++++++++++ .../Pal3/Actor/ActorMovementController.cs | 3 +-- .../Pal3/GamePlay/PlayerGamePlayController.cs | 4 ++-- .../Scripts/Pal3/MetaData/ActorConstants.cs | 6 ++++- Assets/Scripts/Pal3/Pal3.cs | 3 +++ .../Pal3/Scene/SceneObjects/SlideWayObject.cs | 6 ++--- 8 files changed, 38 insertions(+), 10 deletions(-) diff --git a/Assets/Scripts/Core/DataReader/Scn/ScnFile.cs b/Assets/Scripts/Core/DataReader/Scn/ScnFile.cs index 9af35727b..6c89da0d4 100644 --- a/Assets/Scripts/Core/DataReader/Scn/ScnFile.cs +++ b/Assets/Scripts/Core/DataReader/Scn/ScnFile.cs @@ -268,7 +268,7 @@ public class ScnNpcInfo public uint LoopAction; // 移动速度 - public uint Speed; + public uint GameBoxMoveSpeed; [JsonIgnore] public uint[] Reserved; // 29 DWORDs diff --git a/Assets/Scripts/Core/DataReader/Scn/ScnFileReader.cs b/Assets/Scripts/Core/DataReader/Scn/ScnFileReader.cs index 7611ad34e..860e80f70 100644 --- a/Assets/Scripts/Core/DataReader/Scn/ScnFileReader.cs +++ b/Assets/Scripts/Core/DataReader/Scn/ScnFileReader.cs @@ -93,7 +93,7 @@ private static ScnNpcInfo ReadNpcInfo(IBinaryReader reader, int codepage) }, NoTurn = reader.ReadUInt32(), LoopAction = reader.ReadUInt32(), - Speed = reader.ReadUInt32(), + GameBoxMoveSpeed = reader.ReadUInt32(), Reserved = reader.ReadUInt32Array(29), }; } diff --git a/Assets/Scripts/Pal3/Actor/Actor.cs b/Assets/Scripts/Pal3/Actor/Actor.cs index a88f57ed7..ff34814d4 100644 --- a/Assets/Scripts/Pal3/Actor/Actor.cs +++ b/Assets/Scripts/Pal3/Actor/Actor.cs @@ -6,6 +6,7 @@ namespace Pal3.Actor { using Core.DataReader.Scn; + using Core.GameBox; using Data; using MetaData; using UnityEngine; @@ -105,6 +106,27 @@ public string GetWeaponName() value : null; } + public float GetMoveSpeed(MovementMode movementMode) + { + if (Info.GameBoxMoveSpeed > 0) + { + return Info.GameBoxMoveSpeed / GameBoxInterpreter.GameBoxUnitToUnityUnit; + } + + if (Info.Kind == ScnActorKind.MainActor) + { + return movementMode == MovementMode.Run + ? ActorConstants.PlayerActorRunSpeed + : ActorConstants.PlayerActorWalkSpeed; + } + else + { + return movementMode == MovementMode.Run + ? ActorConstants.NpcActorRunSpeed + : ActorConstants.NpcActorWalkSpeed; + } + } + public float GetInteractionMaxDistance() { return Info.Kind switch diff --git a/Assets/Scripts/Pal3/Actor/ActorMovementController.cs b/Assets/Scripts/Pal3/Actor/ActorMovementController.cs index 5c2207a81..0e064c1aa 100644 --- a/Assets/Scripts/Pal3/Actor/ActorMovementController.cs +++ b/Assets/Scripts/Pal3/Actor/ActorMovementController.cs @@ -467,8 +467,7 @@ public MovementResult MoveTowards(Vector3 targetPosition, MovementMode movementM Transform currentTransform = transform; Vector3 currentPosition = currentTransform.position; - // TODO: Use speed info from datascript\scene.txt file when _actor.Info.Speed == 0 - var moveSpeed = _actor.Info.Speed <= 0 ? (movementMode == MovementMode.Run ? 11f : 5f) : _actor.Info.Speed / 11f; + float moveSpeed = _actor.GetMoveSpeed(movementMode); if (!_actor.IsMainActor()) moveSpeed /= 2f; diff --git a/Assets/Scripts/Pal3/GamePlay/PlayerGamePlayController.cs b/Assets/Scripts/Pal3/GamePlay/PlayerGamePlayController.cs index 521b93787..913f93cf3 100644 --- a/Assets/Scripts/Pal3/GamePlay/PlayerGamePlayController.cs +++ b/Assets/Scripts/Pal3/GamePlay/PlayerGamePlayController.cs @@ -972,7 +972,7 @@ public IEnumerator PlayerActorMoveToClimbableObjectAndClimbAsync( var currentHeight = 0f; while (currentHeight < climbableHeight) { - var delta = Time.deltaTime * ActorConstants.ActorClimbSpeed; + var delta = Time.deltaTime * ActorConstants.PlayerActorClimbSpeed; currentHeight += delta; _playerActorGameObject.transform.position += new Vector3(0f, delta, 0f); yield return null; @@ -990,7 +990,7 @@ public IEnumerator PlayerActorMoveToClimbableObjectAndClimbAsync( var currentHeight = climbableHeight; while (currentHeight > 0f) { - var delta = Time.deltaTime * ActorConstants.ActorClimbSpeed; + var delta = Time.deltaTime * ActorConstants.PlayerActorClimbSpeed; currentHeight -= delta; _playerActorGameObject.transform.position -= new Vector3(0f, delta, 0f); yield return null; diff --git a/Assets/Scripts/Pal3/MetaData/ActorConstants.cs b/Assets/Scripts/Pal3/MetaData/ActorConstants.cs index b0d6f6045..dd6570beb 100644 --- a/Assets/Scripts/Pal3/MetaData/ActorConstants.cs +++ b/Assets/Scripts/Pal3/MetaData/ActorConstants.cs @@ -196,7 +196,11 @@ public static class ActorConstants { public const int PlayerActorVirtualID = -1; // or 255 as byte value - public const float ActorClimbSpeed = 2f; + public const float PlayerActorClimbSpeed = 2f; + public const float PlayerActorWalkSpeed = 5f; + public const float PlayerActorRunSpeed = 10f; + public const float NpcActorWalkSpeed = 5f; + public const float NpcActorRunSpeed = 9f; #if PAL3 public const string LongKuiBlueModeActorName = "105"; diff --git a/Assets/Scripts/Pal3/Pal3.cs b/Assets/Scripts/Pal3/Pal3.cs index ecd7252b3..67e1f6bb8 100644 --- a/Assets/Scripts/Pal3/Pal3.cs +++ b/Assets/Scripts/Pal3/Pal3.cs @@ -352,11 +352,14 @@ private void OnEnable() private void Start() { Debug.Log($"[{nameof(Pal3)}] Game started."); + _mainMenu.ShowInitView(); _mainMenu.ShowMenu(); + #if !UNITY_EDITOR // Check latest version and notify if a newer version is found. StartCoroutine(CheckLatestVersionAndNotify()); + #endif } private IEnumerator CheckLatestVersionAndNotify() diff --git a/Assets/Scripts/Pal3/Scene/SceneObjects/SlideWayObject.cs b/Assets/Scripts/Pal3/Scene/SceneObjects/SlideWayObject.cs index 1056c96ae..8efbb3841 100644 --- a/Assets/Scripts/Pal3/Scene/SceneObjects/SlideWayObject.cs +++ b/Assets/Scripts/Pal3/Scene/SceneObjects/SlideWayObject.cs @@ -61,10 +61,10 @@ public override IEnumerator InteractAsync(InteractionContext ctx) movementController.CancelMovement(); var actorController = playerActorGameObject.GetComponent(); - uint originalSpeed = actorController.GetActor().Info.Speed; + uint originalSpeed = actorController.GetActor().Info.GameBoxMoveSpeed; // Temporarily set the speed to a higher value to make the actor slide - actorController.GetActor().Info.Speed = ACTOR_SLIDE_SPEED; + actorController.GetActor().Info.GameBoxMoveSpeed = ACTOR_SLIDE_SPEED; movementController.SetupPath(waypoints, MovementMode.Run, EndOfPathActionType.Idle, ignoreObstacle: true); @@ -74,7 +74,7 @@ public override IEnumerator InteractAsync(InteractionContext ctx) } // Restore the original speed - actorController.GetActor().Info.Speed = originalSpeed; + actorController.GetActor().Info.GameBoxMoveSpeed = originalSpeed; ExecuteScriptIfAny(); _isInteractionInProgress = false;