Пример #1
0
        /// <summary>
        /// A card has been selected by the user.
        /// Shows the <see cref="_cardInfoSidePanel"/> displaying selected card's info.
        /// </summary>
        private async void OnCardSelected(CardSlotUI slot)
        {
            _lastSelectedSlot?.Unselect();

            // Selected card from deck
            if (_lastSelectedSlot == null || !_primedSwap)
            {
                _cardInfoSidePanel.SetActiveCard(slot.Card, BeginSwapCard);
                _cardInfoSidePanel.EnableUpgradeButton(HasGemsForUpgrade());
                _lastSelectedSlot = slot;
                slot.Select();
            }
            else if (_primedSwap)
            {
                string deckCard   = _cardCollection.DeckContains(slot.Card.Id) ? slot.Card.Id : _lastSelectedSlot.Card.Id;
                string storedCard = _cardCollection.StoredContains(slot.Card.Id) ? slot.Card.Id : _lastSelectedSlot.Card.Id;

                _cardCollection = await SwapCards(deckCard, storedCard);

                _cardInfoSidePanel.SetCardCollection(_cardCollection);
                EndSwapCard();
                UpdateDeckCardsUI(_cardCollection.GetDeckList());
                UpdateStoredCardsUI(_cardCollection.GetStoredList());
            }
        }
Пример #2
0
        private async void OnAfterCardUpgraded(Card oldCard, CardData upgradedCardData)
        {
            _lastSelectedSlot = null;

            try
            {
                _connection.Account = await _connection.Client.GetAccountAsync(_connection.Session);

                UpdateGemsUI();
                _cardInfoSidePanel.SetActiveCard(new Card(oldCard.Id, upgradedCardData), BeginSwapCard);
                _cardInfoSidePanel.EnableUpgradeButton(HasGemsForUpgrade());
            }
            catch (ApiResponseException e)
            {
                Debug.LogWarning("Could not upgrade card: " + e.Message);
            }

            if (_cardCollection.DeckContains(oldCard.Id))
            {
                _cardCollection.UpgradeCard(oldCard.Id, upgradedCardData);
                UpdateDeckCardsUI(_cardCollection.GetDeckList());
            }
            else if (_cardCollection.StoredContains(oldCard.Id))
            {
                _cardCollection.UpgradeCard(oldCard.Id, upgradedCardData);
                UpdateStoredCardsUI(_cardCollection.GetStoredList());
            }
        }
Пример #3
0
        /// <summary>
        /// Updates the cards displayed by each <see cref="CardSlotUI"/> in user's deck.
        /// </summary>
        private void UpdateDeckCardsUI(List <string> deckCards)
        {
            foreach (CardSlotUI cardSlot in _deckCardsDisplays)
            {
                GameObject.Destroy(cardSlot.gameObject);
            }

            _deckCardsDisplays.Clear();

            foreach (string id in _cardCollection.GetDeckList())
            {
                CardSlotUI cardDisplay = Instantiate(_slotPrefab, _deckPanel.transform, false);
                cardDisplay.Init(OnCardSelected);
                cardDisplay.SetCard(_cardCollection.GetDeckCard(id));
                _deckCardsDisplays.Add(cardDisplay);
            }
        }
Пример #4
0
        /// <summary>
        /// Generates a new deck based on <see cref="_defaultDeck"/>.
        /// Sends the deck to Nakama server and then stores it locally.
        /// </summary>
        private async void HandleClearCards()
        {
            try
            {
                IApiRpc response = await _connection.Client.RpcAsync(_connection.Session, "reset_card_collection");

                _cardCollection = response.Payload.FromJson <CardCollection>();
                _cardInfoSidePanel.SetCardCollection(_cardCollection);
                _cardInfoSidePanel.EnableUpgradeButton(HasGemsForUpgrade());
            }
            catch (ApiResponseException e)
            {
                Debug.LogWarning("Error clearing cards: " + e.Message);
                return;
            }

            _lastSelectedSlot = null;
            UpdateDeckCardsUI(_cardCollection.GetDeckList());
            UpdateStoredCardsUI(_cardCollection.GetStoredList());
        }
Пример #5
0
        /// <summary>
        /// Add a random card to the owned card list.
        /// </summary>
        private async void HandleBuyRandomCard()
        {
            try
            {
                IApiRpc response = await _connection.Client.RpcAsync(_connection.Session, "add_random_card");

                var    card   = response.Payload.FromJson <Dictionary <string, CardData> >();
                string cardId = card.Keys.First();
                _cardCollection.AddStored(new Card(cardId, card[cardId]));
                _connection.Account = await _connection.Client.GetAccountAsync(_connection.Session);

                _lastSelectedSlot = null;
                UpdateGemsUI();
                UpdateDeckCardsUI(_cardCollection.GetDeckList());
                UpdateStoredCardsUI(_cardCollection.GetStoredList());
                _cardInfoSidePanel.EnableUpgradeButton(HasGemsForUpgrade());
            }
            catch (Exception e)
            {
                Debug.LogWarning("Couldn't handle buy random card: " + e.Message);
                return;
            }
        }