1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-07 13:07:25 +08:00
osu-lazer/osu.Game/Screens/Multi/Play/TimeshiftPlayer.cs

85 lines
2.3 KiB
C#
Raw Normal View History

// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
2018-12-27 20:12:32 +08:00
using System;
using System.Diagnostics;
using System.Threading;
2018-12-14 20:09:17 +08:00
using osu.Framework.Allocation;
using osu.Framework.Logging;
2018-12-14 20:09:17 +08:00
using osu.Game.Online.API;
using osu.Game.Online.API.Requests;
2018-12-21 17:22:13 +08:00
using osu.Game.Online.Multiplayer;
2018-12-14 20:09:17 +08:00
using osu.Game.Scoring;
2018-12-21 17:22:13 +08:00
using osu.Game.Screens.Multi.Ranking;
using osu.Game.Screens.Play;
2018-12-21 17:22:13 +08:00
using osu.Game.Screens.Ranking;
namespace osu.Game.Screens.Multi.Play
{
public class TimeshiftPlayer : Player
{
2018-12-21 17:22:13 +08:00
private readonly Room room;
2018-12-14 20:09:17 +08:00
private readonly int playlistItemId;
[Resolved]
private APIAccess api { get; set; }
2018-12-21 17:22:13 +08:00
public TimeshiftPlayer(Room room, int playlistItemId)
2018-12-14 20:09:17 +08:00
{
2018-12-21 17:22:13 +08:00
this.room = room;
2018-12-14 20:09:17 +08:00
this.playlistItemId = playlistItemId;
}
private int? token;
2018-12-14 20:09:17 +08:00
[BackgroundDependencyLoader]
private void load()
{
token = null;
bool failed = false;
var req = new CreateRoomScoreRequest(room.RoomID.Value ?? 0, playlistItemId);
2018-12-14 20:09:17 +08:00
req.Success += r => token = r.ID;
req.Failure += e =>
{
failed = true;
Logger.Error(e, "Failed to retrieve a score submission token.");
Schedule(() =>
{
ValidForResume = false;
Exit();
});
};
2018-12-14 20:09:17 +08:00
api.Queue(req);
while (!failed && !token.HasValue)
Thread.Sleep(1000);
2018-12-14 20:09:17 +08:00
}
protected override ScoreInfo CreateScore()
2018-12-27 20:12:32 +08:00
{
submitScore();
return base.CreateScore();
}
private void submitScore()
2018-12-14 20:09:17 +08:00
{
var score = base.CreateScore();
2018-12-27 20:12:32 +08:00
score.TotalScore = (int)Math.Round(ScoreProcessor.GetStandardisedScore());
Debug.Assert(token != null);
var request = new SubmitRoomScoreRequest(token.Value, room.RoomID.Value ?? 0, playlistItemId, score);
request.Failure += e => Logger.Error(e, "Failed to submit score");
2018-12-14 20:09:17 +08:00
api.Queue(request);
}
2018-12-21 17:22:13 +08:00
2018-12-26 19:05:57 +08:00
protected override Results CreateResults(ScoreInfo score) => new MatchResults(score, room);
2018-12-14 20:09:17 +08:00
}
}