/// <summary> /// Adds a new intent /// </summary> /// <param name="intent">Target intent</param> /// <param name="issuingPlayerId">The player who issued this intent</param> /// <param name="card">the card involved, null if creature combat</param> /// <param name="sourceId">the attacking creature, if applicable</param> /// <param name="targetId">the receiver, either creature Id or player Id if applicable</param> public void AddIntent(IntentEnum intent, int issuingPlayerId, Card card, int sourceId, int targetId) { // If current intent is pass, check last action to see if it was also pass. If so, resolve if (intent == IntentEnum.PassTurn && this.ActionStack.Count > 0 && this.ActionStack.Peek().Intent == IntentEnum.PassTurn) { this.ResolvePendingActions(); } else { var newIntent = new IntentAction(intent, issuingPlayerId, card, sourceId, targetId); this.ActionStack.Push(newIntent); } // Renders all components TurnManager.CurrentInstance.Render(); this.LastPlayedIntentCardComponent.Render(); this.Render(); }
/// <summary> /// Renders all intent related buttons /// </summary> public void Render() { // Grabs the selected card and selected creature var selectedCard = CardBehavior.CurrentlySelected; var selectedFriendCreature = CreatureBehavior.CurrentlySelectedFriendly; var selectedEnemyCreature = CreatureBehavior.CurrentlySelectedEnemy; var selectedHealthCard = PlayerHealthCards.CurrentlySelected; // Check controllers var gameController = GameController.CurrentInstance; if (gameController == null) { return; } var playerController = PlayerController.LocalPlayer; if (playerController == null) { return; } // Determine turn related variables var isPlayerNormalTurn = gameController.CurrentPlayerId == playerController.PlayerId; bool isPlayerCounterTurn = false; var hasPendingIntentions = this.ActionStack.Count > 0; IntentAction lastAction = this.ActionStack.Count == 0 ? null : this.ActionStack.Peek(); if (lastAction != null && lastAction.IssuingPlayerId != playerController.PlayerId) { isPlayerCounterTurn = true; } // Sets the state of the pass button if (!hasPendingIntentions) { this.PassTurnButton.SetActive(false); } else { this.PassTurnButton.SetActive(isPlayerCounterTurn); } // If it's not the player's turn to counter or normal, then there is nothing that could be done if (!isPlayerCounterTurn && !isPlayerNormalTurn) { this.CounterSpellButton.SetActive(false); this.UseAcePowerButton.SetActive(false); this.UseCardButton.SetActive(false); return; } // If there is a card selected if (selectedCard != null) { // Card selected, cannot initiate creature combat this.CreatureAttackButton.SetActive(false); // Grabs the card value var selectedCardValue = selectedCard.PokerCard; // Check if only one of the three is selected if (selectedFriendCreature != null ^ selectedEnemyCreature != null ^ selectedHealthCard != null) { // Check if it's player's turn to do anything and if the card is NOT a relic if ((isPlayerCounterTurn || isPlayerNormalTurn) && selectedCardValue.CardNumber <= 10) { // Check suits to see if the selected suit is valid // Check spade, can be used on creatures and health cards if (selectedCardValue.CardSuit == CardSuitEnum.Spade) { this.UseCardButton.SetActive(true); this.UseAcePowerButton.SetActive(selectedCardValue.CardNumber == 1); } // Check creature buff/debuff, must NOT have health selected else if (selectedCardValue.CardSuit == CardSuitEnum.Club || selectedCardValue.CardSuit == CardSuitEnum.Diamond) { this.UseCardButton.SetActive(!selectedHealthCard); this.UseAcePowerButton.SetActive(!selectedHealthCard && selectedCardValue.CardNumber == 1); } // Check place health card, must only have health selected else { this.UseCardButton.SetActive(selectedHealthCard); this.UseAcePowerButton.SetActive(selectedHealthCard && selectedCardValue.CardNumber == 1); } this.UseAcePowerButton.SetActive(selectedCardValue.CardNumber == 1); } // Selected card is relic, or player is not in turn, or the card and creature/health card combo does not work else { this.UseCardButton.SetActive(false); this.UseAcePowerButton.SetActive(false); } } // Check if none of the 3 is selected for counter else if (selectedEnemyCreature == null && selectedFriendCreature == null && selectedHealthCard == null) { // Can't just use card this.UseCardButton.SetActive(false); this.UseAcePowerButton.SetActive(false); // Only a card is selected, check if possible counter if (lastAction != null && hasPendingIntentions && isPlayerCounterTurn // Cannot counter creature attack or turn pass && lastAction.Intent != IntentEnum.CreatureAttack && lastAction.Intent != IntentEnum.PassTurn && Helpers.SuitToColor(lastAction.Card.CardSuit) != Helpers.SuitToColor(selectedCardValue.CardSuit) && selectedCardValue.CardNumber < lastAction.Card.CardNumber) { this.CounterSpellButton.SetActive(true); } else { this.CounterSpellButton.SetActive(false); } } // Card and multiple targets selected, does not work else { this.CounterSpellButton.SetActive(false); this.UseAcePowerButton.SetActive(false); this.UseCardButton.SetActive(false); } } // No card selected else { // Can't use any card related buttons if there are no cards selected this.CounterSpellButton.SetActive(false); this.UseAcePowerButton.SetActive(false); this.UseCardButton.SetActive(false); // Check if there's an attacker selected if (selectedFriendCreature == null) { this.CreatureAttackButton.SetActive(false); this.CreatureBlockButton.SetActive(false); } else { // Decides the state of the attack button. It can only happen as the first attack if (this.ActionStack.Count == 0) { // If only health card is selected, any creature can attack that if (selectedHealthCard != null && selectedEnemyCreature == null) { this.CreatureAttackButton.SetActive(true); } // If creature try to attack creature, it must have black as attack else if ( selectedEnemyCreature != null && selectedFriendCreature.CanTargetAttack && selectedHealthCard == null) { this.CreatureAttackButton.SetActive(true); } else { this.CreatureAttackButton.SetActive(false); } } // There's already pending actions, cannot initiate new attack else { this.CreatureAttackButton.SetActive(false); } // Decides the state of the block button. It can only be done if there's an attack happening if (this.ActionStack.Count == 1 && this.ActionStack.Peek().Intent == IntentEnum.CreatureAttack && isPlayerCounterTurn) { // Must have only an ally unit selected, and the ally must be able to block if ( selectedFriendCreature != null && selectedFriendCreature.CanBlock && selectedEnemyCreature == null && selectedHealthCard == null && isPlayerCounterTurn) { this.CreatureBlockButton.SetActive(true); } else { this.CreatureBlockButton.SetActive(false); } } else { this.CreatureBlockButton.SetActive(false); } } } }