// REQUESTS FROM UI TO GAME MANAGER. public void PlayCardFromHand(int instanceId) { if (_duelUiCenter == null) { return; } if (_gameManager.GetCurrentMana() <= 0 || _gameManager.CombatManager.HasWon || _gameManager.CombatManager.HasLost) { return; } HandCardGameObject cardInHand = _playerHand.FirstOrDefault(c => c.InstanceId == instanceId); if (cardInHand != null) { _gameManager.PlayCard(instanceId); // Play logic here. _playerHand.Remove(cardInHand); Destroy(cardInHand.gameObject); _duelUiCenter.SetCardsPlayed(_gameManager.CombatManager.GetGraveyard().Count()); // TODO: Implement proper win detection. if (_gameManager.CombatManager.HasWon) { _duelUiCenter.Win(); } } }
public void RerollCard(int instanceId) { if (_duelUiCenter == null) { return; } if (_gameManager.GetCurrentMana() <= 0) { return; } HandCardGameObject cardInHand = _playerHand.FirstOrDefault(c => c.InstanceId == instanceId); if (cardInHand != null) { // Reroll logic here. _gameManager.RerollCard(cardInHand.InstanceId); _playerHand.Remove(cardInHand); Destroy(cardInHand.gameObject); } }
// REQUESTS FROM GAME MANAGER TO UI /// <summary> /// Add a CardGameObject to the scene corresponding to a card in the player's hand. /// </summary> /// <param name="toAdd">The Card added to the hand for which we need to create a GameObject.</param> /// <param name="position">The position to add the card at.</param> public void AddCardToPlayerHand(Card toAdd, int position) { if (_duelUiCenter == null) { return; } GameObject newCard = Instantiate(CardGameObjectPrefab); HandCardGameObject cardGo = newCard.GetComponent <HandCardGameObject>(); if (cardGo != null) { cardGo.SetCardData(toAdd.CardInfo); cardGo.RegisterBridge(this); cardGo.LoadArtwork(_resourceCenter.CardArtworks[toAdd.CardInfo.Identifier]); } toAdd.OnDataChanged += cardGo.DataChangedCardData; _playerHand.Add(cardGo); _duelUiCenter.AddCardToHand(newCard, position); }