60 lines
2.2 KiB
C#
60 lines
2.2 KiB
C#
using UnityEngine;
|
|
|
|
namespace Beyond
|
|
{
|
|
public class ChargeFaithStep : MonoBehaviour
|
|
{
|
|
public BaseStepController baseStepController; // Referencja do kontrolera kroku
|
|
private bool isFaithCharged = false; // Flaga, która śledzi, czy wiara została naładowana
|
|
|
|
private void Start()
|
|
{
|
|
// Subskrybuje rozpoczęcie kroku tutoriala
|
|
baseStepController.OnStarted += OnStepStarted;
|
|
|
|
// Dodaje warunek do zakończenia kroku
|
|
baseStepController.ConditionsAreMet += () => isFaithCharged;
|
|
|
|
// Dodajemy nasłuchiwanie na zdarzenie użycia przedmiotu przez gracza
|
|
Player.Instance.ItemManager.onUseItem.AddListener(OnUseItem);
|
|
}
|
|
|
|
private void OnStepStarted()
|
|
{
|
|
// Resetujemy flagę na początku kroku
|
|
isFaithCharged = false;
|
|
Debug.Log("Krok 2 rozpoczęty: Czekamy na użycie przedmiotu wiary.");
|
|
}
|
|
|
|
private void OnUseItem(bItem item)
|
|
{
|
|
// Sprawdzamy, czy użyty przedmiot to wiara (typ: ConsumablesFaith)
|
|
if (item.type == bItemType.ConsumablesFaith)
|
|
{
|
|
// Sprawdzamy, czy poziom wiary jest pełny lub użyty przedmiot jest prawidłowy
|
|
var faithAttribute = Player.Instance.GetAttribute("Faith");
|
|
if (faithAttribute.AttributeCurrentValue >= faithAttribute.AttributeMaxValue)
|
|
{
|
|
Debug.Log("Wiara naładowana do pełna. Zakończenie kroku 2.");
|
|
isFaithCharged = true;
|
|
// Usuwamy listener po zakończeniu, aby uniknąć niepotrzebnych nasłuchiwań
|
|
Player.Instance.ItemManager.onUseItem.RemoveListener(OnUseItem);
|
|
}
|
|
else
|
|
{
|
|
Debug.Log("Wiara została użyta, ale nie jest jeszcze pełna.");
|
|
}
|
|
}
|
|
}
|
|
|
|
private void OnDestroy()
|
|
{
|
|
// Usuwamy nasłuchiwanie, aby uniknąć błędów po zniszczeniu obiektu
|
|
if (Player.Instance != null && Player.Instance.ItemManager != null)
|
|
{
|
|
Player.Instance.ItemManager.onUseItem.RemoveListener(OnUseItem);
|
|
}
|
|
}
|
|
}
|
|
}
|