public tnStadiumData GetData(int i_Id)
    {
        tnStadiumData data = null;

        m_Data.TryGetValue(i_Id, out data);
        return(data);
    }
    // LOGIC

    public void Initialize(string i_DatabasePath)
    {
        tnStadiumsDatabase database = Resources.Load <tnStadiumsDatabase>(i_DatabasePath);

        if (database != null)
        {
            for (int index = 0; index < database.stadiumsCount; ++index)
            {
                tnStadiumDataEntry entry = database.GetStadiumDataEntry(index);
                if (entry != null)
                {
                    string key = entry.id;
                    tnStadiumDataDescriptor descriptor = entry.descriptor;
                    if (key != "" && descriptor != null)
                    {
                        int           hash = StringUtils.GetHashCode(key);
                        tnStadiumData data = new tnStadiumData(descriptor);

                        m_Data.Add(hash, data);
                        m_Keys.Add(hash);
                    }
                }
            }
        }
        else
        {
            LogManager.LogWarning(this, "Database not loaded.");
        }
    }
Example #3
0
    // Max players

    private void SetupMaxPlayerSelector(int i_StadiumId)
    {
        SelectorData selectorData = new SelectorData();

        tnStadiumData stadiumData = tnGameData.GetStadiumDataMain(i_StadiumId);

        if (stadiumData != null)
        {
            int minPlayers = 2 * stadiumData.onlineTeamSize.min;
            int maxPlayers = 2 * stadiumData.onlineTeamSize.max;

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

            for (int numPlayers = minPlayers; numPlayers <= maxPlayers; numPlayers += 2)
            {
                if (numPlayers <= localPartySize)
                {
                    continue;
                }

                SelectorItem selectorItem = new SelectorItem(numPlayers, numPlayers.ToString(), "", null);
                selectorData.AddItem(selectorItem);
            }
        }

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

        RefreshMaxPlayers();
    }
        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;
        }
    // INTERNALS

    private void SpawnScorePanel()
    {
        tnMatchSettingsModule matchSettingsModule = GameModulesManager.GetModuleMain <tnMatchSettingsModule>();

        if (matchSettingsModule == null)
        {
            return;
        }

        GameObject scorePanelSpawnPointGo = GameObject.Find(s_ScorePanelSpawnPoint);

        if (scorePanelSpawnPointGo == null)
        {
            return;
        }

        int           stadiumId   = matchSettingsModule.stadiumId;
        tnStadiumData stadiumData = tnGameData.GetStadiumDataMain(stadiumId);

        if (stadiumData == null)
        {
            return;
        }

        int gameModeId = matchSettingsModule.gameModeId;

        GameObject scorePanelPrefab = stadiumData.LoadAndGetScorePanelPrefab(gameModeId);

        if (scorePanelPrefab == null)
        {
            return;
        }

        Vector3    spawnPosition = scorePanelSpawnPointGo.transform.position;
        Quaternion spawnRotation = scorePanelSpawnPointGo.transform.rotation;

        GameObject scorePanelInstance = Instantiate <GameObject>(scorePanelPrefab);

        scorePanelInstance.name = "ScorePanel";

        scorePanelInstance.transform.position = spawnPosition;
        scorePanelInstance.transform.rotation = spawnRotation;

        tnUIStandardScorePanel scorePanel = scorePanelInstance.GetComponentInChildren <tnUIStandardScorePanel>();

        if (scorePanel != null)
        {
            scorePanel.Bind(this);
        }
    }
Example #6
0
    private IEnumerator LoadMap()
    {
        tnMatchSettingsModule matchSettingsModule = GameModulesManager.GetModuleMain <tnMatchSettingsModule>();

        if (matchSettingsModule != null)
        {
            int           stadiumId   = matchSettingsModule.stadiumId;
            tnStadiumData stadiumData = tnGameData.GetStadiumDataMain(stadiumId);
            if (stadiumData != null)
            {
                string      sceneName = stadiumData.sceneName;
                IEnumerator loadScene = LoadSceneAdditiveAsync(sceneName);
                yield return(StartCoroutine(loadScene));
            }
        }
    }
    // INTERNALS

    private void ShowInfo()
    {
        tnMatchSettingsModule matchSettingsModule = GameModulesManager.GetModuleMain <tnMatchSettingsModule>();

        if (matchSettingsModule == null || viewInstance == null)
        {
            return;
        }

        // stadium

        int           stadiumId   = matchSettingsModule.stadiumId;
        tnStadiumData stadiumData = tnGameData.GetStadiumDataMain(stadiumId);

        if (stadiumData != null)
        {
            viewInstance.SetStadiumImage(stadiumData.icon);
            viewInstance.SetStadiumName(stadiumData.name);
            viewInstance.SetStadiumMinPlayers(stadiumData.onlineTeamSize.min * 2);
        }

        // game mode

        int            gameMode     = matchSettingsModule.gameModeId;
        tnGameModeData gameModeData = tnGameData.GetGameModeDataMain(gameMode);

        if (gameModeData != null)
        {
            viewInstance.SetGameMode(gameModeData.name);
        }

        // golden goal, referee, match duration

        string goldengol;

        tnGameData.TryGetGoldenGoalValueMain(matchSettingsModule.goldenGoalOption, out goldengol);

        string referee;

        tnGameData.TryGetGoldenGoalValueMain(matchSettingsModule.refereeOption, out referee);

        float matchDuration;

        tnGameData.TryGetMatchDurationValueMain(matchSettingsModule.matchDurationOption, out matchDuration);

        viewInstance.SetOtherSettings(goldengol == "ON", referee == "ON", matchDuration);
    }
    public int GetMaxPlayers()
    {
        tnStadiumData stadiumData = tnGameData.GetStadiumDataMain(GetStadiumId());

        if (stadiumData == null)
        {
            return(int.MaxValue);
        }

        IntRange teamSizeRange = stadiumData.teamSize;

        if (teamSizeRange == null)
        {
            return(int.MaxValue);
        }

        return(teamSizeRange.max * 2);
    }
    public int GetMinPlayers()
    {
        tnStadiumData stadiumData = tnGameData.GetStadiumDataMain(GetStadiumId());

        if (stadiumData == null)
        {
            return(0);
        }

        IntRange teamSizeRange = stadiumData.teamSize;

        if (teamSizeRange == null)
        {
            return(0);
        }

        return(teamSizeRange.min * 2);
    }
        public override void OnEnter()
        {
            tnMatchSettingsModule module = GameModulesManager.GetModuleMain <tnMatchSettingsModule>();

            if (module != null)
            {
                int           stadiumId   = module.stadiumId;
                tnStadiumData stadiumData = tnGameData.GetStadiumDataMain(stadiumId);

                if (stadiumData != null)
                {
                    if (storeResult != null && !storeResult.IsNone)
                    {
                        storeResult.Value = stadiumData.sceneName;
                    }
                }
            }

            Finish();
        }
        public override void OnEnter()
        {
            tnMatchSettingsModule module = GameModulesManager.GetModuleMain <tnMatchSettingsModule>();

            if (module != null)
            {
                int            gameModeId   = module.gameModeId;
                tnGameModeData gameModeData = tnGameData.GetGameModeDataMain(gameModeId);

                if (gameModeData != null)
                {
                    int          camerasSetId = gameModeData.camerasSetId;
                    tnCamerasSet camerasSet   = tnGameData.GetCameraSetMain(camerasSetId);

                    if (camerasSet != null)
                    {
                        int           stadiumId   = module.stadiumId;
                        tnStadiumData stadiumData = tnGameData.GetStadiumDataMain(stadiumId);

                        if (stadiumData != null)
                        {
                            GameObject cameraPrefab = camerasSet.GetCamera(stadiumData.cameraId);

                            if (cameraPrefab != null)
                            {
                                if (storeResult != null && !storeResult.IsNone)
                                {
                                    storeResult.Value = cameraPrefab.gameObject;
                                }
                            }
                        }
                    }
                }
            }

            Finish();
        }
Example #12
0
    private void CreateCamera()
    {
        GameObject spawnPointGo = GameObject.Find(s_Camera_SpawnPoint_Name);

        Vector3 spawnPointPosition = (spawnPointGo != null) ? spawnPointGo.transform.position : Vector3.zero;

        spawnPointPosition.z = -15f;

        tnMatchSettingsModule matchSettingsModule = GameModulesManager.GetModuleMain <tnMatchSettingsModule>();

        if (matchSettingsModule == null)
        {
            return;
        }

        int            gameModeId   = matchSettingsModule.gameModeId;
        tnGameModeData gameModeData = tnGameData.GetGameModeDataMain(gameModeId);

        if (gameModeData == null)
        {
            return;
        }

        int          cameraSetId = gameModeData.camerasSetId;
        tnCamerasSet cameraSet   = tnGameData.GetCameraSetMain(cameraSetId);

        if (cameraSet == null)
        {
            return;
        }

        int           stadiumId   = matchSettingsModule.stadiumId;
        tnStadiumData stadiumData = tnGameData.GetStadiumDataMain(stadiumId);

        if (stadiumData == null)
        {
            return;
        }

        GameObject cameraPrefab = cameraSet.GetCamera(stadiumData.cameraId);

        if (cameraPrefab == null)
        {
            return;
        }

        m_GameCameraGO      = Instantiate <GameObject>(cameraPrefab);
        m_GameCameraGO.name = "GameCamera";
        m_GameCameraGO.tag  = "GameCamera";

        tnGameCamera gameCamera = m_GameCameraGO.GetComponent <tnGameCamera>();

        if (gameCamera != null)
        {
            gameCamera.SetPosition(spawnPointPosition);
        }
        else
        {
            m_GameCameraGO.transform.position = spawnPointPosition;
        }

        m_GameCameraGO.transform.rotation = Quaternion.identity;
    }
    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);
    }
    private void UpdateView()
    {
        if (viewInstance == null)
        {
            return;
        }

        ClearView();

        int showedRooms = 0;

        for (int index = minShowedIndex; index >= 0 && index <= maxShowedIndex; ++index)
        {
            RoomInfo roomInfo = m_Rooms[index];

            if (roomInfo == null)
            {
                continue;
            }

            int stadiumId;
            PhotonUtils.TryGetRoomCustomProperty <int>(roomInfo, PhotonPropertyKey.s_RoomCustomPropertyKey_Stadium, out stadiumId);

            int gameModeId;
            PhotonUtils.TryGetRoomCustomProperty <int>(roomInfo, PhotonPropertyKey.s_RoomCustomPropertyKey_GameMode, out gameModeId);

            int matchDurationOptionId;
            PhotonUtils.TryGetRoomCustomProperty <int>(roomInfo, PhotonPropertyKey.s_RoomCustomPropertyKey_MatchDuration, out matchDurationOptionId);

            int goldenGoalOptionId;
            PhotonUtils.TryGetRoomCustomProperty <int>(roomInfo, PhotonPropertyKey.s_RoomCustomPropertyKey_GoldenGoal, out goldenGoalOptionId);

            int refereeOptionId;
            PhotonUtils.TryGetRoomCustomProperty <int>(roomInfo, PhotonPropertyKey.s_RoomCustomPropertyKey_Referee, out refereeOptionId);

            string host;
            PhotonUtils.TryGetRoomCustomProperty <string>(roomInfo, PhotonPropertyKey.s_RoomCustomPropertyKey_HostName, out host);

            int playersCount;
            PhotonUtils.TryGetRoomCustomProperty <int>(roomInfo, PhotonPropertyKey.s_RoomCustomPropertyKey_PlayerCount, out playersCount);

            int ping;
            PhotonUtils.TryGetRoomCustomProperty <int>(roomInfo, PhotonPropertyKey.s_RoomCustomPropertyKey_AvgPing, out ping);

            int maxPlayer = roomInfo.MaxPlayers;

            Sprite stadiumThumbnail = null;
            string stadiumName      = "";
            string gameModeName     = "";
            string rules            = "";

            tnStadiumData stadiumData = tnGameData.GetStadiumDataMain(stadiumId);
            if (stadiumData != null)
            {
                stadiumThumbnail = stadiumData.icon;
                stadiumName      = stadiumData.name;
            }

            tnGameModeData gameModeData = tnGameData.GetGameModeDataMain(gameModeId);
            if (gameModeData != null)
            {
                gameModeName = gameModeData.name;
            }

            float matchDuration;
            tnGameData.TryGetMatchDurationValueMain(matchDurationOptionId, out matchDuration);
            string matchDurationRule = TimeUtils.TimeToString(matchDuration, true, true);

            string goldenGoal;
            tnGameData.TryGetGoldenGoalValueMain(goldenGoalOptionId, out goldenGoal);
            string goldenGoalRule = (goldenGoal == "ON") ? "GOLDEN GOAL" : "NO GOLDEN GOAL";

            string referee;
            tnGameData.TryGetRefereeValueMain(refereeOptionId, out referee);
            string refereeRule = (referee == "ON") ? "REFEREE" : "";

            rules = goldenGoalRule + ", " + refereeRule + ((refereeRule == "") ? "" : ", ") + matchDurationRule;

            SetRoomData(showedRooms, stadiumThumbnail, stadiumName, gameModeName, rules, host, playersCount, maxPlayer, ping);
            ++showedRooms;
        }

        int   roomsCount            = m_Rooms.Count;
        float showedRoomsPercentage = (roomsCount > 0) ? (((float)showedRooms) / ((float)roomsCount)) : 1f;

        int   slotCount          = Mathf.Max(0, m_SlotsCount);
        int   possibleStates     = (roomsCount > slotCount) ? (roomsCount - slotCount) : 1;
        int   currentStates      = Mathf.Max(0, minShowedIndex);
        float positionPercentage = ((float)currentStates) / ((float)possibleStates);

        viewInstance.SetScrollbarHandleState(showedRoomsPercentage, positionPercentage);
        viewInstance.SetConfirmTriggerCanSend(roomsCount > 0);
        viewInstance.SetRefreshCommandActive(roomsCount > 0);
    }
    private void SpawnGoals()
    {
        tnMatchSettingsModule matchSettingsModule = GameModulesManager.GetModuleMain <tnMatchSettingsModule>();

        if (matchSettingsModule == null)
        {
            return;
        }

        int stadiumId = matchSettingsModule.stadiumId;

        m_StadiumId = stadiumId;

        tnStadiumData stadiumData = tnGameData.GetStadiumDataMain(stadiumId);

        if (stadiumData == null)
        {
            return;
        }

        tnGoal goalPrefab = stadiumData.LoadAndGetGoalPrefab();

        if (goalPrefab == null)
        {
            return;
        }

        for (int teamIndex = 0; teamIndex < teamsCount; ++teamIndex)
        {
            if (teamIndex >= s_GoalSpawnPoints.Length)
            {
                break;
            }

            int teamId = GetTeamId(teamIndex);

            string     goalSpawnPointName = s_GoalSpawnPoints[teamIndex];
            GameObject goalSpawnPointGo   = GameObject.Find(goalSpawnPointName);

            if (goalSpawnPointGo == null)
            {
                continue;
            }

            TSTransform2D goalSpawnPointTransform = goalSpawnPointGo.GetComponent <TSTransform2D>();

            if (goalSpawnPointTransform == null)
            {
                continue;
            }

            Vector3    spawnPosition = goalSpawnPointGo.transform.position;
            Quaternion spawnRotation = goalSpawnPointGo.transform.rotation;

            tnGoal goalInstance = Instantiate <tnGoal>(goalPrefab);
            goalInstance.gameObject.name = "Goal_" + teamIndex;

            goalInstance.transform.position = spawnPosition;
            goalInstance.transform.rotation = spawnRotation;

            // Configure TSTransform

            TSTransform2D tsTransform = goalInstance.GetComponent <TSTransform2D>();
            if (tsTransform != null)
            {
                tsTransform.position = goalSpawnPointTransform.position;
                tsTransform.rotation = goalSpawnPointTransform.rotation;
            }

            // Rotate.

            if (goalInstance.transform.position.x > 0f)
            {
                goalInstance.Rotate();
            }

            // Setup goal.

            goalInstance.SetTeamId(teamId);

            // Register on TrueSyncController.

            TrueSyncManager.RegisterTrueSyncObjectMain(goalInstance.gameObject);

            // Set data on slow motion controller.

            if (m_SlowMotionController != null)
            {
                m_SlowMotionController.AddSegment(goalInstance.slowMotionPivotA, goalInstance.slowMotionPivotB);
            }

            // Add to goal list.

            m_Goals.Add(goalInstance);
        }
    }
Example #16
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();
    }