Exemple #1
0
        private bool doClientConnection()
        {
            int loopCount = 0;

            foreach (LocalNetworkGamer gamer in _netSession.LocalGamers)
            {
                gamer.ReceiveData(_packetReader, out _sender);
                while (_sender == null)
                {
                    loopCount++;

                    if (loopCount > 600)
                    {
                        return(false);
                    }
                }

                if (_sender.IsHost)
                {
                    if (_remoteMapName == "")
                    {
                        _remoteMapName = ReadMapData();
                    }
                    if (_remoteMatch == null)
                    {
                        _remoteMatch       = new MatchController();
                        _remoteMatch.Match = (MatchType)ReadMatchType();
                        _remoteMatch.BlueTeam.TeamScore = _packetReader.ReadInt32();
                        _remoteMatch.RedTeam.TeamScore  = _packetReader.ReadInt32();
                        _remoteMatch.BlueTeam.Caps      = _packetReader.ReadInt32();
                        _remoteMatch.RedTeam.Caps       = _packetReader.ReadInt32();
                    }

                    if (_remoteItemList == null)
                    {
                        _remoteItemList = ReadRemoteItems(gamer);
                    }
                }
                else
                {
                    _packetReader.BaseStream.Flush();
                    doClientConnection();
                }
            }
            return(true);
        }
 public void RespawnPlayer(SpaceMarine Player, MatchController Controller)
 {
     if (getAvailableSpawn(_spawnList))
     {
         if (Controller.Match != MatchType.CTF)
         {
             doSpawn(Player, _selectedSpawn);
         }
         else
         if (_spawnList[_spawnIndex].Team != Player.Team)
         {
             RespawnPlayer(Player, Controller);
         }
         else
         {
             doSpawn(Player, _selectedSpawn);
         }
     }
 }
Exemple #3
0
        public void Dispose()
        {
            if (_netSession.IsHost)
            {
                _netSession.EndGame();
            }

            _netSession.Dispose();
            _netSession        = null;
            _availableSessions = null;
            _hasLeft           = true;
            _remoteMapName     = "";
            _packetReader.BaseStream.Flush();
            _packetWriter.BaseStream.Flush();
            _remoteItemList  = null;
            _remoteMatch     = null;
            _remoteMatchType = 999;
            _sender          = null;
            _sessionList.Clear();
            _isHost   = false;
            _isClient = false;
            _failure  = false;
        }
Exemple #4
0
        public GameController(Game1 Game, AssetManager assetManager, SessionController sessionManager, GraphicsDevice graphicsDevice)
        {
            m_graphicsDevice  = graphicsDevice;
            gameWorld         = new World(assetManager);
            m_crossHair       = new CrossHair(assetManager.SpriteLib["Crosshair"]);
            m_camera          = new Camera2D(graphicsDevice.Viewport, Vector2.Zero);
            m_controller      = new PolyInputController();
            m_matchController = new MatchController();
            m_sessionManager  = sessionManager;
            try
            {
                if (sessionManager.RecievedMapName != "")
                {
                    m_matchController = sessionManager.RecievedMatch;
                    gameWorld.LoadMap(sessionManager.RecievedMapName, m_matchController);
                }
                else
                {
                    setMatch(Game.SelectedMatch);
                    gameWorld.LoadMap(Game.SelectedMap, m_matchController);
                }
            }
            catch (Exception ex)
            {
                Game1.currentGameState = GameState.Menu;
                gameWorld = null;
                if (sessionManager.isHost)
                {
                    sessionManager.NetSession.EndGame();
                }
                Game.Exception = ex;
                return;
            }


            m_spawnManager                 = new SpawnController();
            m_spawnManager.SpawnList       = gameWorld.SpawnPoints;
            m_spawnManager.WeaponSpawnList = gameWorld.WeaponSpawns;
            m_spawnManager.SpawnAllWeapons(gameWorld.PickupItems);

            foreach (NetworkGamer gamer in sessionManager.NetSession.LocalGamers)
            {
                if (gamer.IsLocal)
                {
                    localPlayer = (SpaceMarine)gamer.Tag;
                }
            }
            m_matchController.NoTeam.AddTeamMember(localPlayer);

            if (sessionManager.RecievedItemList != null)
            {
                gameWorld.PickupItems = sessionManager.RecievedItemList;
                foreach (PickupItem item in gameWorld.PickupItems)
                {
                    if (item.GetType().BaseType == typeof(Weapon))
                    {
                        ((Weapon)item).SpawnPont = getSpawn(item);
                    }

                    else if (item.GetType() == typeof(Flag))
                    {
                        if (((Flag)item).Team == 1)
                        {
                            ((Flag)item).Base = gameWorld.BlueBase;
                        }
                        if (((Flag)item).Team == 2)
                        {
                            ((Flag)item).Base = gameWorld.RedBase;
                        }
                    }
                }
            }



            if (gameWorld.CurrentMatch == MatchType.CTF)
            {
                if (sessionManager.isHost)
                {
                    gameWorld.BlueBase.SpawnFlag(gameWorld.PickupItems);
                    gameWorld.RedBase.SpawnFlag(gameWorld.PickupItems);
                }
            }

            sessionManager.GameManager = this;
        }