Ejemplo n.º 1
0
        public void RefreshContent(BRoundEnd msg)
        {
            if (msg == null)
            {
                return;
            }

            if (!RankContent)
            {
                return;
            }

            var lost      = msg.lost;
            var tableUser = _tableUserData.Read();

            // 只有在已经开局的情况下收到结算命令才有用。
            _ranks[0] = msg.username1;
            _ranks[1] = msg.username2;
            _ranks[2] = msg.username3;
            _ranks[3] = msg.username4;

            _win[0] = true;
            _win[1] = tableUser.IsSameTeam(msg.username2, msg.username1);
            _win[2] = tableUser.IsSameTeam(msg.username3, msg.username1);
            _win[3] = tableUser.IsSameTeam(msg.username4, msg.username1);

            if (lost || SelfWin)
            {
                // 掉线或者赢了,都播放赢的声音。
                _soundController.PlayEndRoundWinSound();
            }
            else
            {
                _soundController.PlayEndRoundLoseSound();
            }

            var user1 = tableUser.GetUserFormUserName(msg.username1);
            var user2 = tableUser.GetUserFormUserName(msg.username2);
            var user3 = tableUser.GetUserFormUserName(msg.username3);
            var user4 = tableUser.GetUserFormUserName(msg.username4);

            var users            = new[] { user1, user2, user3, user4 };
            int currentOtherRank = 0;

            for (int i = 0; i < users.Length; i++)
            {
                var u = users[i];
                if (u == null)
                {
                    continue;
                }

                var win = lost || IsWin(u);
                if (tableUser.IsMySelf(u))
                {
                    if (EndImage)
                    {
                        if (!EndImage.gameObject.activeSelf)
                        {
                            EndImage.gameObject.SetActive(true);
                        }

                        EndImage.sprite = win ? WinImg : LoseImg;
                    }

                    if (!_mySelfRank)
                    {
                        _mySelfRank = _rankMySelfFactory.Create();

                        if (_mySelfRank)
                        {
                            _mySelfRank.transform.SetParent(RankContent, false);
                        }
                    }

                    if (_mySelfRank)
                    {
                        if (!_mySelfRank.gameObject.activeSelf)
                        {
                            _mySelfRank.gameObject.SetActive(true);
                        }

                        var room             = _room.Read();
                        var roomCurrencyType = room == null ? CurrencyType.GOLDEN_EGG : room.currency_type;
                        _mySelfRank.transform.SetSiblingIndex(i);
                        // TODO 完成连打房逻辑
                        _mySelfRank.ApplyData(
                            false,
                            win,
                            u.nickname,
                            u.vip,
                            GetMyExp(msg, i),
                            roomCurrencyType,
                            GetMyMoney(msg, i),
                            msg.race_id,
                            GetMyTotalScore(msg, i),
                            msg.total_multiple);
                    }
                }
                else
                {
                    if (currentOtherRank >= _otherRanks.Count)
                    {
                        var rank = _rankOtherFactory.Create();
                        if (rank)
                        {
                            rank.transform.SetParent(RankContent, false);
                            _otherRanks.Add(rank);
                        }
                    }

                    if (currentOtherRank < _otherRanks.Count)
                    {
                        var rank = _otherRanks[currentOtherRank];
                        if (!rank.gameObject.activeSelf)
                        {
                            rank.gameObject.SetActive(true);
                        }

                        currentOtherRank++;

                        rank.ApplyData(win, u.username, u.nickname, u.vip);
                        rank.transform.SetSiblingIndex(i);
                    }
                }
            }
        }