Files
Pal3.Unity/Assets/Scripts/Pal3.Game/Scene/SceneObjects/RareChestObject.cs
Jiaqi (0x7c13) Liu e870cf487a 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.
2026-11-12 13:37:27 +08:00

88 lines
2.9 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 Command;
using Command.Extensions;
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.Core.Abstraction;
using Engine.Extensions;
using Color = Core.Primitives.Color;
[ScnSceneObject(SceneObjectType.RareChest)]
public sealed class RareChestObject : SceneObject
{
private const float MAX_INTERACTION_DISTANCE = 3f;
private SceneObjectMeshCollider _meshCollider;
public RareChestObject(ScnObjectInfo objectInfo, ScnSceneInfo sceneInfo)
: base(objectInfo, sceneInfo)
{
}
public override bool IsDirectlyInteractable(float distance)
{
return IsActivated && distance < MAX_INTERACTION_DISTANCE;
}
public override bool ShouldGoToCutsceneWhenInteractionStarted() => true;
public override IGameEntity Activate(GameResourceProvider resourceProvider, Color tintColor)
{
if (IsActivated) return GetGameEntity();
IGameEntity sceneObjectGameEntity = base.Activate(resourceProvider, tintColor);
_meshCollider = sceneObjectGameEntity.AddComponent<SceneObjectMeshCollider>();
return sceneObjectGameEntity;
}
public override IEnumerator InteractAsync(InteractionContext ctx)
{
Pal3.Instance.Execute(new ActorStopActionAndStandCommand(ActorConstants.PlayerActorVirtualID));
Pal3.Instance.Execute(new PlayerActorLookAtSceneObjectCommand(ObjectInfo.Id));
Pal3.Instance.Execute(new ActorPerformActionCommand(ActorConstants.PlayerActorVirtualID,
ActorConstants.ActionToNameMap[ActorActionType.Check], 1));
PlaySfx("wg011");
if (ModelType == SceneObjectModelType.CvdModel)
{
yield return GetCvdModelRenderer().PlayOneTimeAnimationAsync(true);
}
PlaySfx("wa006");
for (int i = 0; i < 6; i++)
{
if (ObjectInfo.Parameters[i] != 0)
{
Pal3.Instance.Execute(new InventoryAddItemCommand(ObjectInfo.Parameters[i], 1));
}
}
ChangeAndSaveActivationState(false);
}
public override void Deactivate()
{
if (_meshCollider != null)
{
_meshCollider.Destroy();
_meshCollider = null;
}
base.Deactivate();
}
}
}