Files
A-Fairytale-Gone-Bad-Briar-…/Assets/Scripts/Game/Items/Environment/ChapterOne/VillageStreet/StreetVines.cs

76 lines
2.5 KiB
C#

using BriarQueen.Data.Identifiers;
using BriarQueen.Framework.Events.UI;
using BriarQueen.Framework.Managers.Levels.Data;
using BriarQueen.Framework.Managers.Player.Data;
using BriarQueen.Framework.Managers.UI;
using BriarQueen.Game.Levels.ChapterOne.VillageStreet;
using Cysharp.Threading.Tasks;
using UnityEngine;
namespace BriarQueen.Game.Items.Environment.ChapterOne.VillageStreet
{
public class StreetVines : BaseItem
{
[SerializeField]
private Street _owner;
public override UICursorService.CursorStyle ApplicableCursorStyle => UICursorService.CursorStyle.Inspect;
public override async UniTask OnInteract(ItemDataSo item = null)
{
if (_owner == null)
{
Debug.LogWarning("StreetVines is missing its Street owner.", this);
return;
}
if (!CanUseKnife())
{
PublishFailureMessage();
return;
}
EventCoordinator.Publish(new DisplayInteractEvent(
InteractEventIDs.Get(EnvironmentInteractKey.UsingKnife)));
await _owner.CutVines();
}
private bool CanUseKnife()
{
if (SettingsService.Game.AutoUseTools)
return PlayerManager.HasAccessToTool(ToolID.Knife);
return PlayerManager.GetEquippedTool() == ToolID.Knife;
}
private void PublishFailureMessage()
{
var autoUseTools = SettingsService != null &&
SettingsService.Game != null &&
SettingsService.Game.AutoUseTools;
var equippedTool = PlayerManager.GetEquippedTool();
string message;
if (equippedTool == ToolID.None)
{
message = InteractEventIDs.Get(LevelInteractKey.CutVines);
}
else if (autoUseTools)
{
// In auto-use mode, reaching this point means the player does not have access
// to the required tool at all, so this should still read like a generic failure.
message = InteractEventIDs.Get(LevelInteractKey.CutVines);
}
else
{
// Auto-use is disabled, and the player has some tool equipped that is not valid.
message = InteractEventIDs.Get(ItemInteractKey.WrongTool);
}
EventCoordinator.Publish(new DisplayInteractEvent(message));
}
}
}