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()); } }
/// <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()); } }
/// <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()); }
/// <summary> /// Updates gold counter. /// </summary> public override async void Show(bool isMuteButtonClick = false) { try { var response = await _connection.Client.RpcAsync(_connection.Session, "load_user_cards", ""); _cardCollection = response.Payload.FromJson <CardCollection>(); _cardInfoSidePanel.SetCardCollection(_cardCollection); _cardInfoSidePanel.EnableUpgradeButton(HasGemsForUpgrade()); } catch (ApiResponseException e) { Debug.LogWarning("Could not load user cards: " + e.Message); return; } UpdateDeckCardsUI(_cardCollection.GetDeckList()); UpdateStoredCardsUI(_cardCollection.GetStoredList()); UpdateGemsUI(); base.Show(isMuteButtonClick); }