using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class Deck : MonoBehaviour { public List cardDataList; public List drawList; // Control Card Display public List drawDisplayList; public List handList; public List discardList; // Control Card Display public List discardDisplayList; public List wasteList; public int randomSeed; public GameObject handCardTemplate; public GameObject cardDisplayTemplate; public GameObject drawListContent; public GameObject discardListContent; // Start is called before the first frame update void Start() { randomSeed = 200; Random.InitState(randomSeed); for (int i = 0; i < cardDataList.Count; i++) { drawList.Add(cardDataList[i]); GameObject tempDrawDisplay = Instantiate(cardDisplayTemplate.gameObject, transform.Find("DrawListContent")); tempDrawDisplay.transform.Find("Card").gameObject.GetComponent().SetCardData(cardDataList[i]); tempDrawDisplay.transform.Find("Button").gameObject.GetComponent().sprite = cardDataList[i].artwork; tempDrawDisplay.SetActive(true); drawDisplayList.Add(tempDrawDisplay); } drawListContent.SetActive(false); discardListContent.SetActive(false); } // Update is called once per frame void Update() { } public void DrawCards(int amount) { for (int i = 0; i < amount; i++) { if (drawList.Count == 0) { Shuffle(); } if(drawList.Count==0) { return; } int randomIndex = Random.Range(0, discardList.Count); GameObject cardObj = Instantiate(handCardTemplate.gameObject, transform.Find("Content/HandList")); cardObj.SetActive(true); cardObj.transform.Find("Card").gameObject.GetComponent().SetCardData(drawList[randomIndex]); cardObj.transform.Find("Button").gameObject.GetComponent().sprite = drawList[randomIndex].artwork; drawList.RemoveAt(randomIndex); Destroy(drawDisplayList[randomIndex]); drawDisplayList.RemoveAt(randomIndex); } } public void UseACard(int index) { // TODO: Add card type into card data // Chech if the card is waste card; //if (handList[index].cardTags == wastCard) //{ // wasteList.Add(handList[index]); //} //else //{ discardList.Add(handList[index]); //} handList.RemoveAt(index); } public void UseThisCard(GameObject card) { GameObject tempDiscardDisplay = Instantiate(cardDisplayTemplate.gameObject, transform.Find("DiscardListContent")); tempDiscardDisplay.SetActive(true); tempDiscardDisplay.transform.Find("Card").gameObject.GetComponent().SetCardData(card.transform.Find("Card").gameObject.gameObject.GetComponent().cardData); tempDiscardDisplay.transform.Find("Button").gameObject.GetComponent().sprite = card.transform.Find("Card").gameObject.gameObject.GetComponent().cardData.artwork; discardDisplayList.Add(tempDiscardDisplay); discardList.Add(card.transform.Find("Card").gameObject.gameObject.GetComponent().cardData); Destroy(card); } // When unit dead public void AddACardIntoDiscardList(CardData card) { discardList.Add(card); } public void Shuffle() { // Put all cards in drawList into discardList for (int i = 0; i < drawList.Count; i++) { discardList.Add(drawList[i]); Destroy(drawDisplayList[i]); } drawDisplayList.Clear(); drawList.Clear(); while (discardList.Count != 0) { int index = Random.Range(0, discardList.Count); drawList.Add(discardList[index]); GameObject tempCardDisplay = Instantiate(cardDisplayTemplate.gameObject, transform.Find("DrawListContent")); tempCardDisplay.transform.Find("Card").gameObject.GetComponent().SetCardData(discardList[index]); tempCardDisplay.transform.Find("Button").gameObject.GetComponent().sprite = discardList[index].artwork; tempCardDisplay.SetActive(true); drawDisplayList.Add(tempCardDisplay); discardList[index] = discardList[discardList.Count - 1]; discardList.RemoveAt(discardList.Count - 1); }; for (int i = 0; i < discardDisplayList.Count; i++) { Destroy(discardDisplayList[i]); } } public void ActivateDisplayDrawList() { drawListContent.SetActive(true); } public void DeactivateDisplayDrawList() { drawListContent.SetActive(false); } public void ActivateDisplayDiscardList() { discardListContent.SetActive(true); } public void DeactivateDisplayDiscardList() { discardListContent.SetActive(false); } }