Esempio n. 1
0
 /// <summary>
 /// Adds a player to a team, and attempts to make the teams even. Currently only used for the scout and solider classes.
 /// </summary>
 /// <param name="redTeam"></param>
 /// <param name="bluTeam"></param>
 /// <param name="player"></param>
 /// <param name="desiredClass"></param>
 protected void AddPlayerToTeam( Team redTeam, Team bluTeam, Player player, PlayerClass desiredClass )
 {
     if ((bluTeam.Players[desiredClass].Count < bluTeam.Players[desiredClass].Capacity)
         && (bluTeam.Skill <= redTeam.Skill) || (redTeam.Players[desiredClass].Count == redTeam.Players[desiredClass].Capacity) )
         bluTeam.AddPlayer( player, desiredClass );
     else
         redTeam.AddPlayer( player, desiredClass );
 }
Esempio n. 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 ) );
        }