Ejemplo n.º 1
0
        public void StealSuccess(int thiefID, int pointOfStolenItem)
        {
            ItemController stolenItem = mapDataManager.ItemGenPoints[pointOfStolenItem].Item;

            stolenItems.Add(stolenItem);
            ItemController.RenewDiscoveredItemPrioirty(stolenItem);
            uiManager.RenewStolenItemPanel(stolenItems);

            uiManager.SetAlert("도둑이 아이템 회수에 성공했습니다.");

            if (targetItems.Contains(stolenItem))
            {
                targetItems.Remove(stolenItem);

                /*if (myTeam == ETeam.Thief)
                 *  uiManager.RenewTargetItemList(targetItems);*/

                if (thiefID == PhotonNetwork.player.ID)
                {
                    SetPlayerRecord(curTimestamp - startTimestamp);
                }

                if (targetItems.Count == 0 && PhotonNetwork.isMasterClient)
                {
                    PhotonExtends.SetRoomCustomProp(winTeamKey, (int)ETeam.Thief);
                    PhotonExtends.SetRoomCustomProp(gameSetKey, true);
                }
            }
        }
Ejemplo n.º 2
0
        private void GenLocalPlayerAndReady()
        {
            int genPointIdx = (int)PhotonNetwork.player.CustomProperties[playerGenPointKey];

            Debug.Log("We are Instantiating LocalPlayer from " + SceneManager.GetActiveScene().name);
            Debug.Log("You are a " + myTeam);
            if (myTeam == ETeam.Detective)
            {
                GameObject myDetective = PhotonNetwork.Instantiate(detectivePrefab.name,
                                                                   mapDataManager.DetectiveGenerationPoints[genPointIdx].position, Quaternion.identity, 0);
                myDetective.GetComponent <PlayerController>().CurFloor = 1;
            }
            else if (myTeam == ETeam.Thief)
            {
                GameObject myTheif = PhotonNetwork.Instantiate(thiefPrefab.name,
                                                               mapDataManager.ThiefGenertaionPoints[genPointIdx].position, Quaternion.identity, 0);
                myTheif.GetComponent <PlayerController>().CurFloor = mapDataManager.ThiefGenerationPointsFloor[genPointIdx];

                int NPCIdx = (int)PhotonNetwork.player.CustomProperties[theifFigureIdxKey];
                PhotonView.Get(myTheif).RPC("SetSpriteAndAnimation", PhotonTargets.All, NPCIdx);
            }
            GameState = EGameState.Ready;

            if (PhotonNetwork.isMasterClient)
            {
                foreach (NPCController npc in sceneObjParent.GetComponentsInChildren <NPCController>())
                {
                    npc.Activated = true;
                }

                PhotonExtends.SetRoomCustomProp(startTimeKey, PhotonNetwork.ServerTimestamp + 3000);
            }
        }
Ejemplo n.º 3
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);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Generate NPCs and Items for current game. Should be called by the master client.
        /// </summary>
        private void SetGenPointAndGenSceneObj()
        {
            if (!PhotonNetwork.isMasterClient)
            {
                Debug.LogError("Object generation must be operated by the master client.");
                return;
            }

            // Set the starting point of each players and generate the local players.
            int[] thiefGenPointSelector = new int[mapDataManager.ThiefGenertaionPoints.Count];
            for (int i = 0; i < thiefGenPointSelector.Length; i++)
            {
                thiefGenPointSelector[i] = i;
            }
            GlobalFunctions.RandomizeArray <int>(thiefGenPointSelector);

            for (int i = 0; i < NPCPrefabs.Count; i++)
            {
                randomNPCSelector.Add(i);
            }
            GlobalFunctions.RandomizeList <int>(randomNPCSelector);

            //Set the avatar of the thief player from NPC list and remove selected NPCs from the list.
            //And set the generation points of the thief players.
            for (int i = 0; i < thiefPlayers.Count; i++)
            {
                Hashtable cp = thiefPlayers[i].CustomProperties;
                cp[playerGenPointKey] = thiefGenPointSelector[i];
                cp[theifFigureIdxKey] = randomNPCSelector[0];
                thiefPlayers[i].SetCustomProperties(cp);

                randomNPCSelector.RemoveAt(0);
            }

            //Set the generation points of the detective players.
            for (int i = 0; i < detectivePlayers.Count; i++)
            {
                Hashtable cp = detectivePlayers[i].CustomProperties;
                cp[playerGenPointKey] = i;
                detectivePlayers[i].SetCustomProperties(cp);
            }

            // Generate Scene Objects(NPCs, Items).
            GenerateNPC();
            GenerateItems();

            // Game initiation ends, send ready signal to other players.
            PhotonExtends.SetRoomCustomProp(initializedKey, true);
        }
Ejemplo n.º 5
0
        public override void OnPhotonPlayerConnected(PhotonPlayer newPlayer)
        {
            curPlayerNum.text = PhotonNetwork.room.PlayerCount.ToString();

            // Load scene when the local player is the master client
            if (PhotonNetwork.room.PlayerCount == playersPerRoom && PhotonNetwork.isMasterClient)
            {
                PhotonNetwork.room.IsOpen = false;

                int NPCnum;
                if (int.TryParse(NPCNumInputField.text, out NPCnum))
                {
                    PhotonExtends.SetRoomCustomProp(Constants.NPCNumKey, NPCnum);
                }
                PhotonNetwork.LoadLevel(gameLevelName);
            }
        }
Ejemplo n.º 6
0
        public override void OnPhotonPlayerDisconnected(PhotonPlayer otherPlayer)
        {
            if (GameState == EGameState.Game_Set)
            {
                return;
            }

            if (GameState != EGameState.Started && GameState != EGameState.Preparing)
            {
                LeaveRoomWithError("유저가 게임 준비 도중 접속을 해제했습니다");
                return;
            }


            // Remove player from player list and the master client priorty list.
            if (thiefPlayers.Contains(otherPlayer))
            {
                thiefPlayers.Remove(otherPlayer);
                thievesNum -= 1;
                uiManager.RenewThievesNum(thievesNum - arrestedThievesNum);
            }
            else
            {
                detectivePlayers.Remove(otherPlayer);
            }
            masterPriority.Remove(otherPlayer.ID);

            // If one team has no member, the oppenent team is win.
            if (thievesNum - arrestedThievesNum == 0)
            {
                PhotonExtends.SetRoomCustomProp(winTeamKey, (int)ETeam.Detective);
                PhotonExtends.SetRoomCustomProp(gameSetKey, true);
            }
            else if (PhotonNetwork.playerList.Length == thievesNum)
            {
                PhotonExtends.SetRoomCustomProp(winTeamKey, (int)ETeam.Thief);
                PhotonExtends.SetRoomCustomProp(gameSetKey, true);
            }
        }
Ejemplo n.º 7
0
        public void TryToArrest(int detectiveID, int thiefID)
        {
            if (detectiveID == PhotonNetwork.player.ID)
            {
                arrestButton.SetRemainingCount(--arrestCount);
            }

            if (thiefID == -1)
            {
                uiManager.SetAlert("탐정 " + PhotonPlayer.Find(detectiveID).NickName + "이 도둑 체포 실패!");
                return;
            }

            if (PhotonPlayer.Find(thiefID) == null)
            {
                Debug.LogError("Arrest failed. Wrong Thief ID.");
                return;
            }

            uiManager.SetAlert("도둑 " + PhotonPlayer.Find(detectiveID).NickName + " 체포!");
            arrestedThievesNum += 1;
            uiManager.RenewThievesNum(thievesNum - arrestedThievesNum);

            if (detectiveID == PhotonNetwork.player.ID)
            {
                SetPlayerRecord(curTimestamp - startTimestamp);
            }

            /*if (PhotonNetwork.player.ID == thiefID)
             * {
             *  uiManager.SetObserverModeUI();
             * }*/

            if (thievesNum == arrestedThievesNum)
            {
                PhotonExtends.SetRoomCustomProp(winTeamKey, (int)ETeam.Detective);
                PhotonExtends.SetRoomCustomProp(gameSetKey, true);
            }
        }