Client LuaCsForBarotrauma
PvPMode.cs
3 using System.Collections.Generic;
4 using System.Linq;
5 
6 namespace Barotrauma
7 {
9  {
10  public PvPMode(GameModePreset preset, IEnumerable<MissionPrefab> missionPrefabs) : base(preset, ValidateMissionPrefabs(missionPrefabs, MissionPrefab.PvPMissionClasses)) { }
11 
12  public PvPMode(GameModePreset preset, MissionType missionType, string seed) : base(preset, ValidateMissionType(missionType, MissionPrefab.PvPMissionClasses), seed) { }
13 
14  public void AssignTeamIDs(IEnumerable<Client> clients)
15  {
16  int team1Count = 0, team2Count = 0;
17  //if a client has a preference, assign them to that team
18  List<Client> unassignedClients = new List<Client>(clients);
19  for (int i = 0; i < unassignedClients.Count; i++)
20  {
21  if (unassignedClients[i].PreferredTeam == CharacterTeamType.Team1 ||
22  unassignedClients[i].PreferredTeam == CharacterTeamType.Team2)
23  {
24  assignTeam(unassignedClients[i], unassignedClients[i].PreferredTeam);
25  i--;
26  }
27  }
28 
29  //assign the rest of the clients to the team that has the least players
30  while (unassignedClients.Any())
31  {
32  var randomClient = unassignedClients.GetRandom(Rand.RandSync.Unsynced);
33  assignTeam(randomClient, team1Count < team2Count ? CharacterTeamType.Team1 : CharacterTeamType.Team2);
34  }
35 
36  void assignTeam(Client client, CharacterTeamType team)
37  {
38  client.TeamID = team;
39  unassignedClients.Remove(client);
40  if (team == CharacterTeamType.Team1)
41  {
42  team1Count++;
43  }
44  else
45  {
46  team2Count++;
47  }
48  }
49  }
50  }
51 }
static IEnumerable< MissionPrefab > ValidateMissionPrefabs(IEnumerable< MissionPrefab > missionPrefabs, Dictionary< MissionType, Type > missionClasses)
static MissionType ValidateMissionType(MissionType missionType, Dictionary< MissionType, Type > missionClasses)
void AssignTeamIDs(IEnumerable< Client > clients)
Definition: PvPMode.cs:14
PvPMode(GameModePreset preset, IEnumerable< MissionPrefab > missionPrefabs)
Definition: PvPMode.cs:10
PvPMode(GameModePreset preset, MissionType missionType, string seed)
Definition: PvPMode.cs:12