PRoConEvents.MULTIbalancer.AssignSquadToTeam C# (CSharp) Method

AssignSquadToTeam() private method

private AssignSquadToTeam ( SquadRoster squad, SquadRoster>.Dictionary squadTable, List usScrambled, List ruScrambled, List origTarget ) : void
squad SquadRoster
squadTable SquadRoster>.Dictionary
usScrambled List
ruScrambled List
origTarget List
return void
        private void AssignSquadToTeam(SquadRoster squad, Dictionary<int,SquadRoster> squadTable, List<PlayerModel> usScrambled, List<PlayerModel> ruScrambled, List<PlayerModel> origTarget)
        {
            /*
            The PlayerModel object is still live, so we can't change managed properties like Team or Squad.
            Instead, the assigned team is implied by the list (usScrambled or ruScrambled) the player is added to
            and the squad is remembered in the ScrambledSquad property. This is later used during the move
            command to assign the player to that squad in the destination team.
            */
            List<PlayerModel> target = origTarget;
            int teamMax = MaximumServerSize/2;

            if (usScrambled.Count >= teamMax && ruScrambled.Count >= teamMax) {
            DebugScrambler("BOTH teams full! Skipping remaining free pool!");
            return;
            }
            int wasSquad = squad.Roster[0].Squad;

            // Remap if there is a squad collision
            if (squadTable.ContainsKey(squad.Squad)) {
            RemapSquad(squadTable, squad);
            }
            squadTable[squad.Squad] = squad;
            int wasTeam = squad.Roster[0].Team;

            String special = String.Empty;
            if (squad.WhitelistCount > 0 && (wasTeam == 1 || wasTeam == 2)) {
            target = (wasTeam == 1) ? usScrambled : ruScrambled;
            special = " (" + squad.WhitelistCount + " on Whitelist)";
            }

            String st = GetTeamName(wasTeam);
            String gt = GetTeamName((target == usScrambled) ? 1 : 2);
            DebugScrambler(st + "/" + GetSquadName(wasSquad) + " scrambled to " + gt + "/" + GetSquadName(squad.Squad) + special);

            // Assign the squad to the target team
            int toTeam = (target == usScrambled) ? 1 : 2;
            foreach (PlayerModel clone in squad.Roster) {
            clone.ScrambledSquad = squad.Squad;
            if (target.Count < teamMax && IsKnownPlayer(clone.Name)) {
                clone.Team = toTeam;
                target.Add(clone);
            }
            }
        }
MULTIbalancer