Skip to content

Commit

Permalink
Set different default speed for player and NPC actor
Browse files Browse the repository at this point in the history
  • Loading branch information
0x7c13 committed Aug 5, 2023
1 parent 478b8f7 commit dfdc33c
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Assets/Scripts/Core/DataReader/Scn/ScnFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ public class ScnNpcInfo
public uint LoopAction;

// 移动速度
public uint Speed;
public uint GameBoxMoveSpeed;

[JsonIgnore]
public uint[] Reserved; // 29 DWORDs
Expand Down
2 changes: 1 addition & 1 deletion Assets/Scripts/Core/DataReader/Scn/ScnFileReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
};
}
Expand Down
22 changes: 22 additions & 0 deletions Assets/Scripts/Pal3/Actor/Actor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
namespace Pal3.Actor
{
using Core.DataReader.Scn;
using Core.GameBox;
using Data;
using MetaData;
using UnityEngine;
Expand Down Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions Assets/Scripts/Pal3/Actor/ActorMovementController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
4 changes: 2 additions & 2 deletions Assets/Scripts/Pal3/GamePlay/PlayerGamePlayController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
6 changes: 5 additions & 1 deletion Assets/Scripts/Pal3/MetaData/ActorConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
3 changes: 3 additions & 0 deletions Assets/Scripts/Pal3/Pal3.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
6 changes: 3 additions & 3 deletions Assets/Scripts/Pal3/Scene/SceneObjects/SlideWayObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ public override IEnumerator InteractAsync(InteractionContext ctx)
movementController.CancelMovement();

var actorController = playerActorGameObject.GetComponent<ActorController>();
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);

Expand All @@ -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;
Expand Down

0 comments on commit dfdc33c

Please sign in to comment.