2017-03-15 16:50:52 +08:00
|
|
|
|
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
|
|
|
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
|
|
|
|
|
2017-09-08 18:21:35 +08:00
|
|
|
|
using System;
|
2017-03-15 16:50:52 +08:00
|
|
|
|
using System.Collections.Generic;
|
2017-09-08 18:21:35 +08:00
|
|
|
|
using System.Linq;
|
2017-03-15 13:06:05 +08:00
|
|
|
|
using Newtonsoft.Json;
|
2017-07-26 12:22:46 +08:00
|
|
|
|
using osu.Game.Beatmaps;
|
2017-09-14 19:05:43 +08:00
|
|
|
|
using osu.Game.Rulesets;
|
2017-09-08 18:21:35 +08:00
|
|
|
|
using osu.Game.Users;
|
|
|
|
|
using osu.Game.Rulesets.Replays;
|
2017-04-18 15:05:58 +08:00
|
|
|
|
using osu.Game.Rulesets.Scoring;
|
2017-11-20 13:06:26 +08:00
|
|
|
|
using osu.Game.Screens.Select.Leaderboards;
|
2017-11-22 12:26:01 +08:00
|
|
|
|
using osu.Framework.IO.Network;
|
2017-03-15 13:06:05 +08:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Online.API.Requests
|
|
|
|
|
{
|
|
|
|
|
public class GetScoresRequest : APIRequest<GetScoresResponse>
|
|
|
|
|
{
|
|
|
|
|
private readonly BeatmapInfo beatmap;
|
2017-11-20 13:06:26 +08:00
|
|
|
|
private readonly LeaderboardScope scope;
|
2017-11-21 22:14:38 +08:00
|
|
|
|
private readonly RulesetInfo ruleset;
|
2017-03-15 13:06:05 +08:00
|
|
|
|
|
2017-11-22 12:26:01 +08:00
|
|
|
|
public GetScoresRequest(BeatmapInfo beatmap, RulesetInfo ruleset, LeaderboardScope scope = LeaderboardScope.Global)
|
2017-03-15 13:06:05 +08:00
|
|
|
|
{
|
2017-09-15 11:44:48 +08:00
|
|
|
|
if (!beatmap.OnlineBeatmapID.HasValue)
|
|
|
|
|
throw new InvalidOperationException($"Cannot lookup a beatmap's scores without having a populated {nameof(BeatmapInfo.OnlineBeatmapID)}.");
|
|
|
|
|
|
2017-12-20 19:25:57 +08:00
|
|
|
|
if (scope == LeaderboardScope.Local)
|
|
|
|
|
throw new InvalidOperationException("Should not attempt to request online scores for a local scoped leaderboard");
|
|
|
|
|
|
2017-03-15 13:06:05 +08:00
|
|
|
|
this.beatmap = beatmap;
|
2017-11-20 13:06:26 +08:00
|
|
|
|
this.scope = scope;
|
2017-12-20 19:41:01 +08:00
|
|
|
|
this.ruleset = ruleset ?? throw new ArgumentNullException(nameof(ruleset));
|
2017-08-15 21:30:53 +08:00
|
|
|
|
|
|
|
|
|
Success += onSuccess;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void onSuccess(GetScoresResponse r)
|
|
|
|
|
{
|
2017-09-08 00:20:14 +08:00
|
|
|
|
foreach (OnlineScore score in r.Scores)
|
2017-09-08 18:17:16 +08:00
|
|
|
|
score.ApplyBeatmap(beatmap);
|
2017-03-15 13:06:05 +08:00
|
|
|
|
}
|
|
|
|
|
|
2017-11-22 12:26:01 +08:00
|
|
|
|
protected override WebRequest CreateWebRequest()
|
2017-11-20 13:06:26 +08:00
|
|
|
|
{
|
2017-11-22 12:26:01 +08:00
|
|
|
|
var req = base.CreateWebRequest();
|
|
|
|
|
|
2017-12-20 23:18:30 +08:00
|
|
|
|
req.Timeout = 30000;
|
2017-12-20 19:33:16 +08:00
|
|
|
|
req.AddParameter(@"type", scope.ToString().ToLowerInvariant());
|
2017-12-20 19:41:01 +08:00
|
|
|
|
req.AddParameter(@"mode", ruleset.ShortName);
|
2017-11-22 12:26:01 +08:00
|
|
|
|
|
|
|
|
|
return req;
|
2017-11-20 13:06:26 +08:00
|
|
|
|
}
|
|
|
|
|
|
2017-11-22 12:26:01 +08:00
|
|
|
|
protected override string Target => $@"beatmaps/{beatmap.OnlineBeatmapID}/scores";
|
2017-03-15 13:06:05 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class GetScoresResponse
|
|
|
|
|
{
|
|
|
|
|
[JsonProperty(@"scores")]
|
2017-09-08 00:20:14 +08:00
|
|
|
|
public IEnumerable<OnlineScore> Scores;
|
2017-03-15 13:06:05 +08:00
|
|
|
|
}
|
2017-09-08 18:21:35 +08:00
|
|
|
|
|
|
|
|
|
public class OnlineScore : Score
|
|
|
|
|
{
|
|
|
|
|
[JsonProperty(@"score")]
|
|
|
|
|
private double totalScore
|
|
|
|
|
{
|
|
|
|
|
set { TotalScore = value; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[JsonProperty(@"max_combo")]
|
|
|
|
|
private int maxCombo
|
|
|
|
|
{
|
|
|
|
|
set { MaxCombo = value; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[JsonProperty(@"user")]
|
|
|
|
|
private User user
|
|
|
|
|
{
|
|
|
|
|
set { User = value; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[JsonProperty(@"replay_data")]
|
|
|
|
|
private Replay replay
|
|
|
|
|
{
|
|
|
|
|
set { Replay = value; }
|
|
|
|
|
}
|
|
|
|
|
|
2017-09-14 19:05:43 +08:00
|
|
|
|
[JsonProperty(@"mode_int")]
|
|
|
|
|
public int OnlineRulesetID { get; set; }
|
|
|
|
|
|
2017-09-08 18:21:35 +08:00
|
|
|
|
[JsonProperty(@"score_id")]
|
|
|
|
|
private long onlineScoreID
|
|
|
|
|
{
|
|
|
|
|
set { OnlineScoreID = value; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[JsonProperty(@"created_at")]
|
|
|
|
|
private DateTimeOffset date
|
|
|
|
|
{
|
|
|
|
|
set { Date = value; }
|
|
|
|
|
}
|
|
|
|
|
|
2017-09-14 19:05:43 +08:00
|
|
|
|
[JsonProperty(@"beatmap")]
|
|
|
|
|
private BeatmapInfo beatmap
|
|
|
|
|
{
|
|
|
|
|
set { Beatmap = value; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[JsonProperty(@"beatmapset")]
|
|
|
|
|
private BeatmapMetadata metadata
|
|
|
|
|
{
|
|
|
|
|
set { Beatmap.Metadata = value; }
|
|
|
|
|
}
|
|
|
|
|
|
2017-09-08 18:21:35 +08:00
|
|
|
|
[JsonProperty(@"statistics")]
|
2017-09-28 00:08:42 +08:00
|
|
|
|
private Dictionary<string, object> jsonStats
|
2017-09-08 18:21:35 +08:00
|
|
|
|
{
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
foreach (var kvp in value)
|
|
|
|
|
{
|
2017-12-31 04:23:18 +08:00
|
|
|
|
HitResult newKey;
|
2017-12-31 01:07:30 +08:00
|
|
|
|
switch (kvp.Key)
|
2017-09-08 18:21:35 +08:00
|
|
|
|
{
|
|
|
|
|
case @"count_300":
|
2017-12-31 04:23:18 +08:00
|
|
|
|
newKey = HitResult.Great;
|
2017-09-08 18:21:35 +08:00
|
|
|
|
break;
|
|
|
|
|
case @"count_100":
|
2017-12-31 04:23:18 +08:00
|
|
|
|
newKey = HitResult.Good;
|
2017-09-08 18:21:35 +08:00
|
|
|
|
break;
|
|
|
|
|
case @"count_50":
|
2017-12-31 04:23:18 +08:00
|
|
|
|
newKey = HitResult.Meh;
|
2017-09-08 18:21:35 +08:00
|
|
|
|
break;
|
|
|
|
|
case @"count_miss":
|
2017-12-31 04:23:18 +08:00
|
|
|
|
newKey = HitResult.Miss;
|
2017-09-08 18:21:35 +08:00
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-31 01:07:30 +08:00
|
|
|
|
Statistics.Add(newKey, kvp.Value);
|
2017-09-08 18:21:35 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[JsonProperty(@"mods")]
|
|
|
|
|
private string[] modStrings { get; set; }
|
|
|
|
|
|
|
|
|
|
public void ApplyBeatmap(BeatmapInfo beatmap)
|
|
|
|
|
{
|
|
|
|
|
Beatmap = beatmap;
|
2017-09-14 19:05:43 +08:00
|
|
|
|
ApplyRuleset(beatmap.Ruleset);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void ApplyRuleset(RulesetInfo ruleset)
|
|
|
|
|
{
|
|
|
|
|
Ruleset = ruleset;
|
2017-09-08 18:21:35 +08:00
|
|
|
|
|
|
|
|
|
// Evaluate the mod string
|
|
|
|
|
Mods = Ruleset.CreateInstance().GetAllMods().Where(mod => modStrings.Contains(mod.ShortenedName)).ToArray();
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-09-08 00:20:14 +08:00
|
|
|
|
}
|