Пример #1
0
        protected void GenerateEmptyIdenities()
        {
            m_PlayerIdentities.Clear();
            for (int i = 0; i < m_Players.Length; i++)
            {
                PlayerIdentity playerIdentity = new PlayerIdentity();
                playerIdentity.UpdateNumber(i);
                m_PlayerIdentities.Add(i, playerIdentity);
            }
            UpdatePlayerIdentities();

            m_UnusedIdentities.Clear();
            int identitiesCount = 0;

            foreach (int number in m_CharacterSet.Values)
            {
                identitiesCount += number;
            }
            for (int i = 0; i < identitiesCount - m_Players.Length + 1; i++)
            {
                PlayerIdentity unusedIdentity = new PlayerIdentity();
                unusedIdentity.UpdateNumber(i);
                m_UnusedIdentities.Add(unusedIdentity);
            }
            UpdateUnusedIdentities();
        }
Пример #2
0
        protected override void ReceiveUnusedIdentity(int index, int characterId)
        {
            PlayerIdentity unusedIdentity = m_UnusedIdentities[index];

            unusedIdentity.UpdateIdentity(characterId);
            unusedIdentity.MarkAsRevealed(true);
            onSingleUnusedIdentityUpdate.Invoke(index.ToString(), unusedIdentity);
        }
Пример #3
0
        protected override void ReceivePlayerIdentity(int number, int characterId)
        {
            PlayerIdentity playerIdentity = m_PlayerIdentities[number];

            playerIdentity.UpdateIdentity(characterId);
            playerIdentity.MarkAsRevealed(true);
            onSinglePlayerIdentityUpdate.Invoke(number.ToString(), playerIdentity);
        }
Пример #4
0
        private void ReceiveUnusedIdentityHistory(int index, int characterId)
        {
            PlayerIdentity unusedIdentity = new PlayerIdentity();

            unusedIdentity.UpdateNumber(index);
            unusedIdentity.UpdateIdentity(characterId);

            m_UnusedIdentitiesHistory[m_GameHistoryIndex].Add(unusedIdentity);
        }
Пример #5
0
        public override void GeneratePlayerIdentities()
        {
            if (!PhotonNetwork.isMasterClient)
            {
                return;
            }

            //随机生成玩家编号,0号预留给上帝玩家
            List <int> playerNumbers = new List <int>();

            for (int i = 1; i < m_Players.Length; i++)
            {
                playerNumbers.Add(i);
            }
            playerNumbers = playerNumbers.Shuffle().ToList();

            //向其他玩家分配编号列表
            photonView.RPC("ReceivePlayerNumbers", PhotonTargets.All, playerNumbers.ToArray());

            //生成所有游戏身份
            List <int> characterIds = new List <int>();

            foreach (int id in m_CharacterSet.Keys)
            {
                characterIds.AddRange(Enumerable.Repeat(id, m_CharacterSet[id]));
            }
            characterIds = characterIds.Shuffle().ToList();

            //对应编号分配游戏身份,上帝(0号玩家)本身不获得游戏身份
            int k = 0;

            foreach (int index in m_PlayerIdentities.Keys)
            {
                if (index != 0)
                {
                    PlayerIdentity playerIdentity = m_PlayerIdentities[index];
                    playerIdentity.UpdateIdentity(characterIds[k++]);
                    playerIdentity.MarkAsRevealed(true);
                }
            }
            UpdatePlayerIdentities();

            //收集多余游戏身份
            for (int i = 0; i < characterIds.Count() - k; i++)
            {
                PlayerIdentity unusedIdentity = m_UnusedIdentities[i];
                unusedIdentity.UpdateIdentity(characterIds[k + i]);
                unusedIdentity.MarkAsRevealed(true);
            }
            UpdateUnusedIdentities();

            FindObjectOfType <GameHistoryServiceView>().RecordIdentitiesHistory(m_PlayerIdentities, m_UnusedIdentities);

            //向其他玩家分配各自身份
            DistributePlayerIdentities();
        }
Пример #6
0
        private void ReceivePlayerIdentityHistory(int playerNumber, PhotonPlayer player, int characterId)
        {
            PlayerIdentity playerIdentity = new PlayerIdentity();

            playerIdentity.UpdateNumber(playerNumber);
            playerIdentity.UpdatePlayer(player);
            playerIdentity.UpdateIdentity(characterId);

            m_PlayerIdentitiesHistory[m_GameHistoryIndex][playerNumber] = playerIdentity;
        }
Пример #7
0
        private void Poll(PhotonPlayer player, int vote)
        {
            //todo
            PlayerIdentity voter = m_VoteChecklist.Keys.FirstOrDefault(pi => pi.Player.Equals(player));

            if (voter.Equals(default(PlayerIdentity)) || m_VoteChecklist[voter])
            {
                return;
            }

            m_VoteChecklist[voter] = true;
            List <int> voterList = m_Poll.ContainsKey(vote) ? m_Poll[vote].ToList() : new List <int>();

            voterList.Add(voter.Number);
            m_Poll[vote] = voterList.ToArray();

            UpdatePoll();
        }
Пример #8
0
        private void UpdatePoll()
        {
            Dictionary <int, PlayerIdentity> playerIdentities = m_GameLogic.PlayerIdentities;
            OrderedDictionary dictionary = new OrderedDictionary();

            //todo : m_Poll
            foreach (KeyValuePair <int, int[]> poll in m_Poll)
            {
                PlayerIdentity        candidate = poll.Key != -1 ? playerIdentities[poll.Key] : null;
                List <PlayerIdentity> voters    = new List <PlayerIdentity>();
                foreach (int voterNumber in poll.Value)
                {
                    voters.Add(playerIdentities[voterNumber]);
                }
                //将投票者按编号排序
                voters = voters.OrderBy(pi => pi.Number).ToList();
                dictionary.Add(poll.Key.ToString(), new DataPair <PlayerIdentity, List <PlayerIdentity> >(candidate, voters));
            }
            onPollUpdate.Invoke(dictionary);
        }
 public void RetrieveIdentity(PlayerIdentity identity)
 {
     m_Identity = identity;
 }
Пример #10
0
 public void SetVoteList(PlayerIdentity vote)
 {
     m_Vote = vote;
 }