using System.Collections.Generic; using System.Collections; using UnityEngine; using System; using Random = UnityEngine.Random; using System.IO.Compression; public class EnemyController : MonoBehaviour { public static EnemyController instance; // Awake is called when the script instance is being loaded void Awake() { { instance = this; } } public List deckToUse = new List(); public Card cardToSpawn; public Transform cardSpawnPoint; public enum AIType { placeFromDeck, handRandomPlace, handDefensive, handAttacking }; public AIType enemyAIType; public int startHandSize; private List activeCards = new List(); private List cardsInHand = new List(); // Start is called once before the first execution of Update after the MonoBehaviour is created void Start() { SetUpDeck(); if(enemyAIType != AIType.placeFromDeck) { SetupHand(); } } // Update is called once per frame void Update() { } public void SetUpDeck() { activeCards.Clear(); int interations = 0; List tempDeck = new List(); 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 StartAction() { StartCoroutine(EnemyActionCo()); } IEnumerator EnemyActionCo() { if(activeCards.Count == 0) { SetUpDeck(); } yield return new WaitForSeconds(.5f); List cardPoints = new List(); cardPoints.AddRange(CardPointsController.instance.enemyCardPoints); int randomPoint = Random.Range(0, cardPoints.Count); CardPlacePoint selectedPoint = cardPoints[randomPoint]; if(enemyAIType == AIType.placeFromDeck || enemyAIType == AIType.handRandomPlace) { cardPoints.Remove(selectedPoint); while(selectedPoint.activeCard != null && cardPoints.Count > 0) { randomPoint = Random.Range(0, cardPoints.Count); selectedPoint = cardPoints[randomPoint]; cardPoints.RemoveAt(randomPoint); } } CardScriptableObject selectedCard = null; int interations = 0; switch (enemyAIType) { case AIType.placeFromDeck: if(selectedPoint.activeCard == null) { Card newCard = Instantiate(cardToSpawn, cardSpawnPoint.position, cardSpawnPoint.rotation); newCard.cardSO = activeCards[0]; activeCards.RemoveAt(0); newCard.SetupCard(); newCard.MoveToPoint(selectedPoint.transform.position, selectedPoint.transform.rotation); selectedPoint.activeCard = newCard; newCard.assignedPlace = selectedPoint; } break; case AIType.handRandomPlace: break; case AIType.handDefensive: break; case AIType.handAttacking: break; } yield return new WaitForSeconds(.5f); BattleController.instance.AdvanceTurn(); } void SetupHand() { for(int i = 0; i < startHandSize; i++) { if(activeCards.Count == 0) { SetUpDeck(); } } cardsInHand.Add(activeCards[0]); activeCards.RemoveAt(0); } public void PlayCard(CardScriptableObject cardSO, CardPlacePoint placePoint) { Card newCard = Instantiate(cardToSpawn, cardSpawnPoint.position, cardSpawnPoint.rotation); newCard.cardSO = cardSO; newCard.SetupCard(); newCard.MoveToPoint(placePoint.transform.position, placePoint.transform.rotation); placePoint.activeCard = newCard; newCard.assignedPlace = placePoint; cardsInHand.Remove(cardSO); BattleController.instance.SpendEnemyMana(cardSO.manaCost); } }