public void CreateTeamAIFactory(int i_TeamIndex, tnTeamDescription i_TeamDescription)
    {
        if (!m_SetupDone)
        {
            return;
        }

        if (i_TeamIndex < 0 || i_TeamIndex >= m_AIFactories.Length || i_TeamIndex >= m_TeamSizes.Length)
        {
            return;
        }

        if (i_TeamDescription == null)
        {
            return;
        }

        ClassTypeReference newAIFactoryType = (i_TeamIndex % 2 == 0) ? m_EvenTeamAIFactoryType : m_OddTeamAIFactoryType;

        tnBaseSubbuteoMatchAIFactory newAIFactory = CSharpUtils.Cast <tnBaseSubbuteoMatchAIFactory>(Activator.CreateInstance(newAIFactoryType));

        if (newAIFactory != null)
        {
            newAIFactory.Configure(i_TeamDescription);
        }

        m_AIFactories[i_TeamIndex] = newAIFactory;
        m_TeamSizes[i_TeamIndex]   = i_TeamDescription.charactersCount;
    }
    // UTILS

    private int GetAICount()
    {
        int aiCount = 0;

        tnTeamsModule teamsModule = GameModulesManager.GetModuleMain <tnTeamsModule>();

        if (teamsModule != null)
        {
            for (int teamIndex = 0; teamIndex < teamsModule.teamsCount; ++teamIndex)
            {
                tnTeamDescription teamDescription = teamsModule.GetTeamDescription(teamIndex);

                if (teamDescription == null)
                {
                    continue;
                }

                for (int characterIndex = 0; characterIndex < teamDescription.charactersCount; ++characterIndex)
                {
                    tnCharacterDescription characterDescription = teamDescription.GetCharacterDescription(characterIndex);

                    if (characterDescription == null)
                    {
                        continue;
                    }

                    bool ai = (characterDescription.playerId == Hash.s_NULL);
                    aiCount += (ai) ? 1 : 0;
                }
            }
        }

        return(aiCount);
    }
    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 tnTeamDescription CreateTeam(int i_TeamKey, int i_TeamSize, Color i_TeamColor)
        {
            tnTeamData teamData = tnGameData.GetTeamDataMain(i_TeamKey);

            if (teamData == null || i_TeamSize <= 0)
            {
                return(null);
            }

            tnTeamDescription teamDescription = new tnTeamDescription();

            teamDescription.SetTeamId(i_TeamKey);
            teamDescription.SetTeamColor(i_TeamColor);

            List <int> teamLineup = teamData.GetDefaultLineUp(i_TeamSize);

            for (int characterIndex = 0; characterIndex < teamLineup.Count; ++characterIndex)
            {
                int characterKey = teamLineup[characterIndex];

                tnCharacterDescription characterDescription = new tnCharacterDescription();
                characterDescription.SetCharacterId(characterKey);
                characterDescription.SetPlayerId(StringUtils.s_NULL);
                characterDescription.SetSpawnOrder(characterIndex);

                teamDescription.AddCharacterDescription(characterDescription);
            }

            return(teamDescription);
        }
Exemplo n.º 5
0
    // BUSINESS LOGIC

    public void UpdateModule()
    {
        tnTeamsModule teamsModule = GameModulesManager.GetModuleMain <tnTeamsModule>();

        if (teamsModule == null)
        {
            return;
        }

        // Evaluate teams colors.

        Color[] teamColors = null;

        {
            int[] teamIds = new int[s_MaxPlayers];

            for (int teamIndex = 0; teamIndex < s_MaxPlayers; ++teamIndex)
            {
                teamIds[teamIndex] = GetTeamId(teamIndex);
            }

            teamColors = Utils.ComputeTeamColors(teamIds);
        }

        // Fill team descriptors.

        for (int teamIndex = 0; teamIndex < s_MaxPlayers; ++teamIndex)
        {
            tnTeamDescription teamDescription = teamsModule.GetTeamDescription(teamIndex);

            if (teamDescription == null)
            {
                continue;
            }

            // Set team id.

            int teamId = GetTeamId(teamIndex);

            teamDescription.SetTeamId(teamId);

            // Set team color.

            Color teamColor;

            if (teamColors != null)
            {
                teamColor = teamColors[teamIndex];
            }
            else
            {
                teamColor = Color.white;
            }

            teamDescription.SetTeamColor(teamColor);

            LogManager.Log(this, LogContexts.FSM, "Team " + teamIndex + " : " + teamId + " " + "[" + teamColor + "]");
        }
    }
    public void AddTeamDescription(tnTeamDescription i_Team)
    {
        if (i_Team == null)
        {
            return;
        }

        m_Teams.Add(i_Team);
    }
    protected override void OnCreateTeam(int i_TeamIndex, tnTeamDescription i_TeamDescription)
    {
        base.OnCreateTeam(i_TeamIndex, i_TeamDescription);

        if (m_AIFactoryComponent != null)
        {
            m_AIFactoryComponent.CreateTeamAIFactory(i_TeamIndex, i_TeamDescription);
        }
    }
Exemplo n.º 8
0
    private void CreateCharacters()
    {
        // Cache character prefab path.

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

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

            if (gameModeData != null)
            {
                m_CharacterPrefab = gameModeData.LoadAndGetCharacterPrefabPath();
            }
        }

        // Create teams.

        tnTeamsModule teamsModule = GameModulesManager.GetModuleMain <tnTeamsModule>();

        if (teamsModule == null)
        {
            return;
        }

        for (int teamIndex = 0; teamIndex < teamsModule.teamsCount; ++teamIndex)
        {
            List <GameObject> team = new List <GameObject>();
            m_Teams.Add(team);
        }

        for (int teamIndex = 0; teamIndex < teamsModule.teamsCount; ++teamIndex)
        {
            List <tnAIInputFiller> aiList = new List <tnAIInputFiller>();
            m_LocalAI.Add(aiList);
        }

        for (int teamIndex = 0; teamIndex < teamsModule.teamsCount; ++teamIndex)
        {
            tnTeamDescription teamDescription = teamsModule.GetTeamDescription(teamIndex);

            if (teamDescription == null)
            {
                continue;
            }

            ProceesTeam(teamIndex, teamDescription);
        }

        // Disable Input

        DisableInput();
    }
        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);
                }
            }
        }
Exemplo n.º 10
0
        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();
        }
    public int GetMinTeamSize()
    {
        int minTeamSize = int.MaxValue;

        for (int teamIndex = 0; teamIndex < m_Teams.Count; ++teamIndex)
        {
            tnTeamDescription teamDescription = m_Teams[teamIndex];

            if (teamDescription == null)
            {
                continue;
            }

            minTeamSize = Mathf.Min(teamDescription.charactersCount, minTeamSize);
        }

        return(minTeamSize);
    }
    // tnBaseStandardMatchAIFactory's interface

    protected override void OnConfigure(tnTeamDescription i_TeamDescription)
    {
        if (i_TeamDescription == null)
        {
            return;
        }

        int charactersCount = i_TeamDescription.charactersCount;

        if (charactersCount <= 0 || charactersCount >= s_Roles.Length)
        {
            return;
        }

        AIRole[] roles = s_Roles[charactersCount - 1];

        if (roles == null || roles.Length == 0 || roles.Length != charactersCount)
        {
            return;
        }

        int aiIndex = 0;

        for (int characterIndex = 0; characterIndex < charactersCount; ++characterIndex)
        {
            tnCharacterDescription characterDescription = i_TeamDescription.GetCharacterDescription(characterIndex);

            if (characterDescription == null)
            {
                continue;
            }

            int          playerId   = characterDescription.playerId;
            tnPlayerData playerData = tnGameData.GetPlayerDataMain(playerId);

            if (playerData == null)
            {
                AIRole role = roles[aiIndex++];
                m_Roles.Add(role);
            }
        }

        m_Roles.Sort();
    }
Exemplo n.º 13
0
    // INTERNALS

    private void SelectPlayer(int i_TeamIndex)
    {
        tnTeamsModule teamsModule = GameModulesManager.GetModuleMain <tnTeamsModule>();

        if (teamsModule == null)
        {
            return;
        }

        tnTeamDescription teamDescription = teamsModule.GetTeamDescription(i_TeamIndex);

        if (teamDescription != null)
        {
            int playerId = teamDescription.captainPlayerId;
            m_Ids[i_TeamIndex] = playerId;

            // Cache PlayerInput.

            tnPlayerData playerData = tnGameData.GetPlayerDataMain(playerId);
            if (playerData != null)
            {
                if (!StringUtils.IsNullOrEmpty(playerData.playerInputName))
                {
                    m_Players[i_TeamIndex] = InputSystem.GetPlayerByNameMain(playerData.playerInputName);

                    PushControllingMap(i_TeamIndex, i_TeamIndex);
                }
                else
                {
                    if (!StringUtils.IsNullOrEmpty(playerData.wifiPlayerInputName))
                    {
                        m_WifiPlayers[i_TeamIndex] = WiFiInputSystem.GetPlayerByNameMain(playerData.wifiPlayerInputName);

                        PushControllingMap(i_TeamIndex, i_TeamIndex);
                    }
                }
            }
        }

        // Update image and label.

        UpdateImageColor(i_TeamIndex);
        UpdateLabel(i_TeamIndex);
    }
        private void ProcessTeam(tnTeamDescription i_TeamDescription)
        {
            if (i_TeamDescription == null)
            {
                return;
            }

            InputModule inputModule = UIEventSystem.inputModuleMain;

            if (inputModule == null)
            {
                return;
            }

            for (int characterIndex = 0; characterIndex < i_TeamDescription.charactersCount; ++characterIndex)
            {
                tnCharacterDescription characterDescription = i_TeamDescription.GetCharacterDescription(characterIndex);
                if (characterDescription != null)
                {
                    int          playerId   = characterDescription.playerId;
                    tnPlayerData playerData = tnGameData.GetPlayerDataMain(playerId);

                    if (playerData != null)
                    {
                        string playerInputName     = playerData.playerInputName;
                        string wifiPlayerInputName = playerData.wifiPlayerInputName;

                        if (!StringUtils.IsNullOrEmpty(playerInputName))
                        {
                            inputModule.AddPlayer(playerInputName);
                        }
                        else
                        {
                            if (!StringUtils.IsNullOrEmpty(wifiPlayerInputName))
                            {
                                inputModule.AddWifiPlayer(wifiPlayerInputName);
                            }
                        }
                    }
                }
            }
        }
    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);
    }
    protected override void OnCreateTeam(int i_TeamIndex, tnTeamDescription i_TeamDescription)
    {
        base.OnCreateTeam(i_TeamIndex, i_TeamDescription);

        if (i_TeamIndex < 0 || i_TeamIndex >= m_AIFactories.Length || i_TeamIndex >= m_TeamSize.Length)
        {
            return;
        }

        if (i_TeamDescription == null)
        {
            return;
        }

        tnStandardMatchAIFactory aiFactory = new tnStandardMatchAIFactory();

        aiFactory.Configure(i_TeamDescription);

        m_AIFactories[i_TeamIndex] = aiFactory;
        m_TeamSize[i_TeamIndex]    = i_TeamDescription.charactersCount;
    }
        public override void OnEnter()
        {
            // Clear input module.

            ClearInputModule();

            // Process teams.

            tnTeamsModule teamsModule = GameModulesManager.GetModuleMain <tnTeamsModule>();

            if (teamsModule != null)
            {
                for (int teamIndex = 0; teamIndex < teamsModule.teamsCount; ++teamIndex)
                {
                    tnTeamDescription teamDescription = teamsModule.GetTeamDescription(teamIndex);
                    ProcessTeam(teamDescription);
                }
            }

            Finish();
        }
        private void GetTeamSize(out int o_MinSize, out int o_MaxSize)
        {
            int minSize = int.MaxValue;
            int maxSize = int.MinValue;

            tnTeamsModule teamsModule = GameModulesManager.GetModuleMain <tnTeamsModule>();

            if (teamsModule != null)
            {
                for (int teamIndex = 0; teamIndex < teamsModule.teamsCount; ++teamIndex)
                {
                    tnTeamDescription teamDescription = teamsModule.GetTeamDescription(teamIndex);

                    if (teamDescription != null)
                    {
                        minSize = Mathf.Min(minSize, teamDescription.charactersCount);
                        maxSize = Mathf.Max(maxSize, teamDescription.charactersCount);
                    }
                }
            }

            o_MinSize = minSize;
            o_MaxSize = maxSize;
        }
    // LOGIC

    public void Configure(tnTeamDescription i_TeamDescription)
    {
        OnConfigure(i_TeamDescription);
    }
Exemplo n.º 20
0
    protected override void OnConfigure(tnTeamDescription i_TeamDescription)
    {
        base.OnConfigure(i_TeamDescription);

        //ADD BEHAVIOUR TREE INSTANCE
    }
    // tnBaseStandardMatchAIFactory's interface

    protected override void OnConfigure(tnTeamDescription i_TeamDescription)
    {
    }
    private void CreateSupporters()
    {
        if (!m_CreateSupporters)
        {
            return;
        }

        tnTeamsModule teamsModule = GameModulesManager.GetModuleMain <tnTeamsModule>();

        if (teamsModule == null)
        {
            return;
        }

        System.Random random = new System.Random(m_Seed);

        string[] animatedResourceNames = new string[]
        {
            "Characters/Common/p_Supporter01_Animated",
            "Characters/Common/p_Supporter02_Animated",
            "Characters/Common/p_Supporter03_Animated",
        };

        string[] staticResourceNames = new string[]
        {
            "Characters/Common/p_Supporter01",
            "Characters/Common/p_Supporter02",
            "Characters/Common/p_Supporter03",
        };

        // Load animated resources.

        List <GameObject> animatedResources = new List <GameObject>();

        for (int resourceIndex = 0; resourceIndex < animatedResourceNames.Length; ++resourceIndex)
        {
            GameObject resourcePrefab = (GameObject)Resources.Load <GameObject>(animatedResourceNames[resourceIndex]);

            if (resourcePrefab == null)
            {
                continue;
            }

            animatedResources.Add(resourcePrefab);
        }

        // Load static resources.

        List <GameObject> staticResources = new List <GameObject>();

        for (int resourceIndex = 0; resourceIndex < staticResourceNames.Length; ++resourceIndex)
        {
            GameObject resourcePrefab = (GameObject)Resources.Load <GameObject>(staticResourceNames[resourceIndex]);

            if (resourcePrefab == null)
            {
                continue;
            }

            staticResources.Add(resourcePrefab);
        }

        // Iterate each supporter area.

        tnSupporterArea[] supportersAreas = FindObjectsOfType <tnSupporterArea>();

        for (int supporterAreaIndex = 0; supporterAreaIndex < supportersAreas.Length; ++supporterAreaIndex)
        {
            tnSupporterArea supporterArea = supportersAreas[supporterAreaIndex];

            if (supporterArea == null)
            {
                continue;
            }

            // Compute team colors for this area.

            List <Color> teamColors = new List <Color>();

            Vector3 boundsMin = supporterArea.boundsMin;
            Vector3 boundsMax = supporterArea.boundsMax;

            if (boundsMin.x < 0f || boundsMax.x < 0f)
            {
                // Assign to Team 0.

                tnTeamDescription teamDescription = teamsModule.GetTeamDescription(0);
                if (teamDescription != null)
                {
                    Color[] colorsToAdd = GetTeamColors(teamDescription.teamId);
                    teamColors.AddRange(colorsToAdd);
                }
            }

            if (boundsMin.x > 0f || boundsMax.x > 0f)
            {
                // Assign to Team 1.

                tnTeamDescription teamDescription = teamsModule.GetTeamDescription(1);
                if (teamDescription != null)
                {
                    Color[] colorsToAdd = GetTeamColors(teamDescription.teamId);
                    teamColors.AddRange(colorsToAdd);
                }
            }

            Color[] spawnColors = teamColors.ToArray();

            if (spawnColors.Length == 0)
            {
                continue;
            }

            // Spawn supporters.

            for (int supporterIndex = 0; supporterIndex < supporterArea.numPoints; ++supporterIndex)
            {
                GameObject supporterPrefab = null;

                if (supporterIndex < supporterArea.maxAnimators)
                {
                    // Select an animated resource.

                    int resourceIndex = random.Next(0, animatedResources.Count);
                    supporterPrefab = animatedResources[resourceIndex];
                }
                else
                {
                    // Select a static resource.

                    int resourceIndex = random.Next(0, staticResources.Count);
                    supporterPrefab = staticResources[resourceIndex];
                }

                if (supporterPrefab == null)
                {
                    continue;
                }

                Vector2 spawnPoint    = supporterArea.GetPoint(supporterIndex);
                Vector3 spawnPosition = new Vector3(spawnPoint.x, spawnPoint.y, 0f);

                GameObject supporterInstance = (GameObject)Instantiate(supporterPrefab, spawnPosition, Quaternion.identity);

                if (supporterInstance.transform.position.x > 0f)
                {
                    Vector3 flipScale = supporterInstance.transform.localScale;
                    flipScale.x *= -1f;

                    supporterInstance.transform.localScale = flipScale;
                }

                supporterInstance.transform.SetParent(supporterArea.transform, true);

                tnSupporter supporterComponent = supporterInstance.GetComponent <tnSupporter>();
                if (supporterComponent != null)
                {
                    int   randomIndex = random.Next(0, teamColors.Count);
                    Color randomColor = teamColors[randomIndex];
                    supporterComponent.SetColor(randomColor);
                }

                tnDepth2d depth2d = supporterInstance.GetComponent <tnDepth2d>();
                if (depth2d != null)
                {
                    float scale = 0.5f;
                    depth2d.SetScale(scale);

                    float depthLevel = supporterArea.transform.position.z;
                    depth2d.SetOffset(depthLevel);
                }
            }
        }
    }
    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);
    }
Exemplo n.º 24
0
    private void SpawnCharacter(int i_TeamIndex, int i_TeamSize, int i_SpawnIndex, int i_PhotonPlayerId, tnCharacterDescription i_CharacterDescription)
    {
        if (m_CharacterPrefab == null || i_CharacterDescription == null)
        {
            return;
        }

        int descriptorCharacterId       = i_CharacterDescription.characterId;
        int descriptorOnlinePlayerIndex = i_CharacterDescription.onlinePlayerIndex;
        int descriptorPlayerId          = i_CharacterDescription.playerId;

        string[] spawnPointsNames = SpawnPoints.GetSpawnPoints(i_TeamIndex, i_TeamSize);

        if (spawnPointsNames == null)
        {
            return;
        }

        if (i_SpawnIndex < 0 || i_SpawnIndex >= spawnPointsNames.Length)
        {
            return;
        }

        string     spawnPointName = spawnPointsNames[i_SpawnIndex];
        GameObject spawnPointGo   = GameObject.Find(spawnPointName);

        if (spawnPointGo == null)
        {
            return;
        }

        TSTransform2D spawnPoint = spawnPointGo.GetComponent <TSTransform2D>();

        if (spawnPoint == null)
        {
            return;
        }

        tnCharacterData characterData = tnGameData.GetCharacterDataMain(descriptorCharacterId);

        if (characterData == null)
        {
            return;
        }

        tnTeamsModule teamsModule = GameModulesManager.GetModuleMain <tnTeamsModule>();

        if (teamsModule == null)
        {
            return;
        }

        tnTeamDescription teamDescription = teamsModule.GetTeamDescription(i_TeamIndex);

        if (teamDescription == null)
        {
            return;
        }

        int   teamId    = teamDescription.teamId;
        Color teamColor = teamDescription.teamColor;

        tnTeamData teamData = tnGameData.GetTeamDataMain(teamId);

        if (teamData == null)
        {
            return;
        }

        bool isLocal = (PhotonNetwork.offlineMode) ? true : tnGameModulesUtils.IsLocalPlayer(descriptorOnlinePlayerIndex);
        bool isHuman = (PhotonNetwork.offlineMode) ? (descriptorPlayerId != Hash.s_NULL) : (descriptorOnlinePlayerIndex >= 0);

        Vector3    spawnPosition = spawnPoint.position.ToVector();
        Quaternion spawnRotation = Quaternion.Euler(0f, 0f, spawnPoint.rotation.AsFloat());

        // Spawn character.

        GameObject characterInstance = Instantiate <GameObject>(m_CharacterPrefab);

        characterInstance.name = characterData.displayName;

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

        // Configure TSTransform

        TSTransform2D tsTransform = characterInstance.GetComponent <TSTransform2D>();

        if (tsTransform != null)
        {
            tsTransform.position = spawnPoint.position;
            tsTransform.rotation = spawnPoint.rotation;
        }

        // Configure depth2d.

        tnDepth2d depth2d = characterInstance.GetComponent <tnDepth2d>();

        if (depth2d != null)
        {
            depth2d.SetOffset(spawnPointGo.transform.position.z);
        }

        // Configure character stats database.

        tnStatsDatabase teamStats = teamData.teamStats;

        tnStatsContainer statsContainer = characterInstance.GetComponent <tnStatsContainer>();

        if (statsContainer != null)
        {
            statsContainer.SetStatsDatabase(teamStats);
        }

        // Configure character view.

        tnCharacterViewController characterViewController = characterInstance.GetComponent <tnCharacterViewController>();

        if (characterViewController != null)
        {
            // Base color.

            characterViewController.SetBaseColor(teamColor);

            // Charging force bar.

            characterViewController.SetChargingForceBarColor(teamColor);

            // Energy bar.

            characterViewController.SetEnergyBarColor(teamColor);

            // Flag.

            characterViewController.SetFlagSprite(teamData.baseSprite);

            // Animator

            characterViewController.SetAnimatorController(characterData.animatorController);

            // Set facing right.

            characterViewController.SetFacingRight((spawnPoint.position.x < 0f));

            // Player color.

            characterViewController.TurnOffColor();
            characterViewController.SetArrowVisible(false);
            characterViewController.SetArrowColor(Color.white);

            if (isLocal)
            {
                if (PhotonNetwork.offlineMode)
                {
                    if (isHuman)
                    {
                        tnPlayerData playerData = tnGameData.GetPlayerDataMain(descriptorPlayerId);
                        if (playerData != null)
                        {
                            Color playerColor = playerData.color;

                            characterViewController.SetPlayerColor(playerColor);

                            characterViewController.SetArrowVisible(true);
                            characterViewController.SetArrowColor(playerColor);
                        }
                    }
                }
                else
                {
                    List <int> onlinePlayersKeys = tnGameData.GetOnlinePlayersKeysMain();
                    if (onlinePlayersKeys != null)
                    {
                        if (descriptorOnlinePlayerIndex >= 0 && descriptorOnlinePlayerIndex < onlinePlayersKeys.Count)
                        {
                            int onlinePlayerKey = onlinePlayersKeys[descriptorOnlinePlayerIndex];
                            tnOnlinePlayerData onlinePlayerData = tnGameData.GetOnlinePlayerDataMain(onlinePlayerKey);
                            if (onlinePlayerData != null)
                            {
                                Color playerColor = onlinePlayerData.color;

                                characterViewController.SetPlayerColor(playerColor);

                                characterViewController.SetArrowVisible(true);
                                characterViewController.SetArrowColor(playerColor);
                            }
                        }
                    }
                }
            }
        }

        // Input: NOTE that current aiFacotry assumes that all AI are handled by the same client.
        // If you want to support AI in multiplayer you should change the ai factory implementation.
        // Now multiplayer isn't implemented, so now, if you're using AI, you are playing offline --> All AIs are yours.

        if (isLocal)
        {
            tnInputFiller      inputFiller      = null;
            tnRumbleController rumbleController = null;

            int  localPlayerIndex;
            bool localPlayerIndexFound = tnGameModulesUtils.OnlineToLocalPlayerIndex(descriptorOnlinePlayerIndex, out localPlayerIndex);
            if (localPlayerIndexFound || PhotonNetwork.offlineMode)
            {
                tnLocalPartyModule localPartyModule = GameModulesManager.GetModuleMain <tnLocalPartyModule>();

                int          playerId   = (PhotonNetwork.offlineMode) ? descriptorPlayerId : ((localPartyModule != null) ? localPartyModule.GetPlayerId(localPlayerIndex) : Hash.s_NULL);
                tnPlayerData playerData = tnGameData.GetPlayerDataMain(playerId);

                if (playerData != null)
                {
                    string playerInputName     = playerData.playerInputName;
                    string wifiPlayerInputName = playerData.wifiPlayerInputName;

                    PlayerInput     playerInput     = InputSystem.GetPlayerByNameMain(playerInputName);
                    WiFiPlayerInput wifiPlayerInput = WiFiInputSystem.GetPlayerByNameMain(wifiPlayerInputName);

                    if (playerInput != null)
                    {
                        inputFiller      = new tnPlayerInputFiller(playerInput);
                        rumbleController = new tnRumbleController(playerInput);

                        m_LocalPlayersInput.Add(playerInput);
                    }
                    else
                    {
                        if (wifiPlayerInput != null)
                        {
                            inputFiller = new tnWiFiPlayerInputFiller(wifiPlayerInput);

                            m_LocalWifiPlayersInput.Add(wifiPlayerInput);
                        }
                    }
                }
                else
                {
                    tnAIInputFiller aiInputFiller = CreateAIInputFiller(i_TeamIndex, i_SpawnIndex, characterInstance);
                    inputFiller = aiInputFiller;

                    List <tnAIInputFiller> aiList = m_LocalAI[i_TeamIndex];
                    aiList.Add(aiInputFiller);
                }
            }

            // Bind input filler to character instance.

            if (inputFiller != null)
            {
                tnInputController inputController = new tnInputController(inputFiller);
                inputController.SetRumbleController(rumbleController);

                AddInputController(inputController);

                tnCharacterInput characterInput = characterInstance.GetComponent <tnCharacterInput>();
                if (characterInput != null)
                {
                    characterInput.Bind(inputController);
                }
            }

            // Add rumble component.

            if (isHuman)
            {
                tnRumbleParams rumbleParams = Resources.Load <tnRumbleParams>(s_RumbleParams_ResourcePath);

                if (rumbleParams != null)
                {
                    tnRumble rumbleComponent = characterInstance.GetComponent <tnRumble>();
                    if (rumbleComponent == null)
                    {
                        rumbleComponent = characterInstance.AddComponent <tnRumble>();
                    }

                    rumbleComponent.SetParams(rumbleParams);
                }
            }

            // Input Delay.

            int delay = (TrueSyncManager.isOfflineMain) ? m_OfflinePlayerInputDelay : 0;

            if (!isHuman)
            {
                tnMatchSettingsModule matchSettingsModule = GameModulesManager.GetModuleMain <tnMatchSettingsModule>();
                int       aiLevelIndex = (matchSettingsModule != null) ? matchSettingsModule.aiLevelIndex : (tnGameData.aiLevelCountMain / 2);
                tnAILevel aiLevel      = tnGameData.GetAILevelMain(aiLevelIndex);
                if (aiLevel != null)
                {
                    delay = aiLevel.inputDelay;
                }
            }

            // Register on player input collector.

            RegisterObjectOnInputCollector(characterInstance, delay);
        }

        // Configure character info.

        tnCharacterInfo characterInfo = characterInstance.GetComponent <tnCharacterInfo>();

        if (characterInfo == null)
        {
            characterInfo = characterInstance.AddComponent <tnCharacterInfo>();
        }

        int characterIndex = m_Characters.Count;

        characterInfo.SetCharacterIndex(characterIndex);
        characterInfo.SetCharacterId(descriptorCharacterId);
        characterInfo.SetTeamIndex(i_TeamIndex);
        characterInfo.SetTeamId(teamId);
        characterInfo.SetTeamColor(teamColor);

        // Callback.

        OnCharacterSpawned(i_TeamIndex, characterIndex, characterInstance);

        // Add characters to lists.

        m_Characters.Add(characterInstance);
        if (isLocal)
        {
            m_LocalCharacters.Add(characterInstance);
        }

        List <GameObject> team = m_Teams[i_TeamIndex];

        team.Add(characterInstance);

        // Create character result.

        tnCharacterResults characterResults = CreateCharacterResults(descriptorCharacterId);

        characterResults.isHuman = isHuman;

        tnTeamResults teamResults = GetTeamResultsByIndex(i_TeamIndex);

        if (teamResults != null)
        {
            teamResults.AddCharacterResults(characterResults);
        }

        m_CharactersResults.Add(characterResults);

        // Track character result.

        StateTracker.AddTracking(characterResults);

        // Configure TrueSyncObject.

        TrueSyncObject trueSyncObject = characterInstance.GetComponent <TrueSyncObject>();

        if (trueSyncObject != null)
        {
            trueSyncObject.SetOwnerId(i_PhotonPlayerId);
            TrueSyncManager.RegisterTrueSyncObjectMain(trueSyncObject);
        }
    }
Exemplo n.º 25
0
    private void ProceesTeam(int i_TeamIndex, tnTeamDescription i_TeamDescription)
    {
        if (i_TeamDescription == null)
        {
            return;
        }

        int        teamId   = i_TeamDescription.teamId;
        tnTeamData teamData = tnGameData.GetTeamDataMain(teamId);

        if (teamData == null)
        {
            return;
        }

        m_TeamsIds.Add(teamId);

        // Get team size.

        int teamSize = i_TeamDescription.charactersCount;

        // Create team results.

        tnTeamResults teamResults = CreateTeamResults(teamId);

        m_TeamsResults.Add(teamResults);

        StateTracker.AddTracking(teamResults);

        // Callback.

        OnCreateTeam(i_TeamIndex, i_TeamDescription);

        for (int characterIndex = 0; characterIndex < teamSize; ++characterIndex)
        {
            tnCharacterDescription characterDescription = (PhotonNetwork.offlineMode) ? i_TeamDescription.GetCharacterDescriptionBySpawnOrder(characterIndex) : i_TeamDescription.GetCharacterDescription(characterIndex);

            if (characterDescription == null)
            {
                continue;
            }

            int disconnectedPlayerPhotonId = -1;
            int photonPlayerId;
            if (PhotonNetwork.offlineMode)
            {
                photonPlayerId = 0; // 0 is the default value related to a fake "Local_Player". See TrueSyncController::Initialize.
            }
            else
            {
                int onlinePlayerIndex = characterDescription.onlinePlayerIndex;
                tnGameModulesUtils.GetPhotonPlayerOwnerId(onlinePlayerIndex, out photonPlayerId);

                // Check if the owner of this character is still connected. If not, reset photon player id.

                PhotonPlayer owner = PhotonUtils.GetPhotonPlayer(photonPlayerId);
                disconnectedPlayerPhotonId = (owner == null) ? photonPlayerId : -1;
                photonPlayerId             = (owner != null) ? photonPlayerId : -1;
            }

            // If photon player id is valid, spawn character.

            if (photonPlayerId >= 0)
            {
                SpawnCharacter(i_TeamIndex, teamSize, characterIndex, photonPlayerId, characterDescription);
            }
            else
            {
                Debug.LogWarning("[tnMatchController] Character skipped for photon player id " + disconnectedPlayerPhotonId + ".");
            }
        }
    }
Exemplo n.º 26
0
 protected virtual void OnCreateTeam(int i_TeamIndex, tnTeamDescription i_TeamDescription)
 {
 }
    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 SetupInputModule()
    {
        InputModule inputModule = UIEventSystem.inputModuleMain;

        if (inputModule == null)
        {
            return;
        }

        inputModule.Clear();

        tnTeamsModule teamsModule = GameModulesManager.GetModuleMain <tnTeamsModule>();

        if (teamsModule != null)
        {
            for (int teamIndex = 0; teamIndex < teamsModule.teamsCount; ++teamIndex)
            {
                tnTeamDescription teamDescription = teamsModule.GetTeamDescription(teamIndex);

                if (teamDescription == null)
                {
                    continue;
                }

                for (int characterIndex = 0; characterIndex < teamDescription.charactersCount; ++characterIndex)
                {
                    tnCharacterDescription characterDescription = teamDescription.GetCharacterDescription(characterIndex);

                    if (characterDescription == null)
                    {
                        continue;
                    }

                    int playerId = characterDescription.playerId;

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

                    tnPlayerData playerData = tnGameData.GetPlayerDataMain(playerId);

                    if (playerData == null)
                    {
                        continue;
                    }

                    string playerInputName     = playerData.playerInputName;
                    string wifiPlayerInputName = playerData.wifiPlayerInputName;

                    PlayerInput     playerInput    = InputSystem.GetPlayerByNameMain(playerInputName);
                    WiFiPlayerInput wifiPlyerInput = WiFiInputSystem.GetPlayerByNameMain(wifiPlayerInputName);

                    if (playerInput != null)
                    {
                        inputModule.AddPlayer(playerInput);
                    }
                    else
                    {
                        if (wifiPlyerInput != null)
                        {
                            inputModule.AddWifiPlayer(wifiPlyerInput);
                        }
                    }
                }
            }
        }
    }
    // Protected - Virtuals.

    protected virtual void OnConfigure(tnTeamDescription i_TeamDescription)
    {
    }
Exemplo n.º 30
0
    // INTERNAL

    private void Internal_SetupTeam(int i_TeamIndex, tnTeamDescription i_TeamDescription)
    {
        if (!IsValidIndex(i_TeamIndex))
        {
            return;
        }

        if (i_TeamDescription == null)
        {
            return;
        }

        int        teamId   = i_TeamDescription.teamId;
        tnTeamData teamData = tnGameData.GetTeamDataMain(teamId);

        if (teamData == null)
        {
            return;
        }

        List <int> lineUp = teamData.GetDefaultLineUp(i_TeamDescription.charactersCount);

        if (lineUp == null)
        {
            return;
        }

        SetTeamInfo(i_TeamIndex, teamData);

        // Lineup.

        {
            tnUITeamAnchors teamAnchors = m_TeamAnchorsSets[i_TeamIndex];

            tnUIAnchorsSet anchorsSet = null;

            if (teamAnchors != null)
            {
                anchorsSet = teamAnchors.GetAnchorsSetBySize(i_TeamDescription.charactersCount);
            }

            if (anchorsSet != null)
            {
                for (int index = 0; index < anchorsSet.anchorsCount && index < lineUp.Count; ++index)
                {
                    RectTransform anchor = anchorsSet.GetAnchorByIndex(index);
                    if (anchor != null)
                    {
                        int characterId = lineUp[index];

                        if (!teamData.Contains(characterId))
                        {
                            continue;
                        }

                        tnCharacterData characterData = tnGameData.GetCharacterDataMain(characterId);

                        if (characterData == null)
                        {
                            continue;
                        }

                        FacingDir facingDir = m_Facing[i_TeamIndex];

                        Color  teamColor = i_TeamDescription.teamColor;
                        Sprite flag      = teamData.baseSprite;

                        tnUICharacter character = SpawnCharacter(characterData, facingDir, teamColor, flag);

                        tnUICharacterSlot slot = SpawnCharacterSlot();
                        slot.transform.position = anchor.position;
                        slot.character          = character;
                        slot.characterId        = characterId;

                        bool isHuman = m_Humans[i_TeamIndex, index];
                        if (isHuman)
                        {
                            Color playerColor = m_PlayersColors[i_TeamIndex, index];
                            slot.SetPlayerColor(playerColor);
                        }
                        else
                        {
                            slot.ClearPlayerColor();
                        }

                        SlotList slotList = m_LineUp[i_TeamIndex];
                        slotList.Add(slot);
                    }
                }
            }

            m_TeamAnchors[i_TeamIndex] = anchorsSet;
        }

        // Bench.

        {
            tnUIBench bench = m_TeamAnchorsBench[i_TeamIndex];

            int lastBenchIndexUsed = -1;
            for (int index = 0; index < bench.entriesCount && index < teamData.charactersCount; ++index)
            {
                tnUIBenchEntry benchEntry = bench.GetEntryByIndex(index);
                if (benchEntry != null && benchEntry.anchor != null)
                {
                    int characterId = Hash.s_NULL;

                    for (int characterIndex = lastBenchIndexUsed + 1; characterIndex < teamData.charactersCount; ++characterIndex)
                    {
                        int id = teamData.GetCharacterKey(characterIndex);
                        if (!lineUp.Contains(id))
                        {
                            characterId        = id;
                            lastBenchIndexUsed = characterIndex;
                            break;
                        }
                    }

                    tnCharacterData characterData = tnGameData.GetCharacterDataMain(characterId);

                    if (characterData == null)
                    {
                        continue;
                    }

                    FacingDir facingDir = m_Facing[i_TeamIndex];

                    Color  teamColor = i_TeamDescription.teamColor;
                    Sprite flag      = teamData.baseSprite;

                    tnUICharacter character = SpawnCharacter(characterData, facingDir, teamColor, flag);

                    tnUICharacterSlot slot = SpawnCharacterSlot();
                    slot.transform.position = benchEntry.anchor.position;
                    slot.character          = character;
                    slot.characterId        = characterId;
                    slot.ClearPlayerColor();

                    SlotList slotList = m_Bench[i_TeamIndex];
                    slotList.Add(slot);
                }
            }
        }
    }