2020-05-26 09:12:19 +00:00
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
2022-06-17 07:37:17 +00:00
#nullable disable
2020-05-26 09:12:19 +00:00
using System ;
using System.Collections.Generic ;
2020-05-28 10:57:58 +00:00
using System.Linq ;
2020-07-22 09:52:25 +00:00
using JetBrains.Annotations ;
2020-05-26 09:12:19 +00:00
using Newtonsoft.Json ;
using Newtonsoft.Json.Converters ;
2021-11-04 03:30:19 +00:00
using osu.Game.Beatmaps ;
2020-07-22 09:29:50 +00:00
using osu.Game.Online.API ;
2021-11-04 09:02:44 +00:00
using osu.Game.Online.API.Requests.Responses ;
2021-11-15 07:13:03 +00:00
using osu.Game.Rulesets ;
2020-05-28 11:07:51 +00:00
using osu.Game.Rulesets.Mods ;
2020-05-26 09:12:19 +00:00
using osu.Game.Rulesets.Scoring ;
using osu.Game.Scoring ;
2020-12-25 04:38:11 +00:00
namespace osu.Game.Online.Rooms
2020-05-26 09:12:19 +00:00
{
2020-07-22 09:37:00 +00:00
public class MultiplayerScore
2020-05-26 09:12:19 +00:00
{
[JsonProperty("id")]
2021-02-16 10:29:40 +00:00
public long ID { get ; set ; }
2020-05-26 09:12:19 +00:00
2020-05-28 10:58:07 +00:00
[JsonProperty("user")]
2021-11-04 09:02:44 +00:00
public APIUser User { get ; set ; }
2020-05-26 09:12:19 +00:00
[JsonProperty("rank")]
[JsonConverter(typeof(StringEnumConverter))]
public ScoreRank Rank { get ; set ; }
[JsonProperty("total_score")]
public long TotalScore { get ; set ; }
[JsonProperty("accuracy")]
public double Accuracy { get ; set ; }
[JsonProperty("max_combo")]
public int MaxCombo { get ; set ; }
[JsonProperty("mods")]
public APIMod [ ] Mods { get ; set ; }
[JsonProperty("statistics")]
public Dictionary < HitResult , int > Statistics = new Dictionary < HitResult , int > ( ) ;
[JsonProperty("passed")]
public bool Passed { get ; set ; }
[JsonProperty("ended_at")]
public DateTimeOffset EndedAt { get ; set ; }
2020-07-22 09:52:25 +00:00
/// <summary>
/// The position of this score, starting at 1.
/// </summary>
[JsonProperty("position")]
public int? Position { get ; set ; }
/// <summary>
/// Any scores in the room around this score.
/// </summary>
[JsonProperty("scores_around")]
[CanBeNull]
public MultiplayerScoresAround ScoresAround { get ; set ; }
2022-10-14 09:01:54 +00:00
public ScoreInfo CreateScoreInfo ( ScoreManager scoreManager , RulesetStore rulesets , PlaylistItem playlistItem , [ NotNull ] BeatmapInfo beatmap )
2020-05-26 09:12:19 +00:00
{
2022-02-15 07:01:14 +00:00
var ruleset = rulesets . GetRuleset ( playlistItem . RulesetID ) ;
if ( ruleset = = null )
throw new InvalidOperationException ( $"Couldn't create score with unknown ruleset: {playlistItem.RulesetID}" ) ;
var rulesetInstance = ruleset . CreateInstance ( ) ;
2020-05-28 11:07:51 +00:00
2020-05-26 09:12:19 +00:00
var scoreInfo = new ScoreInfo
{
2021-12-10 06:37:12 +00:00
OnlineID = ID ,
2020-05-26 09:12:19 +00:00
TotalScore = TotalScore ,
MaxCombo = MaxCombo ,
2021-11-04 03:30:19 +00:00
BeatmapInfo = beatmap ,
2022-06-27 16:34:24 +00:00
Ruleset = rulesets . GetRuleset ( playlistItem . RulesetID ) ? ? throw new InvalidOperationException ( $"Ruleset with ID of {playlistItem.RulesetID} not found locally" ) ,
2020-05-28 11:07:54 +00:00
Statistics = Statistics ,
2020-05-28 10:58:07 +00:00
User = User ,
2020-05-26 09:12:19 +00:00
Accuracy = Accuracy ,
Date = EndedAt ,
Hash = string . Empty , // todo: temporary?
Rank = Rank ,
2020-07-28 13:08:10 +00:00
Mods = Mods ? . Select ( m = > m . ToMod ( rulesetInstance ) ) . ToArray ( ) ? ? Array . Empty < Mod > ( ) ,
Position = Position ,
2020-05-26 09:12:19 +00:00
} ;
2022-10-14 09:01:54 +00:00
scoreManager . PopulateMaximumStatistics ( scoreInfo ) ;
2020-05-26 09:12:19 +00:00
return scoreInfo ;
}
}
}