Exemplo n.º 1
0
        /// <summary>
        /// Joins a lobby created by another player.
        /// </summary>
        /// <param name="index">The index of user</param>
        /// <param name="lobbyId">The ID of the lobby to join.</param>
        /// <param name="callback">The function to call when the task completes.</param>
        public void JoinLobby(int index, string lobbyId, Action <RuyiNetLobby> callback)
        {
            var payload = new RuyiNetLobbyJoinRequest()
            {
                lobbyId = lobbyId
            };

            RunPlatformScript(index, "Lobby_Join", JsonConvert.SerializeObject(payload),
                              (RuyiNetLobbyResponse response) =>
            {
                mCurrentLobby = response;
                callback(mCurrentLobby);
                PollLobbyStatus();
            });
        }
Exemplo n.º 2
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();
                    }
                });
            }
        }