RaidRankingData CreateRaidRankingData(ClientPeer peer)
        {
            RaidRankingData data = new RaidRankingData(peer.Id);

            data.Nickname = peer.userAgent.UserData.Info.Nickname;
            data.Index    = peer.userAgent.UserAssetData.Index;
            data.Tier     = peer.userAgent.UserAssetData.Tier;
            return(data);
        }
        static ProtoData.RaidRankingData.RankingData RaidRankingData2Proto(RaidRankingData raidRankingData)
        {
            var rankingData = new ProtoData.RaidRankingData.RankingData( );

            rankingData.nickname = raidRankingData.Nickname;
            rankingData.index    = raidRankingData.Index;
            rankingData.tier     = raidRankingData.Tier;
            rankingData.score    = raidRankingData.Score;
            return(rankingData);
        }
        void OnRequestRaidRankingReceived(ClientPeer peer, OperationRequest operationRequest, SendParameters sendParameters)
        {
            var workRankingList = MongoHelper.RaidRankingCollection.GetAllSorting( ).GetAwaiter( );

            workRankingList.OnCompleted(() =>
            {
                var rankingDataList = workRankingList.GetResult( );
                if (rankingDataList == null || rankingDataList.Count == 0)
                {
                    RaidRankingData data = CreateRaidRankingData(peer);
                    var workRankingAdd   = MongoHelper.RaidRankingCollection.Add(data).GetAwaiter( );
                    workRankingAdd.OnCompleted(() =>
                    {
                        RankingEvent.OnUpdateRaidRanking(peer, data, null, new List <RaidRankingData> {
                            data
                        });
                        BossEvent.OnUpdateRaidBoss(peer, 16);
                    });
                    return;
                }

                // TODO : 보스 디졌는지 안디졌는지 확인

                var myRankingData = rankingDataList.Find(x => x.Key.Equals(peer.Id));
                var lastHitData   = rankingDataList.Find(x => x.LastHit == true);
                if (myRankingData == null)
                {
                    myRankingData      = CreateRaidRankingData(peer);
                    var workRankingAdd = MongoHelper.RaidRankingCollection.Add(myRankingData).GetAwaiter( );
                    workRankingAdd.OnCompleted(() =>
                    {
                        rankingDataList.Add(myRankingData);
                        RankingEvent.OnUpdateRaidRanking(peer, myRankingData, lastHitData, rankingDataList);
                        BossEvent.OnUpdateRaidBoss(peer, 16);
                    });
                }
                else
                {
                    RankingEvent.OnUpdateRaidRanking(peer, myRankingData, lastHitData, rankingDataList);
                    BossEvent.OnUpdateRaidBoss(peer, 16);
                }
            });
        }
        public static void OnUpdateRaidRanking(ClientPeer peer, RaidRankingData myRankingData, RaidRankingData lastHitRankingData, List <RaidRankingData> raidRankingDataList)
        {
            var packet = new ProtoData.RaidRankingData( );

            if (myRankingData != null)
            {
                int ranking = raidRankingDataList.FindIndex(x => x.Equals(myRankingData));
                packet.myRankingData         = RaidRankingData2Proto(myRankingData);
                packet.myRankingData.ranking = ranking + 1;
            }
            if (lastHitRankingData != null)
            {
                int ranking = raidRankingDataList.FindIndex(x => x.Equals(lastHitRankingData));
                packet.lastHitRankingData         = RaidRankingData2Proto(lastHitRankingData);
                packet.lastHitRankingData.ranking = ranking + 1;
            }

            int cnt = 0;

            foreach (var rankingData in raidRankingDataList)
            {
                if (++cnt > 10)
                {
                    break;
                }
                var data = RaidRankingData2Proto(rankingData);
                data.ranking = cnt;
                packet.rankingDataList.Add(data);
            }

            var current = GameUtility.Now( ) - TheLordServer.Instance.bossDataList[0].CreateTime;
            var total   = GameThread.ThreadRaidBoss.bossRemainTime - current;

            packet.tick = total.Ticks;

            EventData eventData = new EventData((byte)EventCode.UpdateRaidRanking);

            eventData.Parameters = BinSerializer.ConvertPacket(packet);
            peer.SendEvent(eventData, new SendParameters( ));
        }