82 lines
2.5 KiB
C#
82 lines
2.5 KiB
C#
using System.Collections.Generic;
|
|
using BriarQueen.Data.Identifiers;
|
|
using BriarQueen.Data.IO.Saves;
|
|
using BriarQueen.Framework.Events.Save;
|
|
using BriarQueen.Framework.Events.UI;
|
|
using BriarQueen.Framework.Managers.Levels.Data;
|
|
using BriarQueen.Framework.Managers.UI;
|
|
using Cysharp.Threading.Tasks;
|
|
using UnityEngine;
|
|
|
|
namespace BriarQueen.Framework.Managers.Player.Data.Codex
|
|
{
|
|
public class CodexTrigger : BaseItem, ICodexTrigger
|
|
{
|
|
[Header("Codex")]
|
|
[SerializeField]
|
|
private CodexEntrySo _codexEntry;
|
|
[SerializeField]
|
|
private bool _removeTrigger;
|
|
|
|
[Header("Events")]
|
|
[SerializeField]
|
|
private SFXKey _soundEffect;
|
|
[SerializeField]
|
|
private VoiceKey _voiceLine;
|
|
|
|
public override UICursorService.CursorStyle ApplicableCursorStyle => UICursorService.CursorStyle.Inspect;
|
|
|
|
public override string InteractableName =>
|
|
!string.IsNullOrWhiteSpace(InteractableTooltip) ? InteractableTooltip : _codexEntry.Title;
|
|
|
|
public GameObject TriggerObject => GameObject;
|
|
public CodexEntrySo Entry => _codexEntry;
|
|
|
|
public bool RemoveTrigger => _removeTrigger;
|
|
|
|
public override async UniTask OnInteract(ItemDataSo item = null)
|
|
{
|
|
if (!CheckEmptyHands())
|
|
return;
|
|
|
|
if (!PlayerManager.CodexUnlocked())
|
|
{
|
|
EventCoordinator.PublishImmediate(new DisplayInteractEvent(InteractEventIDs.Get(ItemInteractKey.CodexLocked)));
|
|
return;
|
|
}
|
|
|
|
|
|
PlayerManager.UnlockCodexEntry(_codexEntry);
|
|
|
|
if (_removeTrigger)
|
|
{
|
|
await Remove();
|
|
}
|
|
|
|
if (_soundEffect != SFXKey.None)
|
|
{
|
|
AudioManager.Play(AudioNameIdentifiers.Get(_soundEffect));
|
|
}
|
|
|
|
if (_voiceLine != VoiceKey.None)
|
|
{
|
|
AudioManager.Play(AudioNameIdentifiers.Get(_voiceLine));
|
|
}
|
|
}
|
|
|
|
protected override void UpdateSaveGameOnRemoval()
|
|
{
|
|
var save = SaveManager.CurrentSave;
|
|
Debug.Log($"[Base Item] Found save - {save.SaveFileName}");
|
|
|
|
save.RemovedItems ??= new List<ItemSaveData>();
|
|
|
|
save.RemovedItems.Add(new ItemSaveData
|
|
{
|
|
UniqueIdentifier = _codexEntry.UniqueID
|
|
});
|
|
|
|
EventCoordinator.PublishImmediate(new RequestGameSaveEvent());
|
|
}
|
|
}
|
|
} |