// //////////////////////////////////////////// public IEnumerator ChooseCard() { GameObject cardChooserObject = Instantiate(cardChooserPrefab); CardChooser cardChooser = cardChooserObject.GetComponent <CardChooser>(); cardChooser.isVisible = false; cardChooser.playerIndex = player.playerIndex; cardChooser.onTable = false; while (cardChooser.chosenCardObject == null) { yield return(null); } GameObject cardChooserObject1 = Instantiate(cardChooserPrefab); CardChooser cardChooser1 = cardChooserObject1.GetComponent <CardChooser>(); cardChooser1.playerIndex = player.playerIndex; cardChooser1.onTable = true; cardChooser1.cardIndexException = -2; cardChooser1.SetChosenCardObject(cardChooser.chosenCardObject); while (cardChooser1.applyToCardObject == null) { yield return(null); } int chosenCardIndex = cardChooser.chosenCardObject.GetComponent <CardVisuals>().cardIndex; player.chosenCard = player.FindCardByIndex(chosenCardIndex); CardPosition cardPos = player.cardTablePart.CardPositionByIndex( cardChooser1.applyToCardObject.GetComponent <CardVisuals>().cardIndex); if (cardPos == null) { cardPos = cardChooser1.applyToCardObject.GetComponent <RowVisuals>().rowPosition; } Destroy(cardChooserObject); Destroy(cardChooserObject1); player.numberOfPlayerCardsInHand--; player.PlayCard(cardPos); }
/// <summary> /// Called from HumanPlayer. /// </summary> /// <param name="cardPosition"></param> /// <param name="chosenCard"></param> /// <returns></returns> public IEnumerator ApplyActive(CardPosition cardPosition, Card chosenCard) { int[] appliedToAllyCards = new int[0]; int[] appliedToOpponentCards = new int[0]; if (chosenCard.HasActiveAbilityToAlly()) { GameObject cardChooserObject = Instantiate(cardChooserPrefab); CardChooser cardChooser = cardChooserObject.GetComponent <CardChooser>(); cardChooser.playerIndex = player.playerIndex; cardChooser.onTable = true; cardChooser.SetChosenCardObject(FindCardObjectByIndex(chosenCard.cardIndex)); CardPosition chosenCardPosition = null; while (cardChooser.applyToCardObject == null) { yield return(null); } chosenCardPosition = player.cardTablePart.CardPositionByIndex( cardChooser.applyToCardObject.GetComponent <CardVisuals>().cardIndex); appliedToAllyCards = chosenCard.ApplyActiveToAlly(player.cardTablePart, chosenCardPosition); //TODO: Update card points text UpdateCardPointsText(chosenCard.cardIndex); Destroy(cardChooserObject); } if (chosenCard.HasActiveAbilityToOpponent() && player.opponent.cardTablePart.GetRandomRowWithCards() != -1) { GameObject cardChooserObject = Instantiate(cardChooserPrefab); CardChooser cardChooser = cardChooserObject.GetComponent <CardChooser>(); cardChooser.SetChosenCardObject(FindCardObjectByIndex(chosenCard.cardIndex)); cardChooser.playerIndex = player.opponent.playerIndex; cardChooser.onTable = true; CardPosition chosenCardPosition = null; while (cardChooser.applyToCardObject == null) { yield return(null); } chosenCardPosition = player.opponent.cardTablePart.CardPositionByIndex( cardChooser.applyToCardObject.GetComponent <CardVisuals>().cardIndex); appliedToOpponentCards = chosenCard.ApplyActiveToOpponent(player.opponent.cardTablePart, chosenCardPosition); //TODO: Update card points text player.opponent.playerVisuals.UpdateCardPointsText( cardChooser.applyToCardObject.GetComponent <CardVisuals>().cardIndex); Destroy(cardChooserObject); } // *** Active abilities animation StartCoroutine(ApplyActive( cardPosition, appliedToAllyCards, appliedToOpponentCards)); player.OnUpdate(); yield return(null); }
// Start is called before the first frame update void Awake() { cardChooser = GetComponent <CardChooser>(); camera = GameObject.FindGameObjectWithTag("MainCamera").GetComponent <Camera>(); }