Compare commits

...
12 Commits
Author SHA1 Message Date
Jackie Liu 6c6f11fb84 Upgrade Unity version to 2022.2.11 2023-03-15 23:41:37 -07:00
Jackie Liu 6d7f2e3cc8 v0.46 2023-03-15 23:27:31 -07:00
Jackie Liu 7abe277d79 Small tweak to the interaction logic of PushableObject 2023-03-15 23:22:06 -07:00
Jackie Liu 1420351153 Bug fixes 2023-03-15 23:12:49 -07:00
Jackie Liu dc200f4bb3 Persist camera rotation in save archive 2023-03-15 19:57:30 -07:00
Jackie Liu 12cfa042c6 Use cache in CRC hash compute 2023-03-15 18:21:50 -07:00
Jiaqi Liu 7b22af124b Tweak min jump distance for better tolerance 2023-03-15 05:36:24 -07:00
Jiaqi Liu 07e6952d17 Add missing line 2023-03-15 05:31:20 -07:00
Jiaqi Liu 91fe12caae Fix a bug in jump logic and make some improvements 2023-03-15 05:30:44 -07:00
Jiaqi Liu 0f8d3caae6 Code refactoring 2023-03-15 04:34:49 -07:00
Jiaqi Liu b065483cab Minor fixes 2023-03-14 22:08:18 -07:00
Jiaqi Liu ea5cede832 Update README.md 2023-03-15 11:18:22 +08:00
24 changed files with 256 additions and 100 deletions

No files matched your search

+22 -3
View File
@@ -6,6 +6,7 @@
namespace Core.DataReader.Cpk
{
using System;
using System.Collections.Generic;
using System.Text;
/// <summary>
@@ -19,6 +20,9 @@ namespace Core.DataReader.Cpk
private static readonly uint[] CrcTable = new uint[CRC_TABLE_MAX];
private bool _initialized;
// Cache the crc32 hash result for string since it's expensive to compute.
private readonly Dictionary<string, uint> _crcResultCache = new();
public void Init()
{
// generate the table of CRC remainders for all possible bytes
@@ -37,10 +41,25 @@ namespace Core.DataReader.Cpk
_initialized = true;
}
public uint ComputeCrc32Hash(string str, int codepage)
public uint ComputeCrc32Hash(string str, int codepage, bool useCache = true)
{
//Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
return ComputeCrc32HashInternal(Encoding.GetEncoding(codepage).GetBytes(str));
if (!useCache)
{
return ComputeCrc32HashInternal(Encoding.GetEncoding(codepage).GetBytes(str));
}
var cacheKey = $"{str}-{codepage}";
if (_crcResultCache.ContainsKey(cacheKey))
{
return _crcResultCache[cacheKey];
}
uint result = ComputeCrc32HashInternal(Encoding.GetEncoding(codepage).GetBytes(str));
_crcResultCache[cacheKey] = result;
return result;
}
private unsafe uint ComputeCrc32HashInternal(byte[] data)
@@ -7,6 +7,7 @@ namespace Core.GameBox
{
using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using UnityEngine;
/// <summary>
@@ -18,51 +19,61 @@ namespace Core.GameBox
public const float GameBoxUnitToUnityUnit = 20f;
public const float GameBoxMv3UnitToUnityUnit = 1270f;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Vector3 ToUnityVertex(Vector3 vertex, float scale)
{
return ToUnityVector3(vertex, scale);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Vector3 ToUnityPosition(Vector3 position, float scale = GameBoxUnitToUnityUnit)
{
return ToUnityVector3(position, scale);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float ToUnityDistance(float gameBoxDistance)
{
return gameBoxDistance / GameBoxUnitToUnityUnit;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float ToUnityXPosition(float gameBoxXPosition)
{
return -gameBoxXPosition / GameBoxUnitToUnityUnit;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float ToUnityYPosition(float gameBoxYPosition)
{
return gameBoxYPosition / GameBoxUnitToUnityUnit;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float ToUnityZPosition(float gameBoxZPosition)
{
return gameBoxZPosition / GameBoxUnitToUnityUnit;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float ToGameBoxXRotation(float eulerAnglesX)
{
return eulerAnglesX;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float ToGameBoxYRotation(float eulerAnglesY)
{
return -eulerAnglesY;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float ToGameBoxZRotation(float eulerAnglesZ)
{
return eulerAnglesZ;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Quaternion ToUnityRotation(Vector3 gameBoxEulerAngles)
{
return Quaternion.Euler(
@@ -71,6 +82,7 @@ namespace Core.GameBox
gameBoxEulerAngles.z);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Vector3 ToGameBoxPosition(Vector3 position, float scale = GameBoxUnitToUnityUnit)
{
return new Vector3(
@@ -79,6 +91,7 @@ namespace Core.GameBox
position.z * scale);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Vector3 CvdPositionToUnityPosition(Vector3 cvdPosition, float scale = GameBoxUnitToUnityUnit)
{
return new Vector3(
@@ -87,6 +100,7 @@ namespace Core.GameBox
-cvdPosition.y / scale);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Vector3 CvdScaleToUnityScale(Vector3 scale)
{
return new Vector3(
@@ -95,6 +109,7 @@ namespace Core.GameBox
scale.y);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Vector3 ToUnityNormal(Vector3 normal)
{
return new Vector3(
@@ -103,16 +118,19 @@ namespace Core.GameBox
normal.z);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Quaternion CvdQuaternionToUnityQuaternion(GameBoxQuaternion quaternion)
{
return new Quaternion(-quaternion.X, quaternion.Z, -quaternion.Y, quaternion.W);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Quaternion Mv3QuaternionToUnityQuaternion(GameBoxQuaternion quaternion)
{
return new Quaternion(-quaternion.X, quaternion.Y, quaternion.Z, quaternion.W);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Quaternion LgtQuaternionToUnityQuaternion(GameBoxQuaternion quaternion)
{
var rotation = new Quaternion(quaternion.X, quaternion.Y, -quaternion.Z, quaternion.W);
@@ -122,6 +140,7 @@ namespace Core.GameBox
return rotation;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Quaternion ToUnityRotation(float pitch, float yaw, float roll)
{
return Quaternion.Euler(pitch - 180, yaw, roll -180);
@@ -130,6 +149,7 @@ namespace Core.GameBox
// Since GameBox engine uses different internal axis system.
// Here we are flipping the x here to minor it back to the Unity axis.
// Also we want to scale it to proper unity unit.
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static Vector3 ToUnityVector3(Vector3 vector3, float scale)
{
return new Vector3(
@@ -138,16 +158,19 @@ namespace Core.GameBox
vector3.z / scale);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void ToUnityTriangles(List<int> triangles)
{
triangles.Reverse();
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void ToUnityTriangles(int[] triangles)
{
Array.Reverse(triangles);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool IsPointInsideRect(GameBoxRect rect, Vector2Int point)
{
return point.x >= rect.Left &&
@@ -156,6 +179,7 @@ namespace Core.GameBox
point.y <= rect.Bottom;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Matrix4x4 ToUnityMatrix4x4(GameBoxMatrix4X4 matrix)
{
return new Matrix4x4(
@@ -8,7 +8,6 @@ namespace Pal3.Actor
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using Command;
using Command.InternalCommands;
@@ -448,7 +447,7 @@ namespace Pal3.Actor
if (!targetPositionFound)
{
targetPosition = tapPoints.First().Value.point;
targetPosition = tapPoints[0].point;
}
MovementMode mode = isDoubleTap ? MovementMode.Run : MovementMode.Walk;
@@ -459,17 +458,6 @@ namespace Pal3.Actor
SetupPath(new[] { targetPosition }, mode, EndOfPathActionType.Idle, ignoreObstacle: false);
}
private bool IsNearPortalAreaOfLayer(Vector3 position, int layerIndex)
{
Vector2Int tilePosition = _tilemap.GetTilePosition(position, layerIndex);
if (_tilemap.IsInsidePortalArea(tilePosition, layerIndex)) return true;
// Check nearby 8 directions
return Enum.GetValues(typeof(Direction)).Cast<Direction>().Any(direction =>
_tilemap.IsInsidePortalArea(tilePosition + DirectionUtils.ToVector2Int(direction), layerIndex));
}
public MovementResult MoveTowards(Vector3 targetPosition, MovementMode movementMode, bool ignoreObstacle = false)
{
Transform currentTransform = transform;
@@ -652,8 +640,8 @@ namespace Pal3.Actor
}
// Special handling for moving between layers (Across portal area)
if (IsNearPortalAreaOfLayer(newPosition, _currentLayerIndex) ||
IsNearPortalAreaOfLayer(newPosition, nextLayer))
if (_tilemap.IsPositionInsidePortalArea(newPosition, _currentLayerIndex) ||
_tilemap.IsPositionInsidePortalArea(newPosition, nextLayer))
{
newYPosition = currentPosition.y;
return true;
+52 -28
View File
@@ -52,6 +52,7 @@ namespace Pal3.Camera
ICommandExecutor<ScenePreLoadingNotification>,
ICommandExecutor<SceneLeavingCurrentSceneNotification>,
ICommandExecutor<GameStateChangedNotification>,
ICommandExecutor<CameraSetInitialStateOnNextSceneLoadCommand>,
ICommandExecutor<ResetGameStateCommand>
{
private const float FADE_ANIMATION_DURATION = 3f;
@@ -93,11 +94,13 @@ namespace Pal3.Camera
private CancellationTokenSource _asyncCameraAnimationCts = new ();
private CancellationTokenSource _cameraFadeAnimationCts = new ();
private const int LAST_KNOWN_SCENE_STATE_LIST_MAX_LENGTH = 1;
private Quaternion? _initRotationOnSceneLoad = null;
private int? _initTransformOptionOnSceneLoad = null;
private const int CAMERA_LAST_KNOWN_STATE_LIST_MAX_LENGTH = 1;
private readonly List<(ScnSceneInfo sceneInfo,
Vector3 cameraPosition,
Quaternion cameraRotation,
Vector3 cameraOffset)> _cameraLastKnownSceneState = new ();
int transformOption)> _cameraLastKnownState = new ();
public void Init(PlayerInputActions inputActions,
PlayerGamePlayController gamePlayController,
@@ -383,7 +386,13 @@ namespace Pal3.Camera
return _currentAppliedDefaultTransformOption;
}
private void ApplySceneSettings(ScnSceneInfo sceneInfo)
public Camera GetMainCamera()
{
return _camera;
}
private void ApplySceneSettings(ScnSceneInfo sceneInfo,
int? initTransformOption = null, Quaternion? initRotation = null)
{
switch (sceneInfo.SceneType)
{
@@ -391,33 +400,35 @@ namespace Pal3.Camera
_lookAtPointYOffset = 0;
_camera.nearClipPlane = 2f;
_camera.farClipPlane = 800f;
ApplyDefaultSettings(0);
ApplyDefaultSettings(initTransformOption ?? 0, initRotation);
break;
case ScnSceneType.InDoor:
_lookAtPointYOffset = SCENE_IN_DOOR_ROOM_FLOOR_HEIGHT;
_camera.nearClipPlane = 1f;
_camera.farClipPlane = 500f;
ApplyDefaultSettings(1);
ApplyDefaultSettings(initTransformOption ?? 1, initRotation);
break;
case ScnSceneType.Maze:
_lookAtPointYOffset = 0;
_camera.nearClipPlane = 2f;
_camera.farClipPlane = 800f;
ApplyDefaultSettings(0);
ApplyDefaultSettings(initTransformOption ?? 0, initRotation);
break;
default:
_lookAtPointYOffset = 0;
_camera.nearClipPlane = 1f;
_camera.farClipPlane = 500f;
ApplyDefaultSettings(0);
ApplyDefaultSettings(initTransformOption ?? 0, initRotation);
break;
}
_shouldResetVelocity = true;
}
private void ApplyDefaultSettings(int option)
private void ApplyDefaultSettings(int option, Quaternion? initRotation = null)
{
_currentAppliedDefaultTransformOption = option;
float cameraDistance;
Quaternion cameraRotation;
float cameraFov;
@@ -428,25 +439,25 @@ namespace Pal3.Camera
_freeToRotate = true;
cameraFov = HorizontalToVerticalFov(26.0f, 4f/3f);
cameraDistance = CAMERA_DEFAULT_DISTANCE;
cameraRotation = GameBoxInterpreter.ToUnityRotation(-30.37f, -52.65f, 0f);
cameraRotation = initRotation ?? GameBoxInterpreter.ToUnityRotation(-30.37f, -52.65f, 0f);
break;
case 1:
_freeToRotate = false;
cameraFov = HorizontalToVerticalFov(24.05f, 4f/3f);
cameraDistance = CAMERA_IN_DOOR_DISTANCE;
cameraRotation = GameBoxInterpreter.ToUnityRotation(-19.48f, 33.24f, 0f);
cameraRotation = initRotation ?? GameBoxInterpreter.ToUnityRotation(-19.48f, 33.24f, 0f);
break;
case 2:
_freeToRotate = false;
cameraFov = HorizontalToVerticalFov(24.05f, 4f/3f);
cameraDistance = CAMERA_IN_DOOR_DISTANCE;
cameraRotation = GameBoxInterpreter.ToUnityRotation(-19.48f, -33.24f, 0f);
cameraRotation = initRotation ?? GameBoxInterpreter.ToUnityRotation(-19.48f, -33.24f, 0f);
break;
case 3:
_freeToRotate = false;
cameraFov = HorizontalToVerticalFov(24.05f, 4f/3f);
cameraDistance = CAMERA_IN_DOOR_DISTANCE;
cameraRotation = GameBoxInterpreter.ToUnityRotation(-19.48f, 0f, 0f);
cameraRotation = initRotation ?? GameBoxInterpreter.ToUnityRotation(-19.48f, 0f, 0f);
break;
default:
return;
@@ -476,7 +487,6 @@ namespace Pal3.Camera
}
ApplyDefaultSettings(command.Option);
_currentAppliedDefaultTransformOption = command.Option;
_cameraFollowPlayer = true;
}
@@ -674,37 +684,48 @@ namespace Pal3.Camera
if (_cameraFollowPlayer && currentScene.GetSceneInfo().SceneType != ScnSceneType.InDoor)
{
var cameraTransform = _camera.transform;
_cameraLastKnownSceneState.Add((
_cameraLastKnownState.Add((
currentScene.GetSceneInfo(),
cameraTransform.position,
cameraTransform.rotation,
_cameraOffset));
_currentAppliedDefaultTransformOption));
if (_cameraLastKnownSceneState.Count > LAST_KNOWN_SCENE_STATE_LIST_MAX_LENGTH)
if (_cameraLastKnownState.Count > CAMERA_LAST_KNOWN_STATE_LIST_MAX_LENGTH)
{
_cameraLastKnownSceneState.RemoveAt(0);
_cameraLastKnownState.RemoveAt(0);
}
}
}
public void Execute(CameraSetInitialStateOnNextSceneLoadCommand command)
{
_initRotationOnSceneLoad = Quaternion.Euler(command.InitRotationInEulerAngles);
_initTransformOptionOnSceneLoad = command.InitTransformOption;
}
public void Execute(ScenePreLoadingNotification notification)
{
_currentAppliedDefaultTransformOption = 0;
ApplySceneSettings(notification.NewSceneInfo);
Quaternion? initRotation = _initRotationOnSceneLoad;
int? initTransformOption = _initTransformOptionOnSceneLoad;
// Apply the last known scene state if found in record.
// Use the last known camera rotation based on last known state found in record.
if (_cameraFollowPlayer && notification.NewSceneInfo.SceneType != ScnSceneType.InDoor)
{
if (_cameraLastKnownSceneState.Count > 0 && _cameraLastKnownSceneState.Any(_ =>
if (_cameraLastKnownState.Count > 0 && _cameraLastKnownState.Any(_ =>
_.sceneInfo.ModelEquals(notification.NewSceneInfo)))
{
(ScnSceneInfo _, Vector3 cameraPosition, Quaternion cameraRotation, Vector3 cameraOffset) =
_cameraLastKnownSceneState.Last(_ => _.sceneInfo.ModelEquals(notification.NewSceneInfo));
(ScnSceneInfo _, Quaternion cameraRotation, int transformOption) =
_cameraLastKnownState.Last(_ => _.sceneInfo.ModelEquals(notification.NewSceneInfo));
_camera.transform.SetPositionAndRotation(cameraPosition, cameraRotation);
_cameraOffset = cameraOffset;
initRotation = cameraRotation;
initTransformOption = transformOption;
}
}
ApplySceneSettings(notification.NewSceneInfo, initTransformOption, initRotation);
// Reset
_initTransformOptionOnSceneLoad = null;
_initRotationOnSceneLoad = null;
}
public void Execute(CameraFocusOnActorCommand command)
@@ -732,7 +753,10 @@ namespace Pal3.Camera
public void Execute(ResetGameStateCommand command)
{
_cameraLastKnownSceneState.Clear();
_currentAppliedDefaultTransformOption = 0;
_initTransformOptionOnSceneLoad = null;
_initRotationOnSceneLoad = null;
_cameraLastKnownState.Clear();
_cameraFollowPlayer = true;
}
@@ -0,0 +1,22 @@
// ---------------------------------------------------------------------------------------------
// Copyright (c) 2021-2023, Jiaqi Liu. All rights reserved.
// See LICENSE file in the project root for license information.
// ---------------------------------------------------------------------------------------------
namespace Pal3.Command.InternalCommands
{
using UnityEngine;
[AvailableInConsole]
public class CameraSetInitialStateOnNextSceneLoadCommand : ICommand
{
public CameraSetInitialStateOnNextSceneLoadCommand(Vector3 initRotationInEulerAngles, int initTransformOption)
{
InitRotationInEulerAngles = initRotationInEulerAngles;
InitTransformOption = initTransformOption;
}
public Vector3 InitRotationInEulerAngles { get; }
public int InitTransformOption { get; }
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 219e9444381246ac9a8792325b863341
timeCreated: 1678928378
@@ -1295,6 +1295,14 @@ namespace Pal3.Command
new ActorSetWorldPositionCommand(actorId, xPosition, zPosition));
}
// <auto-generated/>
[ConsoleMethodAttribute("CameraSetInitialStateOnNextSceneLoad", "Execute CameraSetInitialStateOnNextSceneLoadCommand.")]
public static void CameraSetInitialStateOnNextSceneLoad(UnityEngine.Vector3 initRotationInEulerAngles, System.Int32 initTransformOption)
{
CommandDispatcher<ICommand>.Instance.Dispatch(
new CameraSetInitialStateOnNextSceneLoadCommand(initRotationInEulerAngles, initTransformOption));
}
// <auto-generated/>
[ConsoleMethodAttribute("PlayerActorClimbObject", "Execute PlayerActorClimbObjectCommand.")]
public static void PlayerActorClimbObject(System.Int32 objectId, UnityEngine.Vector2Int fromPosition, UnityEngine.Vector2Int toPosition, System.Boolean crossLayer)
@@ -1215,6 +1215,14 @@ namespace Pal3.Command
new ActorSetWorldPositionCommand(actorId, xPosition, zPosition));
}
// <auto-generated/>
[ConsoleMethodAttribute("CameraSetInitialStateOnNextSceneLoad", "Execute CameraSetInitialStateOnNextSceneLoadCommand.")]
public static void CameraSetInitialStateOnNextSceneLoad(UnityEngine.Vector3 initRotationInEulerAngles, System.Int32 initTransformOption)
{
CommandDispatcher<ICommand>.Instance.Dispatch(
new CameraSetInitialStateOnNextSceneLoadCommand(initRotationInEulerAngles, initTransformOption));
}
// <auto-generated/>
[ConsoleMethodAttribute("PlayerActorClimbObject", "Execute PlayerActorClimbObjectCommand.")]
public static void PlayerActorClimbObject(System.Int32 objectId, UnityEngine.Vector2Int fromPosition, UnityEngine.Vector2Int toPosition, System.Boolean crossLayer)
@@ -6,6 +6,8 @@
namespace Pal3.MetaData
{
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
/*
@@ -33,6 +35,8 @@ namespace Pal3.MetaData
public static class DirectionUtils
{
public static IEnumerable<Direction> AllDirections => Enum.GetValues(typeof(Direction)).Cast<Direction>();
public static Direction GetDirectionFromVector2Int(Vector2Int vector)
{
return (vector.x, vector.y) switch
@@ -71,8 +71,7 @@ namespace Pal3.Player
public int GetTotalMoney()
{
return 7777777; // TODO: Remove this and uncomment the following line
//return _items[MoneyItemID];
return _items[MoneyItemID];
}
public IEnumerable<KeyValuePair<int, int>> GetAllItems()
@@ -46,7 +46,7 @@ namespace Pal3.Player
ICommandExecutor<ToggleBigMapRequest>,
ICommandExecutor<ResetGameStateCommand>
{
private const float MIN_JUMP_DISTANCE = 1.5f;
private const float MIN_JUMP_DISTANCE = 1.2f;
private const float MAX_JUMP_DISTANCE = 8f;
private const float MAX_JUMP_Y_DIFFERENTIAL = 3.5f;
private const float JUMP_HEIGHT = 6f;
@@ -418,25 +418,26 @@ namespace Pal3.Player
Scene currentScene = _sceneManager.GetCurrentScene();
Tilemap tilemap = currentScene.GetTilemap();
bool IsPositionCanJumpTo(Vector3 position, int layerIndex, out float yPosition)
bool IsPositionCanJumpTo(Vector3 position, int layerIndex, out float yPosition, out int distanceToObstacle)
{
Vector2Int tilePosition = tilemap.GetTilePosition(position, layerIndex);
if (tilemap.TryGetTile(position, layerIndex, out NavTile tile) &&
tile.IsWalkable())
{
distanceToObstacle = tile.DistanceToNearestObstacle;
yPosition = GameBoxInterpreter.ToUnityYPosition(tile.GameBoxYPosition);
if (Mathf.Abs(yPosition - currentPosition.y) > MAX_JUMP_Y_DIFFERENTIAL) return false;
if (currentScene.IsPositionInsideJumpableArea(layerIndex, tilePosition) ||
tile.DistanceToNearestObstacle > 1)
if (currentScene.IsPositionInsideJumpableArea(layerIndex, tilePosition))
{
return true;
}
}
yPosition = 0f;
distanceToObstacle = 0;
return false;
}
@@ -450,27 +451,40 @@ namespace Pal3.Player
_playerActorGameObject.transform.forward = jumpDirection;
}
var validJumpTargetPositions = new List<(Vector3 position, int layerIndex)>();
for (float i = MIN_JUMP_DISTANCE; i <= MAX_JUMP_DISTANCE; i += 0.2f)
var validJumpTargetPositions = new List<(Vector3 position, int layerIndex, int distanceToObstacle)>();
for (float i = MIN_JUMP_DISTANCE; i <= MAX_JUMP_DISTANCE; i += 0.1f)
{
Vector3 targetPosition = currentPosition + jumpDirection * i;
for (var j = 0; j < tilemap.GetLayerCount(); j++)
{
if (IsPositionCanJumpTo(targetPosition, j, out var yPosition))
if (IsPositionCanJumpTo(targetPosition, j,
out float yPosition, out int distanceToObstacle))
{
Vector3 position = targetPosition;
position.y = yPosition;
validJumpTargetPositions.Add((position, j));
validJumpTargetPositions.Add((position, j, distanceToObstacle));
}
}
}
var jumpTargetLayer = _playerActorMovementController.GetCurrentLayerIndex();
var currentLayer = _playerActorMovementController.GetCurrentLayerIndex();
var jumpTargetLayer = currentLayer;
if (validJumpTargetPositions.Count > 0)
{
// Pick a position that is closer to the farthest position
(jumpTargetPosition, jumpTargetLayer) = validJumpTargetPositions[(int)(validJumpTargetPositions.Count * (2f / 3f))];
// If there are valid jump target positions in different layers,
// only pick positions in the other layer
if (validJumpTargetPositions.Any(_ => _.layerIndex != currentLayer))
{
validJumpTargetPositions = validJumpTargetPositions.Where(_ => _.layerIndex != currentLayer).ToList();
}
// Pick a position that is farthest from obstacles
int maxDistanceToObstacle = validJumpTargetPositions.Max(_ => _.distanceToObstacle);
var bestPosition = validJumpTargetPositions.First(_ => _.distanceToObstacle == maxDistanceToObstacle);
jumpTargetPosition = bestPosition.position;
jumpTargetLayer = bestPosition.layerIndex;
}
else
{
@@ -480,13 +494,17 @@ namespace Pal3.Player
_playerActorActionController.PerformAction(ActorConstants.ActionNames[ActorActionType.Jump],
overwrite: true, loopCount: 1);
yield return new WaitForSeconds(0.7f);
var distanceOffset = Vector3.Distance(jumpTargetPosition.Value, currentPosition);
var xzOffset = Vector2.Distance(
new Vector2(jumpTargetPosition.Value.x, jumpTargetPosition.Value.z),
new Vector2(currentPosition.x, currentPosition.z));
var startingYPosition = currentPosition.y;
var yOffset = jumpTargetPosition.Value.y - currentPosition.y;
yield return AnimationHelper.EnumerateValueAsync(0f, 1f, 1.1f, AnimationCurveType.Sine,
value =>
{
Vector3 calculatedPosition = currentPosition + jumpDirection * (distanceOffset * value);
Vector3 calculatedPosition = currentPosition + jumpDirection * (xzOffset * value);
calculatedPosition.y = startingYPosition + (0.5f - MathF.Abs(value - 0.5f)) * JUMP_HEIGHT + yOffset * value;
_playerActorGameObject.transform.position = calculatedPosition;
});
@@ -495,9 +513,7 @@ namespace Pal3.Player
_playerActorMovementController.SetNavLayer(jumpTargetLayer);
PlayerActorTilePositionChanged(jumpTargetLayer,
tilemap.GetTilePosition(jumpTargetPosition.Value,
jumpTargetLayer),
false);
tilemap.GetTilePosition(jumpTargetPosition.Value, jumpTargetLayer), false);
_gameStateManager.GoToState(GameState.Gameplay);
}
@@ -988,7 +1004,7 @@ namespace Pal3.Player
if (!Enum.IsDefined(typeof(PlayerActorId), command.ActorId))
{
Debug.LogError($"Cannot enable player control for actor {command.ActorId} " +
$"since actor is not player actor.");
$"since actor is not a player actor.");
return;
}
@@ -1028,8 +1044,7 @@ namespace Pal3.Player
// Set target actor as player actor
_playerActor = _sceneManager.GetCurrentScene().GetActor(command.ActorId);
_playerActorGameObject = _sceneManager.GetCurrentScene()
.GetActorGameObject(command.ActorId);
_playerActorGameObject = _sceneManager.GetCurrentScene().GetActorGameObject(command.ActorId);
_playerActorController = _playerActorGameObject.GetComponent<ActorController>();
_playerActorActionController = _playerActorGameObject.GetComponent<ActorActionController>();
_playerActorMovementController = _playerActorGameObject.GetComponent<ActorMovementController>();
+16 -2
View File
@@ -167,9 +167,23 @@ namespace Pal3.Player
public void Execute(TeamAddOrRemoveActorCommand command)
{
if (!Enum.IsDefined(typeof(PlayerActorId), command.ActorId)) return;
if (!Enum.IsDefined(typeof(PlayerActorId), command.ActorId))
{
Debug.LogError($"Cannot add non-player actor to the team.");
return;
}
var actor = (PlayerActorId) command.ActorId;
PlayerActorId actor = (PlayerActorId) command.ActorId;
#if PAL3
if (actor == PlayerActorId.HuaYing)
#elif PAL3A
if (actor == PlayerActorId.TaoZi)
#endif
{
Debug.LogError($"{actor} cannot be added to the team.");
return;
}
if (command.IsIn == 1)
{
+1 -1
View File
@@ -509,7 +509,7 @@ namespace Pal3.Scene
obstacles.Add(actorTile);
// Mark 8 tiles right next to the actor tile as obstacles
foreach (Direction direction in Enum.GetValues(typeof(Direction)).Cast<Direction>())
foreach (Direction direction in DirectionUtils.AllDirections)
{
Vector2Int neighbourTile = actorTile + DirectionUtils.ToVector2Int(direction);
if (_tilemap.IsTilePositionInsideTileMap(neighbourTile, layerIndex))
@@ -81,7 +81,7 @@ namespace Pal3.Scene.SceneObjects
ObjectInfo.Parameters[0],
ObjectInfo.Parameters[1]));
CommandDispatcher<ICommand>.Instance.Dispatch(
new CameraFocusOnSceneObjectCommand(1));
new CameraFollowPlayerCommand(1));
#elif PAL3A
CommandDispatcher<ICommand>.Instance.Dispatch(
new ActorStopActionAndStandCommand(ActorConstants.PlayerActorVirtualID));
@@ -100,9 +100,9 @@ namespace Pal3.Scene.SceneObjects
Vector3 actorHoldingPosition = pushableObjectPosition + -movingDirection * (movingDistance * 0.8f);
actorHoldingPosition.y = playerActorPosition.y;
// Only allow player to push object if it's close enough to the pushing location
// and there's no obstacle in the way.
if (Vector3.Distance(playerActorPosition, actorHoldingPosition) < 1.5f &&
// Only allow player to push object if actor is close enough
// to the holding position and there's no obstacle in the way.
if (Vector3.Distance(playerActorPosition, actorHoldingPosition) < 1f &&
CanPushTo(movingDirection, movingDistance))
{
RequestForInteraction();
@@ -3,6 +3,8 @@
// See LICENSE file in the project root for license information.
// ---------------------------------------------------------------------------------------------
#if PAL3A
namespace Pal3.Scene.SceneObjects
{
using System.Collections;
@@ -60,4 +62,6 @@ namespace Pal3.Scene.SceneObjects
base.Deactivate();
}
}
}
}
#endif
+32 -9
View File
@@ -7,7 +7,7 @@ namespace Pal3.Scene
{
using System;
using System.Collections.Generic;
using System.Linq;
using Core.Algorithm.PathFinding;
using Core.DataReader.Nav;
using Core.GameBox;
@@ -31,13 +31,6 @@ namespace Pal3.Scene
return _navFile.TileLayers.Length;
}
public bool IsInsidePortalArea(Vector2Int position, int layerIndex)
{
NavTileLayer currentLayer = _navFile.TileLayers[layerIndex];
return currentLayer.Portals.Any(portal =>
GameBoxInterpreter.IsPointInsideRect(portal, position));
}
public bool IsTilePositionInsideTileMap(Vector2Int tilePosition, int layerIndex)
{
return tilePosition.x >=0 && tilePosition.x < _navFile.TileLayers[layerIndex].Width &&
@@ -85,6 +78,36 @@ namespace Pal3.Scene
return currentLayer.Tiles[position.x + position.y * currentLayer.Width];
}
public bool IsPositionInsidePortalArea(Vector3 position, int layerIndex)
{
Vector2Int tilePosition = GetTilePosition(position, layerIndex);
NavTileLayer currentLayer = _navFile.TileLayers[layerIndex];
foreach (GameBoxRect portalRect in currentLayer.Portals)
{
// The original game gives two adjacent portals a 1 unit gap,
// so we need to smartly tweak the portal rect to make sure
// the gap is removed, so that player can walk between two
// adjacent portals freely.
int horizontalLength = portalRect.Right - portalRect.Left;
int verticalLength = portalRect.Bottom - portalRect.Top;
GameBoxRect tweakedRect = new()
{
Left = horizontalLength > verticalLength ? portalRect.Left : portalRect.Left - 1,
Right = horizontalLength > verticalLength ? portalRect.Right : portalRect.Right + 1,
Top = horizontalLength < verticalLength ? portalRect.Top : portalRect.Top - 1,
Bottom = horizontalLength < verticalLength ? portalRect.Bottom : portalRect.Bottom + 1
};
if (GameBoxInterpreter.IsPointInsideRect(tweakedRect, tilePosition)) return true;
}
return false;
}
public Vector2Int[] FindPathToTilePositionThreadSafe(Vector2Int from,
Vector2Int to,
int layerIndex,
@@ -161,7 +184,7 @@ namespace Pal3.Scene
// Get a walkable tile right next to the tile if any.
public bool TryGetAdjacentWalkableTile(Vector2Int position, int layerIndex, out Vector2Int nearestWalkableTile)
{
foreach (Direction direction in Enum.GetValues(typeof(Direction)).Cast<Direction>())
foreach (Direction direction in DirectionUtils.AllDirections)
{
Vector2Int tile = position + DirectionUtils.ToVector2Int(direction);
if (!IsTilePositionInsideTileMap(tile, layerIndex)) continue;
@@ -424,7 +424,9 @@ namespace Pal3.Script
public void Execute(ScriptGetMoneyCommand command)
{
if (!_isExecuting) return;
var totalMoney = ServiceLocator.Instance.Get<InventoryManager>().GetTotalMoney();
// TODO: Remove this and uncomment the following line
var totalMoney = 777777;
// var totalMoney = ServiceLocator.Instance.Get<InventoryManager>().GetTotalMoney();
SetVariableValue(command.Variable, totalMoney);
}
+7 -8
View File
@@ -37,7 +37,7 @@ namespace Pal3.State
public class SaveManager
{
private const string SAVE_FILE_NAME = "save.txt";
private readonly SceneManager _sceneManager;
private readonly PlayerManager _playerManager;
private readonly TeamManager _teamManager;
@@ -177,6 +177,12 @@ namespace Pal3.State
commands.Add(new EffectSetScreenEffectCommand(currentEffectMode));
}
// Save current camera state
int currentCameraTransformOption = _cameraManager.GetCurrentAppliedDefaultTransformOption();
Vector3 cameraCurrentRotationInEulerAngles = _cameraManager.GetMainCamera().transform.rotation.eulerAngles;
commands.Add(new CameraSetInitialStateOnNextSceneLoadCommand(
cameraCurrentRotationInEulerAngles, currentCameraTransformOption));
// Save current scene info and player actor state
commands.AddRange(new List<ICommand>()
{
@@ -297,13 +303,6 @@ namespace Pal3.State
}
#endif
// Save current applied camera settings
var defaultCameraTransformOption = _cameraManager.GetCurrentAppliedDefaultTransformOption();
if (defaultCameraTransformOption != 0)
{
commands.Add(new CameraSetDefaultTransformCommand(defaultCameraTransformOption));
}
// Good to have
commands.Add(new CameraFadeInCommand());
return commands;
+1 -1
View File
@@ -10,7 +10,7 @@
"com.unity.postprocessing": "3.2.2",
"com.unity.test-framework": "1.1.33",
"com.unity.textmeshpro": "3.0.6",
"com.unity.timeline": "1.7.3",
"com.unity.timeline": "1.7.4",
"com.unity.toolchain.win-x86_64-linux-x86_64": "2.0.4",
"com.unity.ugui": "1.0.0",
"com.unity.visualscripting": "1.8.0",
+1 -1
View File
@@ -150,7 +150,7 @@
"url": "https://packages.unity.com"
},
"com.unity.timeline": {
"version": "1.7.3",
"version": "1.7.4",
"depth": 0,
"source": "registry",
"dependencies": {
+1 -1
View File
@@ -133,7 +133,7 @@ PlayerSettings:
vulkanEnableLateAcquireNextImage: 0
vulkanEnableCommandBufferRecycling: 1
loadStoreDebugModeEnabled: 0
bundleVersion: 0.45
bundleVersion: 0.46
preloadedAssets: []
metroInputSource: 0
wsaTransparentSwapchain: 0
+2 -2
View File
@@ -1,2 +1,2 @@
m_EditorVersion: 2022.2.10f1
m_EditorVersionWithRevision: 2022.2.10f1 (bcebec703747)
m_EditorVersion: 2022.2.11f1
m_EditorVersionWithRevision: 2022.2.11f1 (621cd60d08fd)
+2 -2
View File
@@ -11,7 +11,7 @@
</p>
<p align="center">
<a style="text-decoration:none">
<img src="https://img.shields.io/badge/unity-2022.2.10-blue?style=flat-square" alt="Unity Version" />
<img src="https://img.shields.io/badge/unity-2022.2.11-blue?style=flat-square" alt="Unity Version" />
</a>
<a style="text-decoration:none">
<img src="https://img.shields.io/badge/platform-Linux%20%7C%20Win%20%7C%20Mac%20%7C%20iOS%20%7C%20Android-orange?style=flat-square" alt="Platform" />
@@ -60,7 +60,7 @@
- 触屏:仅在有触摸屏的手持设备上才会启用,虚拟摇杆控制行走,交互键互动。
## 项目进度以及路线图
仙剑奇侠传三以及仙剑奇侠传三外传的剧情部分已经全部完成,两部游戏都可以完整的从头玩到尾体验一遍剧情,也可以使用游戏内提供的剧情选择菜单跳转至预设好的剧情时间点。游戏中的迷宫机关,战斗,物品系统,小游戏以及其他的子系统尚未完成,未来的重心将是优先实现迷宫机关,最后是战斗系统以及相关联的各种子系统。另外主菜单和大部分界面也需要重新设计和实现(毕竟现在还要做手机端的适配)
仙剑奇侠传三以及仙剑奇侠传三外传的剧情部分已经全部完成,两部游戏都可以完整的从头玩到尾体验一遍剧情,也可以使用游戏内提供的剧情选择菜单跳转至预设好的剧情时间点。两部游戏中的迷宫机关也基本全部实现,但是战斗,小游戏以及围绕支持战斗系统的各类系统和功能均尚未完成。另外主菜单和大部分界面也需要重新设计和实现(毕竟现在还要做手机端的适配)。
## 如何贡献?
因为项目还处于早期实现过程中,很多系统还没有实现,暂时不接受比较大的Pull request,特别是feature类型,如果您有好的想法,意见或者发现了Bug请欢迎提交issue或者加入交流群与我讨论。