RiftMayhem/Assets/Scripts/Game/ClassUnlockProgressionHandler.cs
Pedro Gomes 9461120386 Rogue-lite progression continued (WIP)
- ability unlocks (90% done)
- class unlocks (working)
- new human base class
- bugfix small issues
2025-01-19 23:18:07 +00:00

86 lines
3.2 KiB
C#

using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
public class ClassUnlockProgressionHandler : MonoBehaviour
{
[SerializeField] private GameEventListener_Int onAbilityUnlocked;
[SerializeField] private GameEventListener_Int onAbilityTomeLearned;
[SerializeField] private TMP_Text unlockAbilityTextWarning;
[SerializeField] private TMP_Text unlockClassTextWarning;
BaseAbility unlockedAbility;
GameTag classTag;
private const string abilityPageLearnedText = " Pages learned: ";
private const string abilityUnlockedText = "New ability learned: ";
private const string classUnlockedText = "New Class Unlocked: ";
Coroutine pageRoutine;
private void Awake()
{
onAbilityUnlocked.Response.AddListener(CheckForUnlockedClass);
onAbilityTomeLearned.Response.AddListener(HandleInfo);
unlockAbilityTextWarning.gameObject.SetActive(false);
unlockClassTextWarning.gameObject.SetActive(false);
}
int count;
private void HandleInfo(int abilityIndex)
{
count = PlayerDataHandler.Instance.LoadAbilityTomeProgress(PlayerDataHandler.Instance.currentPlayerName.Value, abilityIndex);
pageRoutine = StartCoroutine(DelayedPageInfo(AbilityIndexer.Instance.Abilities[abilityIndex].displayName, count.ToString(), GameConstants.GameBalancing.TotalPagesPerAbilityTome.ToString()));
}
private void CheckForUnlockedClass(int abilityIndex)
{
unlockedAbility = AbilityIndexer.Instance.Abilities[abilityIndex];
StopCoroutine(pageRoutine);
pageRoutine = StartCoroutine(DelayedUnlockInfo(unlockedAbility.displayName));
classTag = BuildLibrary.Instance.GetClassBasedOnAbility(unlockedAbility);
if (classTag == null) return;
if (!PlayerDataHandler.Instance.ClassUnlocked(PlayerDataHandler.Instance.currentPlayerName.Value, classTag.name.ToLower()))
{
StartCoroutine(DelayedClassUnlockInfo(classTag.name.ToUpper()));
}
PlayerDataHandler.Instance.SaveClassUnlockedProgress(PlayerDataHandler.Instance.currentPlayerName.Value, classTag.name.ToLower());
}
IEnumerator DelayedPageInfo(string abilityName, string count, string total)
{
unlockAbilityTextWarning.text = abilityName + abilityPageLearnedText + count + "/" + total;
unlockAbilityTextWarning.gameObject.SetActive(true);
yield return new WaitForSeconds(GameConstants.GameBalancing.PermaDeathInfoTime);
unlockAbilityTextWarning.gameObject.SetActive(false);
}
IEnumerator DelayedUnlockInfo(string abilityName)
{
unlockAbilityTextWarning.text = abilityUnlockedText + abilityName;
unlockAbilityTextWarning.gameObject.SetActive(true);
yield return new WaitForSeconds(GameConstants.GameBalancing.PermaDeathInfoTime);
unlockAbilityTextWarning.gameObject.SetActive(false);
}
IEnumerator DelayedClassUnlockInfo(string classname)
{
unlockClassTextWarning.text = classUnlockedText + classname;
unlockClassTextWarning.gameObject.SetActive(true);
yield return new WaitForSeconds(GameConstants.GameBalancing.PermaDeathInfoTime);
unlockClassTextWarning.gameObject.SetActive(false);
}
}