Example #1
0
    // Restart Game

    private void RestartGame_Enter()
    {
        Debug.Log("[RestartGame] Enter");

        // Clear all groups.

        ClearAllGroups();

        // Master client clear propriety for next match.

        if (PhotonNetwork.isMasterClient)
        {
            PhotonUtils.SetRoomCustomProperty(PhotonPropertyKey.s_RoomCustomPropertyKey_GameFinishedStartTimeAlreadySet, false);
        }

        // Open loading.

        if (m_LoadingPanel != null)
        {
            m_LoadingPanel.Present();
        }

        // Stop photon queue.

        PhotonNetwork.isMessageQueueRunning = false;

        // Stop music.

        MusicPlayer.StopMain();
        MusicPlayer.SetPlaylistMain(null);

        // Proceed to game scene.

        SceneManager.LoadSceneAsync("MultiplayerGame", LoadSceneMode.Single);
    }
Example #2
0
    private void UpdateGameFinishedStartTime()
    {
        if (!PhotonNetwork.isMasterClient)
        {
            return;
        }

        Room room = PhotonNetwork.room;

        if (room == null)
        {
            return;
        }

        if (PhotonNetwork.time < 0.0001f)
        {
            m_GameFinishedTimeSynced = false;
            return;
        }

        if (!m_GameFinishedTimePropertyAlreadySet)
        {
            PhotonUtils.SetRoomCustomProperty(PhotonPropertyKey.s_RoomCustomPropertyKey_GameFinishedStartTime, PhotonNetwork.time);
            PhotonUtils.SetRoomCustomProperty(PhotonPropertyKey.s_RoomCustomPropertyKey_GameFinishedStartTimeAlreadySet, true);
            m_GameFinishedTimePropertyAlreadySet = true;
        }
    }
Example #3
0
    // Setup

    private IEnumerator Setup_Enter()
    {
        Debug.Log("[Setup] Enter");

        PhotonUtils.SetPlayerCustomProperty(PhotonNetwork.player, s_PlayerJoined_PropertyKey, false);

        yield return(StartCoroutine(UnloadUnusedAssets()));

        yield return(StartCoroutine(LoadMap()));

        SetupPlayerProperty();

        CreateCamera();

        LoadObjectPools();

        SetupTrueSyncManager();
        CreateMatchController();

        SetupInputModule();

        SetupAudio();

        ProceedTo(tnMultiplayerGameState.Initialize);
    }
Example #4
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();
    }
Example #5
0
    void Client_SendInput(List <Inputs> inputs)
    {
        NetInputMessage msg = new NetInputMessage
        {
            Identifier = _tickNumber,
            Inputs     = inputs
        };

        // If the current client is Master, send input to whole room
        // else send it to only Master (to be distributed later)
        var options = new RaiseEventOptions
        {
            TargetActors = PhotonNetwork.isMasterClient
                ? PhotonUtils.GetPlayerIdsInRoom()
                : new[] { PhotonNetwork.room.MasterClientId }
        };


        // If inputs are coming from the server (Master Server), they will be absolute.
        if (PhotonNetwork.isMasterClient)
        {
            var stateMsg = new NetStateMessage
            {
                Position       = transform.position,
                LastTick       = _tickNumber,
                PhotonPlayerId = PhotonNetwork.player.ID
            };

            PhotonNetwork.RaiseEvent((byte)EventCodes.STOC_ClientInputAcknowledge, stateMsg, false, options);
        }
        else
        {
            PhotonNetwork.RaiseEvent((byte)EventCodes.CTOS_ClientInput, msg, false, options);
        }
    }
Example #6
0
 public override void Attack(Entity target)
 {
     if (target != this)
     {
         base.Attack(target);
         PhotonUtils.Instantiate(this.projectile, this.transform.TransformPoint(this.launchLocation)).Target = target;
     }
 }
        void Start()
        {
            PhotonNetwork.isMessageQueueRunning = true;

#if UNITY_EDITOR
            if (!PhotonUtils.IsConnected())
            {
                PhotonUtils.Login("test1", true).FireAndForget();
            }
#endif
        }
Example #8
0
    private void Synchronization_Update()
    {
        if (PhotonNetwork.room == null)
        {
            RPC_Setup(0);
            return;
        }

        if (!PhotonNetwork.isMasterClient)
        {
            return;
        }

        int totalPlayers = PhotonNetwork.room.PlayerCount;

        // Wait for players.

        if (m_Synchronization_WaitingForPlayers)
        {
            int playersJoined = 0;

            PhotonPlayer[] photonPlayers = PhotonNetwork.playerList;
            if (photonPlayers != null)
            {
                for (int photonPlayerIndex = 0; photonPlayerIndex < photonPlayers.Length; ++photonPlayerIndex)
                {
                    PhotonPlayer photonPlayer = photonPlayers[photonPlayerIndex];

                    if (photonPlayer == null)
                    {
                        continue;
                    }

                    bool playerJoined;
                    if (PhotonUtils.TryGetPlayerCustomProperty <bool>(photonPlayer, s_PlayerJoined_PropertyKey, out playerJoined))
                    {
                        if (playerJoined)
                        {
                            ++playersJoined;
                        }
                    }
                }
            }

            if (playersJoined == totalPlayers)
            {
                m_Synchronization_WaitingForPlayers = false;
                int seed = (m_ForcedSeed >= 0) ? m_ForcedSeed : Random.Range(0, int.MaxValue);
                m_PhotonView.RPC("RPC_Setup", PhotonTargets.AllViaServer, (int)seed);
            }
        }
    }
    private void CheckRoomPing()
    {
        int currentPing = 0;

        PhotonPlayer[] photonPlayers = PhotonNetwork.playerList;
        if (photonPlayers != null)
        {
            if (photonPlayers.Length > 0)
            {
                for (int index = 0; index < photonPlayers.Length; ++index)
                {
                    PhotonPlayer photonPlayer = photonPlayers[index];

                    if (photonPlayer == null)
                    {
                        continue;
                    }

                    int playerPing;
                    PhotonUtils.TryGetPlayerCustomProperty <int>(PhotonPropertyKey.s_PlayerCustomPropertyKey_Ping, out playerPing);

                    currentPing += playerPing;
                }

                currentPing /= photonPlayers.Length;
            }
        }

        int diff    = currentPing - m_LastRoomPing;
        int absDiff = Mathf.Abs(diff);

        if (diff < 0)
        {
            if (absDiff > m_RoomFallingThreshold)
            {
                WriteRoomProperty(currentPing);
            }
        }
        else
        {
            if (diff > 0)
            {
                if (absDiff > m_RoomRisingThreshold)
                {
                    WriteRoomProperty(currentPing);
                }
            }
        }

        m_LastRoomPing = currentPing;
    }
Example #10
0
        private void Update()
        {
            //Check if building, if so check for completion of current unit
            if (this.Mine && this.IsBuilding && this.buildTimer.Elapsed.TotalSeconds >= this.inProgress.BuildTime)
            {
                //Get unit and spawn it
                Unit unit  = this.buildQueue.First.Value;
                Unit clone = PhotonUtils.Instantiate(unit, this.spawnLocation.position, unit.transform.rotation, this.transform.parent);
                clone.MoveUnit(clone.Position + this.transform.forward * 2f, clone.Position);
                GameEvents.OnUnitCreated.Invoke(clone);

                //Pop build queue
                PopQueue();
            }
        }
Example #11
0
        private IEnumerator Start()
        {
            //Check clip length
            AudioClip clip = GetComponent <AudioSource>().clip;

            if (!clip)
            {
                PhotonUtils.Destroy(this);
                yield break;
            }

            //Delayed destruction
            yield return(new WaitForSeconds(clip.length));

            PhotonUtils.Destroy(this);
        }
Example #12
0
    // Game mode

    private void SetupGameModeSelector()
    {
        SelectorData selectorData = new SelectorData();

        List <int> gameModesKeys = tnGameData.GetGameModesKeysMain();

        if (gameModesKeys != null)
        {
            for (int gameModeIndex = 0; gameModeIndex < gameModesKeys.Count; ++gameModeIndex)
            {
                int gameModeId = gameModesKeys[gameModeIndex];

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

                tnGameModeData gameModeData = tnGameData.GetGameModeDataMain(gameModeId);

                if (gameModeData == null)
                {
                    continue;
                }

                if (!gameModeData.hidden)
                {
                    IntRange teamSizeRange = gameModeData.onlinePlayersPerTeamRange;

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

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

                    if (!teamSizeInvalid)
                    {
                        SelectorItem selectorItem = new SelectorItem(gameModeId, gameModeData.name, "", null);
                        selectorData.AddItem(selectorItem);
                    }
                }
            }
        }

        if (viewInstance != null)
        {
            viewInstance.SetGameModeSelectorData(selectorData);
        }
    }
Example #13
0
    private void GameFinished_Update()
    {
        if (m_GameFinishedTimedOut)
        {
            return;
        }

        // Sync time.

        if (!m_GameFinishedTimeSynced)
        {
            UpdateGameFinishedStartTime();
        }

        // Update timer.

        double time = m_TimeForRematch;
        double startTime;
        bool   startTimeAlreadySet = false;

        if (PhotonUtils.TryGetRoomCustomProperty <bool>(PhotonPropertyKey.s_RoomCustomPropertyKey_GameFinishedStartTimeAlreadySet, out startTimeAlreadySet))
        {
            if (startTimeAlreadySet)
            {
                if (PhotonUtils.TryGetRoomCustomProperty <double>(PhotonPropertyKey.s_RoomCustomPropertyKey_GameFinishedStartTime, out startTime))
                {
                    m_GameFinishedTimeSynced = true;
                    double elapsedTime = PhotonNetwork.time - startTime;
                    time = m_TimeForRematch - elapsedTime;
                }
            }
        }

        time = Math.Max(time, 0.0);

        if (m_EndGamePanel != null)
        {
            m_EndGamePanel.SetTimer((float)time);
        }

        // Check time out.

        if (time <= 0.0)
        {
            OnTimedOut();
        }
    }
Example #14
0
        public async Task <IResult <string, Unit> > Login(string roomName)
        {
            var createRoom = true;

#if UNITY_ANDROID && !UNITY_EDITOR
            createRoom = false;
#endif

            var result = await PhotonUtils.Login(roomName, createRoom);

            if (result.IsSuccess)
            {
                PhotonNetwork.isMessageQueueRunning = false;
            }

            return(result);
        }
    public static bool GetPhotonPlayerOwnerId(int i_OnlinePlayerIndex, out int o_Id)
    {
        o_Id = -1;

        tnMultiplayerIndexTable indexTable = null;

        if (PhotonUtils.TryGetRoomCustomProperty <tnMultiplayerIndexTable>(PhotonPropertyKey.s_RoomCustomPropertyKey_AssignedIndices, out indexTable))
        {
            if (indexTable != null)
            {
                int id = indexTable.GetIndexOwnerId(i_OnlinePlayerIndex);
                if (id != -1)
                {
                    o_Id = id;
                    return(true);
                }
            }
        }

        return(false);
    }
Example #16
0
    public static bool CheckPropertyOnAllPlayers <T>(object i_Key, T i_Value)
    {
        Room room = PhotonNetwork.room;

        if (room == null)
        {
            return(false);
        }

        PhotonPlayer[] photonPlayers = PhotonNetwork.playerList;
        if (photonPlayers != null)
        {
            for (int index = 0; index < photonPlayers.Length; ++index)
            {
                PhotonPlayer photonPlayer = photonPlayers[index];

                if (photonPlayer == null)
                {
                    continue;
                }

                T propertyValue;
                if (PhotonUtils.TryGetPlayerCustomProperty <T>(photonPlayer, i_Key, out propertyValue))
                {
                    if (propertyValue.Equals(i_Value))
                    {
                        return(false);
                    }
                }
                else
                {
                    return(false);
                }
            }
        }

        return(true);
    }
 private void WriteRoomProperty(int i_Ping)
 {
     PhotonUtils.SetRoomCustomProperty(PhotonPropertyKey.s_RoomCustomPropertyKey_AvgPing, i_Ping);
 }
Example #18
0
    public void ProcessInputMessages()
    {
        // Get the message
        NetInputMessage msg = _inputMessageQueue.Dequeue();

        // Find out who sent it
        PhotonPlayer photonPlayer = PhotonUtils.GetPlayerById(msg.PhotonPlayerId);

        if (photonPlayer == null)
        {
            return;
        }

        // Get remote player instance
        var remotePlayer = _remotePlayers.Find(x => x.Player.ID == photonPlayer.ID);

        if (remotePlayer == null)
        {
            Transform target = null;
            foreach (var go in GameObject.FindGameObjectsWithTag("NetworkPlayer"))
            {
                if (go.GetComponent <PhotonView>().ownerId == photonPlayer.ID)
                {
                    target = go.transform;
                }
            }

            if (target == null)
            {
                Debug.LogErrorFormat("Could not find Transform component for PhotonPlayer {0}", photonPlayer.ID);
            }
            else
            {
                remotePlayer = new ServerPlayer()
                {
                    Player = photonPlayer, Target = target
                };
                _remotePlayers.Add(remotePlayer);
            }
        }

        if (remotePlayer == null)
        {
            return;
        }

        Player player = remotePlayer.Target.GetComponent <Player>();

        player.Client_SyncServer();

        Server_ApplyInput(msg.Inputs, remotePlayer);

        player.PositionBuffer.Push(remotePlayer.Position.x, remotePlayer.Position.y, player.Syncer.ServerDelta(Time.deltaTime));

        NetStateMessage stateMsg = new NetStateMessage
        {
            Position       = remotePlayer.Position,
            LastTick       = msg.Identifier,
            PhotonPlayerId = remotePlayer.Player.ID
        };

        var options = new RaiseEventOptions {
            TargetActors = PhotonUtils.GetPlayerIdsInRoom()
        };


        // Broadcast new state of the client
        PhotonNetwork.RaiseEvent((byte)EventCodes.STOC_ClientInputAcknowledge, stateMsg, false, options);
    }
 private void WritePlayerProperty(int i_Ping)
 {
     PhotonUtils.SetPlayerCustomProperty(PhotonPropertyKey.s_PlayerCustomPropertyKey_Ping, i_Ping);
 }
Example #20
0
 private void SetupPlayerProperty()
 {
     PhotonUtils.SetPlayerCustomProperty(PhotonNetwork.player, s_RematchVoted_PropertyKey, false);
 }
Example #21
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();
    }
Example #22
0
 private void NotifyJoin()
 {
     PhotonUtils.SetPlayerCustomProperty(PhotonNetwork.player, s_PlayerJoined_PropertyKey, true);
 }
    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);
    }
Example #24
0
    private void WaitForRematch_Update()
    {
        if (m_WaitForRematch_Success || m_WaitForRematch_Failed)
        {
            return;
        }

        if (m_PlayerDisconnectedAfterGameFinished || m_WaitForRematch_Failed)
        {
            if (m_WaitForRematch_QuitDialogOpened)
            {
                return;
            }

            // Set flag.

            m_WaitForRematch_QuitDialogOpened = true;

            // Clear all groups.

            ClearAllGroups();

            // Clear Match controller UI.

            if (m_MatchController != null)
            {
                m_MatchController.ClearUI();
            }

            // Open dialog.

            ShowDialog("MATCH OVER", "You will be returned to the main menu.", On_WaitForRematch_QuitDialogCallback);

            return;
        }

        // Sync time.

        if (!m_GameFinishedTimeSynced)
        {
            UpdateGameFinishedStartTime();
        }

        // Update timer.

        double time = m_TimeForRematch;

        double startTime;

        if (PhotonUtils.TryGetRoomCustomProperty <double>(PhotonPropertyKey.s_RoomCustomPropertyKey_GameFinishedStartTime, out startTime))
        {
            m_GameFinishedTimeSynced = true;
            double elapsedTime = PhotonNetwork.time - startTime;
            time = m_TimeForRematch - elapsedTime;
        }

        time = Math.Max(time, 0.0);

        if (m_EndGamePanel != null)
        {
            m_EndGamePanel.SetTimer((float)time);
        }

        // Check rematch.

        int totalVotes   = 0;
        int rematchVotes = 0;
        int playerCount  = 0;

        PhotonPlayer[] photonPlayers = PhotonNetwork.playerList;
        if (photonPlayers != null)
        {
            playerCount = photonPlayers.Length;

            for (int photonPlayerIndex = 0; photonPlayerIndex < photonPlayers.Length; ++photonPlayerIndex)
            {
                PhotonPlayer photonPlayer = photonPlayers[photonPlayerIndex];

                if (photonPlayer == null)
                {
                    continue;
                }

                bool voted;
                PhotonUtils.TryGetPlayerCustomProperty <bool>(photonPlayer, s_RematchVoted_PropertyKey, out voted);
                if (voted)
                {
                    ++totalVotes;

                    bool vote;
                    PhotonUtils.TryGetPlayerCustomProperty <bool>(photonPlayer, s_RematchVote_PropertyKey, out vote);

                    rematchVotes += (vote) ? 1 : 0;
                }
            }
        }

        if (m_EndGamePanel != null)
        {
            m_EndGamePanel.SetReadyPlayers(rematchVotes, playerCount);
        }

        if (playerCount > 1)
        {
            if (rematchVotes == playerCount)
            {
                m_WaitForRematch_Success = true;

                ProceedTo(tnMultiplayerGameState.RestartGame);
            }
            else
            {
                if (totalVotes == playerCount)
                {
                    m_WaitForRematch_Failed = true;
                }
            }
        }
        else
        {
            m_WaitForRematch_Failed = true;
        }
    }
Example #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 + ".");
            }
        }
    }
Example #26
0
    public void OnEventRaised(byte eventCode, object content, int senderID)
    {
        bool isMaster = PhotonNetwork.isMasterClient;
        bool isMine   = photonView.isMine;

        switch (eventCode)
        {
        case (byte)EventCodes.CTOS_ClientInput:
            if (!isMaster)
            {
                break;
            }

            var msg = (NetInputMessage)content;
            msg.PhotonPlayerId = senderID;
            msg.Time           = Time.time;

            Server_ReceiveInput(msg, senderID);
            break;

        case (byte)EventCodes.STOC_ClientInputAcknowledge:
            var stateMsg = (NetStateMessage)content;

            var photonPlayer = PhotonUtils.GetPlayerById(stateMsg.PhotonPlayerId);
            if (photonPlayer == null)
            {
                break;
            }

            var photonPlayerTransform = PhotonUtils.GetPhotonPlayerTransform(photonPlayer);
            if (photonPlayerTransform == null)
            {
                break;
            }

            bool isMyAck = PhotonNetwork.player.ID == stateMsg.PhotonPlayerId;

            if (isMyAck)
            {
                photonPlayerTransform.position = stateMsg.Position;

                // Server Reconciliation
                if (Conciliation)
                {
                    int j = 0;
                    while (j < _inputBuffer.Count)
                    {
                        var input = _inputBuffer[j];

                        if (input.TickNr <= stateMsg.LastTick)
                        {
                            _inputBuffer.Remove(input);
                        }
                        else
                        {
                            ApplyInput(new List <Inputs> {
                                input
                            }, transform);
                            j++;
                        }
                    }
                }

                PositionBuffer.Push(stateMsg.Position.x, stateMsg.Position.y, Syncer.ServerDelta(Time.deltaTime));
            }
            else
            {
                // Entity Interpolation
                if (Interpolation)
                {
                    Player p = photonPlayerTransform.GetComponent <Player>();

                    p.Client_SyncServer();
                    p.PositionBuffer.Push(stateMsg.Position.x, stateMsg.Position.y, p.Syncer.ServerDelta(Time.deltaTime));
                }
                else
                {
                    photonPlayerTransform.position = stateMsg.Position;
                }
            }
            break;

        default:
            Debug.LogErrorFormat("Unknown event code {0} from {1}", eventCode, senderID);
            break;
        }
    }