103 lines
2.4 KiB
C#
103 lines
2.4 KiB
C#
using UnityEngine;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
|
|
public class DeckController : MonoBehaviour
|
|
{
|
|
public static DeckController instance;
|
|
|
|
public void Awake()
|
|
{
|
|
instance = this;
|
|
}
|
|
|
|
public List<CardScriptableObject> deckToUse = new List<CardScriptableObject>();
|
|
|
|
public Card cardToSpawn;
|
|
|
|
public int drawCardCost = 2;
|
|
|
|
public float waitBetweenDrawingCards = .25f;
|
|
|
|
private List<CardScriptableObject> activeCards = new List<CardScriptableObject>();
|
|
|
|
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
|
void Start()
|
|
{
|
|
SetUpDeck();
|
|
}
|
|
|
|
// Update is called once per frame
|
|
void Update()
|
|
{
|
|
/*if(Input.GetKeyDown(KeyCode.T))
|
|
{
|
|
DrawCardToHand();
|
|
}*/
|
|
}
|
|
|
|
public void SetUpDeck()
|
|
{
|
|
activeCards.Clear();
|
|
|
|
int interations = 0;
|
|
|
|
List<CardScriptableObject> tempDeck = new List<CardScriptableObject>();
|
|
tempDeck.AddRange(deckToUse);
|
|
|
|
while (tempDeck.Count > 0 && interations < 500)
|
|
{
|
|
int selected = Random.Range(0, tempDeck.Count);
|
|
activeCards.Add(tempDeck[selected]);
|
|
tempDeck.RemoveAt(selected);
|
|
|
|
interations++;
|
|
}
|
|
}
|
|
|
|
public void DrawCardToHand()
|
|
{
|
|
if (activeCards.Count == 0)
|
|
{
|
|
SetUpDeck();
|
|
}
|
|
|
|
Card newCard = Instantiate(cardToSpawn, transform.position, transform.rotation);
|
|
newCard.cardSO = activeCards[0];
|
|
newCard.SetupCard();
|
|
|
|
activeCards.RemoveAt(0);
|
|
|
|
HandController.instance.AddCardToHand(newCard);
|
|
}
|
|
|
|
public void DrawCardForMana()
|
|
{
|
|
if (BattleController.instance.playerMana >= drawCardCost)
|
|
{
|
|
DrawCardToHand();
|
|
BattleController.instance.SpendPlayerMana(drawCardCost);
|
|
}
|
|
else
|
|
{
|
|
UIController.instance.ShowManaWarning();
|
|
UIController.instance.drawCardBtn.SetActive(false);
|
|
}
|
|
}
|
|
|
|
public void DrawMultipleCards(int amountToDraw)
|
|
{
|
|
StartCoroutine(DrawMultipleCo(amountToDraw));
|
|
}
|
|
|
|
IEnumerator DrawMultipleCo(int amountToDraw)
|
|
{
|
|
for (int i = 0; i < amountToDraw; i++)
|
|
{
|
|
DrawCardToHand();
|
|
|
|
yield return new WaitForSeconds(waitBetweenDrawingCards);
|
|
}
|
|
}
|
|
}
|