From 5a5daa181cd5ccd77c312c99c390d2be1f7666b0 Mon Sep 17 00:00:00 2001 From: milimoe <110188673+milimoe@users.noreply.github.com> Date: Sun, 19 Nov 2023 15:02:08 +0800 Subject: [PATCH] optimize roomlist --- Model/RoomList.cs | 54 +++++++++++++++++++++++------------------------ 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/Model/RoomList.cs b/Model/RoomList.cs index 17caf3f..d2849cd 100644 --- a/Model/RoomList.cs +++ b/Model/RoomList.cs @@ -10,13 +10,23 @@ namespace Milimoe.FunGame.Core.Model private readonly Dictionary> _PlayerList = new(); private readonly Dictionary> _ReadyPlayerList = new(); + public Room this[string RoomID] => GetRoom(RoomID); + public int Count => _List.Count; + public int GetPlayerCount(string RoomID) => GetPlayerList(RoomID).Count; + + public int GetReadyPlayerCount(string RoomID) => GetReadyPlayerList(RoomID).Count; + public List ListRoom => _List.Values.ToList(); public List ListRoomID => _List.Keys.ToList(); - public Room this[string RoomID] => GetRoom(RoomID); + public List GetPlayerList(string RoomID) => _PlayerList.ContainsKey(RoomID) ? _PlayerList[RoomID] : new(); + + public List GetReadyPlayerList(string RoomID) => _ReadyPlayerList.ContainsKey(RoomID) ? _ReadyPlayerList[RoomID] : new(); + + public List GetNotReadyPlayerList(string RoomID) => _PlayerList.ContainsKey(RoomID) ? _PlayerList[RoomID].Except(GetReadyPlayerList(RoomID)).ToList() : new(); public void Clear() { @@ -57,28 +67,6 @@ namespace Milimoe.FunGame.Core.Model } } - public List GetReadyPlayerList(string RoomID) => _ReadyPlayerList.ContainsKey(RoomID) ? _ReadyPlayerList[RoomID] : new(); - - public int GetReadyPlayerCount(string RoomID) => GetReadyPlayerList(RoomID).Count; - - public List 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 CancelReady(string RoomID, User User) - { - if (RoomID != "-1" && _ReadyPlayerList.ContainsKey(RoomID) && User.Id != 0) - { - _ReadyPlayerList[RoomID].Remove(User); - } - } - public void QuitRoom(string RoomID, User User) { if (RoomID != "-1" && User.Id != 0) @@ -87,6 +75,22 @@ namespace Milimoe.FunGame.Core.Model } } + public void SetReady(string RoomID, User User) + { + if (RoomID != "-1" && User.Id != 0) + { + GetReadyPlayerList(RoomID).Add(User); + } + } + + public void CancelReady(string RoomID, User User) + { + if (RoomID != "-1" && User.Id != 0) + { + GetReadyPlayerList(RoomID).Remove(User); + } + } + public Room GetRoom(string RoomID) => _List.ContainsKey(RoomID) ? _List[RoomID] : General.HallInstance; public bool IsExist(string RoomID) => _List.ContainsKey(RoomID); @@ -108,10 +112,6 @@ namespace Milimoe.FunGame.Core.Model } } - public List GetPlayerList(string RoomID) => _PlayerList.ContainsKey(RoomID) ? _PlayerList[RoomID] : new(); - - public int GetPlayerCount(string RoomID) => GetPlayerList(RoomID).Count; - public IEnumerator GetEnumerator() { foreach (Room room in ListRoom)