添加用于玩家在房间中准备的方法组

This commit is contained in:
milimoe 2023-11-15 20:24:37 +08:00
parent 08670173eb
commit bde93c9833
Signed by: milimoe
GPG Key ID: 05D280912DA6C69E
2 changed files with 25 additions and 2 deletions

View File

@ -9,13 +9,12 @@ namespace Milimoe.FunGame.Core.Entity
public override long Id { get => base.Id ; set => base.Id = value; } public override long Id { get => base.Id ; set => base.Id = value; }
public string Roomid { get; set; } = "-1"; public string Roomid { get; set; } = "-1";
public DateTime CreateTime { get; set; } = General.DefaultTime; public DateTime CreateTime { get; set; } = General.DefaultTime;
public Dictionary<string, User> Players { get; set; } = new();
public User RoomMaster { get; set; } = General.UnknownUserInstance; public User RoomMaster { get; set; } = General.UnknownUserInstance;
public RoomType RoomType { get; set; } public RoomType RoomType { get; set; }
public RoomState RoomState { get; set; } public RoomState RoomState { get; set; }
public bool HasPass => Password.Trim() != ""; public bool HasPass => Password.Trim() != "";
public string Password { get; set; } = ""; public string Password { get; set; } = "";
public GameStatistics? Statistics { get; set; } = null; public GameStatistics Statistics { get; set; } = new();
internal Room() internal Room()
{ {

View File

@ -8,6 +8,7 @@ namespace Milimoe.FunGame.Core.Model
{ {
private readonly Dictionary<string, Room> _List = new(); private readonly Dictionary<string, Room> _List = new();
private readonly Dictionary<string, List<User>> _PlayerList = new(); private readonly Dictionary<string, List<User>> _PlayerList = new();
private readonly Dictionary<string, List<User>> _ReadyPlayerList = new();
public int Count => _List.Count; public int Count => _List.Count;
@ -21,6 +22,7 @@ namespace Milimoe.FunGame.Core.Model
{ {
_List.Clear(); _List.Clear();
_PlayerList.Clear(); _PlayerList.Clear();
_ReadyPlayerList.Clear();
} }
public void AddRoom(Room Room) public void AddRoom(Room Room)
@ -53,6 +55,28 @@ namespace Milimoe.FunGame.Core.Model
} }
} }
public List<User> GetReadyPlayerList(string RoomID) => _ReadyPlayerList.ContainsKey(RoomID) ? _ReadyPlayerList[RoomID] : new();
public int GetReadyPlayerCount(string RoomID) => GetReadyPlayerList(RoomID).Count;
public List<User> GetNotReadyPlayerList(string RoomID) => _PlayerList.ContainsKey(RoomID) ? _PlayerList[RoomID].Except(GetReadyPlayerList(RoomID)).ToList() : new();
public void SetReady(string RoomID, User User)
{
if (RoomID != "-1" && _ReadyPlayerList.ContainsKey(RoomID) && User.Id != 0)
{
_ReadyPlayerList[RoomID].Add(User);
}
}
public void SetNotReady(string RoomID, User User)
{
if (RoomID != "-1" && _ReadyPlayerList.ContainsKey(RoomID) && User.Id != 0)
{
_ReadyPlayerList[RoomID].Remove(User);
}
}
public void QuitRoom(string RoomID, User User) public void QuitRoom(string RoomID, User User)
{ {
if (RoomID != "-1" && User.Id != 0) if (RoomID != "-1" && User.Id != 0)