/// <summary>
        /// Call this to rotate an active player out and start the next waiting player.
        /// </summary>
        /// <param name="netPlayer">The NetPlayer of the player to return</param>
        public void ReturnPlayer(NetPlayer netPlayer)
        {
            NetPlayerState netPlayerState = GetActiveNetPlayerState(netPlayer);

            if (netPlayerState != null)
            {
                m_activePlayers.Remove(netPlayerState); // on enleve le netPlayer de la liste des actifs, s'il y est
            }
            else
            {
                netPlayerState = GetWaitingNetPlayerState(netPlayer);
                if (netPlayerState != null)
                {
                    m_waitingPlayers.Remove(netPlayerState);                     // on enleve le netPlayer de la file d'attente, s'il y est
                }
            }

            AddWaitingPlayer(netPlayerState);

            PlayerState playerState = GetPlayerState(netPlayer);

            if (playerState != null)
            {
                playerState.netPlayer = null;
                // Make the slot available immediately.
                playerState.disconnectTime = Time.time - m_timeoutForDisconnectedPlayersToReconnect;

                StartWaitingPlayers();
            }
        }
 /// <summary>
 /// Call this to rotate an active player out and start the next waiting player.
 /// </summary>
 /// <param name="netPlayer">The NetPlayer of the player to return</param>
 public void ReturnPlayer(NetPlayer netPlayer)
 {
     if (m_playerManager != null)
     {
         m_playerManager.ReturnPlayer(netPlayer);
     }
 }
        // The player has disconnected
        void RemoveNetPlayer(object sender, EventArgs e)
        {
            NetPlayer      netPlayer      = (NetPlayer)sender;
            NetPlayerState netPlayerState = GetActiveNetPlayerState(netPlayer);

            if (netPlayerState != null)
            {
                m_activePlayers.Remove(netPlayerState);
            }

            netPlayerState = GetWaitingNetPlayerState(netPlayer);
            if (netPlayerState != null)
            {
                m_waitingPlayers.Remove(netPlayerState);
            }

            PlayerState playerState = GetPlayerState(netPlayer);

            if (playerState != null)
            {
                playerState.netPlayer      = null;
                playerState.disconnectTime = Time.time;
                StartWaitingPlayers();
            }
        }
        void StartPlayer(NetPlayer netPlayer, object data)
        {
            m_log.Info("Spawn Player");
            GameObject gameObject = (GameObject)Instantiate(prefabToSpawnForPlayer);

            SpawnInfo spawnInfo = new SpawnInfo();

            spawnInfo.netPlayer = netPlayer;
            spawnInfo.data      = data;
            gameObject.SendMessage("InitializeNetPlayer", spawnInfo);
        }
 public void StartLocalPlayer(NetPlayer netPlayer, string name = "", object data = null)
 {
     if (m_playerManager != null)
     {
         m_playerManager.StartLocalPlayer(netPlayer, name, data);
     }
     else
     {
         StartPlayer(netPlayer, data);
     }
 }
 PlayerState GetPlayerState(NetPlayer netPlayer)
 {
     for (int pndx = 0; pndx < m_playerState.Length; ++pndx)
     {
         PlayerState playerState = m_playerState[pndx];
         if (playerState.netPlayer == netPlayer)
         {
             return(playerState);
         }
     }
     return(null);
 }
        void AddWaitingPlayer(NetPlayerState netPlayerState)
        {
            NetPlayer netPlayer = netPlayerState.netPlayer;

            netPlayer.RemoveAllHandlers();
            netPlayer.OnDisconnect += RemoveNetPlayer;
            m_waitingPlayers.Add(netPlayerState);

            // Execute WaitingNetPlayer on the GameObject using this class. In otherwords
            // the game object with the PlayerConnector or PlayerSpawer script component
            SendSpawnInfoToGameObject("WaitingNetPlayer", m_gameObject, netPlayerState, SendMessageOptions.DontRequireReceiver);
        }
        void StartActivePlayer(GameObject gameObject, PlayerState playerState, NetPlayerState netPlayerState)
        {
            m_activePlayers.Add(netPlayerState);

            NetPlayer netPlayer = netPlayerState.netPlayer;

            netPlayer.RemoveAllHandlers();
            netPlayer.OnDisconnect += RemoveNetPlayer;

            playerState.netPlayer = netPlayer;
            playerState.id        = netPlayer.GetSessionId();

            SendSpawnInfoToGameObject("InitializeNetPlayer", gameObject, netPlayerState);
        }
示例#9
0
        private void StartPlayer(int id, string name)
        {
            if (m_players.ContainsKey(id))
            {
                return;
            }

            if (string.IsNullOrEmpty(name))
            {
                name = "Player" + (++m_totalPlayerCount);
            }

            NetPlayer player = new NetPlayer(this, id);

            m_players[id] = player;
            m_eventProcessor.QueueEvent(delegate() {
                // UGH! This is not thread safe because someone might add handler to OnPlayerConnect
                // Odds or low though.
                OnPlayerConnect.Emit(this, new PlayerConnectMessageArgs(player));
            });
        }
        void StartPlayer(NetPlayer netPlayer, object data)
        {
            if (!GameManager.isGameStarted)
            {
                m_log.Info("Spawn Player");
                //random = Random.Range(0, 2);
                if (spawnIndex == 3)
                {
                    spawnIndex = 0;
                }

                if (spawnIndex < 2)
                {
                    random = 1;
                }
                else
                {
                    random = 0;
                }

                spawnIndex++;

                randomSpawn = Random.Range(0, spawnPoints.Count);
                GameObject gameObject = (GameObject)Instantiate(prefabToSpawnForPlayer[random],
                                                                new Vector3(spawnPoints[randomSpawn].transform.position.x, spawnPoints[randomSpawn].transform.position.y, 0), Quaternion.identity);
                gameObject.GetComponent <Player>().team = random;
                gameManager.GetGoblinsBags();
                gameManager.UpdateCount();
                spawnPoints.RemoveAt(randomSpawn);

                SpawnInfo spawnInfo = new SpawnInfo();
                spawnInfo.netPlayer = netPlayer;
                spawnInfo.data      = data;
                gameObject.SendMessage("InitializeNetPlayer", spawnInfo);
            }
        }
示例#11
0
 public PlayerConnectMessageArgs(NetPlayer _netPlayer)
 {
     netPlayer = _netPlayer;
 }
 NetPlayerState GetActiveNetPlayerState(NetPlayer netPlayer)
 {
     return(m_activePlayers.Find((NetPlayerState otherNetPlayerState) => {
         return otherNetPlayerState.netPlayer == netPlayer;
     }));
 }
 public NetPlayerState(NetPlayer _netPlayer, object _data)
 {
     netPlayer = _netPlayer;
     data      = _data;
 }
示例#14
0
 public PlayerConnectMessageArgs(NetPlayer _netPlayer, string _name, object _data)
 {
     netPlayer = _netPlayer;
     name      = _name;
     data      = _data;
 }
 public void StartLocalPlayer(NetPlayer netPlayer, string name = "", object data = null)
 {
     AddWaitingPlayer(new NetPlayerState(netPlayer, data));
     StartWaitingPlayers();
 }
 NetPlayerState GetWaitingNetPlayerState(NetPlayer netPlayer)
 {
     return(m_waitingPlayers.Find((NetPlayerState otherNetPlayerState) => {
         return otherNetPlayerState.netPlayer == netPlayer;
     }));
 }
示例#17
0
 /// <summary>
 /// Call this to rotate an active player out and start the next waiting player.
 /// </summary>
 /// <param name="netPlayer">The NetPlayer of the player to return</param>
 public void ReturnPlayer(NetPlayer netPlayer)
 {
     m_playerManager.ReturnPlayer(netPlayer);
 }