mirror of
https://github.com/0x7c13/Pal3.Unity.git
synced 2026-11-26 17:38:10 +08:00
* Optimize DDS texture creation and static POL meshes Separate file decoding from Unity upload through format-neutral texture data and explicit world, sprite and skybox policies. Validate DDS layouts, preserve alpha coverage and use native BC uploads with software RGBA fallback. Compact referenced POL vertices and batch nearby static opaque groups sharing materials. Keep water and dynamic geometry separate, with source ranges retained only in the Editor. Add DDS layout and POL index regression tests. Validation: PAL3 and PAL3A each passed 24 Editor tests, eight combined Game and ResourceViewer style regressions, 936 paired skybox comparisons, and both macOS Player builds on Metal. Editor provenance and Core tests are excluded from Players. * Add core protocol regression tests and copyright checks Cover SCE command contracts, binary readers, resource layouts and full local CPK decompression for PAL3 and PAL3A. Fix CVD time rebasing, binary read bounds and short reads, and CPK/NAV validation. Standardize first-party copyright headers, preserve correct creation years, and update console source generation. Validate both variants in Unity and verify all live CPK entries. * Implement PAL3A command handlers and isolate script execution Correct PAL3A parameter signatures and add handlers for fortune selection, skybox sequences, actor facing and attacks, team and progression state, camera constraints, and battle preparation flags. Give script instances separate locals, advance grouped waits concurrently, and pause PAL3A parents only for their directly decoded child calls. Cancel stale interactions and save replay on reset, preserve finite action semantics, and restore camera orientation after releasing horizontal constraints. Persist supported state in v2 saves and add protocol, runtime, and progression regressions. Full combat gameplay remains outside this change. Validation: PAL3 274/274 and PAL3A 291/291 EditMode tests; 18 PAL3 and 22 PAL3A runtime checks. All 77,889 PAL3A instruction boundaries match EXE signatures. * Run CI only for pull requests and upgrade build actions
171 lines
6.1 KiB
C#
171 lines
6.1 KiB
C#
// ------------------------------------------------------------------------
|
|
// Copyright (c) 2021-2026, Jiaqi (0x7c13) Liu. All rights reserved.
|
|
// See LICENSE file in the project root for license information.
|
|
// ------------------------------------------------------------------------
|
|
|
|
namespace Pal3.Game.Scene.SceneObjects
|
|
{
|
|
using System.Collections;
|
|
using System.Threading;
|
|
using Actor.Controllers;
|
|
using Command;
|
|
using Common;
|
|
using Core.Command;
|
|
using Core.Command.SceCommands;
|
|
using Core.Contract.Constants;
|
|
using Core.Contract.Enums;
|
|
using Core.DataReader.Scn;
|
|
using Data;
|
|
using Engine.Animation;
|
|
using Engine.Core.Abstraction;
|
|
using Engine.Coroutine;
|
|
using Engine.Extensions;
|
|
|
|
using Bounds = UnityEngine.Bounds;
|
|
using Color = Core.Primitives.Color;
|
|
using Vector3 = UnityEngine.Vector3;
|
|
|
|
[ScnSceneObject(SceneObjectType.DivineTreePortal)]
|
|
public sealed class DivineTreePortalObject : SceneObject
|
|
{
|
|
private float MOVEMENT_ANIMATION_DURATION = 3f;
|
|
|
|
private StandingPlatformController _platformController;
|
|
private CancellationTokenSource _cancellationTokenSource = new ();
|
|
private bool _isInteractionInProgress;
|
|
|
|
public DivineTreePortalObject(ScnObjectInfo objectInfo, ScnSceneInfo sceneInfo)
|
|
: base(objectInfo, sceneInfo)
|
|
{
|
|
}
|
|
|
|
public override IGameEntity Activate(GameResourceProvider resourceProvider,
|
|
Color tintColor)
|
|
{
|
|
if (IsActivated) return GetGameEntity();
|
|
|
|
IGameEntity sceneObjectGameEntity = base.Activate(resourceProvider, tintColor);
|
|
|
|
Bounds bounds = new()
|
|
{
|
|
center = new Vector3(0f, -1f, 0f),
|
|
size = new Vector3(9f, 2f, 9f),
|
|
};
|
|
|
|
_platformController = sceneObjectGameEntity.AddComponent<StandingPlatformController>();
|
|
_platformController.Init(bounds, ObjectInfo.LayerIndex);
|
|
|
|
_platformController.OnPlayerActorEntered += OnPlayerActorEntered;
|
|
_platformController.OnPlayerActorExited += OnPlayerActorExited;
|
|
|
|
return sceneObjectGameEntity;
|
|
}
|
|
|
|
private void OnPlayerActorEntered(object sender, IGameEntity playerActorGameEntity)
|
|
{
|
|
if (_isInteractionInProgress) return;
|
|
|
|
#if PAL3
|
|
Pal3.Instance.Execute(new UIDisplayNoteCommand("等待三秒后,根据当前人物,会向上或向下传送哦。"));
|
|
#elif PAL3A
|
|
Pal3.Instance.Execute(new UIDisplayNoteCommand("等待三秒后,会开始传送哦。"));
|
|
#endif
|
|
_cancellationTokenSource.Cancel();
|
|
_cancellationTokenSource = new CancellationTokenSource();
|
|
Pal3.Instance.StartCoroutine(CountDownForInteractionAsync(_cancellationTokenSource.Token));
|
|
}
|
|
|
|
private void OnPlayerActorExited(object sender, IGameEntity playerActorGameEntity)
|
|
{
|
|
if (_isInteractionInProgress) return;
|
|
_cancellationTokenSource.Cancel();
|
|
}
|
|
|
|
private IEnumerator CountDownForInteractionAsync(CancellationToken cancellationToken)
|
|
{
|
|
yield return CoroutineYieldInstruction.WaitForSeconds(3f);
|
|
if (cancellationToken.IsCancellationRequested) yield break;
|
|
_isInteractionInProgress = true;
|
|
RequestForInteraction();
|
|
}
|
|
|
|
public override bool IsDirectlyInteractable(float distance) => false;
|
|
|
|
public override bool ShouldGoToCutsceneWhenInteractionStarted() => true;
|
|
|
|
public override IEnumerator InteractAsync(InteractionContext ctx)
|
|
{
|
|
#if PAL3
|
|
int upperLevelScriptId = ObjectInfo.Parameters[0];
|
|
int lowerLevelScriptId = ObjectInfo.Parameters[1];
|
|
|
|
bool? shouldGoUp = null;
|
|
|
|
if (upperLevelScriptId == ScriptConstants.InvalidScriptId)
|
|
{
|
|
shouldGoUp = false;
|
|
}
|
|
if (lowerLevelScriptId == ScriptConstants.InvalidScriptId)
|
|
{
|
|
shouldGoUp = true;
|
|
}
|
|
|
|
if (!shouldGoUp.HasValue)
|
|
{
|
|
shouldGoUp = (PlayerActorId) ctx.PlayerActorGameEntity.GetComponent<ActorController>().GetActor().Id is
|
|
PlayerActorId.JingTian or PlayerActorId.XueJian;
|
|
}
|
|
#elif PAL3A
|
|
bool? shouldGoUp = ObjectInfo.Parameters[0] == 1;
|
|
#endif
|
|
|
|
IGameEntity portalEntity = GetGameEntity();
|
|
Vector3 platformPosition = _platformController.Transform.Position;
|
|
Vector3 actorStandingPosition = new(
|
|
platformPosition.x,
|
|
_platformController.GetPlatformHeight(),
|
|
platformPosition.z);
|
|
|
|
ActorMovementController actorMovementController = ctx.PlayerActorGameEntity.GetComponent<ActorMovementController>();
|
|
|
|
yield return actorMovementController.MoveDirectlyToAsync(actorStandingPosition, 0, true);
|
|
|
|
Vector3 finalPosition = portalEntity.Transform.Position;
|
|
finalPosition.y += shouldGoUp.Value ? 10f : -10f;
|
|
|
|
yield return portalEntity.Transform.MoveAsync(finalPosition,
|
|
MOVEMENT_ANIMATION_DURATION,
|
|
AnimationCurveType.Sine);
|
|
|
|
yield return null;
|
|
|
|
#if PAL3
|
|
Pal3.Instance.Execute(new ScriptExecuteCommand(shouldGoUp.Value ? upperLevelScriptId : lowerLevelScriptId));
|
|
#elif PAL3A
|
|
ExecuteScriptIfAny();
|
|
#endif
|
|
|
|
_isInteractionInProgress = false;
|
|
}
|
|
|
|
public override void Deactivate()
|
|
{
|
|
if (!_cancellationTokenSource.IsCancellationRequested)
|
|
{
|
|
_cancellationTokenSource.Cancel();
|
|
}
|
|
|
|
_isInteractionInProgress = false;
|
|
|
|
if (_platformController != null)
|
|
{
|
|
_platformController.OnPlayerActorEntered -= OnPlayerActorEntered;
|
|
_platformController.OnPlayerActorExited -= OnPlayerActorExited;
|
|
_platformController.Destroy();
|
|
_platformController = null;
|
|
}
|
|
|
|
base.Deactivate();
|
|
}
|
|
}
|
|
} |