Пример #1
0
        public override void OnPhotonCustomRoomPropertiesChanged(Hashtable propertiesThatChanged)
        {
            if (GameState == EGameState.None && propertiesThatChanged[teamSettingEndKey] != null)
            {
                GameState = EGameState.Team_Set;
                InitializeGame();
                return;
            }

            if (GameState == EGameState.Team_Set && propertiesThatChanged[initializedKey] != null)
            {
                GameState = EGameState.Initialized;
                GenLocalPlayerAndReady();
                return;
            }

            if (GameState == EGameState.Ready && propertiesThatChanged[startTimeKey] != null)
            {
                prepareStartTimestamp = (int)propertiesThatChanged[startTimeKey];

                if (PhotonNetwork.ServerTimestamp - prepareStartTimestamp < 0)
                {
                    GameState = EGameState.ReadyChecked;
                    PhotonExtends.SetLocalPlayerProp(playerReadyKey, true);
                }
            }

            //When Game set key is set by the master client, let the game be end.
            if (propertiesThatChanged[gameSetKey] != null)
            {
                PhotonNetwork.automaticallySyncScene = false;
                GameState = EGameState.Game_Set;

                ETeam winTeam = (ETeam)propertiesThatChanged[winTeamKey];
                if (winTeam == myTeam)
                {
                    uiManager.SetWinPanel();
                }
                else
                {
                    uiManager.SetLosePanel();
                }

                StartCoroutine("LoadRecordScene");

                foreach (PhotonPlayer player in PhotonNetwork.playerList)
                {
                    Debug.Log("Player " + player.NickName + "\'s Record");
                    if (player.CustomProperties[playerRecordsNumKey] != null)
                    {
                        int recordsNum = (int)player.CustomProperties[playerRecordsNumKey];
                        for (int i = 0; i < recordsNum; i++)
                        {
                            int record = (int)player.CustomProperties[playerRecordsKey + i];
                            Debug.Log(record);
                        }
                    }
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Select thieves player randomly and load scene.
        /// Should be called only by the master client. The master client must not be a detective because of sync delay issue.
        /// Should be called when reset entire game.
        /// </summary>
        private void SetTeamOfPlayers()
        {
            if (!PhotonNetwork.isMasterClient)
            {
                Debug.LogError("Team setting must be operated by the master client.");
                return;
            }

            int playerNum = PhotonNetwork.playerList.Length;

            if (playerNum <= thievesNum)
            {
                Debug.LogError("Not enough player for game(Should be more than " + thievesNum + " players(number of thieves).");
                return;
            }


            // Set each player's team.
            // Default value is detective, and thief players is selected by randomized array.
            foreach (PhotonPlayer player in PhotonNetwork.playerList)
            {
                Hashtable playerCp = player.CustomProperties;
                playerCp[TeamKey] = (int)ETeam.Detective;
                player.SetCustomProperties(playerCp);
            }

            // Choose thief players randomly
            int[] thiefSelector = new int[playerNum - 1];
            int   offset        = 0;

            for (int i = 0; i < playerNum; i++)
            {
                // Because the master client must be a thief, not picked as a random thief player
                if (PhotonNetwork.playerList[i].ID == PhotonNetwork.player.ID)
                {
                    offset = 1;
                    continue;
                }

                thiefSelector[i - offset] = PhotonNetwork.playerList[i].ID;
            }

            GlobalFunctions.RandomizeArray <int>(thiefSelector);

            // Select thieves(master client + others)
            PhotonExtends.SetLocalPlayerProp(TeamKey, (int)ETeam.Thief);
            for (int i = 0; i < thievesNum - 1; i++)
            {
                PhotonPlayer thiefPlayer = PhotonPlayer.Find(thiefSelector[i]);
                Hashtable    playerCp    = thiefPlayer.CustomProperties;
                playerCp[TeamKey] = (int)ETeam.Detective;
                thiefPlayer.SetCustomProperties(playerCp);
            }

            PhotonExtends.SetRoomCustomProp(teamSettingEndKey, true);
        }
Пример #3
0
        private void PostponeStartTime(int newPrepareStartTimestamp)
        {
            int prepareStartTimestamp = newPrepareStartTimestamp;

            if (GameState == EGameState.Ready)
            {
                GameState = EGameState.ReadyChecked;
                PhotonExtends.SetLocalPlayerProp(playerReadyKey, true);
            }
        }
Пример #4
0
        private void OnApplicationPause(bool pauseStatus)
        {
            if (GameState != EGameState.Preparing && GameState != EGameState.Started)
            {
                return;
            }

            PhotonExtends.SetLocalPlayerProp(pauseKey, pauseStatus);
            PhotonNetwork.networkingPeer.SendOutgoingCommands();
        }
Пример #5
0
        private void Awake()
        {
            Debug.Assert(!PhotonNetwork.connected, "Multiplay manager must be used in online environment.");

            // Modify PhotonNetwork settings according to in-game mode.
            PhotonNetwork.BackgroundTimeout   = 1000f;
            PhotonNetwork.sendRate            = 10;
            PhotonNetwork.sendRateOnSerialize = 10;

            //Set the singleton
            Debug.Assert(instance != null, "Multiple instantiation of the room Manager.");
            instance = this;

            mapDataManager = MapDataManager.Instance;
            uiManager      = UIManager.Instance;

            Hashtable roomCp = PhotonNetwork.room.CustomProperties;

            //Get the number of NPCs(only in test version).
            int tempNPCNum;

            if (int.TryParse(roomCp[Constants.NPCNumKey].ToString(), out tempNPCNum))
            {
                NPCNum = tempNPCNum;
            }

            //Get the number of thief players.
            if (!int.TryParse(roomCp["Thieves Number"].ToString(), out thievesNum))
            {
                Debug.LogError("Thieves number(in custom property) is not set properly.");
                return;
            }

            PhotonExtends.SetLocalPlayerProp(pauseKey, false);

            if (PhotonNetwork.isMasterClient)
            {
                //Randomly switch the master client. It prevents that the player who made room always be picked as a thief.
                int[] randomPlayerSelector = new int[PhotonNetwork.playerList.Length];
                for (int i = 0; i < PhotonNetwork.playerList.Length; i++)
                {
                    randomPlayerSelector[i] = PhotonNetwork.playerList[i].ID;
                }

                GlobalFunctions.RandomizeArray <int>(randomPlayerSelector);

                if (randomPlayerSelector[0] == PhotonNetwork.player.ID)
                {
                    SetTeamOfPlayers();
                }
                else
                {
                    Debug.Log("Change the master client.");

                    for (int i = 0; i < randomPlayerSelector.Length; i++)
                    {
                        PhotonPlayer newMaster = PhotonPlayer.Find(randomPlayerSelector[i]);
                        if (newMaster != null &&
                            newMaster.CustomProperties[pauseKey] != null && !(bool)newMaster.CustomProperties[pauseKey])
                        {
                            PhotonNetwork.SetMasterClient(newMaster);
                            break;
                        }
                    }
                }
            }
        }