コード例 #1
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());
            }
        }
コード例 #2
0
        /// <summary>
        /// Takes the first card from user's deck and places it in hand.
        /// If there are no cards left in deck, shuffles all already played
        /// cards and puts them in deck.
        /// </summary>
        public Card DrawCard()
        {
            int    index  = UnityEngine.Random.Range(0, _cardCollection.GetDeckList().Count);
            string randId = _cardCollection.GetDeckList()[index];

            return(_cardCollection.GetDeckCard(randId));
        }
コード例 #3
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());
            }
        }
コード例 #4
0
        /// <summary>
        /// Sets fields of this panel to show <see cref="PlayerData"/> gathered from <paramref name="user"/>.
        /// </summary>
        /// <param name="user">User to be displayed in this panel.</param>
        private async void PopulateDataAsync(IApiUser user)
        {
            StorageObjectId personalStorageId = new StorageObjectId();

            personalStorageId.Collection = "personal";
            personalStorageId.UserId     = _connection.Session.UserId;
            personalStorageId.Key        = "player_data";

            IApiStorageObjects personalStorageObjects = await _connection.Client.ReadStorageObjectsAsync(_connection.Session, personalStorageId);

            PlayerData playerData        = new PlayerData();
            IUserGroupListUserGroup clan = null;

            try
            {
                IApiUserGroupList clanList = await _connection.Client.ListUserGroupsAsync(_connection.Session);

                // user should only be in one clan.
                clan = clanList.UserGroups.Any() ? clanList.UserGroups.First() : null;
            }
            catch (ApiResponseException e)
            {
                Debug.LogWarning("Error fetching user clans " + e.Message);
            }

            CardCollection cardCollection = null;

            try
            {
                var response = await _connection.Client.RpcAsync(_connection.Session, "load_user_cards", "");

                cardCollection = response.Payload.FromJson <CardCollection>();
            }
            catch (ApiResponseException e)
            {
                throw e;
            }

            _usernameText.text = user.Username;
            _statsText.text    = GenerateStats(playerData).TrimEnd();

            _clanNameText.text = clan == null ?
                                 "<i><color=#b0b0b0>[Not a clan member yet]</color></i>" :
                                 clan.Group.Name;

            List <string> deckIds = cardCollection.GetDeckList();

            for (int i = 0; i < deckIds.Count; i++)
            {
                Card card = cardCollection.GetDeckCard(deckIds[i]);
                _cardSlots[i].SetCard(card);
            }
        }
コード例 #5
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());
        }
コード例 #6
0
        /// <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);
        }