private void SetupTeamsModule() { tnTeamsModule teamsModule = GameModulesManager.GetModuleMain <tnTeamsModule>(); if (teamsModule == null) { return; } teamsModule.Clear(); tnGameModeData gameModeData = tnGameData.GetGameModeDataMain(gameMode.Value); if (gameModeData == null) { return; } int numTeams = Random.Range(gameModeData.teamsRange.min, gameModeData.teamsRange.max); int minTeamSize = gameModeData.playersPerTeamRange.min; int maxTeamSize = gameModeData.playersPerTeamRange.max; if (forceTeamSize != null && forceTeamSize.Value) { if (forcedMinTeamSize != null && forcedMinTeamSize.Value > 0) { minTeamSize = forcedMinTeamSize.Value; } if (forcedMaxTeamSize != null && forcedMaxTeamSize.Value > 0) { maxTeamSize = forcedMaxTeamSize.Value; } } int[] teamIds = SelectTeams(numTeams); if (teamIds != null) { int teamSize = Random.Range(minTeamSize, maxTeamSize); Color[] teamColors = Utils.ComputeTeamColors(teamIds); for (int teamIndex = 0; teamIndex < teamIds.Length; ++teamIndex) { int teamId = teamIds[teamIndex]; Color teamColor = teamColors[teamIndex]; tnTeamDescription teamDescription = CreateTeam(teamId, teamSize, teamColor); teamsModule.AddTeamDescription(teamDescription); } } }
public override void OnEnter() { tnTeamsModule teamsModule = GameModulesManager.GetModuleMain <tnTeamsModule>(); if (teamsModule == null) { teamsModule = GameModulesManager.AddModuleMain <tnTeamsModule>(); teamsModule.Clear(); } tnTeamDescription team = new tnTeamDescription(); team.SetTeamId(id.Value); team.SetTeamColor(color.Value); int charactersCount = characters.Length; for (int characterIndex = 0; characterIndex < charactersCount; ++characterIndex) { tnCharacterEntry entry = characters[characterIndex]; if (entry != null) { FsmString characterId = entry.characterId; FsmInt onlinePlayerIndex = entry.onlinePlayerIndex; FsmString playerId = entry.playerId; FsmInt spawnOrder = entry.spawnOrder; if (characterId != null && !characterId.IsNone && onlinePlayerIndex != null && !onlinePlayerIndex.IsNone && playerId != null && !playerId.IsNone && spawnOrder != null && !spawnOrder.IsNone) { tnCharacterDescription character = new tnCharacterDescription(); character.SetCharacterId(characterId.Value); character.SetOnlinePlayerIndex(onlinePlayerIndex.Value); character.SetPlayerId(playerId.Value); character.SetSpawnOrder(spawnOrder.Value); team.AddCharacterDescription(character); } } } teamsModule.AddTeamDescription(team); Finish(); }
private void Internal_AddTeamB(tnTeamsModule i_TeamsModule, int i_CharacterCount) { if (i_TeamsModule == null) { return; } tnTeamDescription teamDescription = new tnTeamDescription(); string teamId = GetTeamB(); teamDescription.SetTeamId(teamId); Color teamColor = GetTeamBColor(); teamDescription.SetTeamColor(teamColor); if (i_CharacterCount >= 0) { tnTeamData teamData = tnGameData.GetTeamDataMain(teamId); if (teamData != null) { int characterCount = Mathf.Min(i_CharacterCount, teamData.charactersCount); for (int index = 0; index < characterCount; ++index) { tnCharacterDescription characterDescription = new tnCharacterDescription(); characterDescription.SetCharacterId(teamData.GetCharacterKey(index)); characterDescription.SetSpawnOrder(index); if (m_AllHumans) { characterDescription.SetPlayerId(GetPlayerIdByIndex(index + characterCount)); } teamDescription.AddCharacterDescription(characterDescription); } } } i_TeamsModule.AddTeamDescription(teamDescription); }
private void SetupTeamB(tnTeamsModule i_Module) { if (m_TeamB == null) { return; } tnTeamDescription teamDescription = new tnTeamDescription(); // Add real players. for (int index = 0; index < m_TeamB.entriesCount; ++index) { GridEntry gridEntry = m_TeamB.GetEntryByIndex(index); if (gridEntry == null) { continue; } bool present = (gridEntry.device != null); if (present) { int playerId = gridEntry.device.playerId; tnCharacterDescription characterDescription = new tnCharacterDescription(); characterDescription.SetPlayerId(playerId); teamDescription.AddCharacterDescription(characterDescription); LogManager.Log(this, LogContexts.FSM, "Added character to Team A [Real player]"); } } // Add bots. for (int index = 0; index < m_TeamB.entriesCount; ++index) { GridEntry gridEntry = m_TeamB.GetEntryByIndex(index); if (gridEntry == null) { continue; } bool present = (gridEntry.isBot); if (present) { tnCharacterDescription characterDescription = new tnCharacterDescription(); characterDescription.SetPlayerId(Hash.s_NULL); teamDescription.AddCharacterDescription(characterDescription); LogManager.Log(this, LogContexts.FSM, "Added character to Team A [BOT]"); } } // Add team description. i_Module.AddTeamDescription(teamDescription); }