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); } }