private void SetupGameModeSelector() { if (m_GameModeSelector == null) { return; } tnTeamsModule teamsModule = GameModulesManager.GetModuleMain <tnTeamsModule>(); if (teamsModule == null) { return; } int maxTeamSize = 0; for (int teamIndex = 0; teamIndex < teamsModule.teamsCount; ++teamIndex) { tnTeamDescription teamDescription = teamsModule.GetTeamDescription(teamIndex); if (teamDescription != null) { maxTeamSize = Mathf.Max(teamDescription.charactersCount, maxTeamSize); } } SelectorData selectorData = new SelectorData(); List <int> gameModesKeys = tnGameData.GetGameModesKeysMain(); if (gameModesKeys != null) { for (int gameModeIndex = 0; gameModeIndex < gameModesKeys.Count; ++gameModeIndex) { int gameModeId = gameModesKeys[gameModeIndex]; tnGameModeData gameModeData = tnGameData.GetGameModeDataMain(gameModeId); if (gameModeData == null) { continue; } if (!gameModeData.hidden) { IntRange teamsRange = gameModeData.teamsRange; IntRange teamSizeRange = gameModeData.playersPerTeamRange; if (teamsRange.IsValueValid(teamsModule.teamsCount)) { if (teamSizeRange.IsValueValid(maxTeamSize)) { SelectorItem selectorItem = new SelectorItem(gameModeId, gameModeData.name, "", null); selectorData.AddItem(selectorItem); } } } } } m_GameModeSelector.SetData(selectorData); }
private void GetRandomStadiumKey(string i_GameModeId, out int o_StadiumKey) { List <int> allowedStadiumKeys = new List <int>(); int minTeamSize; int maxTeamSize; GetTeamSize(out minTeamSize, out maxTeamSize); List <int> stadiyumKeys = tnGameData.GetStadiumsKeysMain(); tnGameModeData gameModeData = tnGameData.GetGameModeDataMain(i_GameModeId); for (int stadiumIndex = 0; stadiumIndex < stadiyumKeys.Count; ++stadiumIndex) { int currentStadiumKey = stadiyumKeys[stadiumIndex]; tnStadiumData stadiumData = tnGameData.GetStadiumDataMain(currentStadiumKey); bool excludedByTag = false; if (gameModeData != null) { for (int excluderTagIndex = 0; excluderTagIndex < gameModeData.fieldsExcludersTagsCount; ++excluderTagIndex) { int excluderTag = gameModeData.GetFieldExcluderTag(excluderTagIndex); if (excluderTag != Hash.s_EMPTY && excluderTag != Hash.s_NULL) { if (stadiumData.HasTag(excluderTag)) { excludedByTag = true; } } } } IntRange allowedTeamSize = stadiumData.teamSize; bool locked = excludedByTag || !allowedTeamSize.IsValueValid(maxTeamSize) || !allowedTeamSize.IsValueValid(minTeamSize); if (!locked) { allowedStadiumKeys.Add(currentStadiumKey); } } int stadiumKey = Hash.s_NULL; if (allowedStadiumKeys.Count > 0) { int randomIndex = Random.Range(0, allowedStadiumKeys.Count); stadiumKey = allowedStadiumKeys[randomIndex]; } o_StadiumKey = stadiumKey; }
private void SetupStadiumSelector(int i_GameModeId) { if (m_StadiumSelector == null) { return; } tnTeamsModule teamModule = GameModulesManager.GetModuleMain <tnTeamsModule>(); if (teamModule == null) { return; } int maxTeamSize = 0; for (int teamIndex = 0; teamIndex < teamModule.teamsCount; ++teamIndex) { tnTeamDescription teamDescription = teamModule.GetTeamDescription(teamIndex); if (teamDescription != null) { maxTeamSize = Mathf.Max(teamDescription.charactersCount, maxTeamSize); } } SelectorData selectorData = new SelectorData(); List <int> stadiumKeys = tnGameData.GetStadiumsKeysMain(); if (stadiumKeys != null) { tnGameModeData gameModeData = tnGameData.GetGameModeDataMain(i_GameModeId); for (int stadiumIndex = 0; stadiumIndex < stadiumKeys.Count; ++stadiumIndex) { int stadiumId = stadiumKeys[stadiumIndex]; tnStadiumData stadiumData = tnGameData.GetStadiumDataMain(stadiumId); if (stadiumData == null) { continue; } bool excludedByTag = false; if (gameModeData != null) { for (int excluderTagIndex = 0; excluderTagIndex < gameModeData.fieldsExcludersTagsCount; ++excluderTagIndex) { int excluderTag = gameModeData.GetFieldExcluderTag(excluderTagIndex); if (excluderTag != Hash.s_EMPTY && excluderTag != Hash.s_NULL) { if (stadiumData.HasTag(excluderTag)) { excludedByTag = true; } } } } IntRange teamSizeRange = stadiumData.teamSize; bool locked = excludedByTag || !(teamSizeRange.IsValueValid(maxTeamSize)); string lockedString = ""; if (locked) { if (excludedByTag) { lockedString = "Not available in this game mode."; } else { lockedString = "From " + teamSizeRange.min + " to " + teamSizeRange.max + " players"; } } SelectorItem selectorItem = new SelectorItem(stadiumId, stadiumData.name, stadiumData.description, stadiumData.icon, locked, lockedString); selectorData.AddItem(selectorItem); } } m_StadiumSelector.SetData(selectorData); }