65 lines
2.0 KiB
C#
65 lines
2.0 KiB
C#
using BriarQueen.Data.Identifiers;
|
|
using BriarQueen.Data.IO.Saves;
|
|
using BriarQueen.Framework.Events.UI;
|
|
using BriarQueen.Framework.Managers.Levels.Data;
|
|
using BriarQueen.Framework.Managers.Player.Data;
|
|
using BriarQueen.Framework.Managers.UI;
|
|
using Cysharp.Threading.Tasks;
|
|
using UnityEngine;
|
|
|
|
namespace BriarQueen.Game.Items.Environment.General
|
|
{
|
|
public class TwistingVines : BaseItem
|
|
{
|
|
[Header("Flags")]
|
|
[SerializeField]
|
|
private LevelFlag _levelFlag;
|
|
|
|
public override string InteractableName => "Twisting Vines";
|
|
public override UICursorService.CursorStyle ApplicableCursorStyle => UICursorService.CursorStyle.Inspect;
|
|
|
|
public override async UniTask OnInteract(ItemDataSo item = null)
|
|
{
|
|
if (item != null)
|
|
{
|
|
EventCoordinator.Publish(
|
|
new DisplayInteractEvent(InteractEventIDs.Get(ItemInteractKey.CantUseItem)));
|
|
return;
|
|
}
|
|
|
|
if (!CanUseKnife())
|
|
{
|
|
PublishFailureMessage();
|
|
return;
|
|
}
|
|
|
|
EventCoordinator.Publish(
|
|
new DisplayInteractEvent(InteractEventIDs.Get(EnvironmentInteractKey.UsingKnife)));
|
|
|
|
await Remove();
|
|
}
|
|
|
|
protected override UniTask OnRemoved()
|
|
{
|
|
SaveManager.SetLevelFlag(_levelFlag, true);
|
|
return UniTask.CompletedTask;
|
|
}
|
|
|
|
private bool CanUseKnife()
|
|
{
|
|
if (SettingsService.Game.AutoUseTools)
|
|
return PlayerManager.HasAccessToTool(ToolID.Knife);
|
|
|
|
return PlayerManager.GetEquippedTool() == ToolID.Knife;
|
|
}
|
|
|
|
private void PublishFailureMessage()
|
|
{
|
|
var message = SettingsService.Game.AutoUseTools
|
|
? InteractEventIDs.Get(LevelInteractKey.CutVines)
|
|
: InteractEventIDs.Get(ItemInteractKey.WrongTool);
|
|
|
|
EventCoordinator.Publish(new DisplayInteractEvent(message));
|
|
}
|
|
}
|
|
} |