using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class Deck : MonoBehaviour { public List cardDataList; //public List drawList; public List drawDisplayList; //public List handList; //public List handDisplayList; //public List discardList; public List discardDisplayList; public List wasteList; public int randomSeed; public GameObject handCardTemplate; public GameObject cardDisplayTemplate; public GameObject drawListContent; public GameObject discardListContent; private int cardInHandAmount = 0; // Card Limit public int maxCardinHandLimit = 10; public int maxCardRemainLimit = 5; private GameObject reachCardinHandLimitWarningDisplay; private float warningDisplayCountDown; private float warningDisplayTime = 1.0f; // Start is called before the first frame update void Start() { reachCardinHandLimitWarningDisplay = transform.Find("Content/LimitWarning").gameObject; reachCardinHandLimitWarningDisplay.SetActive(false); 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/Viewport/Content")); 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() { } private void FixedUpdate() { if (warningDisplayCountDown >= 0.0f) { warningDisplayCountDown -= Time.deltaTime; if (warningDisplayCountDown <= 0.0f) { DeactivateCardInHandLimitWarning(); } } } public void DrawCards(int amount) { for (int i = 0; i < amount; i++) { if (cardInHandAmount > maxCardinHandLimit - 1) { ActivateCardInHandLimitWarning(); return; } if (drawDisplayList.Count == 0) { Shuffle(); } if (drawDisplayList.Count == 0) { return; } int randomIndex = Random.Range(0, drawDisplayList.Count); GameObject cardObj = Instantiate(handCardTemplate.gameObject, transform.Find("Content/HandList")); var tempCardData = drawDisplayList[randomIndex].transform.Find("Card").gameObject.GetComponent().cardData; cardObj.transform.Find("Card").gameObject.GetComponent().SetCardData(tempCardData); cardObj.transform.Find("Button").gameObject.GetComponent().sprite = tempCardData.artwork; cardObj.SetActive(true); cardInHandAmount++; //handDisplayList.Add(cardObj); //handList.Add(drawList[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 //{ //} } public void UseThisCard(GameObject card) { GameObject tempDiscardDisplay = Instantiate(cardDisplayTemplate.gameObject, transform.Find("DiscardListContent/Viewport/Content")); tempDiscardDisplay.SetActive(true); tempDiscardDisplay.transform.Find("Card").gameObject.GetComponent().SetCardData(card.transform.Find("Card").GetComponent().cardData); tempDiscardDisplay.transform.Find("Button").gameObject.GetComponent().sprite = card.transform.Find("Card").GetComponent().cardData.artwork; discardDisplayList.Add(tempDiscardDisplay); //discardList.Add(card.transform.Find("Card").gameObject.gameObject.GetComponent().cardData); //handDisplayList.Find(card); Destroy(card); cardInHandAmount--; } // When unit dead public void AddACardIntoDiscardList(CardData card) { } public void Shuffle() { // Put all cards in drawList into discardList List tempCardDataList = new List(); for (int i = 0; i < drawDisplayList.Count; i++) { tempCardDataList.Add(drawDisplayList[i].transform.Find("Card").GetComponent().cardData); Destroy(drawDisplayList[i]); } drawDisplayList.Clear(); //drawList.Clear(); for (int i = 0; i < tempCardDataList.Count; i++) { GameObject tempCardDisplay = Instantiate(cardDisplayTemplate.gameObject,transform.Find("DrawListContent/Viewport/Content")); tempCardDisplay.transform.Find("Card").gameObject.GetComponent().SetCardData(tempCardDataList[i]); tempCardDisplay.transform.Find("Button").gameObject.GetComponent().sprite = tempCardDataList[i].artwork; tempCardDisplay.SetActive(true); drawDisplayList.Add(tempCardDisplay); } tempCardDataList.Clear(); while (discardDisplayList.Count != 0) { int index = Random.Range(0, discardDisplayList.Count); GameObject tempCardDisplay = Instantiate(cardDisplayTemplate.gameObject, transform.Find("DrawListContent/Viewport/Content")); CardData tempCardData = discardDisplayList[index].transform.Find("Card").GetComponent().cardData; tempCardDisplay.transform.Find("Card").gameObject.GetComponent().SetCardData(tempCardData); tempCardDisplay.transform.Find("Button").gameObject.GetComponent().sprite = tempCardData.artwork; tempCardDisplay.SetActive(true); drawDisplayList.Add(tempCardDisplay); Destroy(discardDisplayList[index]); discardDisplayList.RemoveAt(index); }; Debug.LogError(discardDisplayList.Count); discardDisplayList.Clear(); } public void ActivateDisplayDrawList() { drawListContent.SetActive(true); } public void DeactivateDisplayDrawList() { drawListContent.SetActive(false); } public void ActivateDisplayDiscardList() { discardListContent.SetActive(true); } public void DeactivateDisplayDiscardList() { discardListContent.SetActive(false); } private void ActivateCardInHandLimitWarning() { reachCardinHandLimitWarningDisplay.SetActive(true); warningDisplayCountDown = warningDisplayTime; } private void DeactivateCardInHandLimitWarning() { reachCardinHandLimitWarningDisplay.SetActive(false); } public void EndRound() { if (cardInHandAmount > maxCardRemainLimit) { } } }