2020-12-07 18:50:02 +09: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.
|
|
|
|
|
2020-12-08 14:33:47 +09:00
|
|
|
using System;
|
2021-02-01 17:54:56 +09:00
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Linq;
|
2021-01-26 16:26:03 +09:00
|
|
|
using MessagePack;
|
2020-12-09 15:05:57 +09:00
|
|
|
using Newtonsoft.Json;
|
2021-02-01 17:54:56 +09:00
|
|
|
using osu.Game.Online.API;
|
2021-11-04 18:02:44 +09:00
|
|
|
using osu.Game.Online.API.Requests.Responses;
|
2021-01-03 04:25:06 +03:00
|
|
|
using osu.Game.Online.Rooms;
|
2020-12-07 18:50:02 +09:00
|
|
|
|
2020-12-25 13:38:11 +09:00
|
|
|
namespace osu.Game.Online.Multiplayer
|
2020-12-07 18:50:02 +09:00
|
|
|
{
|
2020-12-08 16:15:51 +09:00
|
|
|
[Serializable]
|
2021-01-26 16:26:03 +09:00
|
|
|
[MessagePackObject]
|
2020-12-08 14:33:47 +09:00
|
|
|
public class MultiplayerRoomUser : IEquatable<MultiplayerRoomUser>
|
2020-12-07 18:50:02 +09:00
|
|
|
{
|
2021-01-26 16:26:03 +09:00
|
|
|
[Key(0)]
|
2020-12-09 12:10:47 +09:00
|
|
|
public readonly int UserID;
|
2020-12-08 16:15:51 +09:00
|
|
|
|
2021-01-26 16:26:03 +09:00
|
|
|
[Key(1)]
|
2020-12-08 16:15:51 +09:00
|
|
|
public MultiplayerUserState State { get; set; } = MultiplayerUserState.Idle;
|
|
|
|
|
2021-08-03 15:09:03 +09:00
|
|
|
[Key(4)]
|
2021-08-03 15:43:04 +09:00
|
|
|
public MatchUserState? MatchState { get; set; }
|
2021-08-03 15:09:03 +09:00
|
|
|
|
2021-01-03 04:25:06 +03:00
|
|
|
/// <summary>
|
2021-01-11 20:28:24 +01:00
|
|
|
/// The availability state of the current beatmap.
|
2021-01-03 04:25:06 +03:00
|
|
|
/// </summary>
|
2021-01-26 16:26:03 +09:00
|
|
|
[Key(2)]
|
2021-01-03 18:34:11 +03:00
|
|
|
public BeatmapAvailability BeatmapAvailability { get; set; } = BeatmapAvailability.LocallyAvailable();
|
2021-01-03 04:25:06 +03:00
|
|
|
|
2021-02-01 18:50:32 +09:00
|
|
|
/// <summary>
|
|
|
|
/// Any mods applicable only to the local user.
|
|
|
|
/// </summary>
|
2021-02-01 19:28:10 +09:00
|
|
|
[Key(3)]
|
2021-02-05 12:40:16 +09:00
|
|
|
public IEnumerable<APIMod> Mods { get; set; } = Enumerable.Empty<APIMod>();
|
2021-02-01 17:54:56 +09:00
|
|
|
|
2021-01-26 16:26:03 +09:00
|
|
|
[IgnoreMember]
|
2021-11-04 18:02:44 +09:00
|
|
|
public APIUser? User { get; set; }
|
2020-12-08 16:15:51 +09:00
|
|
|
|
2020-12-09 15:05:57 +09:00
|
|
|
[JsonConstructor]
|
2021-01-26 16:26:03 +09:00
|
|
|
public MultiplayerRoomUser(int userId)
|
2020-12-07 18:50:02 +09:00
|
|
|
{
|
|
|
|
UserID = userId;
|
|
|
|
}
|
|
|
|
|
2021-11-16 15:44:47 +09:00
|
|
|
public bool Equals(MultiplayerRoomUser? other)
|
2020-12-08 14:33:47 +09:00
|
|
|
{
|
|
|
|
if (ReferenceEquals(this, other)) return true;
|
2021-11-16 15:44:47 +09:00
|
|
|
if (other == null) return false;
|
2020-12-08 14:33:47 +09:00
|
|
|
|
|
|
|
return UserID == other.UserID;
|
|
|
|
}
|
|
|
|
|
2022-12-16 18:16:26 +09:00
|
|
|
public override bool Equals(object? obj)
|
2020-12-08 14:33:47 +09:00
|
|
|
{
|
|
|
|
if (ReferenceEquals(this, obj)) return true;
|
2022-12-16 18:16:26 +09:00
|
|
|
if (obj?.GetType() != GetType()) return false;
|
2020-12-08 14:33:47 +09:00
|
|
|
|
|
|
|
return Equals((MultiplayerRoomUser)obj);
|
|
|
|
}
|
|
|
|
|
|
|
|
public override int GetHashCode() => UserID.GetHashCode();
|
2022-04-21 22:35:07 +09:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Whether this user has finished loading and can start gameplay.
|
|
|
|
/// </summary>
|
|
|
|
public bool CanStartGameplay()
|
|
|
|
{
|
|
|
|
switch (State)
|
|
|
|
{
|
|
|
|
case MultiplayerUserState.Loaded:
|
|
|
|
case MultiplayerUserState.ReadyForGameplay:
|
|
|
|
return true;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2020-12-07 18:50:02 +09:00
|
|
|
}
|
|
|
|
}
|