1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-15 05:42:56 +08:00
osu-lazer/osu.Game/Online/Multiplayer/MultiplayerRoomUser.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

84 lines
2.3 KiB
C#
Raw Normal View History

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