Beispiel #1
0
        public PugTests()
        {
            player1 = new Player("Player01", "Player 01") { Skill = 200 };
            player2 = new Player("Player02", "Player 02") { Skill = 100 };
            player3 = new Player("Player03", "Player 03") { Skill = 200 };
            player4 = new Player("Player04", "Player 04") { Skill = 100 };
            player5 = new Player("Player05", "Player 05") { Skill = 100 };
            player6 = new Player("Player06", "Player 06") { Skill = 100 };
            player7 = new Player("Player07", "Player 07") { Skill = 100 };
            player8 = new Player("Player08", "Player 08") { Skill = 100 };
            player9 = new Player("Player09", "Player 09") { Skill = 100 };
            player10 = new Player( "Player10", "Player 10" ) { Skill = 100 };
            player11 = new Player( "Player11", "Player 11" ) { Skill = 100 };
            player12 = new Player( "Player12", "Player 12" ) { Skill = 100 };

            map = new Map( Guid.Empty, null, null );

            server = new Server( Guid.Empty, null, "dallas1.tf2pug.us", "123", "123" );
        }
Beispiel #2
0
        /// <summary>
        /// Assigns teams and sets up the server for the PUG.
        /// </summary>
        /// <param name="map">Map that will be played.</param>
        /// <param name="server">Server that the PUG will be played on.</param>
        public void Start(Map map, Server server)
        {
            this.Map = map;
            this.Server = server;

            foreach (List<Player> currentClass in Players.Values)
            {
                if (currentClass.Count < currentClass.Capacity)
                    throw new PugNotFullException();
            }

            Team bluTeam = new Team( TeamSide.Blu );
            Team redTeam = new Team( TeamSide.Red );

            Players[PlayerClass.Scout].Sort( new PlayerSkillLevelComparer() );
            Players[PlayerClass.Soldier].Sort( new PlayerSkillLevelComparer() );
            Players[PlayerClass.Demo].Sort( new PlayerSkillLevelComparer() );
            Players[PlayerClass.Medic].Sort( new PlayerSkillLevelComparer() );

            foreach (Player currentPlayer in Players[PlayerClass.Scout])
                AddPlayerToTeam( redTeam, bluTeam, currentPlayer, PlayerClass.Scout );

            foreach (Player currentPlayer in Players[PlayerClass.Soldier])
                AddPlayerToTeam( redTeam, bluTeam, currentPlayer, PlayerClass.Soldier );

            // Add the demo with the higher skill rating to the team that needs it
            if (bluTeam.Skill <= redTeam.Skill)
            {
                bluTeam.AddPlayer( Players[PlayerClass.Demo][0], PlayerClass.Demo );
                redTeam.AddPlayer( Players[PlayerClass.Demo][1], PlayerClass.Demo );
            }
            else
            {
                bluTeam.AddPlayer( Players[PlayerClass.Demo][1], PlayerClass.Demo );
                redTeam.AddPlayer( Players[PlayerClass.Demo][0], PlayerClass.Demo );
            }

            // Add the medic with the higher skill rating to the team that needs it
            if (bluTeam.Skill <= redTeam.Skill)
            {
                bluTeam.AddPlayer( Players[PlayerClass.Medic][0], PlayerClass.Medic );
                redTeam.AddPlayer( Players[PlayerClass.Medic][1], PlayerClass.Medic );
            }
            else
            {
                bluTeam.AddPlayer( Players[PlayerClass.Medic][1], PlayerClass.Medic );
                redTeam.AddPlayer( Players[PlayerClass.Medic][0], PlayerClass.Medic );
            }

            Server.StartPug( this.UniqueId, Map );

            // Save the PUG to the database
            using (SqlConnection sqlConnection = new SqlConnection( ConfigurationManager.ConnectionStrings["pug"].ConnectionString ))
            {
                sqlConnection.Open();

                using (SqlCommand sqlCommand = sqlConnection.CreateCommand())
                {
                    sqlCommand.CommandText = @"INSERT INTO PUGs (UniqueId, MapId, BluScore, RedScore, Started) VALUES (@UniqueId, @MapId, 0, 0, @Started);";
                    sqlCommand.Parameters.Add( new SqlParameter( @"UniqueId", SqlDbType.UniqueIdentifier ) );
                    sqlCommand.Parameters.Add( new SqlParameter( @"MapId", SqlDbType.UniqueIdentifier ) );
                    sqlCommand.Parameters.Add( new SqlParameter( @"Started", SqlDbType.DateTime ) );
                    sqlCommand.Parameters[0].Value = this.UniqueId;
                    sqlCommand.Parameters[1].Value = this.Map.UniqueId;
                    sqlCommand.Parameters[2].Value = DateTime.Now;

                    sqlCommand.ExecuteScalar();
                }

                using (SqlCommand sqlCommand = sqlConnection.CreateCommand())
                {
                    sqlCommand.CommandText = @"sp_AddPlayerToPug";
                    sqlCommand.CommandType = CommandType.StoredProcedure;

                    sqlCommand.Parameters.Add( new SqlParameter( @"PugId", SqlDbType.UniqueIdentifier ) );
                    sqlCommand.Parameters.Add( new SqlParameter( @"PlayerId", SqlDbType.NVarChar ) );
                    sqlCommand.Parameters.Add( new SqlParameter( @"PlayerName", SqlDbType.NVarChar ) );
                    sqlCommand.Parameters.Add( new SqlParameter( @"PlayerClass", SqlDbType.TinyInt ) );

                    sqlCommand.Parameters[0].Value = this.UniqueId;

                    foreach (PlayerClass currentClass in Players.Keys)
                    {
                        foreach (Player currentPlayer in Players[currentClass])
                        {
                            sqlCommand.Parameters[1].Value = currentPlayer.Id;
                            sqlCommand.Parameters[2].Value = currentPlayer.Name;
                            sqlCommand.Parameters[3].Value = currentClass;

                            sqlCommand.ExecuteScalar();
                        }
                    }
                }
            }

            if (null != OnPugStarted)
                OnPugStarted( this, new PugStartedEventsArgs( redTeam, bluTeam ) );
        }