osu/osu.Game/Online/Rooms/MultiplayerScore.cs

91 lines
2.8 KiB
C#
Raw Normal View History

// 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.
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;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using osu.Game.Beatmaps;
using osu.Game.Online.API;
using osu.Game.Online.API.Requests.Responses;
using osu.Game.Rulesets;
2020-05-28 11:07:51 +00:00
using osu.Game.Rulesets.Mods;
using osu.Game.Rulesets.Scoring;
using osu.Game.Scoring;
2020-12-25 04:38:11 +00:00
namespace osu.Game.Online.Rooms
{
2020-07-22 09:37:00 +00:00
public class MultiplayerScore
{
[JsonProperty("id")]
public long ID { get; set; }
2020-05-28 10:58:07 +00:00
[JsonProperty("user")]
public APIUser User { get; set; }
[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; }
public ScoreInfo CreateScoreInfo(RulesetStore rulesets, PlaylistItem playlistItem, [NotNull] BeatmapInfo beatmap)
{
2020-05-28 11:07:51 +00:00
var rulesetInstance = playlistItem.Ruleset.Value.CreateInstance();
var scoreInfo = new ScoreInfo
{
2021-12-10 06:37:12 +00:00
OnlineID = ID,
TotalScore = TotalScore,
MaxCombo = MaxCombo,
BeatmapInfo = beatmap,
2022-01-12 13:34:07 +00:00
Ruleset = rulesets.GetRuleset(playlistItem.RulesetID) ?? throw new InvalidOperationException(),
2020-05-28 11:07:54 +00:00
Statistics = Statistics,
2020-05-28 10:58:07 +00:00
User = User,
Accuracy = Accuracy,
Date = EndedAt,
Hash = string.Empty, // todo: temporary?
Rank = Rank,
Mods = Mods?.Select(m => m.ToMod(rulesetInstance)).ToArray() ?? Array.Empty<Mod>(),
Position = Position,
};
return scoreInfo;
}
}
}