Пример #1
0
    public GameObject GetLocalCharacterById(int i_CharacterId)
    {
        for (int characterIndex = 0; characterIndex < m_LocalCharacters.Count; ++characterIndex)
        {
            GameObject character = m_LocalCharacters[characterIndex];

            if (character == null)
            {
                continue;
            }

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

            if (characterInfo == null)
            {
                continue;
            }

            int characterId = characterInfo.characterId;

            if (characterId == i_CharacterId)
            {
                return(character);
            }
        }

        return(null);
    }
    protected override void OnConfigureStats()
    {
        base.OnConfigureStats();

        for (int characterIndex = 0; characterIndex < charactersCount; ++characterIndex)
        {
            GameObject characterInstance = GetCharacterByIndex(characterIndex);

            if (characterInstance == null)
            {
                continue;
            }

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

            if (characterInfo == null)
            {
                continue;
            }

            tnCharacterStats characterStats = characterInstance.GetComponent <tnCharacterStats>();

            if (characterStats == null)
            {
                continue;
            }

            // Bind results.

            {
                int characterId = characterInfo.characterId;
                tnBaseMatchCharacterResults characterResults = (tnBaseMatchCharacterResults)GetCharacterResultsById(characterId);

                characterStats.SetResults(characterResults);
            }

            // Bind references.

            {
                int characterTeamIndex = characterInfo.teamIndex;

                for (int teamIndex = 0; teamIndex < teamsCount; ++teamIndex)
                {
                    if (teamIndex == characterTeamIndex)
                    {
                        continue;
                    }

                    tnGoal goal = GetGoal(teamIndex);
                    if (goal != null)
                    {
                        characterStats.SetOpponentGoal(goal);
                        break;
                    }
                }
            }
        }
    }
Пример #3
0
    // TrueSyncBehaviour's interface

    public override void OnSyncedStart()
    {
        base.OnSyncedStart();

        tnCharacterInfo characterInfo  = GetComponent <tnCharacterInfo>();
        int             characterIndex = (characterInfo != null) ? characterInfo.characterIndex : 0;
        int             inputBase      = characterIndex * 10;

        m_ButtonDownCode = Convert.ToByte(inputBase + TrueSyncInputKey.s_Taunt_ButtonDown);
    }
    private void ForcedAddTocuh(GameObject i_Source, FP i_Timestamp)
    {
        if (i_Source == null)
        {
            return;
        }

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

        if (characterInfo == null)
        {
            return;
        }

        if (m_Touches.Count > 0)
        {
            tnTouch lastTouch = m_Touches[0];

            if (lastTouch.characterId == characterInfo.characterId)
            {
                return;
            }
        }

        // If queue is full, remove the oldest touch.

        while (m_Touches.Count >= s_MaxTouches)
        {
            m_Touches.RemoveBack();
        }

        // Add new ball touch.

        tnTouch touch = new tnTouch();

        touch.SetCharacterId(characterInfo.characterId);
        touch.SetTeamId(characterInfo.teamId);

        tnCharacterInput characterInput = i_Source.GetComponent <tnCharacterInput>();

        if (characterInput != null)
        {
            touch.SetIsHuman(characterInput.isHumanPlayer);
            touch.SetIsLocal(characterInput.isLocalPlayer);
        }
        else
        {
            touch.SetIsHuman(false);
            touch.SetIsLocal(false);
        }

        touch.SetTimestamp(i_Timestamp);

        m_Touches.AddFront(touch);
    }
    // TrueSyncBehaviour's INTERFACE

    public override void OnSyncedStart()
    {
        base.OnSyncedStart();

        tnCharacterInfo characterInfo  = GetComponent <tnCharacterInfo>();
        int             characterIndex = (characterInfo != null) ? characterInfo.characterIndex : 0;
        int             inputBase      = characterIndex * 10;

        m_HorizontalAxisCode = Convert.ToByte(inputBase + TrueSyncInputKey.s_HorizontalAxis);
        m_VerticalAxisCode   = Convert.ToByte(inputBase + TrueSyncInputKey.s_VerticalAxis);
        m_ButtonPressedCode  = Convert.ToByte(inputBase + TrueSyncInputKey.s_Subbuteo_CharacterController_ButtonPressed);
    }
Пример #6
0
    void Start()
    {
        tnCharacterInfo characterInfo = GetComponentInParent <tnCharacterInfo>();

        if (characterInfo != null)
        {
            int             characterId   = characterInfo.characterId;
            tnCharacterData characterData = tnGameData.GetCharacterDataMain(characterId);
            if (characterData != null)
            {
                string s = characterData.displayName;
                m_Text.text = s;
            }
        }
    }
    // TrueSyncBehaviour's INTERFACE

    public override void OnSyncedStart()
    {
        base.OnSyncedStart();

        m_CurrentLayer = m_OriginalLayer;
        m_CurrentMass  = m_Rigidbody2D.mass;
        m_CurrentDrag  = m_Rigidbody2D.linearDrag;

        tnCharacterInfo characterInfo  = GetComponent <tnCharacterInfo>();
        int             characterIndex = (characterInfo != null) ? characterInfo.characterIndex : 22; // First 22 (0 - 21) indices are for players. If there isn't character info, this is referee.
        int             inputBase      = characterIndex * 10;

        m_HorizontalAxisCode = Convert.ToByte(inputBase + TrueSyncInputKey.s_HorizontalAxis);
        m_VerticalAxisCode   = Convert.ToByte(inputBase + TrueSyncInputKey.s_VerticalAxis);
        m_DashRequestedCode  = Convert.ToByte(inputBase + TrueSyncInputKey.s_Standard_CharacterController_DashRequested);
    }
    private void FillGoalScoredData(int i_SlotIndex, tnStandardMatchController i_MatchController)
    {
        if (i_MatchController == null)
        {
            return;
        }

        int charcatersCount = i_MatchController.charactersCount;

        // Compute total shots count.

        int totalGoalScored = 0;

        for (int characterIndex = 0; characterIndex < charcatersCount; ++characterIndex)
        {
            tnStandardMatchCharacterResults characterResults = (tnStandardMatchCharacterResults)i_MatchController.GetCharacterResultsByIndex(characterIndex);
            if (characterResults != null)
            {
                totalGoalScored += characterResults.goalScored;
            }
        }

        // Get best character for this stat.

        int selectedCharacterIndex = -1;
        int selectedCharacterId    = Hash.s_NULL;

        int maxGoalScored = int.MinValue;

        for (int characterIndex = 0; characterIndex < charcatersCount; ++characterIndex)
        {
            tnStandardMatchCharacterResults characterResults = (tnStandardMatchCharacterResults)i_MatchController.GetCharacterResultsByIndex(characterIndex);
            if (characterResults != null)
            {
                int characterGoalScored = characterResults.goalScored;

                if (characterGoalScored > maxGoalScored)
                {
                    selectedCharacterIndex = characterIndex;
                    selectedCharacterId    = characterResults.id;

                    maxGoalScored = characterGoalScored;
                }
            }
        }

        if (selectedCharacterIndex < 0)
        {
            return;
        }

        // Get team color.

        Color teamColor = Color.white;

        GameObject characterGo = i_MatchController.GetCharacterByIndex(selectedCharacterIndex);

        if (characterGo != null)
        {
            tnCharacterInfo characterInfo = characterGo.GetComponent <tnCharacterInfo>();
            if (characterInfo != null)
            {
                teamColor = characterInfo.teamColor;
            }
        }

        // Fill data.

        string playerName     = "";
        Sprite playerPortrait = null;

        {
            tnCharacterData characterData = tnGameData.GetCharacterDataMain(selectedCharacterId);
            if (characterData != null)
            {
                playerName     = characterData.displayName;
                playerPortrait = characterData.uiIconFacingRight;
            }
        }

        string statValue = maxGoalScored.ToString();

        float partecipationPercentage = 0f;

        if (totalGoalScored > 0)
        {
            partecipationPercentage  = (float)maxGoalScored / (float)totalGoalScored;
            partecipationPercentage *= 100f;

            partecipationPercentage = Mathf.Clamp(partecipationPercentage, 0f, 100f);
        }

        string partecipationValue = partecipationPercentage.ToString("0.00");

        partecipationValue += "%";

        FillData(i_SlotIndex, playerName, playerPortrait, teamColor, s_StatName_GoalScored, statValue, s_PartecipationLabel, partecipationValue);
    }
    protected override void OnEndMatch()
    {
        base.OnEndMatch();

        bool online = !PhotonNetwork.offlineMode;
        tnEndMatchEventParams param = new tnEndMatchEventParams(online);

        param.SetGameModeId(gameModeId);
        param.SetBallId(ballId);
        param.SetStadiumId(stadiumId);
        param.SetHasReferee(hasReferee);
        param.SetGoldenGoalEnabled(goldenGoalEnabled);
        param.SetGoldenGoal(goldenGoal);

        // Compute human players.

        tnStandardMatchTeamResults teamAResults = (tnStandardMatchTeamResults)GetTeamResultsByIndex(0);

        if (teamAResults != null)
        {
            param.SetTeamAId(teamAResults.id);
            param.SetScoreA(teamAResults.score);
            param.SetTeamASize(teamAResults.charactersResultsCount);

            int humanPlayers = 0;

            if (!online)
            {
                for (int index = 0; index < teamAResults.charactersResultsCount; ++index)
                {
                    tnCharacterResults characterResults = teamAResults.GetCharacterResults(index);
                    if (characterResults != null)
                    {
                        if (characterResults.isHuman)
                        {
                            ++humanPlayers;
                        }
                    }
                }
            }
            else
            {
                humanPlayers = teamAResults.charactersResultsCount;
            }

            param.SetTeamAHumanPlayers(humanPlayers);
        }

        tnStandardMatchTeamResults teamBResults = (tnStandardMatchTeamResults)GetTeamResultsByIndex(1);

        if (teamBResults != null)
        {
            param.SetTeamBId(teamBResults.id);
            param.SetScoreB(teamBResults.score);
            param.SetTeamBSize(teamBResults.charactersResultsCount);

            int humanPlayers = 0;

            if (!online)
            {
                for (int index = 0; index < teamBResults.charactersResultsCount; ++index)
                {
                    tnCharacterResults characterResults = teamBResults.GetCharacterResults(index);
                    if (characterResults != null)
                    {
                        if (characterResults.isHuman)
                        {
                            ++humanPlayers;
                        }
                    }
                }
            }
            else
            {
                humanPlayers = teamBResults.charactersResultsCount;
            }

            param.SetTeamBHumanPlayers(humanPlayers);
        }

        // Compute local characters and teams.

        for (int index = 0; index < localCharactersCount; ++index)
        {
            GameObject character = GetLocalCharacterByIndex(index);

            if (character == null)
            {
                continue;
            }

            tnCharacterInfo characterInfo = character.GetComponent <tnCharacterInfo>();
            if (characterInfo != null)
            {
                int characterId = characterInfo.characterId;
                int teamId      = characterInfo.teamId;

                param.AddLocalCharacter(characterId);
                param.AddLocalTeam(teamId);
            }
        }

        // Raise event.

        Messenger.Broadcast <tnEndMatchEventParams>("MatchEnded", param);
    }
Пример #10
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);
        }
    }