예제 #1
0
        /// <summary>
        /// Searches for lobbies created by other players.
        /// </summary>
        /// <param name="index">The index of user</param>
        /// <param name="numResults">The maximum number of lobbies to return.</param>
        /// <param name="lobbyType">Whether or not this lobby is for a RANKED MATCH or a PLAYER MATCH.</param>
        /// <param name="freeSlots">The number of free slots needed.</param>
        /// <param name="searchCriteria">JSON string representing parameters to search for.</param>
        /// <param name="callback">The function to call when the task completes.</param>
        public void FindLobbies(int index, int numResults, RuyiNetLobbyType lobbyType,
                                int freeSlots, string searchCriteria, Action <RuyiNetLobby[]> callback)
        {
            var payload = new RuyiNetLobbyFindRequest()
            {
                appId          = mClient.AppId,
                numResults     = numResults,
                freeSlots      = freeSlots,
                ranked         = (lobbyType == RuyiNetLobbyType.RANKED),
                searchCriteria = searchCriteria
            };

            RunPlatformScript(index, "Lobby_Find", JsonConvert.SerializeObject(payload),
                              (RuyiNetLobbyFindResponse response) =>
            {
                var results = response.data.response.results;
                var lobbies = new RuyiNetLobby[results.count];
                for (int i = 0; i < results.count; ++i)
                {
                    lobbies[i] = new RuyiNetLobby(results.items[i]);
                }

                callback(lobbies);
            });
        }
예제 #2
0
        private void OnLobbyFindResponse(Action <RuyiNetLobby[]> callback, RuyiNetLobbyFindResponse response)
        {
            if (callback != null)
            {
                var results = response.data.lobbies;
                var lobbies = new RuyiNetLobby[results.Length];
                for (int i = 0; i < results.Length; ++i)
                {
                    lobbies[i] = new RuyiNetLobby(results[i]);
                }

                callback(lobbies);
            }
        }
예제 #3
0
        /// <summary>
        /// Creates array of <see cref="RuyiNetLobby"/> from response <see cref="data"/>
        /// </summary>
        public RuyiNetLobby[] GetLobbies()
        {
            if (data == null || data.lobbies == null)
            {
                return(null);
            }
            var results = data.lobbies;
            var lobbies = new RuyiNetLobby[results.Length];

            for (int i = 0; i < results.Length; ++i)
            {
                lobbies[i] = new RuyiNetLobby(results[i]);
            }
            return(lobbies);
        }
예제 #4
0
        internal void Update(Object source, ElapsedEventArgs e)
        {
            if (mCurrentLobby != null)
            {
                var payload = new RuyiNetLobbyJoinRequest()
                {
                    lobbyId = mCurrentLobby.LobbyId
                };
                RunPlatformScript(mClient.ActivePlayerIndex, "Lobby_Update", JsonConvert.SerializeObject(payload),
                                  (RuyiNetLobbyResponse response) =>
                {
                    RuyiNetLobby updatedLobby = response;
                    if (updatedLobby != null)
                    {
                        if (mCurrentLobby != null)
                        {
                            IEnumerable <string> newPlayers = null;
                            IEnumerable <string> oldPlayers = null;

                            bool lobbyClosed = mCurrentLobby.State != "CLOSED" &&
                                               updatedLobby.State == "CLOSED";
                            bool lobbyStarted = mCurrentLobby.State != "STARTED" &&
                                                updatedLobby.State == "STARTED";

                            if (!updatedLobby.MemberProfileIds.SequenceEqual(mCurrentLobby.MemberProfileIds))
                            {
                                newPlayers = updatedLobby.MemberProfileIds.Except(mCurrentLobby.MemberProfileIds);
                                oldPlayers = mCurrentLobby.MemberProfileIds.Except(updatedLobby.MemberProfileIds);
                            }

                            mCurrentLobby = updatedLobby;

                            if (newPlayers != null)
                            {
                                foreach (var i in newPlayers)
                                {
                                    Console.Write("New Player: " + i);
                                    OnPlayerJoinLobby(i);
                                }
                            }

                            if (oldPlayers != null)
                            {
                                foreach (var i in oldPlayers)
                                {
                                    Console.Write("Old Player: " + i);
                                    OnPlayerLeaveLobby(i);
                                }
                            }

                            if (lobbyClosed)
                            {
                                for (var i = 0; i < mClient.CurrentPlayers.Length; ++i)
                                {
                                    if (mClient.CurrentPlayers[i] != null)
                                    {
                                        LeaveLobby(i, mCurrentLobby.LobbyId, null);
                                    }
                                }

                                OnLobbyClosed();
                            }
                            else if (lobbyStarted)
                            {
                                OnLobbyStartGame();
                            }
                        }
                        else
                        {
                            mCurrentLobby = updatedLobby;
                        }

                        PollLobbyStatus();
                    }
                });
            }
        }