PO/Assets/Scripts/DeckManager.cs

127 lines
3.8 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class DeckManager : MonoBehaviour
{
[SerializeField] private List<GameObject> deck = new List<GameObject>();
[SerializeField] private List<Transform> cardsPosition = new List<Transform>();
private List<GameObject> currentDeck = new List<GameObject>();
//private List<CardConfig> passedDeck = new List<CardConfig>();
[HideInInspector] public List<GameObject> CardInTable = new List<GameObject>();
public int numberCurrentCard;
public CardConfig currentCard;
[Header("Stamina")]
[SerializeField] private List<Image> staminaCells = new List<Image>();
[HideInInspector] public int stamina;
public bool waitingEnemyTurn = false;
private void Start()
{
stamina = 3;
CompletionDeck();
HandingOut();
}
public void HandingOut()
{
for (int i = 0; i < 5; i++)
{
if (currentDeck.Count > 0)
{
CompletionDeck();
}
int _number = Random.Range(0, currentDeck.Count);
GameObject _card = Instantiate(currentDeck[_number], cardsPosition[i]);
_card.GetComponent<Card>().number = i;
CardInTable.Add(_card);
currentDeck.RemoveAt(_number);
}
}
public void CompletionDeck()
{
for (int i = 0; i < deck.Count; i++)
{
currentDeck.Add(deck[i]);
}
}
public void NewStaminaQuantity(int q)
{
stamina = q;
for (int i = 0; i < 3; i++)
{
if (i < stamina)
{
staminaCells[i].enabled = true;
}
else
{
staminaCells[i].enabled = false;
}
}
}
public void EndTurn(bool enemyTurn)
{
if (waitingEnemyTurn) return;
for (int i = 0; i < 5; i++)
{
if (CardInTable[i] != null)
{
CardInTable[i].GetComponent<Card>().DestroyObject();
}
}
CardInTable.Clear();
if (stamina < 3)
NewStaminaQuantity(stamina + 1);
//нужна корутина для вражеского хода
if (enemyTurn)
StartCoroutine(EnemyStep());
//а, вот же она
}
public void ActionInEnemy(Enemy enemy)
{
if (waitingEnemyTurn) return;
if (currentCard == null) return;
if (currentCard.CardCharacteristics.damage > 0)
{
enemy.ChangeHp(currentCard.CardCharacteristics.damage);
}
else if (currentCard.CardCharacteristics.healing > 0)
{
enemy.ChangeHp(-currentCard.CardCharacteristics.healing);
}
NewStaminaQuantity(stamina - currentCard.CardCharacteristics.quantityStamina);
CardInTable[numberCurrentCard].GetComponent<Card>().DestroyObject();
currentCard = null;
}
public void ActionInPlayer()
{
if (waitingEnemyTurn) return;
if (currentCard == null) return;
if (currentCard.CardCharacteristics.damage > 0)
{
Player.main.ChangeHp(currentCard.CardCharacteristics.damage);
}
else if (currentCard.CardCharacteristics.healing > 0)
{
Player.main.ChangeHp(-currentCard.CardCharacteristics.healing);
}
NewStaminaQuantity(stamina - currentCard.CardCharacteristics.quantityStamina);
CardInTable[numberCurrentCard].GetComponent<Card>().DestroyObject();
currentCard = null;
}
IEnumerator EnemyStep()
{
waitingEnemyTurn = true;
Session.instance.EnemiesStep();
yield return new WaitForSeconds(0.5f);
waitingEnemyTurn = false;
HandingOut();
}
}