public async Task <string> Load(GuildSettings guildSettings, OsuApi api, ServerReplayDb replays, ServerBeatmapDb beatmaps)
        {
            this.guildSettings = guildSettings;
            JToken score = null;

            if (Username != null && UserId == null)
            {
                UserId = await api.GetUserIdv1(Username);
            }

            if (BeatmapId != null)
            {
                _beatmap = await beatmaps.GetBeatmapFromId(BeatmapId);
            }

            if (ReplayFile != null)
            {
                _replay = new Replay(ReplayFile);
            }
            else if (ScoreId != null)
            {
                if (Mods == null || Beatmap == null)
                {
                    score = await api.GetScorev2(ScoreId);
                }
                else
                {
                    _replay = await replays.GetReplayFromOnlineId(ScoreId, Mods, Beatmap);
                }
            }

            if (_replay == null && PlayIndex.HasValue)
            {
                if (PlayIndex.Value < 0)
                {
                    return("Index value must be greater than 0");
                }

                if (UserId != null && UserScores != null)
                {
                    score = await api.GetUserScoresv2(UserId, UserScores, PlayIndex.Value, FailedScores);
                }
                else if (BeatmapId != null)
                {
                    score = await api.GetBeatmapScoresv2(BeatmapId, PlayIndex.Value);
                }
            }

            if (score != null)
            {
                if (!(bool)score["replay"])
                {
                    return("Replay not saved online");
                }
                if ((bool)score["perfect"])
                {
                    return("No misses");
                }

                if (_beatmap == null)
                {
                    _beatmap = await beatmaps.GetBeatmapFromId((string)score["beatmap"]["id"]);
                }
                _replay = await replays.GetReplayFromScore(score, _beatmap);
            }

            if (_beatmap == null && _replay != null)
            {
                _beatmap = await beatmaps.GetBeatmap(_replay.MapHash);
            }

            if (_beatmap != null && _replay != null && _beatmap.BeatmapHash != _replay.MapHash)
            {
                _beatmap = await beatmaps.GetBeatmapFromId(_beatmap.BeatmapID.Value.ToString(), forceRedl : true);
            }

            if (_replay != null && !_replay.fullLoaded)
            {
                return("Replay does not contain any cursor data - can't analyze");
            }


            if (_replay != null && _beatmap != null)
            {
                if (_beatmap.Mode != GameMode.osu)
                {
                    return(null);
                }

                _analyzer = new ReplayAnalyzer(_beatmap, _replay);
                Loaded    = true;
                return(null);
            }
            return($"Couldn't find {(_replay == null? "replay" : "beatmap")}");
        }
Example #2
0
        public async Task <string> Load(OsuApi api, ServerReplayDb replays, ServerBeatmapDb beatmaps)
        {
            JToken score = null;

            if (Username != null && UserId == null)
            {
                UserId = await api.GetUserIdv1(Username);
            }

            if (BeatmapId != null)
            {
                _beatmap = await beatmaps.GetBeatmapFromId(BeatmapId);
            }

            if (ReplayFile != null)
            {
                _replay = new Replay(ReplayFile);
            }
            else if (ScoreId != null && Mods != null)
            {
                _replay = await replays.GetReplayFromOnlineId(ScoreId, Mods, _beatmap);
            }

            if (_replay == null && PlayIndex.HasValue)
            {
                if (UserId != null && UserScores != null)
                {
                    score = await api.GetUserScoresv2(UserId, UserScores, PlayIndex.Value, FailedScores);
                }
                else if (BeatmapId != null)
                {
                    score = await api.GetBeatmapScoresv2(BeatmapId, PlayIndex.Value);
                }

                if (score != null && _beatmap == null)
                {
                    _beatmap = await beatmaps.GetBeatmapFromId((string)score["beatmap"]["id"]);
                }
            }

            if (score != null && _beatmap != null)
            {
                _replay = await replays.GetReplayFromScore(score, _beatmap);
            }

            if (_beatmap == null && _replay != null)
            {
                _beatmap = await beatmaps.GetBeatmap(_replay.MapHash);
            }

            if (_replay != null && !_replay.fullLoaded)
            {
                return("Replay does not contain any cursor data - can't analyze");
            }

            if (_replay != null && _beatmap != null)
            {
                _analyzer = new ReplayAnalyzer(_beatmap, _replay);
                Loaded    = true;
                return(null);
            }
            return($"Couldn't find {(_replay == null? "replay" : "beatmap")}");
        }