86 lines
1.9 KiB
C#
86 lines
1.9 KiB
C#
using System;
|
|
using Unity.VisualScripting;
|
|
using UnityEngine;
|
|
using System.Collections.Generic;
|
|
using TMPro;
|
|
|
|
public abstract class Lock : MonoBehaviour
|
|
{
|
|
|
|
// Room that must be explored before lock can be unlocked.
|
|
[SerializeField] protected Room blockingRoom;
|
|
private TextMeshProUGUI _lockText;
|
|
public event Action Unlocked;
|
|
|
|
public abstract override bool Equals(object other);
|
|
|
|
public override int GetHashCode() => GetHashCode();
|
|
|
|
public void OnEnable()
|
|
{
|
|
if (blockingRoom != null)
|
|
{
|
|
blockingRoom.ThisRoomExploredByTorch += HandleBlockingRoomExplored;
|
|
blockingRoom.RoomExploredByDice += HandleBlockingRoomExplored;
|
|
}
|
|
}
|
|
|
|
public void OnDisable()
|
|
{
|
|
if (blockingRoom != null)
|
|
{
|
|
blockingRoom.ThisRoomExploredByTorch -= HandleBlockingRoomExplored;
|
|
blockingRoom.RoomExploredByDice -= HandleBlockingRoomExplored;
|
|
}
|
|
}
|
|
|
|
public virtual bool CheckIfKeyFits(DicePair dicePair)
|
|
{
|
|
if (blockingRoom == null || blockingRoom.GetRoomExplored())
|
|
{
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
public virtual void Unlock(DicePair dicePair)
|
|
{
|
|
if (CheckIfKeyFits(dicePair))
|
|
{
|
|
OnUnlock();
|
|
}
|
|
}
|
|
|
|
public void SetBlockingRoom(Room room)
|
|
{
|
|
blockingRoom = room;
|
|
}
|
|
|
|
public virtual void AssignGUI(TextMeshProUGUI text)
|
|
{
|
|
_lockText = text;
|
|
if (blockingRoom != null)
|
|
{
|
|
_lockText.alpha = ColorHelper.TEXT_FADED_OPACITY;
|
|
}
|
|
}
|
|
|
|
private void HandleBlockingRoomExplored(Room room)
|
|
{
|
|
SetBlockingRoomExploredGUI();
|
|
}
|
|
|
|
protected virtual void OnUnlock()
|
|
{
|
|
Unlocked?.Invoke();
|
|
}
|
|
|
|
private void SetBlockingRoomExploredGUI()
|
|
{
|
|
if (_lockText != null)
|
|
{
|
|
_lockText.alpha = ColorHelper.TEXT_FULL_OPACITY;
|
|
}
|
|
}
|
|
}
|