mirror of
https://github.com/0x7c13/Pal3.Unity.git
synced 2026-11-27 18:08:09 +08:00
83 lines
2.8 KiB
C#
83 lines
2.8 KiB
C#
// ---------------------------------------------------------------------------------------------
|
|
// Copyright (c) 2021-2023, Jiaqi Liu. All rights reserved.
|
|
// See LICENSE file in the project root for license information.
|
|
// ---------------------------------------------------------------------------------------------
|
|
|
|
namespace Pal3.Scene.SceneObjects
|
|
{
|
|
using System.Collections;
|
|
using Command;
|
|
using Command.InternalCommands;
|
|
using Command.SceCommands;
|
|
using Common;
|
|
using Core.DataReader.Scn;
|
|
using Data;
|
|
using MetaData;
|
|
using UnityEngine;
|
|
|
|
[ScnSceneObject(ScnSceneObjectType.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 Activated && distance < MAX_INTERACTION_DISTANCE;
|
|
}
|
|
|
|
public override GameObject Activate(GameResourceProvider resourceProvider, Color tintColor)
|
|
{
|
|
if (Activated) return GetGameObject();
|
|
GameObject sceneGameObject = base.Activate(resourceProvider, tintColor);
|
|
_meshCollider = sceneGameObject.AddComponent<SceneObjectMeshCollider>();
|
|
return sceneGameObject;
|
|
}
|
|
|
|
public override IEnumerator InteractAsync(InteractionContext ctx)
|
|
{
|
|
CommandDispatcher<ICommand>.Instance.Dispatch(
|
|
new ActorStopActionAndStandCommand(ActorConstants.PlayerActorVirtualID));
|
|
CommandDispatcher<ICommand>.Instance.Dispatch(
|
|
new PlayerActorLookAtSceneObjectCommand(ObjectInfo.Id));
|
|
CommandDispatcher<ICommand>.Instance.Dispatch(
|
|
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)
|
|
{
|
|
CommandDispatcher<ICommand>.Instance.Dispatch(new InventoryAddItemCommand(ObjectInfo.Parameters[i], 1));
|
|
}
|
|
}
|
|
|
|
ChangeAndSaveActivationState(false);
|
|
}
|
|
|
|
public override void Deactivate()
|
|
{
|
|
if (_meshCollider != null)
|
|
{
|
|
Object.Destroy(_meshCollider);
|
|
}
|
|
|
|
base.Deactivate();
|
|
}
|
|
}
|
|
} |