Esempio n. 1
0
 public ClientSideMatch(bMatch info)
     : this(info.matchType, info.matchScoringType, info.matchTeamType,
            info.playMode, info.gameName, info.gamePassword, info.slotOpenCount,
            info.beatmapName, info.beatmapChecksum, info.beatmapId, info.activeMods, info.hostId, info.specialModes, info.Seed)
 {
     this.slotId = info.slotId;
 }
Esempio n. 2
0
        public static void JoinMatch(bMatch info, string password = null)
        {
            if (Status == LobbyStatus.PendingJoin)
            {
                return;
            }

            if (info.slotOpenCount <= info.slotUsedCount || Status != LobbyStatus.Idle)
            {
                NotificationManager.ShowMessage(LocalisationManager.GetString(OsuString.Lobby_MatchFull));
                AudioEngine.PlaySample(@"match-leave");
            }
            else if (info.passwordRequired && string.IsNullOrEmpty(password))
            {
                JoinGameDialog jgd = new JoinGameDialog(info);
                GameBase.ShowDialog(jgd);
                return;
            }

            MatchSetup.Match = new ClientSideMatch(info);
            if (password != null)
            {
                MatchSetup.Match.gamePassword = password;
            }

            JoinMatch(info.matchId, password);
        }
Esempio n. 3
0
        private void OnQuickJoin(object sender, EventArgs e)
        {
            PlayModes         pm = (PlayModes)ConfigManager.sLobbyPlayMode.Value;
            List <LobbyMatch> availableMatches = null;

            lock (Matches)
            {
                availableMatches = Matches.FindAll(m =>
                {
                    bMatch bm = m.matchInfo;
                    if (bm.passwordRequired || bm.inProgress || bm.slotFreeCount == 0)
                    {
                        return(false);
                    }
                    if (ConfigManager.sLobbyPlayMode.Value != -1 && bm.playMode != pm)
                    {
                        return(false);
                    }
                    return(true);
                });
            }
            if (availableMatches.Count > 0)
            {
                var comparer = new QuickJoinMatchComparer();
                availableMatches.Sort(comparer);

                bMatch selectedMatch = null;
                foreach (var availableMatch in availableMatches)
                {
                    if (!quickJoinIgnoredIds.Contains(availableMatch.matchInfo.matchId))
                    {
                        selectedMatch = availableMatch.matchInfo;
                        break;
                    }
                }

                if (selectedMatch == null)
                {
                    selectedMatch = availableMatches[0].matchInfo;
                    quickJoinIgnoredIds.Clear();
                }
                else if (quickJoinIgnoredIds.Count > 8)
                {
                    quickJoinIgnoredIds.RemoveAt(0);
                }

                quickJoinIgnoredIds.Add(selectedMatch.matchId);
                Debug.Print($"Joining match {selectedMatch.matchId} with score {comparer.CalculateScore(selectedMatch)} ({selectedMatch.beatmapName})");
                JoinMatch(selectedMatch);
            }
            else
            {
                NotificationManager.ShowMessage(LocalisationManager.GetString(OsuString.Lobby_QuickJoin_Fail), Color.Red, 1500);
            }
        }
Esempio n. 4
0
        internal static void LeaveGame()
        {
            if (Lobby.Status == LobbyStatus.Idle)
            {
                return;
            }

            Lobby.Status = LobbyStatus.Idle;
            BanchoClient.SendRequest(RequestType.Osu_MatchPart, null);
            Match = null;

            AudioEngine.PlaySample(AudioEngine.s_MenuBack);

            GameBase.ChangeMode(Modes.Lobby);
        }
Esempio n. 5
0
        public static void MatchStart(bMatch match)
        {
            Match = match;

            if (!hasSong)
            {
                LeaveGame();
                GameBase.ShowMessage("You don't have the beatmap required to play this match.");
                return;
            }
            AudioEngine.PlaySample(AudioEngine.s_MenuHit);
            AudioEngine.PlaySample("match-start");

            Lobby.Status = LobbyStatus.Play;
            GameBase.ChangeMode(Modes.Play);
        }
Esempio n. 6
0
        public static void JoinMatch(bMatch info)
        {
            if (Status == LobbyStatus.PendingJoin)
            {
                return;
            }

            if (info.slotOpenCount > info.slotUsedCount && Status == LobbyStatus.Idle)
            {
                BanchoClient.SendRequest(RequestType.Osu_MatchJoin, new bInt(info.matchId));
                Status = LobbyStatus.PendingJoin;
            }
            else
            {
                GameBase.ShowMessage("This match is full!");
                AudioEngine.PlaySample("match-leave");
            }
        }
Esempio n. 7
0
        public static void IncomingMatch(bMatch match)
        {
            if (MatchSetup.Match != null && MatchSetup.Match.matchId == match.matchId)
            {
                MatchSetup.IncomingMatch(match);
            }

            lock (Matches)
            {
                int found = Matches.FindIndex(m => m.matchInfo.matchId == match.matchId);
                if (found < 0)
                {
                    Matches.Add(new Match(match));
                }
                else
                {
                    Matches[found].matchInfo = match;
                }
            }
            LobbyUpdatePending = true;
        }
Esempio n. 8
0
 internal JoinGameDialog(bMatch info)
     : base("Joining this game requires a password...", true)
 {
     this.info = info;
 }
        internal float CalculateScore(bMatch match)
        {
            float matchScore;

            if (matchScoreCache.TryGetValue(match.matchId, out matchScore))
            {
                return(matchScore);
            }

            // Matches having players with ranks close to the user are better
            var matchPlayersScore = 0.0f;

            var playerScores = new List <float>();

            for (int i = 0; i < match.slotId.Length; i++)
            {
                var playerId = match.slotId[i];
                if (playerId <= 0)
                {
                    continue;
                }

                User player = BanchoClient.GetUserById(playerId);
                if (player == null)
                {
                    continue;
                }

                var playerRank = player.Rank != 0 ? player.Rank : 1000000;
                var userRank   = GameBase.User.Rank != 0 ? GameBase.User.Rank : 1000000;

                var rankDifference = userRank - playerRank;
                var rankDistance   = Math.Abs(rankDifference);
                var rankCap        = rankDifference > 0 ? userRank * 0.5f : userRank * 2f;

                var score = (float)((rankCap - rankDistance) / rankCap);
                if (player.IsFriend)
                {
                    score += 0.1f;
                }
                if (player.CountryCode == GameBase.User.CountryCode)
                {
                    score += 0.05f;
                }

                // Negative scores are there only to differentiate matches when all players are outside the user's range,
                // not to penalize matches that have these players.
                if (score < 0)
                {
                    score *= 0.01f;
                }

                playerScores.Add(score);
            }
            if (playerScores.Count > 0)
            {
                var playerIndex = 0;
                foreach (var score in playerScores.OrderByDescending(c => c))
                {
                    matchPlayersScore += score / (playerIndex + 1);
                    playerIndex++;
                }
            }

            // Matches with a selected map close to the user's recommended difficulty are better
            var matchMapScore = 0f;

            var matchBeatmap = BeatmapManager.GetBeatmapByChecksum(match.beatmapChecksum);

            if (matchBeatmap != null)
            {
                var recommendedDifficulty = GameBase.User.RecommendedDifficulty();

                var difficulty   = matchBeatmap.DifficultyTomStars(match.playMode, match.activeMods);
                var useEyupStars = difficulty < 0;
                if (useEyupStars)
                {
                    difficulty = matchBeatmap.DifficultyEyupStars;
                }
                double difference = Math.Abs(difficulty - recommendedDifficulty);

                matchMapScore = (float)Math.Max(0, 1 - difference);
                if (useEyupStars)
                {
                    matchMapScore = (0.3f + matchMapScore) * 0.5f;
                }
            }
            else
            {
                matchMapScore = 0.3f;
            }

            matchScore = matchPlayersScore + matchMapScore;
            matchScoreCache[match.matchId] = matchScore;
            return(matchScore);
        }
Esempio n. 10
0
 public LobbyMatch(bMatch match)
 {
     matchInfo = match;
 }
        /// <summary>
        /// Handle splitting up and labelling the hitObjects into different player's scopes.
        /// </summary>
        internal override void InitializeHitObjectPostProcessing()
        {
            bMatch match = PlayerVs.Match;

            usedPlayerSlots = new List <int>();

            int playerCount = 0;

            for (int i = 0; i < bMatch.MAX_PLAYERS; i++)
            {
                if ((match.slotStatus[i] & SlotStatus.Playing) > 0 &&
                    match.slotTeam[i] == match.slotTeam[player.localPlayerMatchId])
                {
                    usedPlayerSlots.Add(i);
                    playerCount++;
                }
            }

            HitObjectManager hitObjectManager = player.hitObjectManager;

            int currentPlayer = -1;

            localUserActiveTime = new List <EventBreak>();

            EventBreak currentBreak = null;

            bool firstCombo = true;
            bool customTagColor;

            if (customTagColor = MatchSetup.TagComboColour != Color.TransparentWhite)
            {
                GameBase.Scheduler.Add(delegate
                {
                    SkinManager.SliderRenderer.Tag = MatchSetup.TagComboColour;
                });
            }

            for (int i = 0; i < hitObjectManager.hitObjectsCount; i++)
            {
                HitObject h = hitObjectManager.hitObjects[i];
                //HitObject hLast = i > 0 ? hitObjectManager.hitObjects[i-1] : hitObjectManager.hitObjects[i];

                bool firstInCombo = h.NewCombo || firstCombo;

                bool spinner = h.IsType(HitObjectType.Spinner) || h is HitCircleFruitsSpin;

                if (firstInCombo)
                {
                    if (!spinner)
                    {
                        currentPlayer = (currentPlayer + 1) % playerCount;
                        firstCombo    = false;
                    }

                    if (spinner || usedPlayerSlots[currentPlayer] == player.localPlayerMatchId)
                    {
                        //The local player starts playing at this point.
                        int st = (i > 0
                                      ? Math.Max(h.StartTime - hitObjectManager.HitWindow50,
                                                 hitObjectManager.hitObjects[i - 1].EndTime + 1)
                                      : h.StartTime - hitObjectManager.HitWindow50);
                        int ed = h.EndTime;
                        currentBreak = new EventBreak(st, ed);
                        localUserActiveTime.Add(currentBreak);
                    }
                    else
                    {
                        //Another play has taken over.
                        currentBreak = null;
                    }
                }


                if (spinner || usedPlayerSlots[currentPlayer] == player.localPlayerMatchId)
                {
                    if (currentBreak != null)
                    {
                        //The local player finishes playing at this point (or further).
                        currentBreak.SetEndTime(h.EndTime + hitObjectManager.HitWindow50);
                    }

                    if (customTagColor)
                    {
                        h.SetColour(MatchSetup.TagComboColour);
                    }
                }
                else
                {
                    h.IsScorable = false;
                    h.SetColour(Color.Gray);
                }

                h.TagNumeric = spinner ? -2 : usedPlayerSlots[currentPlayer];
            }

            InitializeWarningArrows();
        }
Esempio n. 12
0
        public static void IncomingMatch(bMatch match)
        {
            if (match.inProgress)
            {
                for (int i = 0; i < 8; i++)
                {
                    if (Match.slotId[i] >= 0 && match.slotId[i] < 0)
                    {
                        PlayerVs.MatchPlayerLeft(i);
                    }
                }
            }
            else
            {
                for (int i = 0; i < 8; i++)
                {
                    bool newPlayer = true;
                    for (int j = 0; j < 8; j++)
                    {
                        if (match.slotId[i] == Match.slotId[j])
                        {
                            newPlayer = false;
                            break;
                        }
                    }
                    if (newPlayer)
                    {
                        User u = BanchoClient.GetUserById(match.slotId[i]);
                        if (u != null)
                        {
                            GameBase.ShowMessage(u.Name + " joined the game.", Color.YellowGreen, 3000);
                            AudioEngine.PlaySample("match-join");
                        }
                    }
                }

                for (int i = 0; i < 8; i++)
                {
                    bool leftPlayer = true;
                    for (int j = 0; j < 8; j++)
                    {
                        if (match.slotId[j] == Match.slotId[i])
                        {
                            leftPlayer = false;
                            break;
                        }
                    }
                    if (leftPlayer)
                    {
                        User u = BanchoClient.GetUserById(Match.slotId[i]);
                        if (u != null)
                        {
                            GameBase.ShowMessage(u.Name + " left the game.", Color.OrangeRed, 3000);
                            AudioEngine.PlaySample("match-leave");
                        }
                    }
                }
            }
            if (match.beatmapChecksum != Match.beatmapChecksum)
            {
                SongChangePending = true;
            }
            if (match.activeMods != Match.activeMods)
            {
                ModChangePending = true;
            }
            Match         = match;
            UpdatePending = true;
        }
Esempio n. 13
0
 public Match(bMatch match)
 {
     matchInfo = match;
 }