Esempio n. 1
0
        public static void TestRankSeq()
        {
            var seq = new RankSequencer()
            {
                rank = 5, min_rank = 1, max_rank = 13
            };

            foreach (var s in seq)
            {
                Log.Information($"{s}");
            }
            var seq2 = new RankSequencer()
            {
                rank = 0, min_rank = 0, max_rank = 0
            };

            foreach (var s in seq2)
            {
                Log.Information($"{s}");
            }
        }
        public static async Task <(MatchResult, bool)> SearchPlayer(Session session, long match_id, JMapData map_data, JGameModeData game_mode)
        {
            bool result      = false;
            var  matchResult = new MatchResult(match_id, session.map_id);

            if (GetStartPlayerCount(game_mode) <= 1)
            {
                return(matchResult, true);
            }

            Session other_session = null;
            var     seq           = new RankSequencer()
            {
                rank = session.rank, min_rank = session.min_rank, max_rank = session.max_rank
            };

            foreach (var rank in seq)
            {
                var users = await WaitingList.GetWaitingUser(session.map_id, rank, defaultGetWaitingUser);

                for (int i = 0; i < users.Count; ++i)
                {
                    //Log.Information($"searching... waiting user : {users[i]}, rank : {rank}");

                    // 자신은 스킵
                    if (users[i] == session.user_no)
                    {
                        continue;
                    }

                    if ((other_session = await Session.GetSession(users[i], false)) == null // 대기중 유저 세션 만료
                        )
                    {
                        Log.Information("cannot find Session {0}", users[i]);
                        await WaitingList.RemoveWaitingUser(users[i]);

                        continue;
                    }

                    if (other_session.rank != rank)
                    {
                        continue;
                    }

                    if (await MatchUser.OccupyMatchUser(users[i], match_id) == false)
                    {
                        continue;
                    }

                    if (await matchResult.AddPlayer(other_session, map_data, game_mode) == false)
                    {
                        Log.Error($"SearchPlayer error user_no:{session.user_no}");
                        continue;
                    }

                    Log.Information($"Candidate User {other_session.user_no}");

                    if (matchResult.replyToBattleServer.players.Count == GetStartPlayerCount(game_mode) - 1)
                    {
                        result = true;
                        return(matchResult, result);
                    }
                }
            }

            return(matchResult, result);
        }