2021-03-23 14:33:31 +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.
|
|
|
|
|
2021-08-24 13:25:29 +08:00
|
|
|
using System.Diagnostics;
|
2024-02-10 16:20:17 +08:00
|
|
|
using osu.Game.Extensions;
|
2021-03-23 14:33:31 +08:00
|
|
|
using osu.Game.Online.API;
|
|
|
|
using osu.Game.Online.Rooms;
|
|
|
|
using osu.Game.Scoring;
|
|
|
|
|
|
|
|
namespace osu.Game.Screens.Play
|
|
|
|
{
|
|
|
|
/// <summary>
|
|
|
|
/// A player instance which submits to a room backing. This is generally used by playlists and multiplayer.
|
|
|
|
/// </summary>
|
|
|
|
public abstract partial class RoomSubmittingPlayer : SubmittingPlayer
|
|
|
|
{
|
|
|
|
protected readonly PlaylistItem PlaylistItem;
|
2021-08-24 12:22:06 +08:00
|
|
|
protected readonly Room Room;
|
2021-03-23 14:33:31 +08:00
|
|
|
|
2024-11-13 15:28:39 +08:00
|
|
|
protected RoomSubmittingPlayer(Room room, PlaylistItem playlistItem, PlayerConfiguration? configuration = null)
|
2021-03-23 14:33:31 +08:00
|
|
|
: base(configuration)
|
|
|
|
{
|
2021-08-24 12:22:06 +08:00
|
|
|
Room = room;
|
2021-03-23 14:33:31 +08:00
|
|
|
PlaylistItem = playlistItem;
|
|
|
|
}
|
|
|
|
|
2024-11-13 15:28:39 +08:00
|
|
|
protected override APIRequest<APIScoreToken>? CreateTokenRequest()
|
2021-03-24 12:23:23 +08:00
|
|
|
{
|
2024-11-13 15:28:39 +08:00
|
|
|
if (Room.RoomID is not long roomId)
|
2021-03-24 12:23:23 +08:00
|
|
|
return null;
|
|
|
|
|
2024-02-10 16:20:17 +08:00
|
|
|
int beatmapId = Beatmap.Value.BeatmapInfo.OnlineID;
|
|
|
|
int rulesetId = Ruleset.Value.OnlineID;
|
|
|
|
|
|
|
|
if (beatmapId <= 0)
|
|
|
|
return null;
|
|
|
|
|
|
|
|
if (!Ruleset.Value.IsLegacyRuleset())
|
|
|
|
return null;
|
|
|
|
|
|
|
|
return new CreateRoomScoreRequest(roomId, PlaylistItem.ID, Beatmap.Value.BeatmapInfo, rulesetId, Game.VersionHash);
|
2021-03-24 12:23:23 +08:00
|
|
|
}
|
2021-03-23 14:33:31 +08:00
|
|
|
|
2021-08-24 13:25:29 +08:00
|
|
|
protected override APIRequest<MultiplayerScore> CreateSubmissionRequest(Score score, long token)
|
|
|
|
{
|
2024-11-13 15:28:39 +08:00
|
|
|
Debug.Assert(Room.RoomID != null);
|
|
|
|
return new SubmitRoomScoreRequest(score.ScoreInfo, token, Room.RoomID.Value, PlaylistItem.ID);
|
2021-08-24 13:25:29 +08:00
|
|
|
}
|
2021-03-23 14:33:31 +08:00
|
|
|
}
|
|
|
|
}
|