using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class DeckManager : MonoBehaviour { public static DeckManager main; [SerializeField] private List deck = new List(); [SerializeField] private List cardsPosition = new List(); private List currentDeck = new List(); //private List passedDeck = new List(); [HideInInspector] public List CardInTable = new List(); public int numberCurrentCard; public CardConfig currentCard; [Header("Stamina")] [SerializeField] private List staminaCells = new List(); [HideInInspector] public int stamina; public bool waitingEnemyTurn = false; private void Awake() { if (main != null && main != this) { Debug.LogWarning("2 base enemy turn on the scene"); Destroy(this); return; } main = this; } 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().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; currentCard = null; MarkersRegulator(); for (int i = 0; i < 5; i++) { if (CardInTable[i] != null) { CardInTable[i].GetComponent().DestroyObject(); } } CardInTable.Clear(); if (stamina < 3) NewStaminaQuantity(stamina + 1); //нужна корутина для вражеского хода if (enemyTurn) StartCoroutine(EnemyStep()); //а, вот же она } public void MarkersRegulator() { List _enemies = Session.main.currentEnemies; for (int i = 0; i < _enemies.Count; i++) { if (_enemies[i] != null) { _enemies[i].GetComponent().OffMarker(); } } Player.main.OffMarker(); if (currentCard == null) { return; } var _specializationCard = currentCard.CardCharacteristics.specialization; for (int i = 0; i < _enemies.Count; i++) { if (_enemies[i] != null) { if (_specializationCard == Specialization.meleeAtack) { _enemies[i].GetComponent().OnMarker(); return; } else if (_specializationCard == Specialization.longAttack) { _enemies[i].GetComponent().OnMarker(); } } } if (_specializationCard == Specialization.healing) { Player.main.OnMarker(); } } public void ActionInEnemy(Enemy enemy) { if (waitingEnemyTurn || currentCard == null || !enemy.CheckMarker()) 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().DestroyObject(); currentCard = null; MarkersRegulator(); } public void ActionInPlayer() { if (waitingEnemyTurn || currentCard == null || !Player.main.CheckMarker()) 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().DestroyObject(); currentCard = null; MarkersRegulator(); } IEnumerator EnemyStep() { waitingEnemyTurn = true; Session.main.EnemiesStep(); yield return new WaitForSeconds(0.5f); waitingEnemyTurn = false; HandingOut(); } }