コード例 #1
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));
        }
コード例 #2
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);
            }
        }
コード例 #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);
            }
        }