Files
beyond/Assets/Scripts/Tutorial/EquipConsumableStep.cs
2024-11-20 15:21:28 +01:00

73 lines
2.4 KiB
C#

using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
namespace Beyond
{
public class EquipConsumableStep : MonoBehaviour
{
public BaseStepController baseStepController;
public TMP_Text equipText;
public bEquipArea equipArea;
private List<bEquipSlot> equipSlots;
public List<Button> buttonsToEnableOnEnd;
public Button consumableButton, equipButton;
public int indexOfItemToEquip = 5;
private int hopeFruitIndex = 84, healingFruitIndex = 83;
// Start is called before the first frame update
private void Start()
{
equipSlots = equipArea.equipSlots;
baseStepController.OnStarted += () => { buttonsToEnableOnEnd.ForEach(button => button.enabled = false); equipButton.enabled = true; };
baseStepController.OnEvaluationStart += () => { /*Player.Instance.ItemManager.AddItemByID(85); */ UnequipConsumables(); equipText.text = "Equip"; };
baseStepController.ConditionsAreMet += () => AreConsumablesEquipped();
baseStepController.OnCompleted += () => { buttonsToEnableOnEnd.ForEach(button => button.enabled = true); consumableButton.enabled = true; };
}
//probably not needed
public void UnequipConsumables()
{
for (int i = 0; i < equipSlots.Count; i++)
{
//check by name, checking by reference is more complicated but would be better
if (equipSlots[i].item != null)
{
equipArea.RemoveItemOfEquipSlot(i);
}
}
}
public bool AreConsumablesEquipped()
{
bool healingEquipped = false;
bool hopeEquipped = false;
for (int i = 0; i < equipSlots.Count; i++)
{
if (equipSlots[i].item == null)
{
continue;
}
if (equipSlots[i].item.id == healingFruitIndex)
{
healingEquipped = true;
}
else if (equipSlots[i].item.id == hopeFruitIndex)
{
hopeEquipped = true;
}
}
if (healingEquipped && hopeEquipped)
{
return true;
}
else
{
return false;
}
}
}
}