52 lines
1.7 KiB
C#
52 lines
1.7 KiB
C#
using UnityEngine;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using TMPro;
|
|
|
|
public class MonsterRoom : Room
|
|
{
|
|
[SerializeField] private GameObject numberTextObject;
|
|
[SerializeField] private int _health; // Number of times the room needs to be unlocked before becoming explored.
|
|
|
|
protected override void InitializeRoom() {
|
|
base.InitializeRoom();
|
|
|
|
// Create the lock numbers on the room.
|
|
numberTextObject.GetComponent<TextMeshProUGUI>().text = ((NumberLock)_locks[0]).GetNumber().ToString();
|
|
GameObject lockToDuplicate = numberTextObject;
|
|
for (int i = 1; i < _locks.Length; i++)
|
|
{
|
|
lockToDuplicate = DuplicateToTheLeft(lockToDuplicate, ((RectTransform)lockToDuplicate.transform).rect.width);
|
|
lockToDuplicate.GetComponent<TextMeshProUGUI>().text = ((NumberLock)_locks[i]).GetNumber().ToString();
|
|
}
|
|
}
|
|
|
|
public override bool TryUnlock(DicePair pair) {
|
|
foreach (NumberLock numberLock in _locks)
|
|
{
|
|
if (pair.Sum() == numberLock.GetNumber())
|
|
{
|
|
return true;
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
public override void SetRoomExplored() {
|
|
_health -= 1;
|
|
if (_health == 0)
|
|
{
|
|
_isExplored = true;
|
|
UnhighlightRoomAsOption();
|
|
gameObject.GetComponent<SpriteRenderer>().color =
|
|
ColorHelper.AddColorTint(gameObject.GetComponent<SpriteRenderer>().color, Color.grey, 0.5f);
|
|
}
|
|
}
|
|
|
|
private GameObject DuplicateToTheLeft(GameObject original, float offset) {
|
|
GameObject clone = Instantiate(original, original.transform.parent);
|
|
clone.transform.localPosition -= new Vector3(offset, 0, 0);
|
|
return clone;
|
|
}
|
|
}
|