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);
    }
Beispiel #3
0
    // Stadium

    private void SetupStadiumSelector(int i_GameModeId)
    {
        SelectorData selectorData = new SelectorData();

        List <int> stadiumKeys = tnGameData.GetStadiumsKeysMain();

        if (stadiumKeys == null)
        {
            return;
        }

        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;
            }

            if (stadiumData.hiddenOnline)
            {
                continue;
            }

            bool excludedByTag = false;

            if (gameModeData != null)
            {
                for (int excluderTagIndex = 0; excluderTagIndex < gameModeData.fieldsExcludersTagsCount; ++excluderTagIndex)
                {
                    int excluderTag = gameModeData.GetFieldExcluderTag(excluderTagIndex);

                    if (Hash.IsNullOrEmpty(excluderTag))
                    {
                        continue;
                    }

                    excludedByTag |= stadiumData.HasTag(excluderTag);
                }
            }

            IntRange teamSizeRange = stadiumData.onlineTeamSize;

            int localPartySize;
            PhotonUtils.TryGetPlayerCustomProperty <int>(PhotonNetwork.player, PhotonPropertyKey.s_PlayerCustomPropertyKey_LocalPartySize, out localPartySize);

            bool teamSizeInvalid = (localPartySize >= teamSizeRange.max * 2);

            bool locked = excludedByTag || teamSizeInvalid;

            SelectorItem selectorItem = new SelectorItem(stadiumId, stadiumData.name, stadiumData.description, stadiumData.icon, locked, String.Empty);
            selectorData.AddItem(selectorItem);
        }

        if (viewInstance != null)
        {
            viewInstance.SetStadiumSelectorData(selectorData);
        }

        SelectFirstUnlockedStadium();
    }