Beispiel #1
0
        /// <summary>
        /// Invoked by <see cref="ClanSearchResult._joinClanButton"/>.
        /// Joins selected clan.
        /// If user is already member of this clan, changes tab to <see cref="_detailsTab"/>.
        /// If user is already member of another clan, does nothing.
        /// </summary>
        private async void JoinClan()
        {
            IUserGroupListUserGroup clan = await ClanManager.GetUserClanAsync(Client, Session);

            if (clan != null)
            {
                if (clan.Group.Id == DisplayedClan.Id)
                {
                    Debug.Log("This user has already joined clan with name \"" + DisplayedClan.Name + "\"");
                    ShowClanDetails(DisplayedClan);
                }
                else
                {
                    Debug.LogWarning("Cannot join more then one clan. Leave current clan first.");
                }
            }
            else
            {
                IApiGroup newClan = await ClanManager.JoinClanAsync(Client, Session, DisplayedClan);

                if (newClan != null)
                {
                    OnClanChanged(newClan);
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// Checks whether local user is a member of a clan, then disables or enables <see cref="_showClan"/>
        /// button accordingly. Shows this menu.
        /// </summary>
        public async override void Show()
        {
            Client   client  = NakamaSessionManager.Instance.Client;
            ISession session = NakamaSessionManager.Instance.Session;

            // If local user is not a member of a clan, disable clan leaderboards
            IUserGroupListUserGroup clan = await ClanManager.GetUserClanAsync(client, session);

            if (clan != null)
            {
                _showClan.gameObject.SetActive(true);
            }
            else
            {
                // User is not a member of any clan
                // Hiding clan score tab

                if (_showClan.interactable == true)
                {
                    // Last showed tab is clan tab
                    // Switching to other tab
                    ShowGlobalLeaderboards();
                }
                _showClan.gameObject.SetActive(false);
            }


            base.Show();
        }
Beispiel #3
0
        /// <summary>
        /// Shows <see cref="_detailsTab"/> panel and hides <see cref="_searchTab"/> panel.
        /// Displays local user clan info and updates user list.
        /// </summary>
        private async void ShowMyClanDetails()
        {
            IUserGroupListUserGroup clan = await ClanManager.GetUserClanAsync(Client, Session);

            if (clan != null)
            {
                ShowClanDetails(clan.Group);
            }
        }
Beispiel #4
0
        /// <summary>
        /// Called when user connects to Nakama server.
        /// Tries to retrieve the clan local user belongs to.
        /// On success calls <see cref="OnClanChanged(IApiGroup)"/>.
        /// </summary>
        private async void Init()
        {
            NakamaSessionManager.Instance.OnConnectionSuccess -= Init;
            IUserGroupListUserGroup clan = await ClanManager.GetUserClanAsync(Client, Session);

            if (clan != null)
            {
                OnClanChanged(clan.Group);
            }
        }
Beispiel #5
0
        /// <summary>
        /// Deletes the clan local user currently belongs to.
        /// Does nothing if user is not a member of any clan or has insufficient permissions.
        /// The name of newly created clan is determined by <see cref="_clanCreateName"/> textfield.
        /// </summary>
        private async void DeleteClan()
        {
            IUserGroupListUserGroup clan = await ClanManager.GetUserClanAsync(Client, Session);

            bool good = await ClanManager.DeleteClanAsync(Client, Session, clan.Group);

            if (good == true)
            {
                OnClanLeft();
            }
        }
        /// <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);
            }
        }
Beispiel #7
0
        /// <summary>
        /// Requests clan search list and clan member list refresh.
        /// </summary>
        public async void RefreshClanMenu()
        {
            SearchClan();
            bool good = await UpdateUserListAsync();

            if (good == false)
            {
                IUserGroupListUserGroup clan = await ClanManager.GetUserClanAsync(Client, Session);

                if (clan == null)
                {
                    OnClanChanged(null);
                }
            }
        }
Beispiel #8
0
        /// <summary>
        /// Method invoked by clicking on <see cref="ClanUserEntry._promoteButton"/>.
        /// Promotes the user to higher <see cref="ClanUserState"/>.
        /// </summary>
        private async void OnUserPromote(IApiUser user)
        {
            IUserGroupListUserGroup clan = await ClanManager.GetUserClanAsync(Client, Session);

            if (clan == null)
            {
                Debug.Log("Not a member of any clan");
            }
            Debug.Log("Promoted user " + user.Username);
            bool good = await ClanManager.PromoteUserAsync(Client, Session, user, clan.Group);

            if (good == true)
            {
                await UpdateUserListAsync();
            }
        }
Beispiel #9
0
        /// <summary>
        /// Leaves current clan.
        /// Invokes <see cref="OnClanLeft"/> on success.
        /// </summary>
        private async void LeaveClan()
        {
            IUserGroupListUserGroup clan = await ClanManager.GetUserClanAsync(Client, Session);

            if (clan == null)
            {
                Debug.Log("User is not a member of any clan");
                return;
            }

            bool good = await ClanManager.LeaveClanAsync(Client, Session, clan.Group);

            if (good == true)
            {
                OnClanLeft();
            }
        }
Beispiel #10
0
        /// <summary>
        /// Activates or deactivates buttons responsible for leaving, joining and removing clan
        /// depending on whether we belong to currently displayed clan.
        /// </summary>
        private async Task SetClanManagementButtonsAsync()
        {
            IUserGroupListUserGroup clan = await ClanManager.GetUserClanAsync(Client, Session);

            if (clan != null && DisplayedClan.Id == clan.Group.Id)
            {
                _joinClanButton.gameObject.SetActive(false);
                _leaveClanButton.gameObject.SetActive(true);
                _removeClanButton.gameObject.SetActive(clan.State == (int)ClanUserState.Superadmin);
                _chatButton.gameObject.SetActive(true);
            }
            else
            {
                _joinClanButton.gameObject.SetActive(true);
                _leaveClanButton.gameObject.SetActive(false);
                _removeClanButton.gameObject.SetActive(false);
                _chatButton.gameObject.SetActive(false);
            }
        }
Beispiel #11
0
        /// <summary>
        /// Fills <see cref="_userList"/> with records of all members of the clan local user belongs to.
        /// </summary>
        public async void ShowClanLeaderboards(string cursor)
        {
            IUserGroupListUserGroup clan = await ClanManager.GetUserClanAsync(Client, Session);

            if (clan == null)
            {
                return;
            }
            IApiLeaderboardRecordList records = await LeaderboardManager.GetClanLeaderboarsAsync(Client, Session, clan.Group, _recordsPerPage, cursor);

            if (records != null)
            {
                SetLeaderboardsCursor(records, ShowClanLeaderboards);
                FillLeaderboard(records.OwnerRecords);

                _showFriends.interactable = true;
                _showClan.interactable    = false;
                _showGlobal.interactable  = true;
            }
        }
Beispiel #12
0
        /// <summary>
        /// Returns the clan this user has joined.
        /// If user hasn't joined any clan yet, null will be returned.
        /// In this demo users can join only one clan at a time.
        /// </summary>
        public static async Task <IUserGroupListUserGroup> GetUserClanAsync(Client client, ISession session, string userId)
        {
            try
            {
                IApiUserGroupList clans = await client.ListUserGroupsAsync(session, userId, null, 1, null);

                if (clans.UserGroups.Count() > 0)
                {
                    IUserGroupListUserGroup userGroup = clans.UserGroups.ElementAt(0);
                    return(userGroup);
                }
                else
                {
                    return(null);
                }
            }
            catch (Exception e)
            {
                Debug.LogWarning("An exception has occured when listing user clans: " + e);
                return(null);
            }
        }
Beispiel #13
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 Task <bool> PopulateDataAsync(IApiUser user)
        {
            Client   client  = NakamaSessionManager.Instance.Client;
            ISession session = NakamaSessionManager.Instance.Session;

            PlayerData data = await _playerDataStorage.LoadDataAsync(user.Id, "player_data");

            IUserGroupListUserGroup clan = await ClanManager.GetUserClanAsync(client, session, user.Id);

            Deck deck = await _deckStorage.LoadDataAsync(user.Id, "deck");

            if (data != null && deck != null)
            {
                _usernameText.text = user.Username;
                _statsText.text    = GenerateStats(data).TrimEnd();

                if (clan != null)
                {
                    _clanNameText.text = clan.Group.Name;
                }
                else
                {
                    _clanNameText.text = "<i><color=#b0b0b0>[Not a clan member yet]</color></i>";
                }

                for (int i = 0; i < deck.usedCards.Count; i++)
                {
                    Card card = deck.usedCards[i];
                    _cardSlots[i].SetCard(card);
                }

                return(true);
            }
            else
            {
                return(false);
            }
        }
        /// <summary>
        /// Sends clan creation request to Nakama server.
        /// Does nothing if user already belongs to a clan.
        /// </summary>
        private async void CreateClan(Action <IApiGroup> onCreated)
        {
            Client   client  = NakamaSessionManager.Instance.Client;
            ISession session = NakamaSessionManager.Instance.Session;

            string name = _clanName.text;
            IUserGroupListUserGroup clan = await ClanManager.GetUserClanAsync(client, session);

            if (clan != null)
            {
                Debug.LogWarning("User is already a member of a clan. Leave current clan first.");
            }
            else
            {
                IApiGroup newClan = await ClanManager.CreateClanAsync(client, session, name, _currentAvatar);

                if (newClan != null)
                {
                    MenuManager.Instance.HideTopMenu();
                    onCreated(newClan);
                }
            }
        }
        /// <summary>
        /// Checks whether local user is a member of a clan, then disables or enables <see cref="_showClan"/>
        /// button accordingly. Shows this menu.
        /// </summary>
        public async override void Show(bool isMuteButtonClick = false)
        {
            IApiUserGroupList clanList = null;

            try
            {
                clanList = await _connection.Client.ListUserGroupsAsync(_connection.Session);
            }
            catch (ApiResponseException e)
            {
                Debug.LogWarning("Error showing clan leaderboards: " + e.Message);
                return;
            }

            _userClan = clanList.UserGroups.FirstOrDefault();

            if (_userClan != null)
            {
                _showClan.gameObject.SetActive(true);
            }
            else
            {
                // User is not a member of any clan
                // Hiding clan score tab
                if (_showClan.interactable)
                {
                    // Last showed tab is clan tab
                    // Switching to other tab
                    ShowGlobalLeaderboards();
                }

                _showClan.gameObject.SetActive(false);
            }

            base.Show(isMuteButtonClick);
        }