mirror of
https://github.com/project-redbud/FunGame-Core.git
synced 2025-12-05 08:09:02 +00:00
优化roomlist
This commit is contained in:
parent
22371d431c
commit
8938581805
@ -6,27 +6,27 @@ namespace Milimoe.FunGame.Core.Model
|
||||
{
|
||||
public class RoomList : IEnumerable<Room>
|
||||
{
|
||||
private readonly Dictionary<string, Room> _List = new();
|
||||
private readonly Dictionary<string, List<User>> _PlayerList = new();
|
||||
private readonly Dictionary<string, List<User>> _ReadyPlayerList = new();
|
||||
private readonly Dictionary<string, Room> _List = [];
|
||||
private readonly Dictionary<string, List<User>> _PlayerList = [];
|
||||
private readonly Dictionary<string, List<User>> _ReadyPlayerList = [];
|
||||
|
||||
public Room this[string RoomID] => GetRoom(RoomID);
|
||||
public Room this[string roomid] => GetRoom(roomid);
|
||||
|
||||
public int Count => _List.Count;
|
||||
|
||||
public int GetPlayerCount(string RoomID) => GetPlayerList(RoomID).Count;
|
||||
public int GetPlayerCount(string roomid) => GetPlayerList(roomid).Count;
|
||||
|
||||
public int GetReadyPlayerCount(string RoomID) => GetReadyPlayerList(RoomID).Count;
|
||||
public int GetReadyPlayerCount(string roomid) => GetReadyPlayerList(roomid).Count;
|
||||
|
||||
public List<Room> ListRoom => _List.Values.ToList();
|
||||
|
||||
public List<string> ListRoomID => _List.Keys.ToList();
|
||||
|
||||
public List<User> GetPlayerList(string RoomID) => _PlayerList.ContainsKey(RoomID) ? _PlayerList[RoomID] : new();
|
||||
public List<User> GetPlayerList(string roomid) => _PlayerList.TryGetValue(roomid, out List<User>? user) ? user : [];
|
||||
|
||||
public List<User> GetReadyPlayerList(string RoomID) => _ReadyPlayerList.ContainsKey(RoomID) ? _ReadyPlayerList[RoomID] : new();
|
||||
public List<User> GetReadyPlayerList(string roomid) => _ReadyPlayerList.TryGetValue(roomid, out List<User>? user) ? user : [];
|
||||
|
||||
public List<User> GetNotReadyPlayerList(string RoomID) => _PlayerList.ContainsKey(RoomID) ? _PlayerList[RoomID].Except(GetReadyPlayerList(RoomID)).ToList() : new();
|
||||
public List<User> GetNotReadyPlayerList(string roomid) => _PlayerList.TryGetValue(roomid, out List<User>? user) ? user.Except(GetReadyPlayerList(roomid)).Except([this[roomid].RoomMaster]).ToList() : [];
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
@ -35,80 +35,80 @@ namespace Milimoe.FunGame.Core.Model
|
||||
_ReadyPlayerList.Clear();
|
||||
}
|
||||
|
||||
public void AddRoom(Room Room)
|
||||
public void AddRoom(Room room)
|
||||
{
|
||||
_List.Add(Room.Roomid, Room);
|
||||
_PlayerList.Add(Room.Roomid, new());
|
||||
_ReadyPlayerList.Add(Room.Roomid, new());
|
||||
_List.Add(room.Roomid, room);
|
||||
_PlayerList.Add(room.Roomid, []);
|
||||
_ReadyPlayerList.Add(room.Roomid, []);
|
||||
}
|
||||
|
||||
public void AddRooms(List<Room> Rooms)
|
||||
public void AddRooms(List<Room> rooms)
|
||||
{
|
||||
foreach (Room Room in Rooms)
|
||||
foreach (Room room in rooms)
|
||||
{
|
||||
AddRoom(Room);
|
||||
AddRoom(room);
|
||||
}
|
||||
}
|
||||
|
||||
public void RemoveRoom(string RoomID)
|
||||
public void RemoveRoom(string roomid)
|
||||
{
|
||||
_List.Remove(RoomID);
|
||||
_PlayerList.Remove(RoomID);
|
||||
_ReadyPlayerList.Remove(RoomID);
|
||||
_List.Remove(roomid);
|
||||
_PlayerList.Remove(roomid);
|
||||
_ReadyPlayerList.Remove(roomid);
|
||||
}
|
||||
|
||||
public void RemoveRoom(Room Room) => RemoveRoom(Room.Roomid);
|
||||
public void RemoveRoom(Room room) => RemoveRoom(room.Roomid);
|
||||
|
||||
public void IntoRoom(string RoomID, User User)
|
||||
public void IntoRoom(string roomid, User user)
|
||||
{
|
||||
if (RoomID != "-1" && User.Id != 0)
|
||||
if (roomid != "-1" && user.Id != 0)
|
||||
{
|
||||
GetPlayerList(RoomID).Add(User);
|
||||
GetPlayerList(roomid).Add(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)
|
||||
{
|
||||
GetPlayerList(RoomID).Remove(User);
|
||||
GetPlayerList(roomid).Remove(user);
|
||||
}
|
||||
}
|
||||
|
||||
public void SetReady(string RoomID, User User)
|
||||
public void SetReady(string roomid, User user)
|
||||
{
|
||||
if (RoomID != "-1" && User.Id != 0)
|
||||
if (roomid != "-1" && user.Id != 0)
|
||||
{
|
||||
GetReadyPlayerList(RoomID).Add(User);
|
||||
GetReadyPlayerList(roomid).Add(user);
|
||||
}
|
||||
}
|
||||
|
||||
public void CancelReady(string RoomID, User User)
|
||||
public void CancelReady(string roomid, User user)
|
||||
{
|
||||
if (RoomID != "-1" && User.Id != 0)
|
||||
if (roomid != "-1" && user.Id != 0)
|
||||
{
|
||||
GetReadyPlayerList(RoomID).Remove(User);
|
||||
GetReadyPlayerList(roomid).Remove(user);
|
||||
}
|
||||
}
|
||||
|
||||
public Room GetRoom(string RoomID) => _List.ContainsKey(RoomID) ? _List[RoomID] : General.HallInstance;
|
||||
public Room GetRoom(string roomid) => _List.TryGetValue(roomid, out Room? room) ? room : General.HallInstance;
|
||||
|
||||
public bool IsExist(string RoomID) => _List.ContainsKey(RoomID);
|
||||
public bool IsExist(string roomid) => _List.ContainsKey(roomid);
|
||||
|
||||
public User GetRoomMaster(string RoomID)
|
||||
public User GetRoomMaster(string roomid)
|
||||
{
|
||||
foreach (Room room in ListRoom.Where(r => r.Roomid == RoomID && r.RoomMaster != null))
|
||||
foreach (Room room in ListRoom.Where(r => r.Roomid == roomid && r.RoomMaster != null))
|
||||
{
|
||||
return room.RoomMaster;
|
||||
}
|
||||
return General.UnknownUserInstance;
|
||||
}
|
||||
|
||||
public void SetRoomMaster(string RoomID, User User)
|
||||
public void SetRoomMaster(string roomid, User user)
|
||||
{
|
||||
if (RoomID != "-1" && User.Id != 0)
|
||||
if (roomid != "-1" && user.Id != 0)
|
||||
{
|
||||
this[RoomID].RoomMaster = User;
|
||||
this[roomid].RoomMaster = user;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user