Files
Pal3.Unity/Assets/Scripts/Pal3.Game/Scene/SceneObjects/PaperweightDeskObject.cs
Jiaqi Liu b1d9e3b0ac Bug fix + Bump Unity version + Update copyright text
- Fixed a bug caused by inconsistent state check between managed and native object.
- Bump Unity version.
- Update copyright text
2025-03-05 21:13:59 -08:00

78 lines
2.8 KiB
C#

// ---------------------------------------------------------------------------------------------
// Copyright (c) 2021-2025, Jiaqi (0x7c13) Liu. All rights reserved.
// See LICENSE file in the project root for license information.
// ---------------------------------------------------------------------------------------------
#if PAL3A
namespace Pal3.Game.Scene.SceneObjects
{
using System.Collections;
using System.Collections.Generic;
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 Engine.Coroutine;
using Engine.Services;
using GameSystems.Inventory;
[ScnSceneObject(SceneObjectType.PaperweightDesk)]
public sealed class PaperweightDeskObject : SceneObject
{
private const float MAX_INTERACTION_DISTANCE = 2f;
private readonly Dictionary<int, int> _deskIdToRequiredItemIdMap = new()
{
[20] = 6657,
[21] = 6659,
[22] = 6658,
};
private readonly InventoryManager _inventoryManager;
public PaperweightDeskObject(ScnObjectInfo objectInfo, ScnSceneInfo sceneInfo)
: base(objectInfo, sceneInfo)
{
_inventoryManager = ServiceLocator.Instance.Get<InventoryManager>();
}
public override bool IsDirectlyInteractable(float distance)
{
return IsActivated &&
distance < MAX_INTERACTION_DISTANCE &&
ObjectInfo.Times > 0;
}
public override bool ShouldGoToCutsceneWhenInteractionStarted() => true;
public override IEnumerator InteractAsync(InteractionContext ctx)
{
if (!_deskIdToRequiredItemIdMap.TryGetValue(ObjectInfo.Id, out int requiredItemId)) yield break;
if (_inventoryManager.HaveItem(requiredItemId))
{
if (!IsInteractableBasedOnTimesCount()) yield break;
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));
yield return CoroutineYieldInstruction.WaitForSeconds(0.8f); // Wait for actor animation to finish
yield return ActivateOrInteractWithObjectIfAnyAsync(ctx, ObjectInfo.LinkedObjectId);
}
else
{
Pal3.Instance.Execute(new UIDisplayNoteCommand("还没有找到合适的东西"));
}
}
}
}
#endif