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); } } }
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); } }
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); } } } } }
/// <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); }
private void PostponeStartTime(int newPrepareStartTimestamp) { int prepareStartTimestamp = newPrepareStartTimestamp; if (GameState == EGameState.Ready) { GameState = EGameState.ReadyChecked; PhotonExtends.SetLocalPlayerProp(playerReadyKey, true); } }
private void OnApplicationPause(bool pauseStatus) { if (GameState != EGameState.Preparing && GameState != EGameState.Started) { return; } PhotonExtends.SetLocalPlayerProp(pauseKey, pauseStatus); PhotonNetwork.networkingPeer.SendOutgoingCommands(); }
/// <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); }
private void Awake() { if (!photonView.isMine) { return; } if (localThief != null) { Debug.LogError("Multiple instantiation of the local thief player."); PhotonExtends.Destroy(gameObject); return; } localThief = this; }
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); } }
private void Awake() { playerInstances.Add(GetComponent <PlayerController>()); if (!photonView.isMine) { return; } if (localDetective != null) { Debug.LogError("Multiple instantiation of local detective."); PhotonExtends.Destroy(gameObject); return; } localDetective = this; }
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); } }
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); } }
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; } } } } }