2022-01-12 10:06:03 +03:00
|
|
|
|
using System.Collections;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
using UnityEngine.UI;
|
|
|
|
|
|
|
|
|
|
public class DeckManager : MonoBehaviour
|
|
|
|
|
{
|
2022-02-09 21:22:43 +03:00
|
|
|
|
public int turn = 0;
|
|
|
|
|
|
2022-01-13 12:07:16 +03:00
|
|
|
|
public static DeckManager main;
|
2022-01-12 10:06:03 +03:00
|
|
|
|
[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;
|
2022-01-20 11:44:38 +03:00
|
|
|
|
[SerializeField] private GameObject firstCard;
|
|
|
|
|
[SerializeField] private GameObject firstEquip;
|
|
|
|
|
[SerializeField] private GameObject secondCard;
|
|
|
|
|
[SerializeField] private GameObject secondEquip;
|
2022-01-13 11:00:37 +03:00
|
|
|
|
public bool waitingEnemyTurn = false;
|
2022-01-13 12:07:16 +03:00
|
|
|
|
|
|
|
|
|
private void Awake()
|
|
|
|
|
{
|
|
|
|
|
if (main != null && main != this)
|
|
|
|
|
{
|
|
|
|
|
Debug.LogWarning("2 base enemy turn on the scene");
|
|
|
|
|
Destroy(this);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
main = this;
|
|
|
|
|
}
|
2022-01-12 10:06:03 +03:00
|
|
|
|
private void Start()
|
|
|
|
|
{
|
|
|
|
|
stamina = 3;
|
|
|
|
|
CompletionDeck();
|
|
|
|
|
HandingOut();
|
2022-01-20 11:44:38 +03:00
|
|
|
|
for (int i = 0; i < DataHolder.main.PlayerEquipment.Count; i++)
|
|
|
|
|
{
|
|
|
|
|
var _equipmentCharacter =
|
|
|
|
|
DataHolder.main.PlayerEquipment[i].GetComponent<Equipment>().equipmentConfig.equipmentCharacteristics;
|
|
|
|
|
if (_equipmentCharacter.equipmentCards.Length != 0)
|
|
|
|
|
{
|
|
|
|
|
for (int j = 0; j < _equipmentCharacter.equipmentCards.Length; j++)
|
|
|
|
|
{
|
|
|
|
|
AddCard(_equipmentCharacter.equipmentCards[i]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-01-12 10:06:03 +03:00
|
|
|
|
}
|
|
|
|
|
|
2022-01-20 11:44:38 +03:00
|
|
|
|
public void AddCard(GameObject card)
|
|
|
|
|
{
|
|
|
|
|
deck.Add(card);
|
|
|
|
|
}
|
|
|
|
|
public void DeletedCard(GameObject card)
|
|
|
|
|
{
|
|
|
|
|
for (int i = 0; i < deck.Count; i++)
|
|
|
|
|
{
|
|
|
|
|
if (deck[i] == card)
|
|
|
|
|
{
|
|
|
|
|
deck.RemoveAt(i);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
Debug.LogWarning("No card found to delete");
|
|
|
|
|
}
|
2022-01-12 10:06:03 +03:00
|
|
|
|
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;
|
2022-01-20 11:44:38 +03:00
|
|
|
|
if (stamina > 3) stamina = 3;
|
|
|
|
|
|
2022-01-12 10:06:03 +03:00
|
|
|
|
for (int i = 0; i < 3; i++)
|
|
|
|
|
{
|
|
|
|
|
if (i < stamina)
|
|
|
|
|
{
|
|
|
|
|
staminaCells[i].enabled = true;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
staminaCells[i].enabled = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-01-13 11:00:37 +03:00
|
|
|
|
public void EndTurn(bool enemyTurn)
|
2022-01-12 10:06:03 +03:00
|
|
|
|
{
|
2022-01-15 10:29:16 +03:00
|
|
|
|
if (waitingEnemyTurn || Session.main.waitingEndingRound) return;
|
2022-01-14 10:42:43 +03:00
|
|
|
|
currentCard = null;
|
|
|
|
|
MarkersRegulator();
|
2022-01-12 10:06:03 +03:00
|
|
|
|
for (int i = 0; i < 5; i++)
|
|
|
|
|
{
|
|
|
|
|
if (CardInTable[i] != null)
|
|
|
|
|
{
|
|
|
|
|
CardInTable[i].GetComponent<Card>().DestroyObject();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
CardInTable.Clear();
|
2022-01-17 17:49:27 +03:00
|
|
|
|
HandingOut();
|
2022-01-12 10:06:03 +03:00
|
|
|
|
if (stamina < 3)
|
|
|
|
|
NewStaminaQuantity(stamina + 1);
|
|
|
|
|
//нужна корутина для вражеского хода
|
2022-01-13 11:00:37 +03:00
|
|
|
|
if (enemyTurn)
|
|
|
|
|
StartCoroutine(EnemyStep());
|
|
|
|
|
//а, вот же она
|
2022-02-09 21:22:43 +03:00
|
|
|
|
turn += 1;
|
2022-01-13 11:00:37 +03:00
|
|
|
|
|
2022-02-09 21:22:43 +03:00
|
|
|
|
for (int i = 0; i < Session.main.currentEnemies.Count; i++)
|
|
|
|
|
{
|
|
|
|
|
Session.main.currentEnemies[i].GetComponent<Enemy>().EffectsBy();
|
|
|
|
|
}
|
2022-01-14 10:42:43 +03:00
|
|
|
|
}
|
|
|
|
|
public void MarkersRegulator()
|
|
|
|
|
{
|
|
|
|
|
List<GameObject> _enemies = Session.main.currentEnemies;
|
|
|
|
|
for (int i = 0; i < _enemies.Count; i++)
|
|
|
|
|
{
|
|
|
|
|
if (_enemies[i] != null)
|
|
|
|
|
{
|
|
|
|
|
_enemies[i].GetComponent<Enemy>().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<Enemy>().OnMarker();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
else if (_specializationCard == Specialization.longAttack)
|
|
|
|
|
{
|
|
|
|
|
_enemies[i].GetComponent<Enemy>().OnMarker();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (_specializationCard == Specialization.healing)
|
|
|
|
|
{
|
|
|
|
|
Player.main.OnMarker();
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-12 10:06:03 +03:00
|
|
|
|
}
|
|
|
|
|
public void ActionInEnemy(Enemy enemy)
|
|
|
|
|
{
|
2022-01-14 10:42:43 +03:00
|
|
|
|
if (waitingEnemyTurn || currentCard == null || !enemy.CheckMarker()) return;
|
2022-01-15 23:26:40 +03:00
|
|
|
|
|
2022-01-27 11:31:20 +03:00
|
|
|
|
var _local = (int)currentCard.CardCharacteristics.enemyCount;
|
|
|
|
|
|
2022-02-09 21:22:43 +03:00
|
|
|
|
if(currentCard.CardCharacteristics.effects.Length > 0)
|
|
|
|
|
{
|
|
|
|
|
for (int i = 0; i < currentCard.CardCharacteristics.effects.Length; i++)
|
|
|
|
|
{
|
|
|
|
|
enemy.effectsName.Add(currentCard.CardCharacteristics.effects[i].effect.ToString());
|
|
|
|
|
enemy.effectsDamage.Add(currentCard.CardCharacteristics.effects[i].damage);
|
|
|
|
|
enemy.effectsTurns.Add(currentCard.CardCharacteristics.effects[i].turns);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-27 11:31:20 +03:00
|
|
|
|
if (_local != 0)
|
2022-01-12 10:06:03 +03:00
|
|
|
|
{
|
2022-01-27 11:31:20 +03:00
|
|
|
|
MassiveAttack(_local);
|
2022-01-13 11:00:37 +03:00
|
|
|
|
}
|
2022-01-27 11:31:20 +03:00
|
|
|
|
else
|
2022-01-12 10:06:03 +03:00
|
|
|
|
{
|
2022-01-27 11:31:20 +03:00
|
|
|
|
if (currentCard.CardCharacteristics.damage > 0)
|
|
|
|
|
{
|
|
|
|
|
enemy.ChangeHp(currentCard.CardCharacteristics.damage);
|
|
|
|
|
}
|
|
|
|
|
else if (currentCard.CardCharacteristics.addHealth > 0)
|
|
|
|
|
{
|
|
|
|
|
enemy.ChangeHp(-currentCard.CardCharacteristics.addHealth);
|
|
|
|
|
}
|
2022-01-12 10:06:03 +03:00
|
|
|
|
}
|
|
|
|
|
NewStaminaQuantity(stamina - currentCard.CardCharacteristics.quantityStamina);
|
|
|
|
|
CardInTable[numberCurrentCard].GetComponent<Card>().DestroyObject();
|
|
|
|
|
currentCard = null;
|
2022-01-14 10:42:43 +03:00
|
|
|
|
MarkersRegulator();
|
2022-01-12 10:06:03 +03:00
|
|
|
|
}
|
2022-01-15 21:47:03 +03:00
|
|
|
|
|
2022-01-13 11:00:37 +03:00
|
|
|
|
IEnumerator EnemyStep()
|
|
|
|
|
{
|
|
|
|
|
waitingEnemyTurn = true;
|
2022-01-14 10:42:43 +03:00
|
|
|
|
Session.main.EnemiesStep();
|
2022-01-13 11:00:37 +03:00
|
|
|
|
yield return new WaitForSeconds(0.5f);
|
|
|
|
|
waitingEnemyTurn = false;
|
2022-01-17 17:49:27 +03:00
|
|
|
|
|
2022-01-12 10:06:03 +03:00
|
|
|
|
}
|
2022-01-27 11:31:20 +03:00
|
|
|
|
|
|
|
|
|
public void MassiveAttack(int _targetCount)
|
|
|
|
|
{
|
|
|
|
|
if(Session.main.currentEnemies.Count < _targetCount)
|
|
|
|
|
{
|
|
|
|
|
_targetCount = Session.main.currentEnemies.Count;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < _targetCount; i++)
|
|
|
|
|
{
|
|
|
|
|
Session.main.currentEnemies[i].GetComponent<Enemy>().ChangeHp(currentCard.CardCharacteristics.damage);
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-01-12 10:06:03 +03:00
|
|
|
|
}
|