2020-05-26 17:12:19 +08: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 15:37:17 +08:00
#nullable disable
2020-05-26 17:12:19 +08:00
using System ;
using System.Collections.Generic ;
2020-05-28 18:57:58 +08:00
using System.Linq ;
2020-07-22 17:52:25 +08:00
using JetBrains.Annotations ;
2020-05-26 17:12:19 +08:00
using Newtonsoft.Json ;
using Newtonsoft.Json.Converters ;
2021-11-04 11:30:19 +08:00
using osu.Game.Beatmaps ;
2020-07-22 17:29:50 +08:00
using osu.Game.Online.API ;
2021-11-04 17:02:44 +08:00
using osu.Game.Online.API.Requests.Responses ;
2021-11-15 15:13:03 +08:00
using osu.Game.Rulesets ;
2020-05-28 19:07:51 +08:00
using osu.Game.Rulesets.Mods ;
2020-05-26 17:12:19 +08:00
using osu.Game.Rulesets.Scoring ;
using osu.Game.Scoring ;
2020-12-25 12:38:11 +08:00
namespace osu.Game.Online.Rooms
2020-05-26 17:12:19 +08:00
{
2020-07-22 17:37:00 +08:00
public class MultiplayerScore
2020-05-26 17:12:19 +08:00
{
[JsonProperty("id")]
2021-02-16 18:29:40 +08:00
public long ID { get ; set ; }
2020-05-26 17:12:19 +08:00
2020-05-28 18:58:07 +08:00
[JsonProperty("user")]
2021-11-04 17:02:44 +08:00
public APIUser User { get ; set ; }
2020-05-26 17:12:19 +08: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 > ( ) ;
2024-07-25 19:06:18 +08:00
[JsonProperty("maximum_statistics")]
public Dictionary < HitResult , int > MaximumStatistics = new Dictionary < HitResult , int > ( ) ;
2020-05-26 17:12:19 +08:00
[JsonProperty("passed")]
public bool Passed { get ; set ; }
[JsonProperty("ended_at")]
public DateTimeOffset EndedAt { get ; set ; }
2020-07-22 17:52:25 +08:00
/// <summary>
/// The position of this score, starting at 1.
/// </summary>
[JsonProperty("position")]
public int? Position { get ; set ; }
2024-07-25 19:06:18 +08:00
[JsonProperty("pp")]
public double? PP { get ; set ; }
2023-09-07 17:26:51 +08:00
[JsonProperty("has_replay")]
public bool HasReplay { get ; set ; }
2024-07-25 19:06:18 +08:00
[JsonProperty("ranked")]
public bool Ranked { get ; set ; }
2020-07-22 17:52:25 +08:00
/// <summary>
/// Any scores in the room around this score.
/// </summary>
[JsonProperty("scores_around")]
[CanBeNull]
public MultiplayerScoresAround ScoresAround { get ; set ; }
2022-10-14 17:01:54 +08:00
public ScoreInfo CreateScoreInfo ( ScoreManager scoreManager , RulesetStore rulesets , PlaylistItem playlistItem , [ NotNull ] BeatmapInfo beatmap )
2020-05-26 17:12:19 +08:00
{
2022-02-15 15:01:14 +08: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 19:07:51 +08:00
2020-05-26 17:12:19 +08:00
var scoreInfo = new ScoreInfo
{
2023-10-16 18:00:33 +08:00
OnlineID = ID ,
2020-05-26 17:12:19 +08:00
TotalScore = TotalScore ,
MaxCombo = MaxCombo ,
2021-11-04 11:30:19 +08:00
BeatmapInfo = beatmap ,
2022-06-28 00:34:24 +08:00
Ruleset = rulesets . GetRuleset ( playlistItem . RulesetID ) ? ? throw new InvalidOperationException ( $"Ruleset with ID of {playlistItem.RulesetID} not found locally" ) ,
2024-07-25 19:06:18 +08:00
Passed = Passed ,
2020-05-28 19:07:54 +08:00
Statistics = Statistics ,
2024-07-25 19:06:18 +08:00
MaximumStatistics = MaximumStatistics ,
2020-05-28 18:58:07 +08:00
User = User ,
2020-05-26 17:12:19 +08:00
Accuracy = Accuracy ,
Date = EndedAt ,
2023-09-07 17:26:51 +08:00
HasOnlineReplay = HasReplay ,
2020-05-26 17:12:19 +08:00
Rank = Rank ,
2020-07-28 21:08:10 +08:00
Mods = Mods ? . Select ( m = > m . ToMod ( rulesetInstance ) ) . ToArray ( ) ? ? Array . Empty < Mod > ( ) ,
2024-07-25 19:06:18 +08:00
PP = PP ,
Ranked = Ranked ,
2020-07-28 21:08:10 +08:00
Position = Position ,
2020-05-26 17:12:19 +08:00
} ;
2022-10-14 17:01:54 +08:00
scoreManager . PopulateMaximumStatistics ( scoreInfo ) ;
2020-05-26 17:12:19 +08:00
return scoreInfo ;
}
}
}