Exemplo n.º 1
0
        /// <summary>
        /// Sets the name of the player, and save it in the PlayerPrefs for future sessions.
        /// </summary>
        /// <param name="value">The name of the Player</param>
        public void SetPlayerName(string value)
        {
            // #Important
            PhotonNetwork.playerName = value + " ";             // force a trailing space string in case value is an empty string, else playerName would not be updated.

            PlayerPrefs.SetString(_playerNamePrefKey, PlayerManager.GetProperName(value));
        }
Exemplo n.º 2
0
        void Update()
        {
            if (VoteManager.Instance != null)
            {
                _dayText.text   = "Day" + VoteManager.Instance.countDay;
                _nightText.text = "Night" + VoteManager.Instance.countNight;
            }
            else
            {
                _dayText.text   = "Day1";
                _nightText.text = "Night0";
            }

            GameObject[] players = GameObject.FindGameObjectsWithTag("Player");
            nbPlayerAlive    = players.Length;
            _nbWerewolfAlive = 0;

            _infoText.text = "";
            foreach (GameObject player in players)
            {
                PlayerManager pM = player.GetComponent <PlayerManager> ();
                if (pM.isAlive)
                {
                    _infoText.text += PlayerManager.GetProperName(player.name);
                    if (pM.role == "Werewolf")
                    {
                        _nbWerewolfAlive++;
                    }
                    if (!pM.isDiscovered)
                    {
                        _infoText.text += " > ( ? )\n";
                    }
                    else
                    {
                        _infoText.text += " > " + pM.role + "\n";
                    }
                }
                else
                {
                    nbPlayerAlive--;
                    _infoText.text += "[┼] " + PlayerManager.GetProperName(player.name) + " > " + pM.role + "\n";
                }
            }

            gameFinished = CheckIfGameFinished();
            _endgamePanel.SetActive(gameFinished);
            if (gameFinished)
            {
                _endgamePanel.transform.GetChild(0).gameObject.SetActive(PhotonNetwork.isMasterClient);
            }
        }
Exemplo n.º 3
0
        void Awake()
        {
            gameObject.name = photonView.owner.NickName;

            if (photonView.isMine)
            {
                isDiscovered = true;
            }
            else
            {
                GetComponentInChildren <TextMesh> ().text = PlayerManager.GetProperName(gameObject.name);
            }

            OnSceneLoaded(SceneManager.GetActiveScene(), LoadSceneMode.Single);
        }
Exemplo n.º 4
0
 void IChatClientListener.OnGetMessages(string channelName, string[] senders, object[] messages)
 {
     for (int i = 0; i < messages.Length; i++)
     {
         if (chatMessages != null)
         {
             chatMessages.text += "[" + GetChannelName(channelName) + "] " + PlayerManager.GetProperName(senders [i]) + " > " + messages [i] + "\n";
             Canvas.ForceUpdateCanvases();
             chatMessages.transform.parent.GetComponent <ScrollRect>().verticalNormalizedPosition = 0f;
             Canvas.ForceUpdateCanvases();
         }
         else
         {
             Debug.Log("Oops, seems there is nothing to contain the message!");
         }
     }
 }
Exemplo n.º 5
0
        /// <summary>
        /// This switches from the ghost form to the incarnated form, depending on the scene loaded.
        /// </summary>
        void OnSceneLoaded(Scene scene, LoadSceneMode mode)
        {
            if (scene.buildIndex == 1)
            {
                gameObject.GetComponent <Rigidbody>().isKinematic = true;
                transform.GetChild(0).gameObject.SetActive(false);
                transform.GetChild(1).gameObject.SetActive(false);
                transform.GetChild(2).gameObject.SetActive(true);

                GetComponent <MinimapObjectID> ().enabled       = false;
                GetComponent <PlayerAnimatorManager> ().enabled = false;
            }
            else if (scene.buildIndex == 2)
            {
                isAlive = true;

                _rolePanel       = GameObject.FindGameObjectWithTag("Canvas").transform.GetChild(1);
                _votedPlayerText = GameObject.FindGameObjectWithTag("Canvas").transform.GetChild(3).GetComponentInChildren <Text> ();

                gameObject.GetComponent <Rigidbody>().isKinematic = false;
                if (isMale)
                {
                    transform.GetChild(0).gameObject.SetActive(true);
                }
                else
                {
                    transform.GetChild(1).gameObject.SetActive(true);
                }
                transform.GetChild(2).gameObject.SetActive(false);

                if (photonView.isMine)
                {
                    VoteManager.Instance.resetVoteButton.GetComponent <Button> ().onClick.AddListener(delegate {
                        ClearVotedPlayer();
                    });
                    // clear the name of the local player to display it at the bottom of the screen
                    _rolePanel.GetChild(4).GetComponentInChildren <Text> ().text = PlayerManager.GetProperName(gameObject.name);
                }
                else
                {
                    GetComponent <MinimapObjectID> ().enabled = true;
                }
                GetComponent <PlayerAnimatorManager> ().enabled = true;
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Add a button linked to the player photonID and add listener on it.
        /// </summary>
        void RegisterPlayerForVote(PlayerManager pM)
        {
            string playerName = pM.gameObject.name;
            Button btn        = Instantiate(voteButton).GetComponent <Button>();

            btn.GetComponentInChildren <Text> ().text = PlayerManager.GetProperName(playerName);

            Image[] images = btn.GetComponentsInChildren <Image> ();
            if (pM.isDiscovered)
            {
                Sprite roleSprite = Resources.Load("Cards/" + pM.role, typeof(Sprite)) as Sprite;
                if (roleSprite != null)
                {
                    images[1].sprite = roleSprite;
                }
                else
                {
                    Debug.Log("No image was found for " + pM.role);
                }
            }
            if (VoteManager.Instance.mayorName == playerName)
            {
                Sprite mayorSprite = Resources.Load("Cards/MayorDay", typeof(Sprite)) as Sprite;
                if (mayorSprite != null)
                {
                    images[2].sprite = mayorSprite;
                }
                else
                {
                    Debug.Log("No image was found for Mayor");
                }
            }

            btn.transform.SetParent(voteButtonGrid);
            btn.onClick.AddListener(delegate {
                OnClicked(playerName);
            });

            playerButtons.Add(new PlayerButton()
            {
                Button = btn, PlayerName = playerName
            });
        }
Exemplo n.º 7
0
 /// <summary>
 /// This function makes a double check: if the house has a owner and if the local player is the owner.
 /// </summary>
 bool CheckOwner(out bool isOwner)
 {
     isOwner = false;
     GameObject[] players = GameObject.FindGameObjectsWithTag("Player");
     foreach (GameObject player in players)
     {
         PlayerManager pM = player.GetComponent <PlayerManager> ();
         if (pM.house != null && pM.house == gameObject)
         {
             _owner = player;
             if (player == PlayerManager.LocalPlayerInstance)
             {
                 isOwner = true;
             }
             displayCanvas.GetComponentInChildren <Text> ().text = PlayerManager.GetProperName(_owner.name);
             return(true);
         }
     }
     displayCanvas.GetComponentInChildren <Text> ().text = "No Owner";
     return(false);
 }
Exemplo n.º 8
0
        /// <summary>
        /// This function indicates to all player what to do depending on the time of the day. It also (in)activate the resetVoteButton
        /// </summary>
        public void UpdateClockText(bool hasStateChanged)
        {
            PlayerManager localPM   = PlayerManager.LocalPlayerInstance.GetComponent <PlayerManager> ();
            Text          smallText = _clockDescriptionTexts [1];
            int           state     = GetCurrentState();

            if (hasStateChanged)
            {
                if (CheckIfPhaseIsPassed() == false)
                {
                    StartCoroutine("RotateHourGlass");
                }

                bool isBigTextActive = ShouldBigTextAppear();
                Text bigText         = _clockDescriptionTexts [0];
                bigText.transform.parent.gameObject.SetActive(isBigTextActive);
                smallText.transform.parent.gameObject.SetActive(!isBigTextActive);

                bigText.text = "";

                if (state == 1)
                {
                    bigText.text += "Wake up!\n\nExplore the Village...\n\nWhat happened during night?";
                }
                else if (state == 2)
                {
                    if (VoteManager.Instance.countDay == 1)
                    {
                        bigText.text += "Discuss on the Chat.\n\nDecide who will be the new Mayor.\n\nThen click on the button \"Vote\" in front of the player Tent!";
                    }
                    else
                    {
                        bigText.text += "Discuss on the Chat.\n\nDecide who will be the next victim.\n\nThen click on the button \"Vote\" in front of the player Tent!";
                    }
                }
                else if (state == 3)
                {
                    bigText.text += "Hurry!\n\nLast chance to vote or change your vote.\n\nDon't forget: click on the button \"Vote\" located in front of the player Tent!";
                }
                else if (state == 4)
                {
                    bigText.text += "Votes have all been counted!\n\nGO BACK TO YOUR TENT (IN RED)!\n\nNight is falling upon the Village...";
                }
                else if (state == 5)
                {
                    bigText.text += "The night has just fallen.\n\nKeep your eyes closed.\n\nWait until asked to play a specific role, if any!";
                }
                else if (state == 6)
                {
                    if (localPM.role == "Seer")
                    {
                        bigText.text += "Come out, come out, wherever you are!\n\nSeer, time for you to come out and discover someone's role!";
                    }
                    else
                    {
                        bigText.text += "Hold on to your little secrets!\n\nThe Seer may have already discovered yours!";
                    }
                }
                else if (state == 7)
                {
                    if (localPM.role == "Werewolf")
                    {
                        bigText.text += "Time for you, as a Werewolf, to strike!\n\nGo on the Chat to discuss!\n\nAgree with other Werewolves on who to kill...";
                    }
                    else
                    {
                        bigText.text += "Time for the Werewolf to strike!\n\nBeware: they are silently agreeing on the Chat on who to devour...";
                    }
                }
                else if (state == 8)
                {
                    if (localPM.role == "Witch")
                    {
                        bigText.text += "Votes have all been counted!\n\nThe choice is your, Witch!\n\nWill you save the victim? Will you kill someone?";
                    }
                    else
                    {
                        bigText.text += "Votes have all been counted!\n\nThe victim's fate is now in the Witch's hands!\n\nWill he be saved? Will someone be killed?";
                    }
                }
            }
            else if (!localPM.isAlive)
            {
                smallText.text = "You died...\nYou may spy the other players or leave the game now...";
            }
            else
            {
                smallText.text = secondsOfPhases[state - 1] + "seconds to:\n";
                string mostVotedPlayer = PlayerManager.GetProperName(VoteManager.Instance.mostVotedPlayer);
                if (mostVotedPlayer == "")
                {
                    mostVotedPlayer = "nobody";
                }
                mostVotedPlayer = "\n\nMost votes: " + mostVotedPlayer;

                if (state == 1)
                {
                    if (VoteManager.Instance.countDay == 1)
                    {
                        smallText.text += "explore the village.";
                    }
                    else
                    {
                        smallText.text += "discover who died during the night.";
                    }
                }
                else if (state == 2)
                {
                    if (VoteManager.Instance.countDay == 1)
                    {
                        smallText.text += "vote for the new Major." + mostVotedPlayer;
                    }
                    else
                    {
                        smallText.text += "vote for the next victim." + mostVotedPlayer;
                    }
                }
                else if (state == 3)
                {
                    if (VoteManager.Instance.countDay == 1)
                    {
                        smallText.text += "modify your vote for the new Mayor." + mostVotedPlayer;
                    }
                    else
                    {
                        smallText.text += "modify your vote for the next victim." + mostVotedPlayer;
                    }
                }
                else if (state == 4)
                {
                    smallText.text += "go back home before night.";
                }
                else if (state == 5)
                {
                    smallText.text += "wait before the Seer may come out.";
                }
                else if (state == 6)
                {
                    if (localPM.role == "Seer")
                    {
                        smallText.text += "discover the role of someone.";
                    }
                    else
                    {
                        smallText.text += "wait while the Seer discover a role.";
                    }
                }
                else if (state == 7)
                {
                    if (localPM.role == "Werewolf")
                    {
                        smallText.text += "vote against a player." + mostVotedPlayer;
                    }
                    else
                    {
                        smallText.text += "wait while Werewolves vote against a player.";
                    }
                }
                else if (state == 8)
                {
                    if (localPM.role == "Witch")
                    {
                        smallText.text += "decide the fate of players." + mostVotedPlayer;
                    }
                    else
                    {
                        smallText.text += "wait while the Witch decides what to do.";
                    }
                }
            }
        }
Exemplo n.º 9
0
        void Update()
        {
            if (SceneManagerHelper.ActiveSceneBuildIndex == 1)
            {
                if (role == "Ready")
                {
                    transform.position = new Vector3(transform.position.x, Mathf.PingPong(Time.time, 1f) + 3, transform.position.z);
                }
            }
            else
            {
                if (isAlive)
                {
                    // We activate the avatar accordingly
                    transform.GetChild(0).gameObject.SetActive(isMale);
                    transform.GetChild(1).gameObject.SetActive(!isMale);
                    transform.GetChild(2).gameObject.SetActive(false);

                    if (photonView.isMine && role == "LittleGirl")
                    {
                        PlayerAnimatorManager.compas.GetComponent <Image> ().color = (littleGirlSpying) ? Color.yellow : Color.red;
                    }
                }
                else
                {
                    if (photonView.isMine)
                    {
                        if (VoteManager.Instance.mayorName == gameObject.name)
                        {
                            VoteManager.Instance.mayorName = "";
                            VoteManager.Instance.StartSingleVote("Mayor");
                        }
                        if (hunterBulletAvailable)
                        {
                            VoteManager.Instance.StartSingleVote("Hunter");
                        }
                        if (VoteManager.Instance.singleVotes.Count == 0)
                        {
                            GameObject[] players = GameObject.FindGameObjectsWithTag("Player");
                            foreach (GameObject player in players)
                            {
                                player.GetComponent <PlayerManager> ().isDiscovered = true;
                            }
                        }
                    }
                    if (!isDiscovered)
                    {
                        isDiscovered = true;
                    }
                    transform.GetChild(0).gameObject.SetActive(false);
                    transform.GetChild(1).gameObject.SetActive(false);
                    transform.GetChild(2).gameObject.SetActive(true);
                }

                if (photonView.isMine)
                {
                    DisplayRole();
                    if (_votedPlayerText != null)
                    {
                        _votedPlayerText.text = PlayerManager.GetProperName(votedPlayer);
                    }
                }
            }
        }
Exemplo n.º 10
0
        /// <summary>
        /// Searches through all the players, updates the voted player list and check if there is a most voted player.
        /// </summary>
        void RefreshVotedPlayers()
        {
            _votedPlayers.Clear();

            GameObject[] players = GameObject.FindGameObjectsWithTag("Player");
            _infoText.text = "";
            foreach (GameObject player in players)
            {
                PlayerManager pM = player.GetComponent <PlayerManager> ();
                if (pM.votedPlayer != "" && pM.isAlive)
                {
                    _votedPlayers.Add(pM.votedPlayer);
                    // Double vote of the Mayor doesn't count during the night if he's a Werewolf!
                    if (DayNightCycle.GetCurrentState() < 5 && player.name == mayorName)
                    {
                        _votedPlayers.Add(pM.votedPlayer);
                    }
                }
                if (player.name == mayorName)
                {
                    _infoText.text += "[M] ";
                }
                _infoText.text += PlayerManager.GetProperName(player.name) + " > " + PlayerManager.GetProperName(pM.votedPlayer) + "\n";
            }

            // This part checks if there is a most voted player
            if (_votedPlayers.Count == 0)
            {
                mostVotedPlayer = "";
            }
            else
            {
                int           previousCount    = _votedPlayers.FindAll(p => p == _votedPlayers [0]).Count;
                List <string> mostVotedPlayers = new List <string> ();
                mostVotedPlayers.Add(_votedPlayers [0]);

                for (int i = 1; i < _votedPlayers.Count; i++)
                {
                    int newCount = _votedPlayers.FindAll(p => p == _votedPlayers [i]).Count;
                    if (newCount > previousCount)
                    {
                        mostVotedPlayers.Remove(_votedPlayers [i - 1]);
                        mostVotedPlayers.Add(_votedPlayers [i]);
                        previousCount = newCount;
                    }
                    else if (newCount == previousCount && !mostVotedPlayers.Contains(_votedPlayers [i]))
                    {
                        mostVotedPlayers.Add(_votedPlayers [i]);
                    }
                }

                if (mostVotedPlayers.Count > 1)
                {
                    mostVotedPlayer = "";
                }
                else
                {
                    mostVotedPlayer = mostVotedPlayers [0];
                }
            }
        }